:root {
  --ink: #10263c;
  --panel: rgba(8, 22, 36, .84);
  --cyan: #35d9f1;
  --blue: #217ce5;
  --yellow: #ffd338;
  --orange: #ff7a2f;
  --red: #ef4545;
  --green: #36d27f;
  --purple: #8c63e9;
  --display: "Fredoka", "Noto Sans SC", sans-serif;
  --body: "Noto Sans SC", sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

html,
body { margin: 0; width: 100%; height: 100%; overflow: hidden; }

body {
  color: white;
  background: #102f45;
  font-family: var(--body);
  overscroll-behavior: none;
  user-select: none;
}

button,
a { font: inherit; }
button { touch-action: none; }

.race-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  background: #b9e4ff;
}

#race-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #b9e4ff;
}

.race-header {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  min-height: 62px;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: .55rem 1rem;
  background: linear-gradient(180deg, rgba(5,16,29,.88), rgba(5,16,29,.48), transparent);
  pointer-events: none;
}

.home-link,
.icon-button,
.race-loadout-chip { pointer-events: auto; }
.race-loadout-chip {
  justify-self: end;
  background: rgba(8, 18, 30, 0.85);
  border: 2px solid #c8a060;
  color: #ffe9a0;
  padding: 0.25rem 0.55rem;
  font-size: 0.68rem;
  max-width: 220px;
  line-height: 1.25;
}
.race-loadout-chip span {
  display: block;
  font-size: 0.55rem;
  color: #8faabb;
}
.race-loadout-chip[data-frame="wood"] { border-color: #8a5a28; }
.race-loadout-chip[data-frame="azure"] { border-color: #4a90d8; box-shadow: 0 0 10px rgba(80,160,255,0.4); }
.race-loadout-chip[data-frame="gold"] { border-color: #e8b020; box-shadow: 0 0 10px rgba(255,200,60,0.4); }
.race-loadout-chip[data-frame="crystal"] { border-color: #a8e0ff; box-shadow: 0 0 12px rgba(160,220,255,0.45); }
.driver-portrait[data-frame="wood"] { border-color: #8a5a28; box-shadow: 0 0 0 2px #c8a070; }
.driver-portrait[data-frame="azure"] { border-color: #4a90d8; box-shadow: 0 0 10px rgba(80,160,255,0.5); }
.driver-portrait[data-frame="gold"] { border-color: #e8b020; box-shadow: 0 0 10px rgba(255,200,60,0.5); }
.driver-portrait[data-frame="crystal"] { border-color: #a8e0ff; box-shadow: 0 0 12px rgba(160,220,255,0.55); }
.castle-link {
  display: inline-block;
  margin-top: 0.25rem;
  color: #ffd45a;
  font-size: 0.55rem;
  text-decoration: none;
}
.castle-link:hover { text-decoration: underline; }
.home-link {
  justify-self: start;
  color: white;
  text-decoration: none;
  font-size: .78rem;
  font-weight: 700;
  text-shadow: 0 2px 4px #000;
}
.race-logo {
  display: flex;
  align-items: center;
  gap: .45rem;
  text-shadow: 0 2px 4px rgba(0,0,0,.6);
}
.logo-bolt {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 14px;
  background: linear-gradient(145deg, #ffb08a, #f28b6b);
  box-shadow: 0 4px 0 #d87050, inset 0 2px 0 rgba(255,255,255,.4);
}
.race-logo strong { display: block; font: 800 1.08rem "Nunito", var(--display); }
.race-logo .logo-eyebrow {
  display: block;
  color: #ffb08a;
  font: 800 .52rem "Nunito", var(--display);
  letter-spacing: .14em;
  text-shadow: none;
}
.race-logo em {
  display: block;
  color: var(--yellow);
  font: 600 .54rem var(--display);
  font-style: normal;
  letter-spacing: .12em;
}
.start-screen.is-visible ~ .race-header,
body:has(.start-screen.is-visible) .race-header {
  background: transparent;
  text-shadow: none;
}
body:has(.start-screen.is-visible) .race-header .home-link,
body:has(.start-screen.is-visible) .race-header .race-logo strong,
body:has(.start-screen.is-visible) .race-header .race-logo em {
  color: #4a4038;
  text-shadow: none;
}
body:has(.start-screen.is-visible) .race-header .icon-button {
  background: #fff;
  color: #4a4038;
  border: none;
  box-shadow: 0 3px 0 #e0d4c4;
}
.icon-button {
  justify-self: end;
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 10px;
  background: rgba(6,22,37,.65);
  color: white;
  cursor: pointer;
  font-weight: 900;
}

.hud {
  position: absolute;
  z-index: 9;
  inset: 72px 14px auto;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  pointer-events: none;
}
.hud > div {
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 7px 18px rgba(0,0,0,.22);
  backdrop-filter: blur(8px);
}
.position-panel {
  min-width: 94px;
  padding: .35rem .6rem;
  display: grid;
  grid-template-columns: auto auto;
  align-items: end;
}
.position-panel strong { color: var(--yellow); font: 700 2rem/1 var(--display); }
.position-panel > span { margin-bottom: .15rem; color: #c9d7e2; font-size: .75rem; }
.position-panel small { grid-column: 1 / -1; color: #9fb4c5; font-size: .58rem; }
.lap-panel,
.timer-panel {
  min-width: 90px;
  padding: .46rem .65rem;
}
.lap-panel span,
.timer-panel span,
.effect-panel small { display: block; color: #9fb4c5; font-size: .57rem; }
.lap-panel strong,
.timer-panel strong { font: 700 .9rem var(--display); }
.speed-panel {
  min-width: 148px;
  margin-left: auto;
  padding: .38rem .55rem .48rem;
  display: grid;
  grid-template-columns: 66px 1fr;
  align-items: center;
  gap: .15rem .45rem;
}
.speed-dial {
  position: relative;
  grid-row: 1 / 3;
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border: 4px solid #152c3f;
  border-radius: 50%;
  background: conic-gradient(from 225deg, #35d9f1 0 22%, #55dc72 22% 43%, #ffd338 43% 64%, #ff7a2f 64% 78%, #ef4545 78% 84%, #253d50 84% 100%);
  box-shadow: inset 0 0 0 4px #071827, 0 3px 8px rgba(0,0,0,.3);
}
.speed-dial::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 45% 38%, #284a62, #071827 70%);
}
.speed-dial > div { position: relative; z-index: 2; text-align: center; }
.speed-dial strong { display: block; font: 700 1.12rem/1 var(--display); }
.speed-dial span { color: #a9bfce; font-size: .46rem; }
.speed-needle {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 50%;
  width: 2px;
  height: 24px;
  border-radius: 2px;
  background: white;
  box-shadow: 0 0 5px rgba(255,255,255,.8);
  transform-origin: 50% 100%;
  transform: rotate(var(--speed-angle, -128deg));
  transition: transform 90ms linear;
}
.speed-needle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  transform: translateX(-50%);
}
.boost-label { align-self: end; display: flex; justify-content: space-between; font: 700 .49rem var(--display); color: #9fb4c5; }
.boost-label strong { color: var(--cyan); font-size: .5rem; }
.speed-bar { grid-column: 2; height: 7px; overflow: hidden; border: 1px solid rgba(255,255,255,.16); border-radius: 5px; background: rgba(255,255,255,.12); }
.speed-bar i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--yellow), var(--red)); transition: width 80ms linear; }
.effect-panel {
  min-width: 230px;
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .36rem .45rem;
}
.effect-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(145deg, #3b5770, #172b3e);
  font-size: 1rem;
}
.effect-panel strong { display: block; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .7rem; }
.effect-panel.is-positive .effect-icon { background: linear-gradient(145deg, var(--green), #168a59); }
.effect-panel.is-negative .effect-icon { background: linear-gradient(145deg, var(--red), #a5213d); }
.item-slot {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(67,91,111,.85), rgba(17,36,53,.9));
  box-shadow: inset 0 1px rgba(255,255,255,.16);
}
.item-slot.is-main {
  width: auto;
  min-width: 132px;
  display: flex;
  justify-content: flex-start;
  gap: .42rem;
  padding: 0 .36rem;
}
.item-slot.is-active {
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(53,217,241,.5), inset 0 1px rgba(255,255,255,.2);
}
.quiz-slot span {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--purple);
  font: 900 1rem var(--display);
}

.live-ranking {
  position: absolute;
  z-index: 10;
  top: 154px;
  left: 14px;
  width: 154px;
  padding: .45rem;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 7px 18px rgba(0,0,0,.22);
  backdrop-filter: blur(8px);
  pointer-events: none;
}
.live-ranking header { display: flex; justify-content: space-between; margin-bottom: .28rem; color: var(--yellow); font-size: .62rem; font-weight: 900; }
.live-ranking header small { color: #9fb5c4; font-size: .5rem; }
.live-ranking ol { display: grid; gap: .18rem; margin: 0; padding: 0; list-style: none; }
.live-ranking li {
  min-height: 20px;
  display: grid;
  grid-template-columns: 18px 18px 1fr;
  gap: .25rem;
  align-items: center;
  padding: .15rem .25rem;
  border-radius: 6px;
  color: #c8d8e3;
  background: rgba(255,255,255,.045);
  font-size: .53rem;
}
.live-ranking li.is-player { color: #172b3e; background: var(--yellow); font-weight: 900; }
.rank-number { font: 900 .6rem var(--display); }
.rank-avatar { text-align: center; }

.race-flow-mini {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 68px;
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .26rem .6rem;
  border-radius: 999px;
  background: rgba(6,20,33,.66);
  color: #8fa7b8;
  font-size: .48rem;
  transform: translateX(-50%);
  pointer-events: none;
}
.race-flow-mini i { width: 18px; height: 1px; background: #547087; }
.race-flow-mini .is-current { color: var(--yellow); font-weight: 900; }

.race-message {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 20%;
  padding: .55rem 1rem;
  border: 2px solid white;
  border-radius: 999px;
  background: rgba(8,22,36,.9);
  box-shadow: 0 5px 0 rgba(0,0,0,.28);
  font-weight: 800;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}
.race-message.is-visible { opacity: 1; transform: translate(-50%, 0); }

.countdown {
  position: absolute;
  z-index: 13;
  left: 50%;
  top: 48%;
  color: white;
  font: 900 clamp(4rem, 15vw, 9rem)/1 var(--display);
  text-shadow: 0 7px 0 #17283a, 0 0 30px rgba(255,211,56,.75);
  transform: translate(-50%, -50%) scale(.8);
  opacity: 0;
  pointer-events: none;
}
.countdown.is-active { animation: countdown-pop .72s ease; }
@keyframes countdown-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  22%, 72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.2); }
}

.touch-controls {
  position: absolute;
  z-index: 15;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: end;
  padding: 0 14px;
  pointer-events: none;
}
.quiz-hint-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}
.quiz-hint-bar p {
  margin: 0;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(255, 248, 236, 0.88);
  box-shadow: 0 6px 18px rgba(90, 70, 50, 0.12);
  color: #6a5848;
  font: 800 0.78rem "Nunito", "Noto Sans SC", sans-serif;
  letter-spacing: 0.01em;
}
.touch-controls > div { display: flex; gap: .55rem; align-items: end; }
.touch-controls button {
  width: 62px;
  height: 62px;
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 50%;
  background: rgba(7,22,36,.64);
  box-shadow: 0 5px 0 rgba(0,0,0,.32);
  color: white;
  font-weight: 900;
  pointer-events: auto;
}
.touch-controls button.is-held { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.32); background: rgba(33,124,229,.85); }
.touch-drive .touch-gas {
  width: 76px;
  height: 76px;
  border-color: #ffe888;
  background: rgba(239,69,69,.75);
}
.touch-drive .touch-drift { font-size: .72rem; background: rgba(140,99,233,.75); }

.overlay {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(3, 14, 25, 0.7);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
.overlay.is-visible { opacity: 1; visibility: visible; }

/* ===== Clay lobby (start screen) ===== */
.start-screen.overlay {
  background:
    radial-gradient(circle at 12% 18%, rgba(126, 200, 220, 0.18), transparent 34%),
    radial-gradient(circle at 88% 8%, rgba(242, 139, 107, 0.16), transparent 30%),
    linear-gradient(165deg, #fffdf9 0%, #fdf8f3 48%, #f5ebe0 100%);
  backdrop-filter: none;
  align-content: start;
  overflow: auto;
  place-items: start center;
  padding: 1.1rem 1rem 2rem;
}
.start-card {
  width: min(920px, 96vw);
  max-height: none;
  margin: 0 auto;
  overflow: visible;
  border: none;
  border-radius: 0;
  padding: 0.4rem 0.2rem 1.2rem;
  background: transparent;
  box-shadow: none;
  text-align: center;
  color: #4a4038;
}
.start-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  margin-bottom: 0.35rem;
}
.start-bolt {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(145deg, #ffb08a, #f28b6b);
  box-shadow: 0 5px 0 #d87050, inset 0 2px 0 rgba(255, 255, 255, 0.45);
  font-size: 1.4rem;
}
.start-card .eyebrow {
  margin: 0;
  color: #f28b6b;
  font: 800 0.68rem/1.2 "Nunito", var(--display);
  letter-spacing: 0.18em;
}
.start-card h1 {
  margin: 0.08rem 0 0;
  font: 900 clamp(1.8rem, 5vw, 2.8rem)/1.05 "Nunito", var(--display);
  color: #4a4038;
  text-shadow: none;
  letter-spacing: -0.02em;
}

.quiz-card,
.pause-card,
.finish-card {
  width: min(650px, 96vw);
  max-height: 94vh;
  overflow: auto;
  border: none;
  border-radius: 26px;
  padding: 1.25rem;
  background: #fffdf9;
  color: #4a4038;
  box-shadow:
    0 18px 40px rgba(140, 100, 70, 0.16),
    inset 0 2px 0 rgba(255, 255, 255, 0.9);
  text-align: center;
}

.flow-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin: 0.85rem 0 1.1rem;
  color: #a89888;
  font: 700 0.72rem "Nunito", var(--display);
}
.flow-steps span { display: flex; align-items: center; gap: 0.35rem; }
.flow-steps b {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 2px solid #e0d4c4;
  border-radius: 50%;
  background: #fff;
  color: #a89888;
  font: 800 0.7rem "Nunito", var(--display);
  box-shadow: inset 0 1px 0 #fff, 0 2px 0 #e8dcc8;
}
.flow-steps i {
  width: clamp(28px, 6vw, 56px);
  height: 3px;
  border-radius: 999px;
  background: #e5d8c8;
}
.flow-steps .is-current {
  color: #4a4038;
  font-weight: 800;
}
.flow-steps .is-current b {
  border-color: #f28b6b;
  background: linear-gradient(145deg, #ffb08a, #f28b6b);
  color: #fff;
  box-shadow: 0 3px 0 #d87050;
}

.select-title {
  margin: 0.35rem 0 0.7rem;
  color: #4a4038;
  font: 800 1.05rem "Nunito", var(--display);
  text-align: left;
}
.character-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
}
.character-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  padding: 0.7rem 0.4rem 0.65rem;
  border: 2.5px solid transparent;
  border-radius: 20px;
  background: #fff;
  color: #4a4038;
  cursor: pointer;
  box-shadow:
    0 8px 18px rgba(150, 110, 80, 0.1),
    inset 0 2px 0 rgba(255, 255, 255, 0.95);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.character-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 22px rgba(150, 110, 80, 0.14);
}
.character-card[aria-selected="true"] {
  border-color: #8ecbff;
  box-shadow:
    0 0 0 3px rgba(142, 203, 255, 0.25),
    0 10px 22px rgba(100, 150, 190, 0.16);
}
.char-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  display: none;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #7ecfc4, #4fafa6);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  box-shadow: 0 3px 0 #3a8e86;
}
.character-card[aria-selected="true"] .char-check { display: grid; }

.char-stage {
  position: relative;
  width: 100%;
  height: 78px;
  display: grid;
  place-items: center;
  margin-bottom: 0.15rem;
}
.char-blob {
  position: absolute;
  bottom: 8px;
  width: 58px;
  height: 16px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--driver-color) 28%, #efe4d6);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--driver-color) 35%, #c8b8a0);
}
.character-avatar {
  position: relative;
  z-index: 2;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, #fff, transparent 42%),
    var(--driver-color);
  box-shadow:
    0 4px 0 color-mix(in srgb, var(--driver-color) 70%, #4a4038),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
  font-size: 1.7rem;
  transform: translateY(-6px);
}
.character-kart {
  position: absolute;
  z-index: 1;
  bottom: 10px;
  width: 64px;
  height: 26px;
  border: none;
  border-radius: 14px 14px 9px 9px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--driver-color), white 40%), var(--driver-color));
  box-shadow: 0 3px 0 color-mix(in srgb, var(--driver-color) 65%, #4a4038);
}
.character-kart::before,
.character-kart::after {
  content: "";
  position: absolute;
  bottom: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #3a3a42;
  box-shadow: inset 0 -2px 0 #222, 0 0 0 2px #c8c0b8;
}
.character-kart::before { left: 6px; }
.character-kart::after { right: 6px; }
.character-card strong {
  font: 800 0.78rem "Nunito", var(--display);
  color: #4a4038;
}
.character-card small {
  color: #9a8a7a;
  font-size: 0.58rem;
  font-weight: 700;
}

.selected-driver {
  display: grid;
  grid-template-columns: auto 1fr minmax(180px, 0.85fr);
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border: none;
  border-radius: 20px;
  background: #fff;
  text-align: left;
  box-shadow:
    0 8px 20px rgba(150, 110, 80, 0.1),
    inset 0 2px 0 rgba(255, 255, 255, 0.95);
}
.driver-portrait {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, #fff, transparent 42%),
    var(--selected-driver-color, #f28b6b);
  font-size: 1.7rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12), inset 0 2px 0 rgba(255, 255, 255, 0.4);
}
.driver-copy small {
  display: block;
  color: #9a8a7a;
  font-size: 0.68rem;
  font-weight: 700;
}
.driver-copy small strong { color: #4a4038; font-size: 0.86rem; }
.driver-copy span {
  display: block;
  margin-top: 0.2rem;
  color: #6a5a4a;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.35;
}
.castle-link {
  display: inline-block;
  margin-top: 0.3rem;
  color: #f28b6b;
  font-size: 0.62rem;
  font-weight: 800;
  text-decoration: none;
}
.castle-link:hover { text-decoration: underline; }
.driver-stats { display: grid; gap: 0.35rem; }
.driver-stats label {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.62rem;
  font-weight: 800;
  color: #8a7a6a;
}
.driver-stats i {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #efe4d6;
  box-shadow: inset 0 1px 2px rgba(140, 100, 70, 0.12);
}
.driver-stats b {
  display: block;
  width: 50%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7ecfc4, #4fafa6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.track-select-title { margin-top: 1.15rem; }
.track-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}
.track-card {
  position: relative;
  min-height: 118px;
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-content: end;
  justify-items: start;
  gap: 0.15rem;
  padding: 0.55rem 0.65rem 0.65rem;
  border: 2.5px solid transparent;
  border-radius: 20px;
  color: #4a4038;
  background: #fff;
  cursor: pointer;
  text-align: left;
  box-shadow:
    0 8px 18px rgba(150, 110, 80, 0.1),
    inset 0 2px 0 rgba(255, 255, 255, 0.95);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.track-card:hover { transform: translateY(-2px); }
.track-card[aria-selected="true"] {
  border-color: #8ecbff;
  box-shadow:
    0 0 0 3px rgba(142, 203, 255, 0.25),
    0 10px 22px rgba(100, 150, 190, 0.14);
}
.track-stage {
  position: relative;
  width: 100%;
  height: 68px;
  margin: 0 0 0.2rem;
  border-radius: 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 78% 22%, var(--track-sun), transparent 28%),
    linear-gradient(145deg, var(--track-sky), var(--track-ground));
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.08);
}
.track-route-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.9;
}
.track-route-preview polyline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2));
}
.track-card strong {
  position: relative;
  z-index: 1;
  font: 800 0.82rem "Nunito", var(--display);
}
.track-card small {
  position: relative;
  z-index: 1;
  color: #9a8a7a;
  font-size: 0.58rem;
  font-weight: 700;
}
.track-card .track-check {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  display: none;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #7ecfc4, #4fafa6);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
  box-shadow: 0 3px 0 #3a8e86;
}
.track-card[aria-selected="true"] .track-check { display: grid; }

.selected-track-info {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  margin-top: 0.75rem;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: #fff;
  color: #8a7a6a;
  font-size: 0.68rem;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(150, 110, 80, 0.08);
}
.selected-track-info > span { display: flex; align-items: center; gap: 0.3rem; }
.selected-track-info b { font-size: 1rem; }
.selected-track-info strong { color: #4a4038; }
.track-level strong { color: #4aaa72 !important; }

.control-guide {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  margin: 1rem 0 0.9rem;
  color: #8a7a6a;
  font-size: 0.72rem;
  font-weight: 700;
}
kbd {
  display: inline-grid;
  min-width: 28px;
  min-height: 26px;
  place-items: center;
  margin-inline: 0.1rem;
  border: none;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 3px 0 #e0d4c4, inset 0 1px 0 #fff;
  color: #4a4038;
  font: 800 0.68rem "Nunito", var(--body);
}

.race-primary,
.race-secondary {
  min-width: min(100%, 420px);
  min-height: 54px;
  border: none;
  border-radius: 999px;
  color: white;
  cursor: pointer;
  font: 800 0.95rem "Nunito", var(--display);
  letter-spacing: 0.04em;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.race-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: min(100%, 520px);
  background: linear-gradient(160deg, #ffb08a, #f28b6b);
  box-shadow: 0 7px 0 #d87050, 0 12px 22px rgba(230, 120, 80, 0.28);
  text-transform: uppercase;
}
.race-primary .flag { font-size: 1.15rem; }
.race-primary:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}
.race-secondary {
  margin-top: 0.7rem;
  background: linear-gradient(160deg, #7ecfc4, #4fafa6);
  box-shadow: 0 5px 0 #3a8e86;
  color: #fff;
}
.text-link {
  display: block;
  margin-top: 1rem;
  color: #a89888;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
}
.text-link:hover { color: #f28b6b; }

/* Clay quiz / pause / finish accents */
.quiz-card { text-align: left; }
.quiz-head { display: grid; grid-template-columns: auto 1fr auto; gap: 0.7rem; align-items: center; }
.quiz-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 18px;
  background: linear-gradient(145deg, #d4b8ff, #9f7ae8);
  color: #fff;
  font: 900 2rem "Nunito", var(--display);
  box-shadow: 0 5px 0 #7a58c0;
  transform: none;
}
.quiz-head p { margin: 0; color: #8a6ad0; font-size: 0.72rem; font-weight: 800; }
.quiz-head h2 { margin: 0.05rem 0 0; font: 800 1.3rem "Nunito", var(--display); color: #4a4038; }
.quiz-stakes {
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: #fff0d8;
  color: #c08030;
  font-size: 0.64rem;
  font-weight: 800;
}
.question-stem { margin: 1rem 0; font-weight: 700; line-height: 1.6; color: #4a4038; }
.answer-list { display: grid; gap: 0.5rem; }
.answer-option {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem;
  border: none;
  border-radius: 16px;
  background: #f5efe6;
  color: #4a4038;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
  box-shadow: inset 0 1px 0 #fff;
}
.answer-option:hover:not(:disabled) { background: #e8f6f4; }
.answer-letter {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  font-weight: 800;
  box-shadow: 0 2px 0 #e0d4c4;
}
.answer-option.is-correct { background: #dff5ea; }
.answer-option.is-wrong { background: #ffe4de; }
.answer-feedback {
  margin-top: 0.8rem;
  padding: 0.7rem;
  border-radius: 14px;
  background: #f5efe6;
  font-size: 0.78rem;
  line-height: 1.5;
  color: #4a4038;
}
.answer-feedback strong { display: block; margin-bottom: 0.15rem; font-weight: 800; }
.answer-feedback.correct strong { color: #4aaa72; }
.answer-feedback.wrong strong { color: #e06058; }
.pause-card .eyebrow,
.finish-card .eyebrow {
  color: #f28b6b;
  font: 800 0.7rem "Nunito", var(--display);
  letter-spacing: 0.16em;
}
.pause-card h2,
.finish-card h2 {
  color: #4a4038;
  font: 900 1.8rem "Nunito", var(--display);
}
.quiz-continue { display: block; width: 100%; margin-top: 0.8rem; }
.quiz-continue[hidden] { display: none; }

.pause-card { width: min(380px, 94vw); }
.pause-card h2,
.finish-card h2 { margin: 0.25rem 0 0.8rem; }
.finish-card { width: min(520px, 94vw); }
.finish-trophy { font-size: 4rem; }
.finish-card > p:not(.eyebrow) { color: #8a7a6a; font-weight: 600; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin: 1rem 0; }
.result-stats div {
  padding: 0.65rem 0.3rem;
  border-radius: 14px;
  background: #f5efe6;
  box-shadow: inset 0 1px 0 #fff;
}
.result-stats small { display: block; color: #9a8a7a; font-size: 0.62rem; font-weight: 700; }
.result-stats strong { display: block; color: #f28b6b; font: 800 1.05rem "Nunito", var(--display); }
.finish-flow { margin-top: 0.35rem; }
.final-ranking {
  overflow: hidden;
  margin-top: 0.7rem;
  border: none;
  border-radius: 16px;
  background: #f5efe6;
  text-align: left;
  box-shadow: inset 0 1px 0 #fff;
}
.final-ranking header {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0.7rem;
  background: linear-gradient(90deg, #ffe8d8, #e8f6f4);
}
.final-ranking header strong { color: #f28b6b; font-size: 0.72rem; }
.final-ranking header span { color: #9a8a7a; font: 800 0.52rem "Nunito", var(--display); }
.final-ranking ol { display: grid; gap: 1px; margin: 0; padding: 0; list-style: none; }
.final-ranking li {
  display: grid;
  grid-template-columns: 36px 28px 1fr auto;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0.3rem 0.7rem;
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.66rem;
  font-weight: 700;
  color: #4a4038;
}
.final-ranking li.is-player {
  background: #fff0e4;
  color: #c06040;
  font-weight: 900;
}
.final-rank-number { color: #f28b6b; font: 900 0.85rem "Nunito", var(--display); }
.final-rank-time { color: #9a8a7a; font: 700 0.56rem "Nunito", var(--display); }

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls { display: flex; }
  .race-header { min-height: 52px; padding: .35rem .55rem; }
  .race-logo small { display: none; }
  .race-logo strong { font-size: .9rem; }
  .logo-bolt { width: 32px; height: 32px; }
  .home-link { font-size: 0; }
  .home-link::before { content: "←"; font-size: 1.1rem; }
  .icon-button { width: 34px; height: 34px; }
  .hud { top: 55px; inset-inline: 6px; gap: .25rem; }
  .hud > div { border-radius: 8px; }
  .position-panel { min-width: 70px; padding: .28rem .42rem; }
  .position-panel strong { font-size: 1.45rem; }
  .lap-panel { min-width: 67px; padding: .35rem .45rem; }
  .timer-panel { display: none; }
  .speed-panel { min-width: 105px; grid-template-columns: 46px 1fr; padding: .25rem .35rem; }
  .speed-dial { width: 46px; height: 46px; border-width: 3px; }
  .speed-dial::after { inset: 6px; }
  .speed-dial strong { font-size: .78rem; }
  .speed-needle { height: 16px; }
  .boost-label { font-size: .4rem; }
  .effect-panel { position: absolute; top: 50px; right: 0; min-width: 137px; padding: .3rem; }
  .effect-icon { width: 29px; height: 29px; }
  .item-slot { width: 31px; height: 31px; border-radius: 8px; }
  .item-slot.is-main { min-width: 98px; }
  .item-slot.is-main + .item-slot { display: none; }
  .live-ranking,
  .race-flow-mini { display: none; }
  .start-card,
  .quiz-card { padding: .9rem; border-radius: 18px; }
  .character-grid { grid-template-columns: repeat(2, 1fr); }
  .char-stage { height: 70px; }
  .character-avatar { width: 46px; height: 46px; font-size: 1.45rem; }
  .character-kart { width: 54px; }
  .selected-driver { grid-template-columns: auto 1fr; }
  .driver-stats { grid-column: 1 / -1; }
  .track-grid { grid-template-columns: 1fr; }
  .track-card { min-height: 100px; }
  .selected-track-info { flex-wrap: wrap; gap: .35rem .7rem; border-radius: 18px; }
  .control-guide { display: none; }
  .select-title { font-size: 0.95rem; text-align: left; }
  .quiz-head { grid-template-columns: auto 1fr; }
  .quiz-stakes { grid-column: 1 / -1; justify-self: start; }
  .question-stem { font-size: .88rem; }
  .answer-option { padding: .52rem; font-size: .78rem; }
}

@media (max-width: 430px) {
  .touch-controls button { width: 54px; height: 54px; }
  .touch-drive .touch-gas { width: 68px; height: 68px; }
  .touch-controls { padding-inline: 8px; }
  .feature-grid strong { font-size: .68rem; }
  .start-copy { font-size: .76rem; }
  .flow-steps i { width: 18px; }
  .flow-steps { font-size: .52rem; gap: .25rem; }
  .result-stats { grid-template-columns: 1fr; }
  .result-stats div { padding: .4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* ===== Clay circuit HUD + art cards (mock-aligned) ===== */
body.clay-circuit {
  --clay-ink: #4a4038;
  --clay-cream: #fffdf8;
  --clay-panel: #fff9f1;
  --clay-line: #eadfce;
  --clay-accent: #f28b6b;
  --clay-teal: #4fafa6;
  --clay-sky: #8ecbff;
}

body.clay-circuit .race-header {
  grid-template-columns: auto 1fr auto auto auto auto;
  background: linear-gradient(180deg, rgba(255, 253, 248, 0.92), rgba(255, 253, 248, 0.35), transparent);
  color: var(--clay-ink);
}
body.clay-circuit .home-link {
  padding: 0.42rem 0.75rem;
  border-radius: 14px;
  background: var(--clay-cream);
  color: var(--clay-ink);
  text-shadow: none;
  box-shadow: 0 4px 0 #e0d4c4, inset 0 1px 0 #fff;
  font: 800 0.72rem "Nunito", var(--display);
}
body.clay-circuit .race-logo small { color: var(--clay-accent); }
body.clay-circuit .race-logo strong { color: var(--clay-ink); text-shadow: none; }
body.clay-circuit .race-logo em { color: #6a8f5a; }
body.clay-circuit .logo-bolt {
  background: linear-gradient(145deg, #ffb08a, #f28b6b);
  box-shadow: 0 4px 0 #d87050;
  border: none;
}
body.clay-circuit .icon-button {
  border: none;
  border-radius: 14px;
  background: var(--clay-cream);
  color: var(--clay-ink);
  box-shadow: 0 4px 0 #e0d4c4;
}
body.clay-circuit .race-flow-mini {
  position: static;
  justify-self: center;
  background: rgba(255, 253, 248, 0.88);
  color: #9a8a7a;
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  box-shadow: 0 3px 10px rgba(150, 110, 80, 0.1);
}
body.clay-circuit .race-flow-mini .is-current { color: var(--clay-accent); font-weight: 900; }

body.clay-circuit .hud {
  inset: 68px 14px auto;
  justify-content: space-between;
  gap: 0.65rem;
}
body.clay-circuit .hud-left-stack,
body.clay-circuit .hud-right-stack {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.45rem;
}
body.clay-circuit .hud-right-stack {
  margin-left: auto;
  justify-content: flex-end;
}
body.clay-circuit .hud > div,
body.clay-circuit .hud-left-stack > div,
body.clay-circuit .hud-right-stack > div,
body.clay-circuit .position-panel,
body.clay-circuit .race-progress-panel,
body.clay-circuit .speed-panel,
body.clay-circuit .effect-panel,
body.clay-circuit .live-ranking {
  border: none;
  background: var(--clay-panel);
  color: var(--clay-ink);
  box-shadow: 0 8px 18px rgba(150, 110, 80, 0.12), inset 0 1px 0 #fff;
  backdrop-filter: none;
}
body.clay-circuit .race-progress-panel {
  display: flex;
  gap: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-radius: 16px;
}
body.clay-circuit .race-progress-panel .lap-panel,
body.clay-circuit .race-progress-panel .timer-panel {
  min-width: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  border: none;
}
body.clay-circuit .position-panel {
  border-radius: 18px;
  padding: 0.4rem 0.7rem;
}
body.clay-circuit .position-panel strong { color: var(--clay-accent); }
body.clay-circuit .position-panel > span,
body.clay-circuit .position-panel small,
body.clay-circuit .lap-panel span,
body.clay-circuit .timer-panel span,
body.clay-circuit .effect-panel small {
  color: #9a8a7a;
}
body.clay-circuit .lap-panel strong,
body.clay-circuit .timer-panel strong { color: var(--clay-ink); }

body.clay-circuit .speed-panel {
  margin-left: 0;
  border-radius: 20px;
  padding: 0.45rem 0.65rem;
}
body.clay-circuit .boost-label span { color: #9a8a7a; }
body.clay-circuit .boost-label strong { color: var(--clay-teal); }
body.clay-circuit .speed-dial {
  border-color: #efe4d6;
  box-shadow: inset 0 0 0 3px #fff, 0 3px 8px rgba(150, 110, 80, 0.12);
}
body.clay-circuit .speed-dial::after {
  background: radial-gradient(circle at 45% 38%, #fff, #f4ebe0 72%);
}
body.clay-circuit .speed-dial strong { color: var(--clay-ink); }
body.clay-circuit .speed-dial span { color: #9a8a7a; }
body.clay-circuit .speed-needle { background: var(--clay-accent); box-shadow: none; }

body.clay-circuit .effect-panel {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem;
  border-radius: 18px;
}
body.clay-circuit .item-slot {
  background: #fff;
  border: none;
  box-shadow: 0 3px 0 #eadfce;
  color: var(--clay-ink);
}
body.clay-circuit .item-slot.is-main {
  min-width: 148px;
  background: #fff;
}
body.clay-circuit .item-slot.quiz-slot {
  background: linear-gradient(145deg, #a78bfa, #7c5cff);
  color: #fff;
  font-weight: 900;
}

body.clay-circuit .live-ranking {
  top: 168px;
  left: 14px;
  width: min(210px, 42vw);
  border-radius: 18px;
  padding: 0.55rem 0.55rem 0.45rem;
}
body.clay-circuit .live-ranking header {
  color: var(--clay-ink);
  letter-spacing: 0.06em;
}
body.clay-circuit .live-ranking header small { color: #9a8a7a; }
body.clay-circuit .live-ranking li {
  background: transparent;
  color: var(--clay-ink);
  border-radius: 12px;
}
body.clay-circuit .live-ranking li.is-player {
  background: #ffe8a3;
  color: #5a4030;
}

body.clay-circuit .race-message {
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(520px, 88vw);
  border: none;
  border-radius: 999px;
  background: rgba(255, 249, 241, 0.94);
  color: var(--clay-ink);
  box-shadow: 0 8px 20px rgba(150, 110, 80, 0.14);
  font-weight: 800;
}

body.clay-circuit .quiz-hint-bar p {
  background: rgba(255, 248, 236, 0.92);
  color: #6a5848;
}

body.clay-circuit .character-card.has-art,
body.clay-circuit .track-card.has-art {
  padding: 0.35rem 0.35rem 0.55rem;
  overflow: hidden;
}
body.clay-circuit .char-art-wrap,
body.clay-circuit .track-art-wrap {
  display: block;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: #f4ebe0;
}
body.clay-circuit .char-art,
body.clay-circuit .track-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1.05;
  object-fit: cover;
  object-position: center top;
}
body.clay-circuit .track-art {
  aspect-ratio: 1.35 / 1;
  object-position: center;
}
body.clay-circuit .character-card.has-art strong,
body.clay-circuit .track-card.has-art strong {
  margin-top: 0.35rem;
}
body.clay-circuit .character-card[aria-selected="true"] .char-check,
body.clay-circuit .track-card[aria-selected="true"] .track-check {
  display: grid;
  background: linear-gradient(145deg, #9ad8ff, #5bb4ef);
  box-shadow: 0 3px 0 #3f8fc4;
}
body.clay-circuit .driver-portrait {
  width: 64px;
  height: 64px;
  overflow: hidden;
  padding: 0;
  background: #f4ebe0;
}
body.clay-circuit .driver-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

body.clay-circuit.menu-open .hud,
body.clay-circuit.menu-open .live-ranking,
body.clay-circuit.menu-open .quiz-hint-bar,
body.clay-circuit.menu-open .race-flow-mini {
  opacity: 0;
  pointer-events: none;
}

body.clay-circuit.is-lobby .hud,
body.clay-circuit.is-lobby .live-ranking,
body.clay-circuit.is-lobby .quiz-hint-bar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 760px) {
  body.clay-circuit .race-header {
    grid-template-columns: auto 1fr auto auto;
  }
  body.clay-circuit .race-flow-mini { display: none; }
  body.clay-circuit .hud {
    flex-direction: column;
    align-items: stretch;
  }
  body.clay-circuit .hud-right-stack {
    margin-left: 0;
    justify-content: flex-start;
  }
  body.clay-circuit .live-ranking {
    top: auto;
    bottom: 110px;
    left: 8px;
    width: min(170px, 46vw);
  }
  body.clay-circuit .char-art { aspect-ratio: 1 / 1.1; }
}
