:root {
  color-scheme: dark;
  --ink: #101923;
  --cream: #f4e7c7;
  --teal: #73d5c7;
  --cyan: #8aefff;
  --amber: #f9a45e;
  --red: #ff6b55;
  --muted: #a5b8ba;
  --panel: #0f1b24e6;
  --line: #f4e7c726;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--cream);
  background: var(--ink);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--ink); overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
kbd { display: inline-block; min-width: 1.6em; padding: 2px 5px; border: 1px solid #f4e7c755; border-bottom-width: 2px; border-radius: 4px; font: 700 10px/1.2 Arial, sans-serif; text-align: center; color: var(--cream); background: #ffffff0d; }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- Start screen ---------- */
.screen { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; }
#menu { background: linear-gradient(90deg, #101923f2 0%, #101923d9 34%, #10192366 62%, transparent 85%), linear-gradient(0deg, #101923d0, transparent 35%); overflow-y: auto; }
.masthead { display: flex; justify-content: space-between; align-items: center; padding: calc(26px + var(--safe-t)) calc(4.8vw + var(--safe-r)) 10px calc(4.8vw + var(--safe-l)); }
.brand { display: flex; gap: 13px; align-items: center; font-size: 13px; font-weight: 700; letter-spacing: 2px; line-height: 1.4; }
.brand svg { width: 38px; height: 38px; stroke: var(--cream); stroke-width: 1.3; }
.brand b { font-size: 8px; letter-spacing: 2.1px; font-weight: 400; opacity: .55; }
.edition { font-size: 9px; letter-spacing: 1.8px; color: #b7b2a9; }
.edition i { margin: 0 12px; font-style: normal; color: #70cdbd; }
.menu-body { flex: 1; display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 340px); justify-content: space-between; gap: 5vw; align-items: center; padding: 10px calc(4.8vw + var(--safe-r)) calc(28px + var(--safe-b)) calc(8vw + var(--safe-l)); }
.eyebrow { display: flex; align-items: center; gap: 11px; margin: 0 0 18px; font-size: 9px; letter-spacing: 2.5px; color: #79d5c7; }
.eyebrow span { width: 20px; height: 1px; background: currentColor; }
h1 { margin: 0 0 18px -4px; font-family: Impact, 'Arial Black', sans-serif; font-size: clamp(64px, 7.4vw, 120px); font-weight: 900; line-height: .88; letter-spacing: -.035em; }
h1 > span { color: var(--teal); }
h1 .title-dot { color: var(--amber); }
.tagline { font-size: clamp(19px, 1.9vw, 27px); line-height: 1.25; letter-spacing: -.5px; margin: 0 0 12px; }
.description { font-size: 13px; line-height: 1.7; color: var(--muted); margin: 0 0 24px; max-width: 470px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 520px; }
.mode { text-align: left; padding: 16px 16px 14px; border: 1px solid #f4e7c744; background: #12212bcc; cursor: pointer; display: flex; flex-direction: column; gap: 7px; min-height: 48px; transition: background .15s, border-color .15s; }
.mode strong { font-size: 17px; letter-spacing: .2px; }
.mode span { font-size: 11.5px; line-height: 1.5; color: var(--muted); }
.mode em { font-style: normal; font-size: 11px; color: var(--teal); margin-top: auto; }
.mode.primary { background: var(--cream); color: #18242b; border-color: var(--cream); }
.mode.primary span { color: #3b4a50; }
.mode.primary em { color: #1f6e66; font-weight: 700; }
.mode:hover { border-color: var(--cyan); }
.mode.primary:hover { background: #fff6dd; }
.controls { align-self: end; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; }
.controls h2 { margin: 0 0 12px; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--teal); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 12px; align-items: center; }
.keys dt { white-space: nowrap; color: var(--muted); }
.keys dd { margin: 0; }
.touch-help, .rules { color: var(--muted); line-height: 1.55; margin: 0 0 10px; }
.touch-help b { color: var(--cream); }
body.touch .keys { display: none; }
body.touch .touch-help { color: var(--cream); font-size: 13px; }
.settings { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.settings label { display: flex; align-items: center; gap: 7px; cursor: pointer; min-height: 32px; }
.settings input { width: 18px; height: 18px; accent-color: var(--teal); }
.storage-note { color: var(--amber); margin: 10px 0 0; line-height: 1.4; }

/* ---------- Panels ---------- */
.screen.dim { background: #0a1219a8; align-items: center; justify-content: center; }
#crash { align-items: center; justify-content: flex-end; padding: 0 16px calc(22px + var(--safe-b)); pointer-events: none; }
body.crashed .hud-flight, body.crashed #touch { display: none; }
.panel { pointer-events: auto; width: min(440px, calc(100vw - 32px)); padding: 26px 26px 22px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 20px 60px #0008; }
.panel.compact { width: min(520px, calc(100vw - 32px)); padding: 14px 18px 12px; border-left: 3px solid var(--red); }
.panel.compact p { margin-bottom: 6px; }
.panel.compact .buttons { margin-top: 8px; }
.panel h2 { margin: 0 0 8px; font-family: Impact, 'Arial Black', sans-serif; font-weight: 900; letter-spacing: .5px; font-size: 34px; }
#crash h2 { font-size: 26px; color: var(--red); }
.panel p { margin: 0 0 10px; line-height: 1.5; }
.panel .detail { color: var(--muted); font-size: 12px; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.buttons button { min-height: 44px; padding: 10px 14px; border: 1px solid #f4e7c755; background: #ffffff0a; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.buttons button:hover { border-color: var(--cyan); }
.buttons button.primary { background: var(--cream); color: #18242b; border-color: var(--cream); font-weight: 700; }
.buttons button.primary kbd { color: #18242b; border-color: #18242b55; }
.big-time { font-family: Impact, 'Arial Black', sans-serif; font-size: 64px; letter-spacing: 1px; color: var(--teal); margin: 6px 0 4px !important; line-height: 1; }
#finish-record { color: var(--amber); font-weight: 700; }
#finish h2 { font-size: 46px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.hud-top { position: absolute; top: calc(14px + var(--safe-t)); left: calc(18px + var(--safe-l)); right: calc(18px + var(--safe-r)); display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 18px; align-items: start; text-shadow: 0 1px 6px #000a; }
.hud-route { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.chip { align-self: flex-start; font-size: 9px; letter-spacing: 1.8px; padding: 3px 7px; border: 1px solid #8aefff88; color: var(--cyan); background: #0b1a2299; }
.chip.practice { border-color: #f9a45e99; color: var(--amber); }
#hud-section { font-size: 13px; font-weight: 700; letter-spacing: .5px; }
.progress { position: relative; width: min(260px, 38vw); height: 6px; background: #f4e7c722; border-radius: 3px; }
#hud-progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--teal), var(--cyan)); border-radius: 3px; }
#hud-ticks i { position: absolute; top: -3px; width: 2px; height: 12px; background: #f4e7c766; }
#hud-ticks i.active { background: var(--amber); }
#hud-progress-plane { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--cream); box-shadow: 0 0 8px var(--cyan); }
.hud-gates { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.hud-gates span { font-size: 9px; letter-spacing: 2px; color: var(--muted); }
.hud-gates b { font-size: 20px; }
.hud-time { justify-self: end; text-align: right; display: flex; flex-direction: column; gap: 3px; }
.hud-time b { font-family: Impact, 'Arial Black', sans-serif; font-size: 28px; letter-spacing: .5px; font-weight: 400; font-variant-numeric: tabular-nums; }
.hud-time span { font-size: 11px; color: var(--muted); }
.hud-buttons { display: flex; gap: 8px; pointer-events: auto; }
.icon-button { width: 48px; height: 48px; border: 1px solid #f4e7c744; background: #0d1820b3; border-radius: 50%; cursor: pointer; font-size: 15px; display: grid; place-items: center; }
.icon-button[aria-pressed="true"] { color: var(--red); text-decoration: line-through; }
.hud-flight { position: absolute; left: calc(22px + var(--safe-l)); bottom: calc(20px + var(--safe-b)); display: flex; align-items: flex-end; gap: 18px; text-shadow: 0 1px 6px #000a; }
.speed { display: flex; align-items: baseline; gap: 6px; }
.speed b { font-family: Impact, 'Arial Black', sans-serif; font-size: 40px; font-weight: 400; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.speed span { font-size: 10px; letter-spacing: 1.5px; color: var(--muted); }
.speed.boosting b { color: var(--cyan); }
.boost-meter { position: relative; width: 170px; padding-top: 16px; }
.boost-meter::before { content: ''; display: block; height: 8px; border-radius: 4px; background: #f4e7c722; }
#hud-boost-fill { position: absolute; left: 0; top: 16px; height: 8px; width: 100%; border-radius: 4px; background: var(--cyan); box-shadow: 0 0 10px #8aefff88; transition: background .2s; }
#hud-boost-fill.low { background: #f4e7c766; box-shadow: none; }
#hud-boost-fill.active { background: #e5fbff; }
.boost-meter span { position: absolute; top: 0; left: 0; font-size: 9px; letter-spacing: 1.6px; color: var(--muted); }
.boost-meter kbd { font-size: 8px; padding: 0 4px; }
.autopilot-tag { position: absolute; top: calc(90px + var(--safe-t)); left: 50%; transform: translateX(-50%); padding: 4px 10px; background: #ffd23f; color: #222; font: 700 11px Arial; letter-spacing: 2px; }

#banner { position: fixed; z-index: 6; left: 50%; top: 24%; transform: translateX(-50%); text-align: center; pointer-events: none; opacity: 0; transition: opacity .35s; font-family: Impact, 'Arial Black', sans-serif; font-size: clamp(28px, 5vw, 52px); letter-spacing: 1px; text-shadow: 0 2px 18px #000c; white-space: nowrap; }
#banner small { display: block; font: 700 11px Arial, sans-serif; letter-spacing: 3px; color: var(--teal); margin-bottom: 6px; }
#banner.show { opacity: 1; }
#banner.warn { color: var(--amber); }
#countdown { position: fixed; z-index: 6; left: 50%; top: 42%; transform: translate(-50%, -50%); font-family: Impact, 'Arial Black', sans-serif; font-size: 72px; pointer-events: none; text-shadow: 0 2px 24px #000; }

#debug-panel { position: fixed; z-index: 8; left: calc(12px + var(--safe-l)); top: 110px; white-space: pre; font: 11px/1.45 Menlo, Consolas, monospace; color: #eafcff; background: #000b; padding: 10px 12px; pointer-events: none; }

/* ---------- Touch ---------- */
#touch { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#steer-zone { position: absolute; left: 0; top: 18%; bottom: 0; width: 55%; pointer-events: auto; touch-action: none; }
.touch-hint { position: absolute; left: calc(26px + var(--safe-l)); bottom: calc(96px + var(--safe-b)); font-size: 10px; letter-spacing: 2px; color: #f4e7c780; }
#stick { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid #8aefff66; background: #0b1a2240; pointer-events: none; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%; background: #8aefffaa; transform: translate(-50%, -50%); }
#boost-button { position: absolute; right: calc(26px + var(--safe-r)); bottom: calc(30px + var(--safe-b)); width: 96px; height: 96px; border-radius: 50%; border: 0; background: #0d1820c0; pointer-events: auto; touch-action: none; display: grid; place-items: center; font-weight: 700; font-size: 11px; letter-spacing: 1.6px; padding: 0; }
#boost-button svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
#boost-button .track { fill: none; stroke: #f4e7c733; stroke-width: 6; }
#boost-button .ring { fill: none; stroke: var(--cyan); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 276.5; stroke-dashoffset: 0; }
#boost-button.held { background: #8aefff55; }
#boost-button span { position: relative; }
body.touch .hud-flight .boost-meter { display: none; }
body.touch .hud-flight { left: auto; right: calc(140px + var(--safe-r)); bottom: calc(40px + var(--safe-b)); }

#scene-error { position: fixed; z-index: 30; left: 50%; top: 40%; transform: translateX(-50%); width: min(420px, 90vw); padding: 24px; border: 1px solid #f4e7c755; background: #192630f2; }
#scene-error p { color: #bac7c9; font-size: 13px; line-height: 1.6; }
#scene-error button { min-height: 44px; padding: 10px 18px; border: 0; background: var(--cream); color: #18242b; font-weight: 700; cursor: pointer; }
body.failed .modes, body.failed .controls { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .menu-body { grid-template-columns: 1fr; gap: 18px; padding: 8px 16px calc(24px + var(--safe-b)); align-items: start; }
  .controls { align-self: start; }
  #menu { background: linear-gradient(0deg, #101923f5 30%, #101923b0 70%, #10192388); }
  .masthead { padding: calc(16px + var(--safe-t)) 16px 6px; }
  .edition { display: none; }
  h1 { font-size: clamp(56px, 15vw, 96px); }
  .modes { grid-template-columns: 1fr 1fr; }
  .hud-top { grid-template-columns: 1fr auto auto; gap: 10px; left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); top: calc(10px + var(--safe-t)); }
  .hud-gates { display: none; }
  .hud-time b { font-size: 22px; }
  .progress { width: min(200px, 44vw); }
  .icon-button { width: 44px; height: 44px; }
}
@media (max-width: 480px) {
  .modes { grid-template-columns: 1fr; }
  .mode { padding: 12px 14px; }
  .description { font-size: 12px; margin-bottom: 16px; }
  .controls { padding: 14px 16px; }
  .speed b { font-size: 30px; }
  #hud-best { display: none; }
  .panel h2 { font-size: 28px; }
  .big-time { font-size: 48px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .menu-body { grid-template-columns: 1fr 1fr; padding-top: 0; }
  h1 { font-size: 54px; }
  .description { display: none; }
  .controls { font-size: 11px; padding: 12px 14px; }
  .keys { gap: 4px 10px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
body.reduced *, body.reduced *::before, body.reduced *::after { transition: none !important; animation: none !important; }

.quality-setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 15px; font-size: 12px; color: #c5d1d2; }
.quality-setting select, #scene-inspector select { color: #f4e7c7; background: #15232b; border: 1px solid #738b8d77; border-radius: 3px; padding: 8px 30px 8px 12px; font: inherit; min-height: 40px; }
.quality-setting select:focus-visible, #scene-inspector :focus-visible { outline: 2px solid #8aefff; outline-offset: 3px; }
body.inspection #menu, body.inspection #hud, body.inspection #countdown, body.inspection #banner { display: none !important; }
#scene-inspector { position: fixed; left: 24px; bottom: 24px; z-index: 30; width: min(350px, calc(100vw - 48px)); display: grid; gap: 12px; padding: 18px; border: 1px solid #b6c9ca44; border-radius: 7px; background: #102027df; backdrop-filter: blur(12px); color: #e6ebdf; font-size: 12px; }
#scene-inspector strong { font-size: 10px; letter-spacing: 2px; color: #95e6dc; }
#scene-inspector label { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
#scene-inspector input { flex: 1; accent-color: #82dace; min-width: 0; }
#scene-inspector output { font-size: 10px; line-height: 1.6; color: #b5c6c8; }
#scene-inspector a { justify-self: start; color: #f0e6cf; text-decoration: none; border-bottom: 1px solid #b2c1bf88; padding-bottom: 4px; }
