:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #5d6871;
  --paper: #f7ecd8;
  --panel: #fffaf0;
  --line: #dbc7a6;
  --road: #4e565d;
  --road-light: #6b747b;
  --left: #0d8c8f;
  --left-dark: #086669;
  --right: #df5b42;
  --right-dark: #a73d30;
  --yellow: #f3c94d;
  --green: #4fa35f;
  --blue: #7ab8d8;
  --shadow: 0 24px 70px rgba(47, 36, 20, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(#9bd4ec 0 40%, transparent 40%),
    linear-gradient(180deg, #f7ecd8 0%, #f0d3a2 100%);
}

button {
  font: inherit;
}

.game {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 4px;
  color: #42616f;
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.8rem, 8vw, 6.8rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.hud {
  display: flex;
  gap: 10px;
  align-items: center;
}

.pill,
.icon-button,
.help-button {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 0 rgba(23, 32, 38, 0.14);
}

.pill {
  min-width: 104px;
  min-height: 60px;
  padding: 7px 14px;
  display: grid;
  place-items: center;
}

.pill span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.pill strong {
  font-size: 1.8rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.icon-button {
  width: 58px;
  min-height: 58px;
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 950;
  cursor: pointer;
}

.help-button {
  min-height: 58px;
  padding: 0 14px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 950;
}

.race-card,
.question-card {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: var(--shadow);
  overflow: visible;
}

.race-card {
  position: relative;
  min-height: 355px;
}

.skyline {
  position: absolute;
  inset: 0 0 42%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 70%),
    #9bd4ec;
}

.sun,
.cloud,
.tree {
  position: absolute;
  display: block;
}

.sun {
  right: 8%;
  top: 26px;
  width: 64px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 12px rgba(243, 201, 77, 0.26);
}

.cloud {
  width: 92px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  bottom: 12px;
  border-radius: 50%;
  background: inherit;
}

.cloud::before {
  left: 15px;
  width: 34px;
  height: 34px;
}

.cloud::after {
  right: 14px;
  width: 44px;
  height: 44px;
}

.cloud-one {
  left: 12%;
  top: 34px;
}

.cloud-two {
  left: 46%;
  top: 66px;
  transform: scale(0.8);
}

.tree {
  bottom: 0;
  width: 32px;
  height: 58px;
  border-radius: 18px 18px 6px 6px;
  background: var(--green);
}

.tree::after {
  content: "";
  position: absolute;
  left: 13px;
  bottom: -16px;
  width: 7px;
  height: 22px;
  background: #7c5936;
}

.tree-one {
  left: 7%;
}

.tree-two {
  left: 82%;
  transform: scale(1.15);
}

.tree-three {
  left: 91%;
  transform: scale(0.8);
}

.track {
  position: absolute;
  inset: 44% 22px 22px;
  border: 4px solid #384047;
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, transparent 0 36px, rgba(255, 255, 255, 0.22) 36px 72px),
    linear-gradient(var(--road) 0 49%, #f7df7e 49% 52%, var(--road-light) 52% 100%);
  overflow: hidden;
}

.finish-line {
  position: absolute;
  top: 0;
  right: 6.5%;
  width: 24px;
  height: 100%;
  background:
    conic-gradient(#fff 25%, #111 0 50%, #fff 0 75%, #111 0) 0 / 16px 16px;
  opacity: 0.95;
}

.lane {
  position: relative;
  height: 50%;
}

.lane-left {
  border-bottom: 2px dashed rgba(255, 255, 255, 0.58);
}

.lane-label {
  position: absolute;
  z-index: 3;
  left: 14px;
  top: 12px;
  min-width: 80px;
  max-width: 150px;
  min-height: 42px;
  padding: 5px 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 32, 38, 0.5);
  font-weight: 950;
}

.lane-label strong {
  max-width: 86px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane-label span {
  color: var(--yellow);
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
}

.car {
  --x: 4%;
  position: absolute;
  z-index: 2;
  left: var(--x);
  bottom: 8px;
  width: clamp(74px, 11vw, 118px);
  height: clamp(40px, 6vw, 62px);
  border-radius: 22px 30px 14px 14px;
  transform: translateX(-8%);
  transition: left 260ms cubic-bezier(0.2, 0.85, 0.2, 1.15);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.14);
}

.left-car {
  background: var(--left);
}

.right-car {
  background: var(--right);
}

.car::before {
  content: "";
  position: absolute;
  left: 12%;
  top: -36%;
  width: 52%;
  height: 58%;
  border-radius: 18px 20px 4px 4px;
  background: inherit;
}

.car-window {
  position: absolute;
  left: 25%;
  top: -25%;
  width: 28%;
  height: 38%;
  border-radius: 10px 10px 3px 3px;
  background: #e5fbff;
  border: 3px solid rgba(0, 0, 0, 0.12);
  z-index: 1;
}

.driver {
  position: absolute;
  left: 27%;
  top: -42%;
  width: 30%;
  aspect-ratio: 1;
  border: 3px solid rgba(0, 0, 0, 0.14);
  border-radius: 50%;
  background: #ffd7b0;
  z-index: 4;
  overflow: hidden;
}

.xixi-driver {
  background: #ffe0c4;
}

.hair {
  position: absolute;
  left: -6%;
  top: -16%;
  width: 112%;
  height: 42%;
  border-radius: 50% 50% 35% 35%;
  background: #2b211c;
}

.xixi-driver .hair {
  background: #3d252a;
}

.face-eye {
  position: absolute;
  top: 43%;
  width: 12%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #171f25;
}

.face-eye-left {
  left: 31%;
}

.face-eye-right {
  right: 31%;
}

.smile {
  position: absolute;
  left: 36%;
  bottom: 22%;
  width: 28%;
  height: 14%;
  border-bottom: 3px solid #8f463d;
  border-radius: 0 0 999px 999px;
}

.xixi-driver .smile {
  width: 34%;
  left: 33%;
  border-bottom-color: #a53c66;
}

.car-eye {
  position: absolute;
  top: 32%;
  width: 12%;
  aspect-ratio: 1;
  border: 3px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
  background:
    radial-gradient(circle at 58% 42%, #111 0 28%, transparent 30%),
    #fff;
  z-index: 2;
}

.eye-one {
  right: 30%;
}

.eye-two {
  right: 14%;
}

.headlight {
  position: absolute;
  right: -2px;
  top: 44%;
  width: 12%;
  height: 18%;
  border-radius: 999px 0 0 999px;
  background: #fff1a8;
  box-shadow: 10px 0 22px rgba(255, 241, 168, 0.38);
}

.exhaust {
  position: absolute;
  left: -18px;
  bottom: 13px;
  width: 26px;
  height: 15px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  transform: scale(0);
  opacity: 0;
}

.car.zoom .exhaust {
  animation: puff 330ms ease;
}

.wheel {
  position: absolute;
  bottom: -10px;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #171f25;
  border: 5px solid #f5f0e5;
}

.wheel::after {
  content: "";
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: #9aa4aa;
}

.wheel-front {
  right: 12%;
}

.wheel-back {
  left: 12%;
}

.zoom {
  animation: zoom 320ms ease;
}

.bump {
  animation: bump 260ms ease;
}

.question-card {
  padding: 18px;
  display: grid;
  gap: 14px;
  text-align: center;
}

.level-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.level-button {
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  cursor: pointer;
  font-weight: 950;
}

.level-button.active {
  background: var(--ink);
  color: #fffdf7;
}

.round {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.problem {
  font-size: clamp(3.4rem, 9vw, 6.6rem);
  font-weight: 950;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.answer-card {
  min-height: 112px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(78px, 0.62fr) minmax(86px, 1fr) minmax(78px, 0.62fr);
  gap: 0;
  align-items: stretch;
  box-shadow: 0 9px 0 rgba(23, 32, 38, 0.16);
  overflow: hidden;
  touch-action: manipulation;
}

.answer-card:hover {
  transform: translateY(-2px);
}

.answer-card strong {
  font-size: clamp(2.6rem, 7vw, 5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: center;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.touch-zone {
  min-height: 100%;
  padding: 10px 8px;
  display: grid;
  gap: 7px;
  place-items: center;
}

.touch-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.left-touch {
  border-right: 2px dashed rgba(13, 140, 143, 0.24);
  background: rgba(13, 140, 143, 0.08);
}

.right-touch {
  border-left: 2px dashed rgba(223, 91, 66, 0.22);
  background: rgba(223, 91, 66, 0.08);
}

.choice-key {
  justify-self: center;
}

.left-choice-key {
  border-color: rgba(13, 140, 143, 0.45);
  background: #e9fbf8;
}

.right-choice-key {
  border-color: rgba(223, 91, 66, 0.42);
  background: #fff0ea;
}

kbd {
  min-width: 34px;
  min-height: 30px;
  padding: 3px 8px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #cbb792;
  border-bottom-width: 5px;
  border-radius: 8px;
  background: #fff7e7;
  color: #2a3339;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 950;
}

.players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.player-strip {
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  gap: 10px;
  align-items: center;
  color: #fff;
  font-weight: 950;
  transition: transform 160ms ease;
}

.name-input {
  width: min(150px, 42%);
  min-height: 34px;
  border: 2px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font: inherit;
  font-weight: 950;
  text-align: center;
  text-transform: uppercase;
}

.name-input:focus {
  outline: 3px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
  background: rgba(255, 255, 255, 0.22);
}

.left-strip {
  background: var(--left-dark);
}

.right-strip {
  background: var(--right-dark);
}

.player-strip.hit {
  transform: translateY(-4px);
}

.player-strip.miss {
  transform: translateX(4px);
}

.status {
  min-height: 28px;
  color: var(--muted);
  font-weight: 900;
}

.credit {
  padding: 0 4px 4px;
  color: #5d6871;
  font-size: 0.9rem;
  font-weight: 900;
  text-align: center;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 38, 0.45);
}

.help-modal.open {
  display: grid;
}

.help-panel {
  position: relative;
  width: min(640px, 100%);
  padding: 24px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
}

.help-panel h2 {
  margin: 0 0 16px;
  font-size: clamp(2.2rem, 7vw, 4rem);
  line-height: 0.95;
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.5rem;
  font-weight: 950;
}

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

.help-grid div {
  min-height: 112px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  display: grid;
  gap: 8px;
  place-items: center;
  text-align: center;
  font-weight: 950;
}

.help-grid strong {
  width: 42px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-size: 1.5rem;
}

.help-keys {
  margin: 16px 0 0;
  display: grid;
  gap: 8px;
}

.help-keys p,
.help-levels {
  margin: 0;
  color: var(--muted);
  font-weight: 900;
}

.help-levels {
  margin-top: 14px;
}

@keyframes zoom {
  0%,
  100% {
    transform: translateX(-8%) rotate(0);
  }
  45% {
    transform: translateX(-4%) rotate(-2deg);
  }
}

@keyframes bump {
  0%,
  100% {
    transform: translateX(-8%) rotate(0);
  }
  35% {
    transform: translateX(-14%) rotate(-4deg);
  }
  70% {
    transform: translateX(-5%) rotate(3deg);
  }
}

@keyframes puff {
  0% {
    transform: translateX(0) scale(0.25);
    opacity: 0.7;
  }
  100% {
    transform: translateX(-26px) scale(1.4);
    opacity: 0;
  }
}

@media (max-width: 760px) {
  .game {
    width: min(100vw - 20px, 1120px);
    padding: 12px 0;
    grid-template-rows: auto auto auto;
  }

  .topbar {
    align-items: flex-start;
  }

  .hud {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .pill {
    min-width: 78px;
  }

  .icon-button {
    width: 50px;
    min-height: 50px;
  }

  .help-button {
    min-height: 50px;
  }

  .race-card {
    min-height: 300px;
  }

  .track {
    inset: 38% 12px 16px;
  }

  .level-picker,
  .answers,
  .players {
    grid-template-columns: 1fr;
  }

  .answer-card {
    min-height: 96px;
    grid-template-columns: minmax(82px, 0.72fr) minmax(82px, 1fr) minmax(82px, 0.72fr);
  }

  .help-grid {
    grid-template-columns: 1fr;
  }
}
