:root {
  --accent: #ff4d5e;
  --hold: #ffb020;
  --fg: #f4f5f7;
  --dim: rgba(244, 245, 247, 0.62);
  --faint: rgba(244, 245, 247, 0.12);
  --panel: rgba(13, 14, 19, 0.94);
  --line: rgba(255, 255, 255, 0.09);
  --hud-fg: #f4f5f7;
  --hud-dim: rgba(244, 245, 247, 0.6);
  --hud-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: Saira, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
body[data-light="1"] {
  --hud-fg: #0f1217;
  --hud-dim: rgba(15, 18, 23, 0.6);
  --hud-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0a0b0f; color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; touch-action: none; }
button { font-family: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.hidden { display: none !important; }

#cv { position: fixed; inset: 0; display: block; }
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(120% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.42) 100%);
}
body[data-light="1"] #vignette { background: radial-gradient(120% 100% at 50% 50%, transparent 60%, rgba(60, 40, 20, 0.16) 100%); }
#tap { position: fixed; inset: 0; z-index: 2; touch-action: none; pointer-events: none; }
body.playing #tap { pointer-events: auto; }

/* ───────────── HUD ───────────── */
#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; color: var(--hud-fg); text-shadow: var(--hud-shadow); }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + var(--sat)) calc(14px + var(--sar)) 0 calc(12px + var(--sal));
}
.icon-btn {
  pointer-events: auto; flex: none;
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
  color: var(--fg); fill: currentColor;
}
body[data-light="1"] #hud .icon-btn { background: rgba(0, 0, 0, 0.07); color: #0f1217; border-color: rgba(0, 0, 0, 0.1); }
/* lap progress: fill it and the music speeds up */
.progress { position: relative; flex: 1; height: 40px; min-width: 60px; display: flex; flex-direction: column; justify-content: center; gap: 5px; }
.prog-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 10px; font-weight: 800; letter-spacing: 0.16em; line-height: 1; }
.prog-row .lap { color: var(--hud-fg); }
.prog-row .next { color: var(--hud-dim); font-style: italic; letter-spacing: 0.08em; }
.progress.near .prog-row .next { color: var(--accent); }
.progress .bar { position: relative; height: 6px; border-radius: 3px; background: var(--faint); overflow: hidden; }
body[data-light="1"] .progress .bar { background: rgba(0, 0, 0, 0.1); }
.progress .fill { position: absolute; inset: 0; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); border-radius: 3px; }
.progress .ticks { position: absolute; inset: 0; }
.progress .ticks i { position: absolute; top: 0; width: 2px; height: 6px; margin-left: -1px; background: rgba(0, 0, 0, 0.45); }
.progress.pulse .bar { box-shadow: 0 0 0 2px var(--accent); }
.score { flex: none; text-align: right; min-width: 92px; }
.score .label { font-size: 10px; font-weight: 700; letter-spacing: 0.18em; color: var(--hud-dim); }
.score .label b { color: var(--accent); font-style: italic; letter-spacing: 0.02em; margin-left: 4px; font-size: 12px; }
.score .val { font-size: clamp(20px, 3.4vw, 30px); font-weight: 800; font-style: italic; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 16px calc(34px + var(--sab));
}
.combo { display: flex; align-items: baseline; gap: 8px; opacity: 0; transition: opacity 0.2s; font-variant-numeric: tabular-nums; }
.combo.on { opacity: 1; }
.combo span { font-size: clamp(26px, 5vw, 40px); font-weight: 800; font-style: italic; line-height: 1; }
.combo small { font-size: 10px; font-weight: 700; letter-spacing: 0.2em; color: var(--hud-dim); }
.meters { display: flex; gap: 14px; }
.meter { display: flex; align-items: center; gap: 7px; }
.meter span { font-size: 9px; font-weight: 700; letter-spacing: 0.18em; color: var(--hud-dim); width: 40px; text-align: right; }
.meter.nitro span { text-align: left; order: 2; }
.meter .m { width: clamp(80px, 22vw, 150px); height: 5px; border-radius: 3px; background: var(--faint); overflow: hidden; }
body[data-light="1"] .meter .m { background: rgba(0, 0, 0, 0.1); }
.meter i { display: block; height: 100%; background: var(--hud-fg); transform-origin: 0 50%; border-radius: 3px; }
.meter.grip.low i { background: #ff3b47; animation: blink 0.5s steps(2) infinite; }
.meter.nitro i { background: var(--accent); }
.meter.nitro .m { transform: scaleX(-1); }
.meter.nitro.on i { background: linear-gradient(90deg, var(--accent), #fff, var(--accent)); }
@keyframes blink { 50% { opacity: 0.45; } }

.toast { position: absolute; left: 50%; transform: translateX(-50%); text-align: center; opacity: 0; pointer-events: none; white-space: nowrap; }
.toast.show { animation: toast 3.6s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 6px); } 8% { opacity: 1; transform: translate(-50%, 0); } 82% { opacity: 1; } 100% { opacity: 0; } }
.track-toast { top: calc(62px + var(--sat)); }
.track-toast .k { font-size: 10px; font-weight: 700; letter-spacing: 0.24em; color: var(--accent); }
.track-toast .t { font-size: clamp(14px, 2.4vw, 18px); font-weight: 700; max-width: 86vw; overflow: hidden; text-overflow: ellipsis; }
.track-toast .a { font-size: 12px; color: var(--hud-dim); }
.zone-toast { top: 28%; font-size: clamp(13px, 2.2vw, 16px); font-weight: 700; letter-spacing: 0.5em; padding-left: 0.5em; color: var(--hud-fg); }
.zone-toast.show { animation: toast 2.4s ease forwards; }
.mid-toast { top: 21%; font-size: clamp(16px, 3vw, 22px); font-weight: 800; font-style: italic; letter-spacing: 0.06em; color: var(--accent); }
.mid-toast.show { animation: toast 2.2s ease forwards; }

/* new lap: big banner */
.lap-banner { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); text-align: center; opacity: 0; pointer-events: none; white-space: nowrap; }
.lap-banner small { display: block; font-size: clamp(12px, 2.2vmin, 16px); font-weight: 800; letter-spacing: 0.4em; padding-left: 0.4em; color: var(--hud-fg); }
.lap-banner b { display: block; font-size: clamp(40px, 11vmin, 92px); font-weight: 900; font-style: italic; line-height: 0.95; letter-spacing: -0.02em; color: var(--accent); text-shadow: 0 4px 24px rgba(0, 0, 0, 0.4); }
.lap-banner span { display: block; margin-top: 4px; font-size: clamp(11px, 1.8vmin, 14px); font-weight: 700; letter-spacing: 0.2em; color: var(--hud-dim); text-transform: uppercase; }
.lap-banner.show { animation: lapIn 2.8s cubic-bezier(.2, .9, .3, 1) forwards; }
@keyframes lapIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(0.96); }
  16% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(1); }
}

/* first-run coaching */
.coach {
  position: absolute; left: 50%; transform: translate(-50%, 6px); opacity: 0; transition: opacity 0.3s, transform 0.3s;
  max-width: min(92vw, 380px); padding: 9px 14px; border-radius: 14px; text-align: center; white-space: nowrap;
  background: rgba(10, 11, 16, 0.82); color: #f4f5f7; text-shadow: none;
  font-size: 14px; font-weight: 600; line-height: 1.25; border: 1px solid rgba(255, 255, 255, 0.14);
}
.coach b { color: var(--accent); font-weight: 800; }
.coach.on { opacity: 1; transform: translate(-50%, 0); }
.coach-bar { top: calc(60px + var(--sat)); }
/* bottom callouts sit in the combo's slot (hidden while they show), clear of the judgment pop */
.coach-tap { bottom: calc(58px + var(--sab)); display: flex; align-items: center; gap: 10px; }
.coach-grip { bottom: calc(58px + var(--sab)); }
#hud.coach-low .combo { visibility: hidden; }
.coach .arrow { position: absolute; left: 50%; width: 0; height: 0; margin-left: -7px; border: 7px solid transparent; }
.coach .arrow.up { top: -14px; border-bottom-color: rgba(10, 11, 16, 0.82); }
.coach .arrow.down { bottom: -14px; border-top-color: rgba(10, 11, 16, 0.82); }
.coach-bar .arrow.up { left: 50%; }
.finger { position: relative; width: 22px; height: 22px; flex: none; }
.finger::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--accent); }
.finger::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); animation: tapPing 0.9s ease-out infinite; }
@keyframes tapPing { from { transform: scale(0.5); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }

/* ───────────── 3D overlays (judgment, count-in, hold ring, timing bar, tips, drift) ───────────── */
.ov { position: absolute; inset: 0; pointer-events: none; }
.ov-judge { position: absolute; left: 50%; top: 77%; transform: translate(-50%, -50%); text-align: center; opacity: 0; white-space: nowrap; }
.ov-judge b { display: block; font-size: clamp(22px, 4.4vmin, 40px); font-weight: 800; font-style: italic; letter-spacing: 0.02em; line-height: 1; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45); }
.ov-judge small { display: block; margin-top: 3px; font-size: clamp(10px, 1.6vmin, 13px); font-weight: 700; letter-spacing: 0.22em; color: var(--hud-dim); }
.ov-judge[data-k="p"] b { color: var(--accent); }
.ov-judge[data-k="g"] b { color: var(--hud-fg); }
.ov-judge[data-k="d"] b { color: #9aa0aa; }
.ov-judge[data-k="m"] b { color: #ff3b47; }
.ov-judge[data-k="h"] b { color: var(--hold, #ffb020); }
.ov-judge[data-k="x"] b { color: var(--accent); font-size: clamp(28px, 6vmin, 54px); }
.ov-judge.go { animation: judge 0.62s cubic-bezier(.2, .9, .3, 1) forwards; }
@keyframes judge {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.45); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(0.96); }
  22% { transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}
.ov-count { position: absolute; left: 50%; top: 37%; transform: translate(-50%, -50%); font-size: clamp(80px, 24vmin, 200px); font-weight: 900; font-style: italic; line-height: 1; color: var(--hud-fg); opacity: 0; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.35); }
.ov-count.word { color: var(--accent); font-size: clamp(64px, 19vmin, 160px); }
.ov-count.go { animation: count 0.62s cubic-bezier(.2, .9, .3, 1) forwards; }
@keyframes count { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0.08; transform: translate(-50%, -50%) scale(0.92); } }
.ov-ring { position: absolute; left: 0; top: 0; width: 76px; height: 76px; margin: -38px 0 0 -38px; opacity: 0; transition: opacity 0.12s; will-change: transform; }
.ov-ring.on { opacity: 1; }
.ov-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ov-ring circle { fill: none; stroke-width: 4; }
.ov-ring .bg { stroke: rgba(255, 255, 255, 0.22); }
.ov-ring .fg { stroke: var(--hold, #ffb020); stroke-dasharray: 100; stroke-dashoffset: 100; stroke-linecap: round; }
.ov-ring.soon .fg { stroke-width: 6; }
.ov-ring span { position: absolute; left: 50%; top: -14px; transform: translateX(-50%); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; color: var(--hold, #ffb020); opacity: 0; transition: opacity 0.1s; white-space: nowrap; }
.ov-ring.soon span { opacity: 1; }
.ov-err { position: absolute; left: 50%; bottom: calc(14px + var(--sab)); width: min(180px, 40vw); height: 13px; transform: translateX(-50%); opacity: 0; }
.ov-err.on { opacity: 1; }
.ov-err::before { content: ""; position: absolute; left: 0; right: 0; top: 6px; height: 1px; background: var(--hud-fg); opacity: 0.35; }
.ov-err .mid { position: absolute; left: 50%; top: 0; width: 2px; height: 13px; margin-left: -1px; background: var(--hud-fg); opacity: 0.55; }
.ov-err .tk { position: absolute; top: 1px; width: 3px; height: 11px; margin-left: -1.5px; border-radius: 1px; background: var(--hud-fg); opacity: 0; }
.ov-err .tk[data-j="1"] { background: var(--accent); }
.ov-err .tk[data-j="3"] { background: #8b919c; }
.ov-err .tk.go { animation: tick 3.2s linear forwards; }
@keyframes tick { from { opacity: 0.95; } to { opacity: 0; } }
.ov-tip { position: absolute; left: 0; top: 0; padding: 5px 10px; border-radius: 12px; background: var(--hud-fg); color: #0b0c10; font-size: 13px; font-weight: 800; letter-spacing: 0.04em; white-space: nowrap; opacity: 0; transition: opacity 0.2s; }
.ov-tip.on { opacity: 1; }
.ov-tip::after { content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px; border: 5px solid transparent; border-bottom: 0; border-top-color: var(--hud-fg); }
/* drift points sit under AURA and fly up into it when banked */
.ov-drift { position: absolute; right: calc(14px + var(--sar)); top: calc(56px + var(--sat)); text-align: right; opacity: 0; white-space: nowrap; transform-origin: 100% 0; transition: opacity 0.15s; }
.ov-drift .k { display: block; font-size: 9px; font-weight: 800; letter-spacing: 0.2em; color: var(--hold, #ffb020); }
.ov-drift .v { display: block; font-size: clamp(16px, 2.8vmin, 24px); font-weight: 800; font-style: italic; font-variant-numeric: tabular-nums; line-height: 1.05; }
.ov-drift.on { opacity: 1; }
.ov-drift.bank { animation: bank 1.05s cubic-bezier(.2, .9, .3, 1) forwards; }
.ov-drift.bank .v { color: var(--hold, #ffb020); }
.ov-drift.lost { animation: lost 0.9s ease-in forwards; }
.ov-drift.lost .v, .ov-drift.lost .k { color: #ff3b47; }
@keyframes bank { 0% { opacity: 1; transform: scale(1.3); } 20% { transform: scale(1); } 70% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-26px) scale(0.85); } }
@keyframes lost { 0% { opacity: 1; } 100% { opacity: 0; transform: translateY(14px) rotate(-3deg); } }
@media (orientation: landscape) {
  .ov-judge { top: 80%; }
}
@media (prefers-reduced-motion: reduce) { .ov-judge.go { animation-duration: 0.5s; } }

/* ───────────── SCREENS ───────────── */
.screen {
  position: fixed; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  overflow-y: auto; touch-action: pan-y;
}
.screen.dim { background: rgba(6, 7, 10, 0.72); }
.corner-btns { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 15px; font-weight: 600; padding: 12px 18px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); color: var(--fg);
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: transparent; font-weight: 800; font-style: italic; letter-spacing: 0.05em; text-transform: uppercase; box-shadow: 0 8px 28px -10px rgba(255, 77, 94, 0.7); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.big { width: 100%; font-size: 24px; padding: 16px 22px; border-radius: 18px; letter-spacing: 0.08em; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.danger { color: #ff7a84; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn kbd { font-family: inherit; font-style: normal; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; padding: 3px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.22); }
@media (hover: none) { .btn kbd { display: none; } }

/* ── home: logo up top, the car drives through the middle, everything you need at the bottom ── */
#title { padding: 0; align-items: stretch; background: linear-gradient(180deg, rgba(6, 7, 10, 0.62) 0%, rgba(6, 7, 10, 0.1) 34%, rgba(6, 7, 10, 0.06) 52%, rgba(6, 7, 10, 0.8) 82%, rgba(6, 7, 10, 0.9) 100%); }
.home {
  flex: 1; min-height: 100%; display: flex; flex-direction: column; align-items: center;
  padding: calc(12px + var(--sat)) calc(16px + var(--sar)) calc(18px + var(--sab)) calc(16px + var(--sal));
}
.home-top { width: 100%; display: flex; align-items: center; justify-content: space-between; min-height: 40px; }
.home-top .corner-btns { margin-left: auto; }
.best-chip { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 18px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); color: var(--hold); }
.best-chip .k { font-size: 10px; font-weight: 800; letter-spacing: 0.18em; color: var(--dim); }
.best-chip b { font-size: 15px; font-weight: 800; font-style: italic; color: var(--fg); font-variant-numeric: tabular-nums; }
.home-hero { text-align: center; margin-top: clamp(4px, 4vh, 40px); }
.logo { margin: 0; line-height: 0.9; font-size: clamp(64px, 19vw, 128px); font-weight: 900; font-style: italic; letter-spacing: -0.035em; }
.logo span {
  display: inline-block; padding: 0 0.08em;
  text-shadow: -0.06em 0 0 rgba(255, 77, 94, 0.55), -0.13em 0 0 rgba(255, 77, 94, 0.22), -0.21em 0 0 rgba(255, 77, 94, 0.08);
  animation: logoIn 0.7s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes logoIn { from { opacity: 0; transform: translateX(-0.3em) skewX(-8deg); } to { opacity: 1; transform: none; } }
.tag { margin: 6px 0 0; font-size: 15px; font-weight: 600; color: var(--fg); opacity: 0.86; letter-spacing: 0.02em; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }
.home-spacer { flex: 1; min-height: 24px; }
.home-bottom { width: min(100%, 400px); display: flex; flex-direction: column; gap: 12px; }
#btnPlay svg { margin-left: -6px; }
.home-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 12px;
  border-radius: 16px; border: 1px solid var(--line); background: rgba(16, 17, 23, 0.82); color: var(--fg); text-align: left;
  transition: transform 0.08s ease, background 0.15s;
}
.tile:hover { background: rgba(30, 32, 40, 0.9); }
.tile:active { transform: scale(0.97); }
.tile .tt { display: flex; flex-direction: column; min-width: 0; }
.tile b { font-size: 13px; font-weight: 800; letter-spacing: 0.08em; }
.tile small { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .ic { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.1); font-weight: 800; font-size: 16px; }
.swatch { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--sw-body, #f2f3f5); box-shadow: inset 0 0 0 5px var(--sw-acc, #ff4d5e), 0 0 0 1px rgba(255, 255, 255, 0.2); }
.new-dot { position: absolute; top: -7px; right: -4px; padding: 2px 6px; border-radius: 8px; background: var(--hold); color: #1a1205; font-size: 9px; font-weight: 800; letter-spacing: 0.12em; }
.next-unlock { padding: 2px 4px 0; }
.nu-top { display: flex; justify-content: space-between; gap: 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; color: var(--dim); }
.nu-top b { color: var(--fg); margin-left: 4px; }
.nu-bar { margin-top: 6px; height: 5px; border-radius: 3px; background: var(--faint); overflow: hidden; }
.nu-bar i { display: block; height: 100%; width: 0; background: var(--hold); border-radius: 3px; transition: width 0.6s cubic-bezier(.2, .8, .2, 1); }
.loading-line { position: fixed; top: calc(60px + var(--sat)); left: 0; right: 0; text-align: center; font-size: 11px; letter-spacing: 0.16em; color: var(--dim); pointer-events: none; }

/* panels */
.panel { width: min(100%, 600px); margin: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 26px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8); }
.panel.narrow { width: min(100%, 380px); }
.panel h2 { margin: 0 0 6px; font-size: 24px; font-weight: 800; font-style: italic; letter-spacing: -0.01em; }
.panel .row { display: flex; gap: 10px; }
.panel .row .btn { flex: 1; }

/* garage */
.garage-panel { width: min(100%, 560px); gap: 10px; padding: 18px; max-height: calc(100vh - 32px - var(--sat) - var(--sab)); max-height: calc(100dvh - 32px - var(--sat) - var(--sab)); }
.gp-head { display: flex; align-items: center; gap: 12px; }
.gp-head h2 { margin: 0; flex: 1; }
.gp-count { font-size: 13px; font-weight: 700; color: var(--dim); font-variant-numeric: tabular-nums; }
.gp-stage { display: flex; flex-direction: column; align-items: center; padding: 4px 0 2px; border-radius: 16px; background: radial-gradient(60% 70% at 50% 60%, rgba(255, 255, 255, 0.07), transparent 70%); }
#carPreview { width: 240px; height: 120px; }
.gp-name { font-size: 15px; font-weight: 800; letter-spacing: 0.24em; padding-left: 0.24em; margin-top: -4px; }
.gp-hint { font-size: 12px; color: var(--dim); min-height: 16px; }
.gp-hint.locked { color: var(--hold); }
.gp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; overflow-y: auto; min-height: 120px; padding: 2px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.liv-cell { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px 7px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--fg); }
.liv-cell canvas { width: 88px; height: 47px; }
.liv-cell .n { font-size: 10px; font-weight: 800; letter-spacing: 0.1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.liv-cell .s { font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }
.liv-cell.locked .n { color: var(--dim); }
.liv-cell.locked .s::before { content: "🔒 "; }
.liv-cell.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: rgba(255, 77, 94, 0.1); }
.liv-cell.view:not(.sel) { border-color: rgba(255, 255, 255, 0.35); }
.liv-cell .new-dot { top: -6px; right: -3px; }

/* how to play */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.card h3 { margin: 6px 0 4px; font-size: 15px; font-weight: 800; }
.card p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--dim); }
.ill { width: 100%; height: 70px; }
.ill .road { fill: none; stroke: #2a2d36; stroke-width: 16; stroke-linecap: round; stroke-linejoin: round; }
.ill .road.hold { stroke: #3a3220; }
.ill .gate { stroke: var(--accent); stroke-width: 4; stroke-linecap: round; }
.ill .gate.y { stroke: var(--hold); }
.ill .dot { fill: #fff; }
.ill .arc { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 5 6; stroke-linecap: round; }
.how-bar { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 16px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.how-bar p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--dim); }
.how-bar p b { color: var(--fg); }
.mini-bar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 6px; font-size: 9px; font-weight: 800; letter-spacing: 0.1em; }
.mini-bar i { height: 6px; border-radius: 3px; background: var(--faint); overflow: hidden; }
.mini-bar i b { display: block; height: 100%; width: 70%; background: var(--accent); animation: fillDemo 2.6s ease-in-out infinite; }
@keyframes fillDemo { 0% { width: 8%; } 80%, 100% { width: 100%; } }
.keys { margin: 4px 0 0; font-size: 12px; color: var(--dim); text-align: center; }
.keys b { color: var(--fg); font-weight: 600; }
@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; gap: 8px; }
  .card { display: grid; grid-template-columns: 88px 1fr; column-gap: 12px; align-items: center; padding: 10px 12px; }
  .card .ill { grid-row: span 2; height: 56px; }
  .card h3 { margin: 0; }
  .how-bar { grid-template-columns: 1fr; gap: 8px; }
}

.pause-stats { font-size: 13px; color: var(--dim); margin-top: -6px; font-variant-numeric: tabular-nums; }

/* results */
.results { gap: 14px; }
.res-title { font-size: clamp(40px, 9vw, 64px); font-weight: 900; font-style: italic; line-height: 0.95; letter-spacing: -0.03em; }
.res-title.win { color: var(--hold); text-shadow: -0.06em 0 0 rgba(255, 77, 94, 0.5); }
.res-sub { font-size: 14px; color: var(--dim); margin-top: 4px; }
.res-main { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.res-main > div { border-radius: 14px; padding: 10px 14px; background: rgba(255, 255, 255, 0.04); }
.res-main .label { font-size: 10px; font-weight: 700; letter-spacing: 0.22em; color: var(--dim); }
.res-score .val { font-size: clamp(30px, 7vw, 44px); font-weight: 800; font-style: italic; line-height: 1.05; font-variant-numeric: tabular-nums; }
.res-best .val { font-size: clamp(20px, 4.4vw, 28px); font-weight: 800; font-style: italic; line-height: 1.2; font-variant-numeric: tabular-nums; color: var(--dim); }
.badge { display: inline-block; margin-top: 2px; font-size: 10px; font-weight: 800; letter-spacing: 0.18em; padding: 4px 8px; border-radius: 6px; background: var(--hold); color: #1a1205; }
.res-unlock { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; row-gap: 6px; padding: 10px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.res-unlock #resCar { grid-row: span 2; }
.res-unlock #btnUseCar { grid-column: 2; justify-self: start; }
.res-unlock.got { border-color: var(--hold); background: rgba(255, 176, 32, 0.1); }
#resCar { flex: none; width: 100px; height: 51px; }
.ru-txt { flex: 1; min-width: 0; }
.ru-k { font-size: 10px; font-weight: 800; letter-spacing: 0.2em; color: var(--dim); }
.res-unlock.got .ru-k { color: var(--hold); }
.ru-n { font-size: 16px; font-weight: 800; letter-spacing: 0.06em; line-height: 1.2; }
.ru-bar { margin: 5px 0 3px; height: 5px; border-radius: 3px; background: var(--faint); overflow: hidden; }
.ru-bar i { display: block; height: 100%; width: 0; background: var(--hold); border-radius: 3px; transition: width 1s cubic-bezier(.2, .8, .2, 1); }
.ru-s { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.res-grid div { background: rgba(255, 255, 255, 0.04); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; }
.res-grid span { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; color: var(--dim); text-transform: uppercase; }
.res-grid b { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.c-p { color: var(--accent); } .c-m { color: #ff7a84; }
.res-sync { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-size: 13px; color: var(--dim); }
.res-sync.done { color: var(--fg); }
.res-sync .btn { flex: none; }
.res-btns { display: flex; flex-direction: column; gap: 10px; }
.res-btns .btn.primary { font-size: 19px; padding: 15px; }

/* settings */
.settings .field { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 12px; font-size: 14px; }
.settings .field > span { color: var(--dim); }
.settings output { font-size: 13px; min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.settings .offset { grid-template-columns: 110px 1fr auto; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); font-size: 18px; }
.stepper output { min-width: 60px; text-align: center; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; touch-action: pan-x; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--fg); border: 0; }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--fg); border: 0; }
.seg { display: flex; background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 3px; grid-column: span 2; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 0; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--dim); }
.seg button.on { background: rgba(255, 255, 255, 0.14); color: var(--fg); }
.toggle { display: flex; align-items: center; gap: 12px; font-size: 14px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 40px; height: 24px; border-radius: 12px; background: rgba(255, 255, 255, 0.14); position: relative; transition: background 0.15s; flex: none; }
.toggle i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(16px); }
.toggle input:focus-visible + i { outline: 2px solid var(--fg); outline-offset: 2px; }
.setlist { margin-top: 2px; border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 5px; text-align: left; }
.setlist .hd { font-size: 10px; font-weight: 700; letter-spacing: 0.2em; color: var(--dim); display: flex; justify-content: space-between; }
.setlist .tr { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: baseline; font-size: 12px; }
.setlist .tr .n { color: var(--accent); font-weight: 800; font-style: italic; }
.setlist .tr .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.setlist .tr .t small { color: var(--dim); margin-left: 6px; }
.setlist .tr .d { color: var(--dim); font-variant-numeric: tabular-nums; }

/* calibration */
.calib { text-align: center; align-items: center; }
.calib p { margin: 0; color: var(--dim); font-size: 14px; }
.calib-ring { position: relative; width: 140px; height: 140px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; margin: 8px 0; }
.calib-ring .dot { position: absolute; inset: 14px; border-radius: 50%; background: var(--accent); opacity: 0.15; transform: scale(0.6); }
.calib-ring .dot.beat { animation: beat 0.35s ease-out; }
@keyframes beat { from { opacity: 0.9; transform: scale(1); } to { opacity: 0.15; transform: scale(0.6); } }
.calib-ring .num { position: relative; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.calib-res { min-height: 20px; font-weight: 700; }
.calib .row { width: 100%; }

#loader { position: fixed; inset: 0; z-index: 9; display: grid; place-content: center; justify-items: center; gap: 12px; background: rgba(6, 7, 10, 0.6); font-size: 13px; letter-spacing: 0.12em; color: var(--dim); }
.spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#err { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%); z-index: 10; background: #2a0f13; border: 1px solid #ff4d5e66; color: #ffd3d7; padding: 10px 14px; border-radius: 10px; font-size: 13px; max-width: 90vw; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; }

/* small landscape phones */
@media (max-height: 520px) and (orientation: landscape) {
  .home { padding-top: calc(8px + var(--sat)); padding-bottom: calc(10px + var(--sab)); }
  .home-hero { margin-top: -8px; }
  .logo { font-size: 58px; }
  .tag { font-size: 13px; margin-top: 2px; }
  .home-bottom { width: min(100%, 580px); display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px 12px; align-items: stretch; }
  .home-bottom #btnPlay { grid-row: span 2; font-size: 22px; }
  .home-row { grid-column: 2; }
  .home-row .tile { min-height: 50px; padding: 6px 10px; }
  .next-unlock { grid-column: 2; }
  .hud-bottom { padding-bottom: calc(14px + var(--sab)); }
  .panel { padding: 16px; }
  .results { gap: 8px; }
  .res-title { font-size: 34px; }
  .res-grid b { font-size: 16px; }
  .res-grid div { padding: 5px 10px; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  .card { display: block; padding: 10px; }
  .card .ill { height: 46px; }
  .card p { font-size: 12px; }
  .garage-panel { flex-direction: row; flex-wrap: wrap; }
  .gp-head { width: 100%; }
  .gp-stage { width: 40%; justify-content: center; }
  #carPreview { width: 200px; height: 100px; }
  .gp-grid { flex: 1; max-height: calc(100vh - 140px); }
  #btnGarageDone { width: 100%; padding: 9px; }
  /* the judgment pop owns the bottom-centre in landscape: coach from the left edge instead */
  .coach-tap, .coach-grip { left: calc(16px + var(--sal)); bottom: auto; top: 46%; transform: translate(0, 6px); white-space: normal; max-width: 30vw; text-align: left; }
  .coach-tap.on, .coach-grip.on { transform: translate(0, 0); }
  .coach-grip .arrow.down { display: none; }
}
/* short portrait phones: everything on one screen */
@media (max-height: 720px) and (orientation: portrait) {
  .panel { padding: 18px; gap: 9px; }
  .panel h2 { font-size: 21px; margin-bottom: 2px; }
  .cards { gap: 6px; }
  .card { padding: 8px 10px; }
  .card .ill { height: 46px; }
  .card p, .how-bar p { font-size: 12px; line-height: 1.38; }
  .how-bar { padding: 9px 12px; gap: 6px; }
  .keys { display: none; }
  .results { gap: 9px; }
  .res-title { font-size: 38px; }
  .res-main > div { padding: 8px 12px; }
  .res-unlock { padding: 8px 12px; }
  .res-grid div { padding: 6px 10px; }
  .res-grid b { font-size: 16px; }
  .res-btns .btn.primary { padding: 12px; font-size: 17px; }
  .res-btns .btn { padding: 10px 14px; }
}
@media (max-width: 380px) {
  .hud-top { gap: 10px; }
  .score { min-width: 76px; }
  .res-grid b { font-size: 17px; }
  .settings .field { grid-template-columns: 90px 1fr auto; }
  .tile { gap: 8px; padding: 8px 10px; }
  .tile b { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .logo span { animation: none; }
  .finger::after, .mini-bar i b { animation: none; }
}
