:root {
  --ink: #12151c;
  --panel: rgba(16, 20, 28, 0.86);
  --panel-solid: #161b25;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f1f3f7;
  --muted: #a7b0c0;
  --yellow: #ffc531;
  --red: #e23b3b;
  --blue: #4fb3ff;
  --display: 'Racing Sans One', 'Arial Black', sans-serif;
  --body: 'Barlow Semi Condensed', 'Arial Narrow', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9cc8f0; color: var(--text); font-family: var(--body); }
canvas#game { position: fixed; inset: 0; display: block; }
button { font-family: var(--body); }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- setup ---------- */
.setup { position: fixed; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px); gap: 24px; padding: 28px; background: linear-gradient(90deg, rgba(10, 14, 22, 0) 30%, rgba(10, 14, 22, 0.55) 62%); }
.setup[hidden] { display: none; }
.brand { align-self: start; display: flex; flex-direction: column; gap: 6px; }
.back { color: #fff; text-decoration: none; font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }
.back:hover, .back:focus-visible { text-decoration: underline; }
.brand h1 { margin: 8px 0 0; font-family: var(--display); font-weight: 400; font-size: clamp(56px, 8vw, 110px); line-height: 0.9; letter-spacing: 0.01em; color: #fff; text-shadow: 0 4px 0 var(--red), 0 8px 24px rgba(0, 0, 0, 0.35); transform: skewX(-6deg); }
.brand h1 span { color: var(--yellow); }
.tagline { margin: 6px 0 0; font-size: 20px; font-weight: 600; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }
.panel { align-self: stretch; overflow-y: auto; padding: 18px 20px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.panel h2 { margin: 6px 0 0; font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.picks { display: grid; gap: 8px; }
.tracks { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.opponents { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pick { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 12px; border: 2px solid transparent; background: rgba(255, 255, 255, 0.06); color: var(--text); text-align: left; cursor: pointer; min-width: 0; }
.pick:hover { background: rgba(255, 255, 255, 0.1); }
.pick[aria-pressed="true"] { border-color: var(--yellow); background: rgba(255, 197, 49, 0.12); }
.pick b { font-size: 18px; font-weight: 700; line-height: 1.1; }
.pick small { font-size: 13.5px; color: var(--muted); line-height: 1.3; }
.pick canvas { width: 100%; max-width: 120px; aspect-ratio: 1; align-self: center; border-radius: 8px; background: rgba(95, 154, 69, 0.55); }
.swatch { width: 100%; height: 8px; border-radius: 4px; background: var(--c); margin-bottom: 4px; }
.stats { display: flex; flex-direction: column; gap: 3px; width: 100%; margin-top: 4px; font-size: 12px; color: var(--muted); }
.stats span { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 6px; }
.stats i { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--yellow) var(--v), rgba(255, 255, 255, 0.12) var(--v)); }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.toggle { display: inline-flex; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.08); }
.toggle button { min-height: 36px; padding: 0 16px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 16px; font-weight: 600; cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--text); color: var(--ink); }
.best { margin: 0; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.go { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--yellow); color: #231a00; font-family: var(--display); font-size: 26px; cursor: pointer; box-shadow: 0 4px 0 #b88a12; }
.go small { font-family: var(--body); font-size: 14px; font-weight: 700; opacity: 0.7; }
.go:hover { filter: brightness(1.05); }
.keys { margin: 2px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--muted); }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud[hidden] { display: none; }
.box { padding: 6px 14px 8px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; }
.box span { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
.box b { font-size: 30px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.tl { position: absolute; left: 18px; top: 18px; display: flex; flex-direction: column; gap: 8px; }
.oppbox b { font-size: 20px; color: var(--blue); }
.oppbox[hidden] { display: none; }
.tr { position: absolute; right: 18px; top: 18px; }
.map { position: relative; width: 170px; height: 170px; border-radius: 14px; background: rgba(16, 20, 28, 0.55); border: 1px solid var(--line); }
.map canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.br { position: absolute; right: 18px; bottom: 18px; }
.cluster { display: grid; grid-template-columns: auto auto; grid-template-areas: "tach tach" "speed gear"; gap: 6px 14px; padding: 12px 16px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); min-width: 230px; }
.tach { grid-area: tach; height: 10px; border-radius: 5px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.tach i { display: block; height: 100%; width: calc(var(--rpm, 0) * 100%); background: linear-gradient(90deg, #6fdc8c, var(--yellow) 70%, var(--red)); }
.tach.red i { animation: blink 0.15s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
.readout { grid-area: speed; display: flex; align-items: baseline; gap: 6px; }
.readout b { font-family: var(--display); font-weight: 400; font-size: 56px; line-height: 0.95; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.readout span { color: var(--muted); font-weight: 600; }
.gearbox { grid-area: gear; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 6px; border-left: 1px solid var(--line); }
.gearbox span { font-size: 11px; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; }
.gearbox b { font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1; color: var(--yellow); }
.bl { position: absolute; left: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 2px; padding: 8px 14px; border-radius: 12px; background: rgba(16, 20, 28, 0.6); }
.bl b { font-size: 16px; }
.bl span { font-size: 13px; color: var(--muted); }
.msg { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%) skewX(-6deg); font-family: var(--display); font-size: clamp(48px, 9vw, 120px); color: #fff; text-shadow: 0 4px 0 var(--red), 0 10px 30px rgba(0, 0, 0, 0.45); white-space: nowrap; }
.msg[hidden] { display: none; }
.replaybar { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 8px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; color: var(--muted); white-space: nowrap; }
.replaybar b { color: var(--red); letter-spacing: 0.12em; }
.replaybar[hidden] { display: none; }
/* cockpit view: a dashboard across the bottom */
.dash { display: none; position: absolute; left: 0; right: 0; bottom: 0; height: 26%; background: radial-gradient(120% 140% at 50% 120%, #20242c 55%, #14171d 70%, rgba(20, 23, 29, 0) 71%); }
body.cockpit .dash { display: block; }
body.cockpit .br { right: 50%; transform: translateX(50%); bottom: 4%; }

/* ---------- overlays ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(10, 14, 22, 0.45); }
.screen[hidden] { display: none; }
.card { width: min(92vw, 460px); padding: 22px 26px; border-radius: 18px; background: var(--panel-solid); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 48px; color: var(--yellow); transform: skewX(-6deg); }
.card p { margin: 0; font-size: 18px; }
.reslines { display: flex; flex-direction: column; gap: 4px; font-variant-numeric: tabular-nums; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.actions button:not(.go) { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 18px; font-weight: 600; cursor: pointer; }
.actions button small { font-size: 14px; color: var(--muted); }

@media (max-width: 900px) {
  .setup { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); background: rgba(10, 14, 22, 0.35); padding: 16px; }
  .brand h1 { font-size: 56px; }
  .tracks, .cars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .map { width: 120px; height: 120px; }
}
@media (max-width: 560px) { .tracks, .cars, .opponents { grid-template-columns: minmax(0, 1fr); } .pick canvas { max-width: 90px; } }
@media (prefers-reduced-motion: reduce) { .tach.red i { animation: none; } }
