/* The start page and the game's stage. Every margin, padding and gap is a multiple of 4 px; controls are 40 px tall with 8 px corners,
   panels have 12 px corners. One accent: the colour of the change below is the whole page's. */
:root {
  /* the cover's night: deep blue, a teal glow, chrome lettering, the police lights and the car's yellow */
  --bg: #050b14;
  --panel: #0d1a2b;
  --well: #081220;
  --line: #1d3350;
  --text: #eef3fa;
  --muted: #9db0c7;
  --chrome: #c9d7e8;
  --accent: #ffb81c;
  --accent-soft: #ffb81c1f;
  --accent-glow: #ffb81c40;
  --on-accent: #1a1200;
  --siren-red: #ff2e3f;
  --siren-blue: #2f7dff;
  --plate: #1f4fb0;
  --bad: #ff5a66;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { background:
    radial-gradient(1100px 560px at 12% -8%, #16427f80, transparent 62%),
    radial-gradient(900px 520px at 92% -4%, #0b5f5c66, transparent 60%),
    radial-gradient(1000px 700px at 50% 115%, #0d2c5a55, transparent 65%),
    var(--bg);
  background-attachment: fixed; }
html, body { margin: 0; min-height: 100%; color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---- layout ---- */
.app { max-width: 1152px; margin: 0 auto; padding: 24px; display: grid; gap: 24px;
  grid-template-columns: minmax(0, 384px) minmax(0, 1fr); grid-template-areas: "top top" "side content"; }
.top { grid-area: top; }
.side { grid-area: side; display: grid; gap: 24px; align-content: start; }
.content { grid-area: content; display: grid; gap: 24px; align-content: start; }
@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "side" "content"; padding: 16px; gap: 16px; }
  .side, .content { gap: 16px; }
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; box-shadow: 0 8px 32px #00000059; }
.panel > :first-child { margin-top: 0; }
.panel > :last-child { margin-bottom: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-head h2 { margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

h1, h2, .status { font-style: italic; font-weight: 800; letter-spacing: -0.01em; }
h1 { margin: 0; font-size: 32px; line-height: 40px; }
h2 { margin: 0 0 16px; font-size: 20px; line-height: 28px; color: var(--accent); }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.nowrap { white-space: nowrap; }
.check { display: flex; align-items: center; gap: 12px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; }
/* the Graphics panel: groups of rows, a label and its help on the left, the control on the right */
.gfx-intro { margin: 0 0 16px; }
.gfx-group + .gfx-group { margin-top: 24px; }
.gfx-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.gfx-head h3 { margin: 0; padding: 8px 0; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--chrome); }
.gfx-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(160px, 240px); gap: 8px 24px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.gfx-row:last-child { border-bottom: 0; }
.gfx-label { font-weight: 600; }
.gfx-help { margin: 4px 0 0; }
.gfx-control { display: flex; align-items: center; gap: 12px; }
.gfx-control select { width: 100%; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--well); color: var(--text); font: inherit; cursor: pointer; }
.gfx-control select:disabled, .gfx-control input:disabled { opacity: .5; cursor: not-allowed; }
.gfx-control input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.gfx-control output { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.gfx-page-option { grid-template-columns: minmax(0, 1fr); }
.gfx-page-option .check { min-height: 0; }
@media (max-width: 560px) { .gfx-row { grid-template-columns: minmax(0, 1fr); } }
.tag { margin-left: 8px; padding: 2px 8px; border: 1px solid var(--accent); border-radius: 999px; color: var(--accent); font-size: 12px; font-style: normal; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }

/* ---- header: the light bar on top, the title in chrome with its blue plate ---- */
.top { position: relative; overflow: hidden; padding-top: 28px; }
.lightbar { position: absolute; inset: 0 0 auto; height: 4px; display: flex; }
.lightbar span { flex: 1; }
.lightbar span:first-child { background: var(--siren-red); box-shadow: 0 0 16px 2px var(--siren-red); animation: siren 1.6s steps(1) infinite; }
.lightbar span:last-child { background: var(--siren-blue); box-shadow: 0 0 16px 2px var(--siren-blue); animation: siren 1.6s steps(1) infinite 0.8s; }
@keyframes siren { 0% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .lightbar span { animation: none; } }
.title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 36px; line-height: 44px; font-weight: 900; }
.chrome { background: linear-gradient(180deg, #ffffff 0%, #e8f0f9 36%, #7f9bbb 50%, #d4e1ef 64%, #ffffff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: 4px;
  filter: drop-shadow(0 2px 0 #0a2a57) drop-shadow(0 0 14px #3d7fe055); }
.plate { display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: 4px; transform: skewX(-12deg);
  background: linear-gradient(180deg, #3d7be6 0%, var(--plate) 55%, #163b8a 100%); border: 1px solid #8fb5ff; color: #fff;
  font-size: 18px; letter-spacing: 0.08em; text-transform: uppercase; box-shadow: 0 0 18px #2f6fe066; }
@media (max-width: 880px) {
  .title { font-size: 28px; line-height: 36px; gap: 8px; }
  .plate { height: 28px; font-size: 15px; padding: 0 10px; }
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap; }
.brand .hint { margin: 4px 0 0; }
.brand .hint a { color: var(--chrome); }
.top-end .btn { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.top-end svg { width: 20px; height: 20px; flex-shrink: 0; }
.top-end .donate { border-color: var(--siren-red); }
.top-end .donate svg { fill: var(--siren-red); }
.top-end .donate:hover:not(:disabled) { background: #ff2e3f26; border-color: #ff6b77; }

/* ---- dialogs ---- */
.dlg { width: min(440px, calc(100% - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  color: var(--text); box-shadow: 0 16px 48px #000000a6; }
.dlg::backdrop { background: #02060cb3; }
.dlg h2 { margin: 0 0 12px; }
.dlg p { margin: 0 0 24px; color: var(--muted); }
.row.end { justify-content: flex-end; }
.btn.go { display: inline-flex; align-items: center; text-decoration: none; border-color: var(--accent); background: var(--accent);
  color: var(--on-accent); }
.btn.go:hover { filter: brightness(1.08); background: var(--accent); }
.bar { height: 8px; margin-top: 20px; border-radius: 4px; background: var(--well); overflow: hidden; }
.bar.small { height: 6px; margin-top: 0; }
.bar-fill { height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, #ff9d0a, var(--accent) 60%, #ffd257);
  box-shadow: 0 0 12px var(--accent-glow); transition: width 0.2s; }

/* ---- play ---- */
.status { margin: 0; font-size: 32px; line-height: 40px; color: var(--accent); }
.status.bad { color: var(--bad); }
.status-sub { margin: 4px 0 24px; color: var(--muted); }
.play { width: 100%; height: 56px; border-radius: 12px; border: 0; color: var(--on-accent); cursor: pointer;
  background: linear-gradient(180deg, #ffd65a 0%, var(--accent) 45%, #f29a00 100%);
  font: italic 900 22px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; display: flex; align-items: center;
  justify-content: center; gap: 12px; box-shadow: 0 0 28px var(--accent-glow), inset 0 1px 0 #fff4c2; }
.play:hover:not(:disabled) { filter: brightness(1.08); }
.play:focus-visible { outline: 3px solid var(--siren-blue); outline-offset: 3px; }
.play:disabled { border: 2px solid var(--line); background: transparent; color: var(--muted); box-shadow: none; cursor: default; }
.play kbd { border-color: currentColor; color: inherit; background: #ffffff33; font-size: 13px; }
.problems { margin: 16px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.problems:empty { display: none; }
.problems li { padding: 12px 16px; border-radius: 8px; background: #ff2e3f1a; color: #ffd4d8; border-left: 4px solid var(--siren-red); }

/* ---- buttons, keys ---- */
.btn { height: 40px; padding: 0 16px; border-radius: 8px; border: 2px solid var(--chrome); background: transparent; color: var(--text);
  font: italic 700 15px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #2f7dff26; border-color: #e4edf7; }
.btn:disabled { border-color: var(--line); color: var(--muted); cursor: default; }
.text-btn { height: 40px; padding: 0 8px; border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; }
.text-btn:hover { color: var(--text); }
kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 8px; border-radius: 6px;
  border: 1.5px solid var(--chrome); background: #ffffff08; font: italic 700 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 24px; margin-bottom: 16px; }
.tab { height: 32px; padding: 0; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); cursor: pointer;
  font: italic 700 16px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
#about .tabs .tab, #manage .tabs .tab { font-size: 20px; font-weight: 800; height: 36px; }
#manage .tabs { margin-bottom: 20px; }
.pane[hidden] { display: none; }
/* a tab's own buttons (backup, preload, reset) at the top right of its pane: the tab is the heading */
.pane-head { justify-content: flex-end; }

/* ---- controls ---- */
.keys { margin: 0; padding: 0; list-style: none; }
.keys li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; padding: 4px 0;
  border-bottom: 1px solid var(--line); }
.keys li:last-child { border-bottom: 0; }
.keys li > span:last-child { display: flex; gap: 4px; flex-shrink: 0; }

/* ---- saves, game data ---- */
.box { margin: 0; padding: 12px 16px; border-radius: 8px; background: var(--well); color: var(--muted); font-size: 14px; }
.profiles { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.profiles:empty { display: none; }
.profiles li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: 8px;
  background: var(--well); }
.profiles .hint { margin: 0; }
.msg { margin: 12px 0 0; font-size: 14px; }
.msg.bad { color: var(--bad); }
.data-text { margin: 12px 0 0; font-variant-numeric: tabular-nums; }
.prose p { margin: 0 0 12px; }
.prose p:last-child { margin-bottom: 0; }

/* ---- the game ---- */
#stage { position: fixed; inset: 0; background: #000; }
#screen { width: 100%; height: 100%; display: block; outline: none; cursor: default; }
#screen.nocursor { cursor: none; }
.hud { position: absolute; top: 8px; right: 12px; font: 12px/1.4 ui-monospace, Menlo, monospace; color: #fffa; text-shadow: 0 1px 2px #000;
  pointer-events: none; white-space: pre; }
/* a new version is out (main.js): a few seconds over the picture, between races */
.note { position: absolute; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 3; margin: 0;
  max-width: calc(100% - 32px); width: max-content; padding: 10px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: #05101ee6; color: var(--text); font: 14px/1.4 system-ui, sans-serif; text-align: center; pointer-events: none; }

/* ---- touch controls (touch.js): over the game held sideways; held upright, the picture on top and the controls under it.
   --t is a big button's size, from the screen's short side; the phone's rounded corners and notch are kept clear (safe-area) ---- */
.touch { position: absolute; inset: 0; pointer-events: none; z-index: 2; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; --t: clamp(56px, 19vmin, 104px); --gap: clamp(8px, 2.4vmin, 14px);
  --sl: max(16px, env(safe-area-inset-left)); --sr: max(16px, env(safe-area-inset-right));
  --st: max(12px, env(safe-area-inset-top)); --sb: max(16px, env(safe-area-inset-bottom)); }
#stage.touching { touch-action: none; }
.touch .t-drive, .touch .t-menu { display: contents; }
.touch[data-scene="drive"] .t-menu, .touch[data-scene="menu"] .t-drive { display: none; }
.t-btn { pointer-events: auto; touch-action: none; display: flex; align-items: center; justify-content: center; padding: 0;
  border: 2px solid #ffffff59; border-radius: 14px; background: #05101e8c; color: #fffffff0; font: 700 14px/1 system-ui, sans-serif;
  letter-spacing: 0.02em; -webkit-tap-highlight-color: transparent; backdrop-filter: blur(2px); }
.t-btn svg { width: 46%; height: 46%; fill: currentColor; }
.t-btn.held { background: #ffb81cd9; border-color: var(--accent); color: var(--on-accent); }
.t-row { position: absolute; display: flex; gap: 8px; }
.t-tl { left: var(--sl); top: var(--st); }
.t-tr { right: var(--sr); top: var(--st); }
.t-small { height: 40px; min-width: 44px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.t-small svg { width: 20px; height: 20px; }

/* driving: steering under the left thumb, the pedals under the right */
.t-steer { position: absolute; left: var(--sl); bottom: var(--sb); display: grid; gap: var(--gap); justify-items: start; }
.t-arrows { display: flex; gap: var(--gap); }
.t-arrow { width: calc(var(--t) * 1.1); height: calc(var(--t) * 1.1); border-radius: 50%; }
.t-gears { display: flex; gap: 8px; }
.t-gear { width: calc(var(--t) * 0.62); height: calc(var(--t) * 0.5); font-size: 22px; border-radius: 10px; }
.t-pedals { position: absolute; right: var(--sr); bottom: var(--sb); display: grid; gap: var(--gap);
  grid-template-columns: calc(var(--t) * 1.05) calc(var(--t) * 1.15); grid-template-areas: "hand gas" "brake gas"; align-items: end; }
.t-hand { grid-area: hand; height: calc(var(--t) * 0.6); font-size: 12px; }
.t-brake { grid-area: brake; height: calc(var(--t) * 1.1); }
.t-gas { grid-area: gas; height: calc(var(--t) * 1.8); font-size: 16px; }

/* menus: a tap on the picture is a click; arrows, OK and Back beside it */
.t-dpad { position: absolute; left: var(--sl); bottom: var(--sb); display: grid; gap: 6px;
  grid-template: repeat(3, calc(var(--t) * 0.7)) / repeat(3, calc(var(--t) * 0.7)); grid-template-areas: ". u ." "l . r" ". d ."; }
.t-up { grid-area: u; } .t-left { grid-area: l; } .t-right { grid-area: r; } .t-down { grid-area: d; }
.t-d { border-radius: 12px; }
.t-okback { position: absolute; right: var(--sr); bottom: var(--sb); display: grid; gap: var(--gap); justify-items: end; }
.t-ok { width: calc(var(--t) * 1.15); height: calc(var(--t) * 1.15); border-radius: 50%; font-size: 18px; }
.t-back { width: calc(var(--t) * 0.95); height: calc(var(--t) * 0.6); font-size: 14px; }

/* upright: the picture fills the width at the top, the controls go in the space under it */
@media (orientation: portrait) {
  #stage.touching #screen { height: min(75vw, 58vh); }
  .touch { --t: clamp(56px, 17vw, 104px); }
  .t-tl, .t-tr { top: calc(min(75vw, 58vh) + 12px); }
  .t-tr { flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - var(--sl) - var(--sr) - 112px); }
}
/* the phone's keyboard types into this box, out of sight; the Keyboard button brings it up while the game waits for a name */
.type-box { position: absolute; left: 50%; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; font-size: 16px; }
.t-kbd { position: absolute; left: 50%; top: var(--st); transform: translateX(-50%); padding: 0 16px; }
