/* Backroad Rally: the page. Colours and fonts are tokens on :root; nothing below sets a font or a colour of its own. */
:root {
  --font-display: Bahnschrift, "DIN Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --ink: #101713; --panel: #19231d; --panel-2: #223028; --line: #3a4a40;
  --cream: #f4e4bd; --muted: #b9c2b0; --yellow: #f0c458; --teal: #2a9d8f; --red: #e2574c; --good: #8bd17c;
  --hud: rgba(14, 22, 18, 0.82);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--cream); font-family: var(--font-body); -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.04em; margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; visibility: hidden; touch-action: none; }
#stage[data-active="true"] { visibility: visible; }

.screen { position: fixed; inset: 0; overflow: auto; }
.eyebrow { margin: 0; font: 700 0.72rem/1.2 var(--font-body); letter-spacing: 0.14em; text-transform: uppercase; color: var(--yellow); }
.hint, .bar-note { color: var(--muted); font-size: 0.85rem; margin: 0; }
.label { margin: 12px 0 6px; font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 20px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel-2); color: var(--cream); font: 700 0.95rem/1 var(--font-display); letter-spacing: 0.06em; text-transform: uppercase; text-decoration: none; cursor: pointer; }
.btn:hover:not([disabled]) { border-color: var(--cream); }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: #1c1a10; }
.btn.danger { border-color: #7d3a35; color: #f0b3ad; }
.btn.small { min-height: 38px; padding: 6px 14px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.stack { display: grid; gap: 10px; }

/* ---- title */
.title { display: grid; align-items: center; }
.title-art { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10, 16, 12, 0.94) 0%, rgba(10, 16, 12, 0.72) 38%, rgba(10, 16, 12, 0.1) 100%), url('./assets/art/region-amber.webp') center / cover; }
.title-card { position: relative; max-width: 440px; margin-inline: clamp(16px, 6vw, 88px); padding: 18px 0; display: grid; gap: 8px; }
.title-emblem { width: 72px; height: auto; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5)); }
.wordmark { margin: 0; line-height: 0; }
.wordmark picture, .wordmark img { display: block; }
.wordmark img { width: min(100%, 330px); height: auto; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5)); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.painted-icon { flex: none; display: inline-block; vertical-align: middle; object-fit: contain; }
.tagline { margin: 0 0 8px; font-size: 1.05rem; color: var(--cream); }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu .btn:first-child { grid-column: 1 / -1; min-height: 54px; font-size: 1.1rem; }
.notice { margin: 8px 0 0; color: var(--muted); font-size: 0.78rem; }

/* ---- boards */
.board { display: grid; grid-template-rows: auto 1fr; background: radial-gradient(1200px 600px at 20% 0%, #26362c, var(--ink)); }
.bar { display: flex; align-items: center; gap: 16px; padding: 14px clamp(14px, 3vw, 32px); border-bottom: 1px solid var(--line); }
.bar h2 { flex: 1; font-size: 1.4rem; }
.board-body, .garage-body, .daily-body { padding: 16px clamp(14px, 3vw, 32px) 28px; overflow: auto; width: 100%; max-width: 1240px; margin-inline: auto; }
.cup-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { display: inline-flex; gap: 6px; align-items: center; padding: 9px 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel); font: 700 0.85rem var(--font-display); letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; }
.tab.selected { background: var(--cream); color: var(--ink); border-color: var(--cream); }
.tab[disabled] { opacity: 0.5; cursor: not-allowed; }
.cup-main { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 16px 22px; }
.cup-intro { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; }
.cup-badge[hidden] { display: none; }
.cup-badge[data-won='true'] .painted-icon { filter: drop-shadow(0 3px 8px rgba(240, 196, 88, 0.5)); }
.cup-badge[data-won='false'] .painted-icon { filter: grayscale(0.5) brightness(0.9); opacity: 0.9; }
.cup-intro h3 { font-size: 1.5rem; }
.cup-intro p { margin: 4px 0 0; color: var(--muted); }
.stage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; align-content: start; }
.stage-card { display: grid; gap: 6px; text-align: left; padding: 14px; min-height: 140px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; align-content: start; }
.stage-card:hover:not([disabled]) { border-color: var(--yellow); }
.stage-card strong { font: 700 1.2rem/1.1 var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; }
.stage-card small { color: var(--muted); }
.stage-card.locked { opacity: 0.55; cursor: not-allowed; }
.stage-card.ghosted { border-style: dashed; }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; color: var(--cream); font-style: normal; }
.card-foot em { font-style: normal; font-weight: 700; }
.standings { padding: 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel); align-self: start; }
.standings h3 { font-size: 1rem; margin-bottom: 8px; }
.standings ol { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.standings li { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.04); }
.standings li.you { background: rgba(240, 196, 88, 0.2); font-weight: 700; }

/* ---- garage and daily */
.garage-body { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; }
.car-list { display: grid; gap: 10px; align-content: start; }
.car-option { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); text-align: left; cursor: pointer; }
.car-option.selected { border-color: var(--yellow); }
.car-option[disabled] { opacity: 0.5; cursor: not-allowed; }
.car-option img { max-height: 70px; object-fit: contain; justify-self: center; transform: rotate(0deg); }
.car-option strong { display: block; font: 700 1.05rem var(--font-display); text-transform: uppercase; }
.car-option small { color: var(--muted); }
.car-detail { display: grid; gap: 8px; align-content: start; }
.car-big { justify-self: start; max-height: 220px; width: auto; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5)); }
.car-detail h3 { font-size: 1.6rem; }
.car-detail p { margin: 0; color: var(--muted); max-width: 60ch; }
.stats { display: grid; gap: 8px; max-width: 420px; margin-top: 6px; }
.stats > div { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 10px; font-size: 0.85rem; }
.bar-track { height: 9px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar-track i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--yellow)); }
.livery-row { display: flex; gap: 10px; flex-wrap: wrap; }
.livery { display: grid; gap: 4px; justify-items: center; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; }
.livery.selected { border-color: var(--yellow); }
.livery[disabled] { opacity: 0.5; cursor: not-allowed; }
.livery small { color: var(--muted); }
.daily-card { max-width: 560px; margin: 0 auto; padding: 22px; border-radius: 16px; border: 2px solid var(--line); background: var(--panel); display: grid; gap: 12px; }
.daily-card h3 { font-size: 2rem; }
.daily-card p { margin: 0; color: var(--muted); }

/* ---- briefing and result */
.brief, .result { display: grid; place-items: center; padding: 16px; background: radial-gradient(900px 500px at 50% 20%, #2a3b30, var(--ink)); }
.brief-card, .result-card { width: min(560px, 100%); padding: 22px; border-radius: 16px; border: 2px solid var(--line); background: var(--panel); display: grid; gap: 10px; }
.brief-card h2, .result-card h2 { font-size: 2rem; line-height: 1; }
.brief-blurb { margin: 0; color: var(--muted); }
.facts { display: grid; gap: 4px; margin: 6px 0; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.045); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; text-align: right; }
.medal-row { display: flex; gap: 10px; flex-wrap: wrap; }
.medal-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); font-variant-numeric: tabular-nums; }
.controls-hint { margin: 6px 0 0; font-size: 0.82rem; color: var(--muted); }
.result-medal { display: flex; align-items: center; gap: 14px; }
.result-medal strong { font: 700 2.2rem var(--font-display); text-transform: uppercase; }
.result-line { margin: 0; color: var(--yellow); font-weight: 700; }
.result-notes { margin: 0; padding-left: 18px; color: var(--cream); display: grid; gap: 3px; }

/* ---- the race */
.hud { position: fixed; inset: 0; pointer-events: none; padding-top: var(--safe-t); }
/* a quick wash over the picture when the car is put back on the road (the page skips it under reduced motion) */
.screen-flash { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, rgba(255, 244, 214, 0.1) 30%, rgba(255, 236, 190, 0.72) 100%); }
.screen-flash.on { animation: screen-flash 0.4s ease-out; }
@keyframes screen-flash { from { opacity: 1; } to { opacity: 0; } }
.hud-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 10px; align-items: flex-start; padding-top: var(--safe-t); }
.hud-card { background: var(--hud); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 12px; padding: 8px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); }
.hud-card .label { display: block; margin: 0; font-size: 0.62rem; }
.hud-card.time strong { font: 700 2rem/1 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.penalty { margin-left: 8px; color: var(--red); font: 700 1rem var(--font-display); }
.hud-card.stage { margin-left: auto; min-width: 150px; display: grid; gap: 6px; font: 700 0.9rem var(--font-display); text-transform: uppercase; letter-spacing: 0.05em; }
.progress { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--yellow); }
.hud-pause { margin-left: auto; pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.2); background: var(--hud); color: var(--cream); font-size: 1.1rem; cursor: pointer; }
.hud-note { position: absolute; top: 74px; right: 10px; display: grid; grid-template-columns: auto 1fr; gap: 0 8px; align-items: center; padding: 8px 14px 8px 8px; border-radius: 12px; background: var(--cream); color: var(--ink); }
.hud-note svg { grid-row: span 2; }
.hud-note strong { font: 700 1.15rem var(--font-display); text-transform: uppercase; }
.hud-note small { color: #4a5648; font-weight: 700; }
.hud-flash { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); font: 700 1.5rem var(--font-display); text-transform: uppercase; letter-spacing: 0.05em; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); white-space: nowrap; }
.hud-flash[data-tone="bad"] { color: #ff8379; }
.hud-flash[data-tone="good"] { color: var(--good); }
.hud-hint { position: absolute; top: 31%; left: 50%; transform: translateX(-50%); width: max-content; max-width: min(520px, calc(100vw - 32px)); padding: 8px 16px; border-radius: 10px; background: var(--cream); color: var(--ink); font: 700 1.05rem/1.25 var(--font-display); text-align: center; text-wrap: balance; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); }
.hud-count { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); font: 800 7rem/1 var(--font-display); color: var(--cream); text-shadow: 0 4px 0 #8a5d1c, 0 10px 24px rgba(0, 0, 0, 0.6); }
.hud-brake { position: absolute; bottom: 24%; left: 50%; transform: translateX(-50%); padding: 6px 18px; border-radius: 8px; background: var(--red); color: #fff; font: 800 1.2rem var(--font-display); text-transform: uppercase; letter-spacing: 0.08em; }
.hud-bottom { position: absolute; left: 10px; bottom: calc(12px + var(--safe-b)); }
.dial { display: grid; grid-template-columns: auto auto 1fr; align-items: baseline; gap: 2px 8px; min-width: 190px; }
.dial strong { font: 700 2.4rem/1 var(--font-display); font-variant-numeric: tabular-nums; }
.dial span { color: var(--muted); font-size: 0.8rem; }
.dial .gear { justify-self: end; color: var(--cream); font-weight: 700; }
.rev { grid-column: 1 / -1; height: 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.rev i { display: block; height: 100%; width: 10%; background: linear-gradient(90deg, var(--teal), var(--yellow), var(--red)); }
.dial .surface { grid-column: 1 / -1; font-weight: 700; color: var(--cream); text-transform: uppercase; letter-spacing: 0.08em; }

/* HUD pieces sit over a canvas that changes every frame: each gets its own compositing layer so its blur and translucency are not repainted with the picture. */
.hud-card, .hud-note, .hud-pause, .hud-flash, .hud-hint, .hud-count, .hud-brake, .touch button, .touch .recover { will-change: transform; }

/* ---- touch controls */
.touch { position: fixed; inset: auto 0 0 0; padding: 0 12px calc(14px + var(--safe-b)); display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
.pad { display: flex; gap: 12px; align-items: flex-end; }
.pad.right { flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
.touch button { pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; min-width: 74px; height: 74px; border-radius: 18px; border: 2px solid rgba(255, 255, 255, 0.28); background: rgba(14, 22, 18, 0.62); color: var(--cream); font: 700 1.1rem var(--font-display); text-transform: uppercase; }
.touch button.go { background: rgba(240, 196, 88, 0.55); color: #1c1a10; min-width: 96px; height: 96px; }
.touch button.small { min-width: 62px; height: 52px; font-size: 0.8rem; }
.touch button.held { background: rgba(244, 228, 189, 0.7); color: #1c1a10; }
.touch .recover { position: fixed; top: calc(10px + var(--safe-t)); left: 130px; min-width: 56px; height: 40px; border-radius: 10px; font-size: 0.78rem; }
/* with the on-screen buttons up, the dial leaves the bottom corner for them */
body:has(#touch:not([hidden])) .hud-bottom { bottom: auto; top: calc(62px + var(--safe-t)); }
body:has(#touch:not([hidden])) .hud-note { top: calc(70px + var(--safe-t)); }
@media (max-width: 480px) {
  .touch { padding-inline: 8px; }
  .touch button { min-width: 64px; height: 64px; font-size: 0.95rem; }
  .touch button.go { min-width: 84px; height: 84px; }
  .pad.right { max-width: 190px; gap: 8px; }
  .pad { gap: 8px; }
  .touch .recover { left: auto; right: 64px; }
}

/* ---- dialogs */
.modal { width: min(440px, calc(100vw - 28px)); max-height: calc(100vh - 28px); overflow: auto; padding: 22px; border-radius: 16px; border: 2px solid var(--line); background: var(--panel); color: var(--cream); }
.modal.wide { width: min(620px, calc(100vw - 28px)); }
.modal::backdrop { background: rgba(5, 9, 7, 0.78); }
.modal h2 { margin-bottom: 14px; font-size: 1.5rem; }
.settings { display: grid; gap: 6px; }
.setting { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.045); }
.setting label { display: grid; gap: 1px; }
.setting small { color: var(--muted); }
.setting select { min-height: 38px; padding: 4px 10px; border-radius: 8px; border: 2px solid var(--line); background: var(--panel-2); }
.setting input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--yellow); }
.setting input[type="range"] { width: 160px; accent-color: var(--yellow); }
.loading { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 16, 12, 0.82); font: 700 1.4rem var(--font-display); text-transform: uppercase; letter-spacing: 0.1em; z-index: 5; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; background: var(--ink); }

/* ---- small screens */
@media (max-width: 760px) {
  .cup-main { grid-template-columns: 1fr; }
  .garage-body { grid-template-columns: 1fr; }
  .menu { grid-template-columns: 1fr; }
  .hud-card.stage { display: none; }
  .hud-count { font-size: 5rem; }
}
@media (max-height: 520px) {
  .title-card { gap: 4px; padding: 8px 0; max-width: 560px; }
  .title-emblem { width: 44px; }
  .wordmark img { width: min(100%, 300px); }
  .menu { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .menu .btn { min-height: 38px; padding: 6px 10px; font-size: 0.8rem; }
  .menu .btn:first-child { grid-column: 1 / -1; min-height: 42px; }
  .hud-card.time strong { font-size: 1.4rem; }
  .hud-card { padding: 5px 10px; }
  .dial strong { font-size: 1.7rem; }
  .dial { min-width: 150px; }
  .hud-count { font-size: 4rem; top: 26%; }
  .hud-note { top: 58px; padding: 4px 10px 4px 4px; }
  .touch button { min-width: 62px; height: 62px; }
  .touch button.go { min-width: 80px; height: 80px; }
  body:has(#touch:not([hidden])) .hud-bottom { top: calc(54px + var(--safe-t)); }
  .brief-card, .result-card { padding: 14px; gap: 6px; }
  .brief-card h2, .result-card h2 { font-size: 1.5rem; }
}
/* ---- briefing and result on a short landscape screen: two columns, so Start, Try again and Next stage stay on the screen without scrolling */
@media (max-height: 520px) and (orientation: landscape) {
  .brief, .result { padding: 8px 12px; }
  .brief-card, .result-card { width: min(780px, 100%); grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 18px; row-gap: 5px; padding: 12px 16px; align-content: center; }
  .brief-card > .facts, .result-card > .facts { grid-column: 2; grid-row: 1 / span 6; align-self: start; margin: 0; }
  .brief-card > .row, .result-card > .row { grid-column: 1 / -1; margin-top: 4px; }
  .brief-card h2, .result-card h2 { font-size: 1.35rem; }
  .facts > div { padding: 4px 10px; }
  .controls-hint { font-size: 0.74rem; }
  .result-medal strong { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } .screen-flash { display: none; } }
