:root {
  --ink: #23313a;
  --soft-ink: #657784;
  --paper: #fffdf5;
  --cream: #fff3c4;
  --sun: #f6d56b;
  --leaf: #49bf83;
  --sky: #71c7ff;
  --pink: #ff8ebd;
  --coral: #ff7968;
  --panel: rgba(255, 253, 245, 0.86);
  --shadow: rgba(51, 65, 75, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Mali", "Segoe UI", Tahoma, sans-serif;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0 2px, transparent 2px 46px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 46%),
    linear-gradient(160deg, #fff8d9 0%, #d7f0ef 48%, #ffe1ec 100%),
    var(--cream);
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  font-size: 16px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.game-shell {
  width: min(980px, calc(100% - 16px));
  margin: 0 auto;
  padding: 12px 0 24px;
  display: grid;
  gap: 12px;
}

.top-panel {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: 8px;
  padding: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.34)),
    repeating-linear-gradient(135deg, rgba(255, 142, 189, 0.14) 0 8px, rgba(255, 255, 255, 0) 8px 18px);
  box-shadow: 0 16px 30px rgba(51, 65, 75, 0.1);
}

.title-block {
  display: grid;
  gap: 10px;
}

.back-link {
  width: max-content;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid rgba(35, 49, 58, 0.14);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 8px 18px rgba(51, 65, 75, 0.08);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
}

.eyebrow {
  margin: 0;
  color: #a35c00;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.35;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #2f3c32;
  font-size: 2.35rem;
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: 0;
}

.selected-pill {
  min-height: 48px;
  display: grid;
  align-content: center;
  gap: 2px;
  border: 1px solid rgba(35, 49, 58, 0.12);
  border-radius: 8px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 10px 22px rgba(51, 65, 75, 0.08);
}

.selected-pill span {
  color: var(--soft-ink);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.25;
}

.selected-pill strong {
  font-size: 1.04rem;
  font-weight: 700;
  line-height: 1.25;
}

.pick-panel,
.race-panel {
  border: 1px solid rgba(35, 49, 58, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 253, 245, 0.74)),
    var(--panel);
  box-shadow: 0 18px 36px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.74);
}

.pick-panel {
  padding: 12px;
  display: grid;
  gap: 12px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.panel-head h2 {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
}

.selected-pill {
  min-width: 112px;
  min-height: 48px;
  padding: 8px 10px;
}

.pick-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.pick-card {
  position: relative;
  overflow: hidden;
  min-height: 76px;
  display: grid;
  place-items: center;
  gap: 4px;
  border: 1px solid rgba(35, 49, 58, 0.12);
  border-radius: 8px;
  padding: 8px 4px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.52)),
    var(--runner-color);
  box-shadow: 0 10px 18px rgba(51, 65, 75, 0.1);
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.pick-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 0 55%, rgba(255, 255, 255, 0.34) 55% 66%, transparent 66%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent);
}

.pick-card::after {
  content: "✓";
  position: absolute;
  right: 8px;
  top: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fffdf5;
  background: var(--leaf);
  box-shadow: 0 8px 14px rgba(73, 191, 131, 0.24);
  font-size: 0.82rem;
  font-weight: 700;
  transform: scale(0);
  transition: transform 160ms ease;
}

.pick-card:active {
  transform: scale(0.98);
}

.pick-card.is-selected {
  border-color: rgba(35, 49, 58, 0.34);
  box-shadow: 0 14px 24px rgba(51, 65, 75, 0.16), 0 0 0 3px rgba(255, 255, 255, 0.74) inset;
}

.pick-card.is-selected::after {
  transform: scale(1);
}

.pick-card:disabled {
  opacity: 0.76;
}

.pick-icon {
  position: relative;
  z-index: 1;
  font-size: 1.75rem;
  line-height: 1;
  filter: drop-shadow(0 8px 10px rgba(51, 65, 75, 0.16));
}

.pick-name {
  position: relative;
  z-index: 1;
  min-height: 2.18em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.24;
  text-align: center;
  overflow-wrap: anywhere;
}

.start-btn,
.again-btn,
.choose-btn {
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  color: #2a2409;
  background: linear-gradient(180deg, #ffe892, var(--sun));
  box-shadow: 0 12px 22px rgba(129, 88, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.74);
  font-weight: 700;
  line-height: 1.25;
}

.choose-btn {
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #e6f6f3);
  box-shadow: 0 12px 22px rgba(51, 65, 75, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.start-btn:disabled {
  color: rgba(42, 36, 9, 0.58);
  background: linear-gradient(180deg, #e9dfb8, #d4c996);
}

.race-panel {
  position: relative;
  padding: 10px;
  display: grid;
  gap: 8px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.76) 0%, rgba(232, 250, 255, 0.82) 38%, rgba(230, 247, 218, 0.88) 100%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.36) 0 2px, transparent 2px 12px);
}

.race-panel::before {
  content: "";
  position: absolute;
  left: -4%;
  right: -4%;
  bottom: -48px;
  height: 130px;
  border-radius: 50% 50% 0 0;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.24) 0 6px, transparent 6px 22px),
    linear-gradient(180deg, rgba(121, 215, 134, 0.68), rgba(73, 191, 131, 0.54));
  pointer-events: none;
}

.race-panel > * {
  position: relative;
  z-index: 1;
}

.track-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border: 1px solid rgba(35, 49, 58, 0.1);
  border-radius: 8px;
  padding: 7px 10px;
  color: rgba(35, 49, 58, 0.7);
  background: rgba(255, 255, 255, 0.54);
  font-size: 0.72rem;
  font-weight: 700;
}

.race-board {
  display: grid;
  gap: 8px;
}

.lane {
  --lane-color: #f6d56b;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(35, 49, 58, 0.1);
  border-radius: 8px;
  padding: 7px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.38)),
    var(--lane-color);
  box-shadow: 0 10px 18px rgba(51, 65, 75, 0.1);
  transition: opacity 260ms ease, transform 260ms ease, box-shadow 260ms ease;
}

.lane.is-winner {
  transform: translateY(-2px);
  box-shadow: 0 16px 28px rgba(73, 191, 131, 0.22), 0 0 0 2px rgba(73, 191, 131, 0.34) inset;
}

.lane.is-dimmed {
  opacity: 0.58;
}

.lane.is-picked-loser {
  animation: sadLane 760ms ease both;
}

.lane-label {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
}

.lane-label strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.24;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane-number {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #23313a;
  background: rgba(255, 255, 255, 0.66);
  font-size: 0.75rem;
  font-weight: 700;
}

.lane-road {
  position: relative;
  min-height: 58px;
  overflow: hidden;
  border: 1px solid rgba(35, 49, 58, 0.1);
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.48) 0 14px, transparent 14px 30px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.2)),
    var(--lane-color);
}

.lane-road::before {
  content: "";
  position: absolute;
  inset: auto 0 7px 0;
  height: 3px;
  background: rgba(35, 49, 58, 0.12);
}

.lane-road::after {
  content: "";
  position: absolute;
  top: 0;
  right: 8px;
  width: 15px;
  height: 100%;
  background:
    repeating-conic-gradient(#23313a 0 25%, #fffdf5 0 50%) 0 0 / 15px 15px;
  opacity: 0.62;
}

.progress-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 1;
  width: 100%;
  height: 5px;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--leaf), var(--sky), var(--pink));
  transition: transform 90ms linear;
}

.runner {
  position: absolute;
  left: 8px;
  top: 50%;
  z-index: 2;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  transform: translate3d(0, -50%, 0);
  will-change: transform;
}

.runner-bubble {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 50%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.22)),
    var(--runner-color);
  box-shadow: 0 10px 18px rgba(51, 65, 75, 0.18);
}

.runner-icon {
  font-size: 1.86rem;
  line-height: 1;
  filter: drop-shadow(0 5px 6px rgba(51, 65, 75, 0.16));
}

.runner-trail {
  position: absolute;
  left: -18px;
  top: 50%;
  width: 30px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.44);
  opacity: 0;
  transform: translateY(-50%);
}

.race-board.is-running .runner-bubble {
  animation: runnerBounce 280ms ease-in-out infinite alternate;
}

.race-board.is-running .runner-trail {
  animation: dustPulse 340ms ease-in-out infinite;
}

.result-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(35, 49, 58, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.result-layer.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.result-card {
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  border: 1px solid rgba(35, 49, 58, 0.14);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
  background: rgba(255, 253, 245, 0.96);
  box-shadow: 0 28px 70px rgba(35, 49, 58, 0.28);
  overflow-y: auto;
}

.result-layer.is-correct .result-card {
  animation: winPop 540ms cubic-bezier(0.16, 0.9, 0.28, 1.26) both;
}

.result-layer.is-wrong .result-card {
  animation: sadDrop 620ms cubic-bezier(0.16, 0.76, 0.28, 1) both;
}

.result-scene {
  position: relative;
  min-height: 154px;
  display: grid;
  place-items: center;
}

.result-mascot {
  position: relative;
  z-index: 2;
  font-size: 5rem;
  line-height: 1;
  filter: drop-shadow(0 18px 22px rgba(51, 65, 75, 0.18));
}

.is-correct .result-mascot {
  animation: mascotCelebrate 760ms ease-in-out infinite;
}

.is-wrong .result-mascot {
  animation: mascotSad 1.15s ease-in-out infinite;
  filter: grayscale(0.35) drop-shadow(0 18px 22px rgba(51, 65, 75, 0.14));
}

.result-kicker {
  color: #a35c00;
  font-size: 0.78rem;
  font-weight: 600;
}

.result-card h2 {
  margin-top: 2px;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.22;
}

.result-card p {
  color: var(--soft-ink);
  line-height: 1.55;
}

.ranking-title {
  margin-top: 14px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
}

.ranking-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.rank-item {
  min-height: 48px;
  display: grid;
  grid-template-columns: 34px 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(35, 49, 58, 0.1);
  border-radius: 8px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
  text-align: left;
}

.rank-item.is-first {
  background: linear-gradient(180deg, rgba(255, 232, 146, 0.76), rgba(255, 255, 255, 0.72));
}

.rank-place {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #2a2409;
  background: linear-gradient(180deg, #ffe892, var(--sun));
  font-size: 0.82rem;
  font-weight: 700;
}

.rank-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.rank-item strong {
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.party-bit,
.rain-bit,
.heart-bit {
  position: absolute;
  left: 50%;
  top: 50%;
  pointer-events: none;
}

.party-bit {
  width: 9px;
  height: 15px;
  border-radius: 3px;
  background: hsl(var(--h), 84%, 62%);
  animation: partyBurst 920ms cubic-bezier(0.18, 0.84, 0.26, 1) var(--delay) both;
}

.heart-bit {
  color: #ff6aa9;
  font-size: 1.2rem;
  animation: heartFloat 1.1s ease-out var(--delay) both;
}

.rain-bit {
  width: 4px;
  height: 20px;
  border-radius: 999px;
  background: rgba(113, 199, 255, 0.78);
  animation: sadRain 920ms linear var(--delay) infinite;
}

.sad-cloud {
  position: absolute;
  top: 10px;
  width: 104px;
  height: 42px;
  border-radius: 999px;
  background: #c9d7df;
  box-shadow: -26px 8px 0 #d9e4ea, 24px 7px 0 #b8c9d2;
  opacity: 0.88;
  animation: cloudSway 1.3s ease-in-out infinite alternate;
}

@keyframes runnerBounce {
  from {
    transform: translateY(1px) rotate(-3deg);
  }
  to {
    transform: translateY(-4px) rotate(4deg);
  }
}

@keyframes dustPulse {
  0% {
    opacity: 0;
    transform: translate(10px, -50%) scaleX(0.3);
  }
  42% {
    opacity: 0.72;
  }
  100% {
    opacity: 0;
    transform: translate(-14px, -50%) scaleX(1.2);
  }
}

@keyframes winPop {
  0% {
    transform: scale(0.84) translateY(18px);
    opacity: 0;
  }
  70% {
    transform: scale(1.03) translateY(0);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes sadDrop {
  0% {
    transform: translateY(-12px);
    opacity: 0;
  }
  45% {
    transform: translateY(5px);
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes mascotCelebrate {
  0%,
  100% {
    transform: translateY(0) rotate(-4deg) scale(1);
  }
  45% {
    transform: translateY(-16px) rotate(6deg) scale(1.08);
  }
}

@keyframes mascotSad {
  0%,
  100% {
    transform: translateY(6px) rotate(-5deg);
  }
  50% {
    transform: translateY(10px) rotate(5deg);
  }
}

@keyframes partyBurst {
  0% {
    transform: translate(-50%, -50%) rotate(0) scale(0.4);
    opacity: 0;
  }
  16% {
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(520deg) scale(1);
    opacity: 0;
  }
}

@keyframes heartFloat {
  0% {
    transform: translate(-50%, -35%) scale(0.5);
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1.2);
    opacity: 0;
  }
}

@keyframes sadRain {
  0% {
    transform: translate(calc(-50% + var(--x)), -82px);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--x)), 82px);
    opacity: 0;
  }
}

@keyframes cloudSway {
  from {
    transform: translateX(-10px);
  }
  to {
    transform: translateX(10px);
  }
}

@keyframes sadLane {
  0%,
  100% {
    transform: translateX(0);
  }
  24% {
    transform: translateX(-5px);
  }
  48% {
    transform: translateX(4px);
  }
  72% {
    transform: translateX(-2px);
  }
}

@media (min-width: 760px) {
  .game-shell {
    width: min(1040px, calc(100% - 32px));
    padding: 24px 0 34px;
    gap: 14px;
  }

  .top-panel {
    align-items: end;
  }

  h1 {
    font-size: 4rem;
  }

  .pick-panel,
  .race-panel {
    padding: 14px;
  }

  .pick-card {
    min-height: 88px;
    padding: 9px 6px;
  }

  .pick-icon {
    font-size: 2.1rem;
  }

  .pick-name {
    font-size: 0.76rem;
  }

  .lane {
    grid-template-columns: 88px minmax(0, 1fr);
    min-height: 78px;
    padding: 8px;
  }

  .lane-road {
    min-height: 64px;
  }

  .runner {
    width: 56px;
    height: 56px;
  }

  .runner-bubble {
    width: 52px;
    height: 52px;
  }

  .runner-icon {
    font-size: 2.05rem;
  }

  .result-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 380px) {
  .game-shell {
    width: min(100% - 12px, 980px);
  }

  h1 {
    font-size: 2.1rem;
  }

  .pick-card {
    min-height: 68px;
    padding: 7px 3px;
  }

  .pick-icon {
    font-size: 1.5rem;
  }

  .pick-name {
    font-size: 0.6rem;
  }

  .lane {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
  }

  .lane-label strong {
    font-size: 0.68rem;
  }

  .runner {
    width: 46px;
    height: 46px;
  }

  .runner-bubble {
    width: 42px;
    height: 42px;
  }

  .runner-icon {
    font-size: 1.62rem;
  }
}
