:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: #9aa8ba;
  --panel: rgba(8, 13, 22, 0.78);
  --line: rgba(46, 233, 255, 0.22);
  --hot: #ff315c;
  --cyan: #2ee9ff;
  --gold: #ffd166;
}

/* Color-blind palette — swap red/green pairs for blue/orange + brighter
   contrast. Activated by .is-colorblind on body. */
body.is-colorblind {
  --hot: #ff8c2e;       /* orange instead of red */
  --cyan: #5ec8ff;      /* lighter cyan, easier with deuteranopia */
  --gold: #ffe24a;      /* brighter yellow */
  --line: rgba(94, 200, 255, 0.34);
}

/* Reduced motion — disables shake animations / heavy transforms. */
body.is-reduce-motion .race-callout,
body.is-reduce-motion .countdown-num {
  animation: none !important;
  transition: opacity 120ms ease !important;
}
body.is-reduce-motion .gear-pill { animation: none !important; }
body.is-reduce-motion .toast { animation: toast-in 240ms ease-out forwards; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 20% 10%, rgba(255,49,92,0.18), transparent 35%),
              radial-gradient(circle at 80% 90%, rgba(46,233,255,0.18), transparent 35%),
              #060710;
}

.shell { height: 100%; display: grid; place-items: center; padding: clamp(8px, 2vw, 24px); }

/* Victory confetti — pure CSS, position fixed to viewport. Active when
   body has .is-victory. Strips of color sweep down + rotate. */
body.is-victory::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(45deg, transparent 0 24px, rgba(46,233,255,0.18) 24px 28px),
    repeating-linear-gradient(-45deg, transparent 0 28px, rgba(255,49,92,0.16) 28px 32px),
    repeating-linear-gradient(0deg, transparent 0 16px, rgba(255,209,102,0.14) 16px 20px);
  animation: victory-flash 4s ease-out forwards;
}

@keyframes victory-flash {
  0%   { opacity: 0; transform: translateY(-20px); }
  10%  { opacity: 1; transform: translateY(0); }
  90%  { opacity: 0.6; }
  100% { opacity: 0; }
}

/* Splash screen */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,49,92,0.20), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(46,233,255,0.20), transparent 45%),
    #060710;
  transition: opacity 280ms ease;
}

.splash.is-fading {
  opacity: 0;
  pointer-events: none;
}

.splash-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.splash-eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.20em;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--cyan);
}

.splash-title {
  margin: 0;
  font-size: clamp(48px, 9vw, 96px);
  line-height: 0.92;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 5px 5px 0 rgba(255, 49, 92, 0.78), -3px -3px 0 rgba(46, 233, 255, 0.55);
}

.splash-loader {
  width: 220px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.splash-loader > span {
  display: block;
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--hot));
  animation: splash-loader 1.2s ease-in-out infinite;
}

@keyframes splash-loader {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(380%); }
}

.splash-status {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
}

.game-frame {
  position: relative;
  width: min(100%, 1400px);
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  overflow: hidden;
  background: #02040a;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

#game { display: block; width: 100%; height: 100%; }

/* Top-left compact strip */
.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 6px;
  align-items: stretch;
  pointer-events: none;
  z-index: 3;
}

.hud-top { gap: 6px; }

.hud-stack {
  pointer-events: auto;
  min-width: 56px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  display: grid;
  align-content: center;
}

.label {
  display: block;
  color: rgba(46, 233, 255, 0.78);
  font-size: 9px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  font-weight: 900;
}

.hud strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  line-height: 1;
  font-weight: 900;
}

.hud small {
  color: var(--muted);
  font-size: 10px;
  margin-left: 2px;
}

/* Top-right action buttons (mute / pause / back) */
.hud-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  z-index: 3;
}

.hud-actions .back-link {
  margin: 0;
  pointer-events: auto;
}

/* Center-top status pills (combo, draft) — only shown when active */
.hud-pills {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 3;
  pointer-events: none;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 900;
}

.hud-pill .label { font-size: 9px; }
.hud-pill strong { font-size: 14px; font-weight: 900; }

.back-link {
  margin-left: auto;
  pointer-events: auto;
  align-self: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.back-link:hover { color: var(--cyan); border-color: var(--cyan); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 49, 92, 0.22), transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(46, 233, 255, 0.18), transparent 50%),
    rgba(5, 8, 15, 0.94);
  z-index: 4;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay[hidden] { display: none !important; }

.title-card {
  width: min(620px, 100%);
  margin: auto 0;
  padding: 24px 28px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(8, 13, 22, 0.88);
  text-align: left;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(24px, 4vw, 42px);
  letter-spacing: -0.01em;
  line-height: 1.05;
}

.title-card p {
  margin: 6px 0;
  color: #c4cfdf;
  line-height: 1.4;
}

.title-card .small {
  font-size: 12px;
  color: var(--muted);
  margin-top: 12px;
}

button {
  margin-top: 16px;
  padding: 12px 22px;
  background: linear-gradient(135deg, rgba(255, 49, 92, 0.95), rgba(255, 143, 31, 0.95));
  color: white;
  font: inherit;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(255, 49, 92, 0.32);
}

button:hover { filter: brightness(1.08); }

.leaderboard {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 152px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  z-index: 3;
}

.leaderboard ol {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 3px;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 800;
  color: #dce6f4;
  background: rgba(255, 255, 255, 0.05);
}

.leaderboard li.is-player {
  color: #05070c;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

.boost-wrap {
  min-width: 140px;
  display: grid;
  align-content: center;
}

.boost-meter {
  height: 8px;
  margin-top: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}

.boost-meter > span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--hot));
  box-shadow: 0 0 12px rgba(46, 233, 255, 0.6);
  transition: width 80ms linear;
}

.heat-meter > span {
  background: linear-gradient(90deg, #4adf80, var(--gold), var(--hot));
  box-shadow: 0 0 10px rgba(255, 49, 92, 0.4);
}

.heat-meter.is-overheating {
  box-shadow: 0 0 0 1px var(--hot) inset;
  animation: heat-pulse 0.4s ease-in-out infinite alternate;
}

@keyframes heat-pulse {
  from { background: rgba(255, 49, 92, 0.18); }
  to   { background: rgba(255, 49, 92, 0.42); }
}

.track-picker, .mode-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 16px;
}

.mode-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 22, 0.78);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  transition: border-color 100ms ease, transform 80ms ease;
}

.mode-card[aria-checked="true"] {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan) inset, 0 6px 18px rgba(46, 233, 255, 0.18);
  background: linear-gradient(155deg, rgba(46, 233, 255, 0.16), rgba(8, 13, 22, 0.85));
}

.mode-card .name {
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mode-card .desc {
  margin: 0;
  color: #c4cfdf;
  font-size: 11px;
  line-height: 1.3;
}

.track-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 22, 0.78);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  text-transform: none;
  letter-spacing: 0;
  box-shadow: none;
  margin: 0;
  transition: border-color 100ms ease, transform 80ms ease;
}

.track-card:hover {
  transform: translateY(-1px);
  border-color: rgba(46, 233, 255, 0.6);
}

.track-card[aria-checked="true"] {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan) inset, 0 6px 18px rgba(46, 233, 255, 0.18);
  background: linear-gradient(155deg, rgba(46, 233, 255, 0.16), rgba(8, 13, 22, 0.85));
}

.track-card .name {
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.track-card .desc {
  margin: 0;
  color: #c4cfdf;
  font-size: 11px;
  line-height: 1.3;
}

.track-card .swatch {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}

.track-card .swatch span {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.minimap {
  position: absolute;
  right: 14px;
  top: 56px;
  width: 132px;
  height: 88px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(8, 13, 22, 0.78);
  backdrop-filter: blur(12px);
  z-index: 3;
}

.combo-stack {
  border-color: rgba(255, 209, 102, 0.45);
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.25) inset, 0 0 14px rgba(255, 209, 102, 0.18);
}

.combo-stack .label {
  color: rgba(255, 209, 102, 0.92);
}

.combo-stack strong {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.55);
}

.combo-stack.is-hot strong {
  color: var(--hot);
  text-shadow: 0 0 14px rgba(255, 49, 92, 0.7);
}

.race-callout {
  position: absolute;
  left: 50%;
  top: 36%;
  transform: translate(-50%, -50%) scale(1);
  z-index: 5;
  color: white;
  font-size: clamp(36px, 6vw, 72px);
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0;
  line-height: 0.95;
  pointer-events: none;
  opacity: 0;
  text-shadow:
    4px 4px 0 rgba(255, 49, 92, 0.85),
    -3px -3px 0 rgba(46, 233, 255, 0.7),
    0 0 36px rgba(255, 255, 255, 0.3);
  transition: opacity 200ms ease;
}

.race-callout.is-visible { opacity: 1; }

.start-lights {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  padding: 14px 22px;
  border: 1px solid rgba(46, 233, 255, 0.35);
  border-radius: 10px;
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(10px);
  z-index: 5;
}

.start-lights span {
  width: clamp(18px, 2vw, 28px);
  height: clamp(18px, 2vw, 28px);
  border-radius: 50%;
  background: rgba(255, 49, 92, 0.12);
  border: 1px solid rgba(255, 49, 92, 0.25);
}

.start-lights span.is-lit {
  background: #ff315c;
  box-shadow: 0 0 18px rgba(255, 49, 92, 0.85);
}

.start-lights[hidden] { display: none !important; }

.garage-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.garage-row span {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.garage-row input[type="text"] {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 13, 22, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
}

.garage-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 4px;
}

.garage-stats div {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 13, 22, 0.78);
  text-align: center;
}

.garage-stats .label {
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.garage-stats .value {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  font-weight: 900;
}

.garage-cars {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.garage-car {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 13, 22, 0.78);
  display: grid;
  gap: 8px;
}

.garage-car .name {
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 13px;
}

.garage-car .pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.garage-car .pickers label {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 6px;
  align-items: center;
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--muted);
}

.garage-car .pickers input[type="color"] {
  width: 100%;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  background: transparent;
  padding: 2px;
  cursor: pointer;
}

.garage-car .pickers select {
  width: 100%;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: rgba(2, 4, 10, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  cursor: pointer;
}

.garage-car .pickers select:focus {
  outline: none;
  border-color: var(--cyan);
}

.garage-car .pickers .spoiler-pick {
  grid-column: 1 / -1;
}

/* ---- Speedometer cluster (bottom-left) ---- */
.speedo {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: 168px;
  height: 110px;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 4px 18px rgba(46, 233, 255, 0.18));
}

.speedo svg { display: block; }

.speedo-readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 4px;
  pointer-events: none;
}

.speedo-readout strong {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  text-shadow: 0 0 14px rgba(46, 233, 255, 0.35);
}

.speedo-readout .unit {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 1px;
}

.gear-pill {
  position: absolute;
  bottom: 0;
  right: 6px;
  min-width: 22px;
  text-align: center;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 900;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--cyan), var(--gold));
  color: #05070c;
  box-shadow: 0 0 12px rgba(46, 233, 255, 0.45);
}

.speedo-meters {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -38px;
  padding: 0 6px;
  display: grid;
  gap: 4px;
  pointer-events: none;
}

.meter-row {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 6px;
  align-items: center;
}

.meter-label {
  font-size: 8px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: rgba(46, 233, 255, 0.75);
}

.gear-pill.is-shifting { animation: shift-pulse 0.18s ease-out; }

.rpm-readout {
  position: absolute;
  bottom: 22px;
  right: 8px;
  font-size: 9px;
  font-family: ui-monospace, monospace;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--muted);
}

@keyframes shift-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.18); filter: brightness(1.4); }
  100% { transform: scale(1); }
}

/* Damage flash — red border + brief shake when player hits a barrier. */
body.is-damaged .game-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  box-shadow: inset 0 0 0 6px rgba(255, 49, 92, 0.85),
              inset 0 0 80px rgba(255, 49, 92, 0.40);
  animation: damage-flash 0.45s ease-out forwards;
}

@keyframes damage-flash {
  0%   { opacity: 1; }
  60%  { opacity: 0.6; }
  100% { opacity: 0; }
}

/* Drift score float — number drifts up + fades. */
.drift-popup {
  position: absolute;
  pointer-events: none;
  font-size: 18px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.85);
  animation: drift-pop 0.9s ease-out forwards;
  z-index: 5;
}

@keyframes drift-pop {
  0%   { transform: translate(-50%, 0)    scale(0.8); opacity: 0; }
  20%  { transform: translate(-50%, -10px) scale(1.0); opacity: 1; }
  100% { transform: translate(-50%, -64px) scale(1.05); opacity: 0; }
}

/* Slipstream FX — subtle cyan radial pulse when drafting. */
body.is-drafting .game-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 38%, rgba(46,233,255,0.0) 35%, rgba(46,233,255,0.10) 60%, rgba(46,233,255,0.16) 100%);
  z-index: 2;
  mix-blend-mode: screen;
  animation: drafting-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes drafting-pulse {
  from { opacity: 0.6; }
  to   { opacity: 1.0; }
}

/* ---- Boost FX overlay ---- */
.boost-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms linear;
  z-index: 2;
  background:
    radial-gradient(ellipse at center, transparent 35%, rgba(255, 49, 92, 0.18) 75%, rgba(255, 49, 92, 0.42) 100%);
}

.boost-fx.is-active { opacity: 1; }

.boost-fx .speedlines {
  position: absolute;
  inset: 0;
  background-image:
    repeating-radial-gradient(circle at 50% 50%,
      rgba(255, 255, 255, 0.0) 0 8%,
      rgba(255, 255, 255, 0.06) 8% 9%,
      rgba(255, 255, 255, 0.0) 9% 18%);
  mask-image: radial-gradient(ellipse at center, transparent 30%, #000 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 30%, #000 75%);
  animation: speedlines 0.6s linear infinite;
}

@keyframes speedlines {
  0%   { transform: scale(1.0); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ---- Tutorial control grid ---- */
.control-grid {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}

.control-grid li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 13, 22, 0.68);
  font-size: 12px;
}

.control-grid kbd {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 6px;
  border: 1px solid rgba(255,255,255,0.2);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  color: var(--ink);
}

.control-grid span {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
}

/* ---- Settings rows ---- */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 13, 22, 0.68);
  font-weight: 700;
  font-size: 13px;
}

.settings-row > span {
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
}

.settings-row select,
.settings-row input[type="range"] {
  width: 220px;
}

.settings-row input[type="range"] { accent-color: var(--cyan); }

.settings-row select {
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: rgba(2, 4, 10, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
}

/* ---- Final-lap glow on lap badge ---- */
.hud-stack.is-final {
  border-color: var(--hot);
  background: linear-gradient(180deg, rgba(255, 49, 92, 0.30), rgba(8, 13, 22, 0.85));
  animation: final-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes final-pulse {
  from { box-shadow: 0 0 0 0 rgba(255, 49, 92, 0.0); }
  to   { box-shadow: 0 0 18px 2px rgba(255, 49, 92, 0.45); }
}

/* ---- Responsive layout ---- */

/* Tablet portrait + small landscape — shrink everything a notch. */
@media (max-width: 900px) {
  .game-frame {
    aspect-ratio: auto;
    height: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .shell { padding: 0; }
  .hud { top: 8px; left: 8px; gap: 4px; }
  .hud-actions { top: 8px; right: 8px; gap: 4px; }
  .hud-pills { top: 8px; }
  .hud-stack { padding: 3px 8px; min-width: 48px; }
  .hud strong { font-size: 14px; }
  .speedo { left: 8px; bottom: 8px; width: 144px; height: 96px; }
  .speedo-readout strong { font-size: 20px; }
  .gear-pill { font-size: 11px; padding: 2px 6px; }
  .speedo-meters { bottom: -32px; }
  .leaderboard { right: 8px; bottom: 8px; width: 132px; padding: 6px 8px; }
  .leaderboard li { font-size: 10px; padding: 2px 6px; }
  .minimap { right: 8px; top: 44px; width: 110px; height: 70px; }
  .back-link { padding: 4px 8px; font-size: 11px; }
}

/* Phone-friendly pre-race: tighter cards, single-column on small widths. */
@media (max-width: 700px) {
  .title-card { padding: 18px 16px; }
  .title-card h1 { font-size: 28px; }
  .title-card p { font-size: 13px; }
  .track-picker, .mode-picker { gap: 6px; grid-template-columns: 1fr; }
  .mode-card, .track-card { padding: 8px 10px; }
  .mode-card .name, .track-card .name { font-size: 12px; }
  .mode-card .desc, .track-card .desc { font-size: 10px; }
  .track-preview { height: 50px; max-width: 100%; }
}

/* Phone portrait — stack things differently. */
@media (max-width: 540px) {
  .hud-stack { padding: 2px 6px; min-width: 40px; }
  .hud strong { font-size: 12px; }
  .label { font-size: 8px; }
  .speedo { width: 124px; height: 80px; }
  .speedo-readout strong { font-size: 18px; }
  .speedo-readout .unit { font-size: 8px; }
  .leaderboard { width: 110px; }
  .minimap { width: 92px; height: 58px; top: 38px; }
  .hud-pill { padding: 3px 8px; font-size: 10px; }
  .hud-pill strong { font-size: 11px; }
  .touch-btn { width: 56px; height: 56px; font-size: 22px; }
  .touch-pad { gap: 10px; bottom: 16px; }
  .touch-left { left: 14px; }
  .touch-right { right: 14px; gap: 10px; }
  /* Hide minimap on tiny screens to save space. */
  .minimap { display: none; }
  /* Hide back link on phones — Esc / pause covers it. */
  .hud-actions a.back-link { display: none; }
}

/* Phone landscape — use the wider screen, push touch pads out. */
@media (max-width: 900px) and (orientation: landscape) {
  .touch-left { left: 16px; bottom: 16px; }
  .touch-right { right: 16px; bottom: 16px; }
  .touch-btn { width: 60px; height: 60px; }
}

/* High-DPI tap targets — make every button comfortably 44px+. */
@media (pointer: coarse) {
  .back-link { min-height: 36px; padding: 8px 12px; }
  button, .mode-card, .track-card, .engine-card { min-height: 40px; }
  .touch-btn { width: 70px; height: 70px; font-size: 28px; }
}

/* Notch-aware safe area on phones with display cutouts. */
@supports (padding: env(safe-area-inset-top)) {
  .hud { padding-top: env(safe-area-inset-top); }
  .hud-actions { padding-top: env(safe-area-inset-top); }
  .speedo, .leaderboard { padding-bottom: env(safe-area-inset-bottom); }
  .touch-left { padding-left: env(safe-area-inset-left); }
  .touch-right { padding-right: env(safe-area-inset-right); }
}

/* ---- Mobile touch controls ---- */
.touch-pad {
  position: absolute;
  bottom: 24px;
  z-index: 4;
  display: flex;
  gap: 14px;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.touch-pad[hidden] { display: none; }

.touch-left { left: 24px; }
.touch-right { right: 24px; flex-direction: column; }

.touch-btn {
  margin: 0;
  width: 64px;
  height: 64px;
  font-size: 28px;
  font-weight: 900;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(8, 13, 22, 0.78);
  color: var(--ink);
  backdrop-filter: blur(10px);
  text-transform: none;
  letter-spacing: 0;
  box-shadow: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 60ms ease, background 80ms ease;
}

.touch-btn:active {
  transform: scale(0.92);
  background: rgba(46, 233, 255, 0.30);
}

.touch-throttle { background: rgba(46, 233, 255, 0.30); }
.touch-brake    { background: rgba(255, 49, 92, 0.28); }
.touch-boost    { background: rgba(255, 209, 102, 0.30); }
.touch-drift    { background: rgba(166, 108, 255, 0.30); }

/* Photo mode — hide HUD, leaderboard, minimap. Press P to toggle. */
body.is-photo-mode .hud,
body.is-photo-mode .hud-actions,
body.is-photo-mode .hud-pills,
body.is-photo-mode .speedo,
body.is-photo-mode .leaderboard,
body.is-photo-mode .minimap,
body.is-photo-mode .touch-pad {
  display: none !important;
}

body.is-replay .hud,
body.is-replay .hud-actions,
body.is-replay .hud-pills,
body.is-replay .speedo,
body.is-replay .leaderboard,
body.is-replay .minimap,
body.is-replay .touch-pad {
  display: none !important;
}

body.is-spectator::after {
  content: "SPECTATOR — V to exit";
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 999px;
  z-index: 10;
}

body.is-replay::after {
  content: "REPLAY — Esc to exit";
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  z-index: 10;
}

body.is-photo-mode::after {
  content: "PHOTO MODE — P to exit · ←→ orbit · ↑↓ zoom";
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  z-index: 10;
}

/* Track preview SVG inside the picker card */
.track-preview {
  width: 100%;
  max-width: 180px;
  height: 80px;
  margin: 6px 0;
  display: block;
  opacity: 0.92;
  filter: drop-shadow(0 0 8px rgba(46, 233, 255, 0.18));
}

.track-card[aria-checked="true"] .track-preview {
  opacity: 1;
}

/* Big animated countdown numbers */
.countdown-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
}

.countdown-num.is-show {
  animation: countdown-fade 0.6s ease-out forwards;
}

.countdown-num::after {
  content: attr(data-num);
  font-size: clamp(80px, 18vw, 220px);
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(46, 233, 255, 0.5),
               6px 6px 0 rgba(255, 49, 92, 0.6);
}

.countdown-num.is-go::after {
  color: #4adf80;
  text-shadow: 0 0 32px rgba(74, 223, 128, 0.8),
               6px 6px 0 rgba(255, 209, 102, 0.7);
}

@keyframes countdown-fade {
  0%   { transform: scale(0.5); opacity: 0; }
  20%  { transform: scale(1.0); opacity: 1; }
  80%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Pre-race rotating tip */
.race-tip {
  margin-top: 16px;
  padding: 8px 12px;
  border-left: 2px solid var(--cyan);
  background: rgba(46, 233, 255, 0.08);
  font-size: 11px;
  color: var(--ink);
  font-style: italic;
  line-height: 1.5;
}

.race-tip::before {
  content: "Tip · ";
  color: var(--cyan);
  font-weight: 900;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  font-size: 9px;
}

/* Rival driver-name labels — projected from world to screen each frame */
.rival-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.rival-label {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 13, 22, 0.78);
  backdrop-filter: blur(8px);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink);
  white-space: nowrap;
  line-height: 1.2;
  display: flex;
  gap: 6px;
  align-items: center;
}

.rival-label::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.rival-label.is-near { border-color: var(--cyan); }
.rival-label.is-far  { opacity: 0.4; }

/* Finish-screen time-trial leaderboard */
.finish-leaderboard {
  list-style: none;
  margin: 14px 0;
  padding: 0;
  display: grid;
  gap: 4px;
  font-family: ui-monospace, monospace;
}

.finish-leaderboard li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(8, 13, 22, 0.55);
  font-size: 13px;
  font-weight: 800;
  align-items: center;
}

.finish-leaderboard li:first-child {
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(255,209,102,0.18), rgba(8,13,22,0.55));
}

.finish-leaderboard li.empty {
  text-align: center;
  font-style: italic;
  color: var(--muted);
  grid-template-columns: 1fr;
}

.finish-leaderboard li > span:last-child {
  color: var(--cyan);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Tire grip indicator */
.grip-bar {
  position: absolute;
  left: 14px;
  bottom: 168px;
  width: 168px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 8px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 5px;
  z-index: 3;
  pointer-events: none;
}

.grip-meter {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

#grip-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--hot), var(--gold), #4adf80);
  transition: width 80ms linear;
}

/* Lap delta indicator (vs personal best) */
.lap-delta {
  position: absolute;
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 14px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  z-index: 3;
  pointer-events: none;
}

.lap-delta .label {
  font-size: 8px;
  color: var(--muted);
  letter-spacing: 0.10em;
}

.lap-delta strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  font-weight: 900;
  font-family: ui-monospace, monospace;
}

.lap-delta.is-faster strong { color: #4adf80; }
.lap-delta.is-slower strong { color: var(--hot); }

/* Sector split panel */
.sectors {
  position: absolute;
  left: 14px;
  top: 60px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 3;
  pointer-events: none;
}

.sector-row {
  display: grid;
  grid-template-columns: 26px 56px 50px;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  font-size: 10px;
  font-family: ui-monospace, monospace;
  font-weight: 800;
  align-items: center;
}

.sector-row.is-active {
  border-color: var(--cyan);
  background: rgba(46, 233, 255, 0.12);
}

.sector-label {
  color: rgba(46, 233, 255, 0.85);
  font-size: 9px;
}

.sector-time {
  color: var(--ink);
  text-align: right;
}

.sector-delta {
  font-size: 9px;
  text-align: right;
}

.sector-delta.is-faster { color: #4adf80; }
.sector-delta.is-slower { color: var(--hot); }

/* Achievement toasts */
.toast-stack {
  position: absolute;
  right: 16px;
  top: 60%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 8;
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--cyan);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(46,233,255,0.18), rgba(8,13,22,0.92));
  backdrop-filter: blur(12px);
  color: var(--ink);
  min-width: 200px;
  max-width: 280px;
  animation: toast-in 240ms ease-out forwards, toast-out 380ms ease-in 4.6s forwards;
  box-shadow: 0 8px 22px rgba(46,233,255,0.18);
}

.toast .label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 4px;
  letter-spacing: 0.14em;
}

.toast strong {
  display: block;
  font-size: 14px;
  font-weight: 900;
  margin-bottom: 2px;
}

.toast small { font-size: 11px; color: var(--muted); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* FPS overlay */
.fps-overlay {
  position: absolute;
  top: 14px;
  right: 50%;
  transform: translateX(50%);
  margin-top: 32px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 900;
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  z-index: 6;
  font-family: ui-monospace, monospace;
}

/* ---- Race callout (centered notification) ---- */
.race-callout {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  padding: 14px 26px;
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(8, 13, 22, 0.85);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-shadow: 0 0 18px rgba(255, 209, 102, 0.6);
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, transform 220ms cubic-bezier(.2,.9,.2,1.1);
  z-index: 5;
}

.race-callout.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.garage-actions, .prerace-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 18px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: none;
}

.ghost-btn:hover { border-color: var(--cyan); color: var(--cyan); }

.title-card .small {
  font-size: 11px;
  color: var(--muted);
  margin: 16px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
}
