:root {
  color-scheme: light;
  --black: #070708;
  --rail: #1b1c1f;
  --groove: #2d3035;
  --pink: #f08ca3;
  --pink-dark: #dc6f89;
  --white: #f3f0e6;
  --white-dark: #d8d2c2;
  --table: #eef2f4;
  --ink: #1b1b1d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  background:
    radial-gradient(circle at 22% 10%, rgba(255, 255, 255, 0.9), transparent 30rem),
    linear-gradient(135deg, #f7f8fa, #e6ebef);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.game-shell {
  width: min(1280px, 100%);
  height: 100vh;
  margin: 0 auto;
  padding: 8px 14px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.board-stage {
  position: relative;
  min-width: 0;
  display: grid;
  place-items: center;
}

.board {
  width: min(calc(100vh - 310px), 660px, 94vw);
  aspect-ratio: 13 / 12;
  filter: drop-shadow(0 26px 36px rgba(22, 18, 12, 0.25));
  touch-action: none;
}

.win-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 12;
  transform: translate(-50%, -50%) rotate(-2deg);
  width: min(48%, 390px);
  padding: 12px 18px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: rgba(7, 7, 8, 0.86);
  color: #fffdf5;
  box-shadow: 0 20px 36px rgba(0, 0, 0, 0.34);
  font-size: clamp(28px, 4.8vw, 56px);
  font-weight: 950;
  line-height: 0.95;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}

.confetti-piece {
  position: fixed;
  top: -18px;
  z-index: 60;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  pointer-events: none;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, -24px, 0) rotate(0deg);
    opacity: 1;
  }

  100% {
    transform: translate3d(var(--drift), calc(100vh + 42px), 0) rotate(var(--spin));
    opacity: 0.96;
  }
}

.board-base {
  fill: var(--black);
  stroke: #121316;
  stroke-width: 4;
}

.track-hole {
  fill: #030304;
  stroke: #454950;
  stroke-width: 1.25;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.18));
}

.track-hole.available {
  stroke: #d4d9de;
  stroke-width: 4;
}

.holding-hole {
  fill: #030304;
  stroke: #e5e9eb;
  stroke-width: 1.25;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.2));
}

.holding-hole.available {
  stroke: #ffffff;
  stroke-width: 4;
}

.track-marker {
  fill: #e5e9eb;
  opacity: 0.95;
}

.track-reference-line {
  fill: #f4f6f5;
  stroke: #9aa1a6;
  stroke-width: 1.6;
  opacity: 0.98;
}

.track-reference-line.mile-45 {
  fill: #d9dee1;
  stroke: #eef2f2;
}

.slot {
  fill: #24262b;
  stroke: #020203;
  stroke-linejoin: round;
  stroke-width: 8;
  cursor: pointer;
  transition: filter 140ms ease;
}

.slot:focus {
  outline: none;
}

.slot.available {
  filter: brightness(1.45);
}

.slot.filled-pink {
  fill: var(--pink);
}

.slot.filled-white {
  fill: var(--white);
}

.slot-peg {
  pointer-events: none;
}

.racer {
  cursor: default;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.45));
  touch-action: none;
  transition: transform 120ms ease-in-out;
}

.racer.dragging {
  filter: drop-shadow(0 5px 4px rgba(0, 0, 0, 0.5));
}

.piece-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-content: stretch;
  max-height: 266px;
  overflow: hidden;
}

.piece-panel .game-control {
  order: 0;
}

#pinkBin {
  order: 1;
}

#whiteBin {
  order: 2;
}

.piece-panel.human-white #whiteBin {
  order: 1;
}

.piece-panel.human-white #pinkBin {
  order: 2;
}

.game-control {
  display: flex;
  flex-direction: column;
  padding: 10px;
  border: 1px solid rgba(22, 22, 24, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
  box-shadow: 0 14px 26px rgba(48, 40, 31, 0.12);
}

.score-row {
  min-height: 0;
  display: grid;
  gap: 3px;
  align-items: start;
}

.game-control.game-over .score-row {
  min-height: 30px;
}

.status-text {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.15;
}

.status-text:empty {
  display: none;
}

.score-text {
  white-space: normal;
  overflow-wrap: anywhere;
}

.computer-score {
  text-align: left;
}

.landing-choice {
  display: grid;
  gap: 6px;
}

.landing-play-button {
  width: 100%;
  height: 33px;
  border: 1px solid rgba(20, 20, 22, 0.28);
  border-radius: 6px;
  background: #1d1e21;
  color: #f8f5ea;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.prompt-text {
  min-height: 18px;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 750;
}

.game-control.game-over .prompt-text {
  display: none;
}

.instruction-text {
  margin: 6px 0 0;
  color: rgba(27, 27, 29, 0.78);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.clock-text {
  margin-top: 4px;
  color: rgba(27, 27, 29, 0.72);
  font-size: 12px;
  font-weight: 800;
}

.stats-widget {
  display: grid;
  gap: 2px;
  margin-top: 5px;
  padding-top: 6px;
  border-top: 1px solid rgba(27, 27, 29, 0.12);
  color: rgba(27, 27, 29, 0.76);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.18;
}

.game-control.game-over .stats-widget {
  grid-template-columns: 1fr;
  gap: 1px;
  margin-top: 3px;
  padding-top: 4px;
}

.stats-widget strong {
  color: #1b1b1d;
  font-weight: 900;
}

.pit-stop-button {
  width: 100%;
  min-height: 34px;
  margin-top: 6px;
  padding: 5px 8px;
  border: 1px solid rgba(20, 20, 22, 0.24);
  border-radius: 6px;
  background: #1d1e21;
  color: #f8f5ea;
  font: inherit;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.2;
  cursor: pointer;
}

.pit-stop-button[disabled] {
  cursor: not-allowed;
  opacity: 0.45;
}

.play-again-button {
  width: 100%;
  height: 31px;
  margin-top: 6px;
  border: 1px solid rgba(20, 20, 22, 0.24);
  border-radius: 6px;
  background: var(--pink);
  color: #1b1b1d;
  font: inherit;
  font-size: 13px;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(150, 54, 78, 0.34);
}

.waitlist-form {
  display: grid;
  gap: 4px;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(27, 27, 29, 0.14);
}

.waitlist-label {
  color: rgba(27, 27, 29, 0.78);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.12;
}

.waitlist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.waitlist-row input {
  min-width: 0;
  height: 29px;
  padding: 0 9px;
  border: 1px solid rgba(20, 20, 22, 0.24);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.82);
  color: #1b1b1d;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.waitlist-row button {
  height: 29px;
  padding: 0 12px;
  border: 1px solid rgba(20, 20, 22, 0.24);
  border-radius: 6px;
  background: #1d1e21;
  color: #f8f5ea;
  font: inherit;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}

.waitlist-row button[disabled] {
  cursor: wait;
  opacity: 0.62;
}

.waitlist-message {
  min-height: 13px;
  color: rgba(27, 27, 29, 0.68);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.1;
}

.choice-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}

.choice-button {
  height: 32px;
  border: 1px solid rgba(20, 20, 22, 0.22);
  border-radius: 6px;
  color: #1b1b1d;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.pink-choice {
  background: var(--pink);
}

.white-choice {
  background: var(--white);
}

.difficulty-control {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.difficulty-label {
  color: rgba(27, 27, 29, 0.72);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.difficulty-button {
  height: 29px;
  min-width: 0;
  padding: 0 4px;
  border: 1px solid rgba(20, 20, 22, 0.22);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.7);
  color: #1b1b1d;
  font: inherit;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.difficulty-button.selected {
  background: #1d1e21;
  color: #f8f5ea;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.player-colors {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 750;
}

.bin {
  min-height: 0;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #08090b;
  box-shadow: 0 18px 32px rgba(48, 40, 31, 0.14);
  color: #f8f5ea;
}

.bin.inactive {
  opacity: 0.48;
}

.bin.inactive .piece-token {
  cursor: not-allowed;
}

.bin.empty .piece-pile {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 55%),
    #101216;
}

.bin-top {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
}

.bin-top strong {
  min-width: 36px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  font-size: 14px;
}

.piece-pile {
  position: relative;
  height: 86px;
  margin-top: 6px;
  border-radius: 6px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.11), transparent 55%),
    #101216;
  overflow: hidden;
  touch-action: none;
}

.piece-token {
  position: absolute;
  width: 46px;
  height: 41px;
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
  cursor: grab;
  user-select: none;
  touch-action: none;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.16));
  transform-origin: 50% 50%;
  will-change: transform;
}

.piece-token::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 18px;
  width: 12px;
  height: 19px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0.12) 42%, rgba(0, 0, 0, 0.1));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.36),
    inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.piece-token[data-color="pink"] {
  background: linear-gradient(145deg, #f7a5b6, var(--pink-dark));
}

.piece-token[data-color="white"] {
  background: linear-gradient(145deg, #fffdf5, var(--white-dark));
}

.piece-token.drag-origin {
  opacity: 0.28;
  cursor: grabbing;
}

.piece-token.dragging {
  position: fixed;
  z-index: 20;
  cursor: grabbing;
  opacity: 0.94;
  transform-origin: 50% 50%;
  pointer-events: none;
}

.piece-token.computer-moving {
  cursor: default;
  pointer-events: none;
  transition:
    left 560ms ease-in-out,
    top 560ms ease-in-out,
    transform 560ms ease-in-out;
  z-index: 1000;
  will-change: left, top, transform;
}

@media (max-width: 760px) {
  .game-shell {
    height: 100vh;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: start;
    padding: 8px;
  }

  .board {
    width: min(100%, 54vh);
  }

  .piece-panel {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    max-height: 48vh;
    overflow: hidden;
  }

  .game-control {
    grid-column: 1 / -1;
    max-height: 18vh;
    overflow: hidden;
    padding: 7px 8px;
  }

  .game-control.setup-mode {
    max-height: none;
    overflow: visible;
  }

  .game-control.setup-mode .instruction-text {
    display: block;
    margin-top: 5px;
    font-size: 11px;
    line-height: 1.2;
  }

  .instruction-text {
    display: none;
  }

  .pit-stop-button {
    order: 1;
    min-height: 28px;
    max-height: 42px;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.08;
  }

  .game-control.pit-stop-available .stats-widget {
    display: none;
  }

  .game-control.pit-stop-available .pit-stop-button {
    margin-top: 4px;
  }
}

@media (max-width: 560px) {
  .game-shell {
    padding: 6px;
  }

  .piece-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bin {
    min-height: 104px;
    padding: 6px;
  }

  .piece-pile {
    height: 66px;
  }
}
