:root {
  --ink: #05070c;
  --bone: #f4ece0;
  --dim: rgba(244, 236, 224, 0.55);
  --faint: rgba(244, 236, 224, 0.18);
  --fire: #ff6a1a;
  --fire-hot: #ffb36b;
  --siren-red: #ff2a1f;
  --siren-blue: #2f7bff;
  --display: "Anton", "Arial Narrow", "Helvetica Neue", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --cjk: "Helvetica Neue", Arial, "PingFang TC", "Hiragino Sans", sans-serif;
  --pad: clamp(16px, 2.6vw, 40px);
  color-scheme: dark;
}
/* Body text per language; the display, serif and mono faces stay the same everywhere. */
:root:lang(zh-Hant) { --cjk: "PingFang TC", "Hiragino Sans CNS", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
:root:lang(ja) { --cjk: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--ink); color: var(--bone); overflow: hidden; }
body { font-family: var(--cjk); -webkit-font-smoothing: antialiased; user-select: none; }
.mono { font-family: var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.eyebrow { font-size: 11px; color: var(--dim); }

#app { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.layer, .screen { position: absolute; inset: 0; pointer-events: none; }

/* ---------- screens ---------- */
.screen { display: flex; opacity: 0; visibility: hidden; transition: opacity 0.5s ease, visibility 0.5s; }
#app[data-screen="boot"] #screen-boot,
#app[data-screen="title"] #screen-title,
#app[data-screen="season"] #screen-season,
#app[data-screen="pause"] #screen-pause,
#app[data-screen="results"] #screen-results { opacity: 1; visibility: visible; pointer-events: auto; }

#screen-boot { background: var(--ink); align-items: center; justify-content: center; }
.boot { text-align: center; display: grid; gap: 14px; justify-items: center; }
.boot-gate { display: flex; align-items: baseline; gap: 10px; }
.boot-gate span { font-size: 12px; color: var(--dim); }
.boot-gate b { font-family: var(--display); font-size: 64px; font-weight: 400; line-height: 1; color: var(--fire); }
.boot-name { font-family: var(--display); font-size: clamp(28px, 4vw, 44px); letter-spacing: 0.02em; font-style: italic; }
.boot-name span { color: var(--fire); }
.boot-bar { width: 220px; height: 2px; background: var(--faint); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: var(--fire); transition: width 0.2s; }
.boot-status { font-size: 11px; color: var(--dim); }

#screen-title::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, rgba(5, 7, 12, 0.88) 0%, rgba(5, 7, 12, 0.55) 38%, rgba(5, 7, 12, 0) 70%); }
.title { margin: auto var(--pad); max-width: 620px; display: grid; gap: 18px; }
.title h1 { font-family: var(--display); font-weight: 400; font-style: italic; line-height: 0.86; font-size: clamp(72px, 12vw, 168px); letter-spacing: -0.01em; display: grid; }
.title h1 span:last-child { color: var(--fire); text-shadow: 0 0 40px rgba(255, 106, 26, 0.35); }
.title-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.title-row b { font-family: var(--display); font-weight: 400; font-size: 34px; }
.title-row span { font-size: 11px; color: var(--dim); }
.tagline { font-size: 16px; line-height: 1.7; color: rgba(244, 236, 224, 0.82); max-width: 30em; }
.tagline em { font-family: var(--serif); font-size: 21px; color: var(--fire-hot); margin-left: 6px; }
.gate { font-size: 12px; display: flex; align-items: center; gap: 10px; color: var(--bone); }
.gate i { width: 8px; height: 8px; background: var(--siren-red); box-shadow: 0 0 10px var(--siren-red); animation: blink 1s steps(2) infinite; }
.cursor { animation: blink 1s steps(2) infinite; color: var(--fire); }
.start { font-size: 14px; color: var(--ink); background: var(--bone); border: 0; justify-self: start; padding: 12px 18px; cursor: pointer; pointer-events: auto; transition: background 0.2s; }
.start:hover { background: var(--fire); }
.controls { display: grid; gap: 6px; font-size: 11px; color: var(--dim); letter-spacing: 0.04em; text-transform: none; }
kbd { font-family: var(--mono); font-size: 10px; border: 1px solid var(--faint); padding: 1px 6px; margin-right: 4px; color: var(--bone); border-radius: 2px; }

/* Night season: rounds across the top, the round's events on the left, the selected event's card on the right. */
#screen-season { isolation: isolate; }
#screen-season::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, rgba(5, 7, 12, 0.93) 0%, rgba(5, 7, 12, 0.8) 55%, rgba(5, 7, 12, 0.4) 100%); }
.season { margin: auto var(--pad); width: min(980px, calc(100vw - 2 * var(--pad))); display: grid; gap: 14px; }
.season-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.season-head h2 { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(40px, 5vw, 64px); line-height: 0.95; }
.season-stars { font-size: 14px; color: var(--fire-hot); }
.season-rounds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.season-rounds button { all: unset; cursor: pointer; display: grid; gap: 2px; padding: 9px 12px; background: rgba(244, 236, 224, 0.05); }
.season-rounds span { font-size: 10px; color: var(--dim); }
.season-rounds b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: 22px; letter-spacing: 0.01em; text-transform: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.season-rounds em { font-style: normal; font-size: 10px; color: var(--dim); }
.season-rounds button.on { background: var(--bone); color: var(--ink); }
.season-rounds button.on span, .season-rounds button.on em { color: rgba(5, 7, 12, 0.6); }
.season-rounds button.locked:not(.on) { opacity: 0.5; }
.season-body { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.season-events { list-style: none; display: grid; gap: 2px; max-height: 54vh; overflow-y: auto; }
.season-events li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; padding: 10px 14px; background: rgba(244, 236, 224, 0.05); cursor: pointer; font-size: 14px; }
.season-events li b { font-weight: 600; }
.season-events .dir { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; color: var(--dim); }
.season-events .stars { font-size: 13px; letter-spacing: 0.12em; color: var(--fire); min-width: 4.2em; text-align: right; }
.season-events li:hover { background: rgba(244, 236, 224, 0.12); }
.season-events li.on { background: var(--bone); color: var(--ink); }
.season-events li.on .dir { color: rgba(5, 7, 12, 0.6); }
.season-events li.on .stars { color: #c2410c; }
.season-events li.locked:not(.on) { opacity: 0.45; }
.season-events li.extra { box-shadow: inset 3px 0 0 var(--fire); }
.season-card { display: grid; gap: 12px; align-content: start; padding: 18px 20px; background: rgba(5, 7, 12, 0.72); border: 1px solid var(--faint); }
.season-card h3 { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(28px, 3.2vw, 40px); line-height: 1; }
.season-card p { font-size: 14px; line-height: 1.65; color: rgba(244, 236, 224, 0.85); }
.season-card .targets { display: grid; gap: 4px; font-size: 11px; color: var(--dim); text-transform: none; }
.season-card .best { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; padding-top: 8px; border-top: 1px solid var(--faint); }
.season-card .best span { color: var(--dim); }
.season-card .best b { font-weight: 500; color: var(--fire-hot); }
.season-card .lock { font-size: 12px; color: var(--fire-hot); text-transform: none; }
.season-card .start { justify-self: stretch; text-align: center; }
.season-foot { display: flex; align-items: center; gap: 18px; font-size: 11px; color: var(--dim); }
.season-back { all: unset; cursor: pointer; padding: 8px 12px; border: 1px solid var(--faint); color: var(--bone); }
.season-back:hover { background: var(--bone); color: var(--ink); }
.season-back:focus-visible, .season-rounds button:focus-visible { outline: 2px solid var(--fire); outline-offset: 2px; }

#screen-pause { background: rgba(5, 7, 12, 0.6); backdrop-filter: blur(6px); align-items: center; justify-content: center; }
.pause { display: grid; gap: 16px; min-width: min(420px, 90vw); }
.pause h2 { font-family: var(--display); font-weight: 400; font-size: 64px; font-style: italic; }
.menu { display: grid; gap: 2px; }
.menu button { all: unset; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: rgba(244, 236, 224, 0.05); cursor: pointer; font-size: 15px; }
.menu button b { font-weight: 600; }
.menu button span { font-size: 11px; color: var(--dim); }
.menu button:hover, .menu button.sel { background: var(--bone); color: var(--ink); }
.menu button:hover span, .menu button.sel span { color: var(--ink); }

/* ---------- HUD ---------- */
#hud { opacity: 0; transition: opacity 0.4s; }
#app[data-screen="race"] #hud, #app[data-screen="countdown"] #hud, #app[data-screen="finish"] #hud { opacity: 1; }
.hud-tl { position: absolute; left: var(--pad); top: var(--pad); display: grid; gap: 6px; }
.lap { display: flex; align-items: baseline; gap: 8px; }
.lap span { font-size: 11px; color: var(--dim); }
.lap b { font-family: var(--display); font-weight: 400; font-size: 46px; line-height: 1; font-style: italic; }
.lap b.pos { font-size: 64px; color: var(--fire); margin-right: 14px; text-shadow: 0 0 24px rgba(255, 106, 26, 0.35); }
.style { display: flex; gap: 12px; align-items: baseline; font-size: 12px; margin-top: 4px; }
.style span { color: var(--dim); width: 44px; }
.style b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: 26px; letter-spacing: 0.02em; color: var(--bone); }
.popups { position: relative; height: 0; }
.pop { position: absolute; left: 56px; top: 0; font-size: 12px; color: var(--fire-hot); white-space: nowrap; animation: pop 1.4s ease-out forwards; }
.pop.bad { color: #ff8a80; }
@keyframes pop { 0% { opacity: 0; transform: translateY(6px); } 15% { opacity: 1; transform: translateY(0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-18px); } }
/* The event's own readout (time-attack medal, hits, drift score, curfew intercept). */
.mode { display: grid; gap: 4px; min-width: 200px; margin-top: 6px; padding: 7px 12px; font-size: 12px; border-left: 2px solid var(--fire); background: rgba(5, 7, 12, 0.62); }
.mode[hidden] { display: none; }
.mode div { display: flex; justify-content: space-between; gap: 14px; }
.mode span { color: rgba(244, 236, 224, 0.72); }
.mode b { font-weight: 500; font-variant-numeric: tabular-nums; }
.mode .meter { display: block; height: 6px; margin-top: 3px; background: rgba(244, 236, 224, 0.1); transform: skewX(-18deg); overflow: hidden; }
.mode .meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--siren-blue), var(--siren-red)); }
.mode.warn { border-color: var(--siren-red); }
.mode.warn .meter i { animation: blink 0.3s steps(2) infinite; }
.gaps { display: grid; gap: 4px; font-size: 11px; color: var(--dim); }
.gaps div { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.gaps i { width: 8px; height: 8px; display: inline-block; }
.gaps b { color: var(--bone); font-weight: 500; font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }

/* ---------- cut-in ---------- */
.cutin { position: absolute; right: 0; top: 13%; width: 58vw; height: 31vh; pointer-events: none; opacity: 0; }
.cutin .panel { position: absolute; inset: 0; clip-path: polygon(10% 12%, 100% 0, 100% 100%, 0 88%); background: #07080c; overflow: hidden; }
.cutin .panel::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(255, 106, 26, 0.35) 1.6px, transparent 2px) 0 0 / 9px 9px; mix-blend-mode: screen; opacity: 0.55; }
.cutin .panel::after { content: ""; position: absolute; inset: 0; border: 0; box-shadow: inset 0 0 0 4px var(--fire); clip-path: inherit; }
.cutin img { position: absolute; right: 2%; bottom: -18%; height: 150%; filter: contrast(1.15) saturate(1.1); mask-image: linear-gradient(90deg, transparent 0%, #000 30%); -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 30%); }
/* The line stays left of the portrait's face, which the delivered art keeps in the right third. */
.cutin .line { position: absolute; left: 14%; top: 26%; display: grid; gap: 8px; max-width: 40%; }
.cutin.short .line { top: 20%; gap: 6px; }
.cutin.short .line b { font-size: clamp(22px, 2.9vw, 42px); }
.cutin .line b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(30px, 4.4vw, 66px); line-height: 0.95; color: var(--fire); text-shadow: 0 0 28px rgba(255, 106, 26, 0.55); }
.cutin .line span { font-size: 11px; color: var(--bone); }
.cutin.ren .panel::before { background-image: radial-gradient(circle, rgba(255, 42, 42, 0.35) 1.6px, transparent 2px); }
.cutin.ren .panel::after { box-shadow: inset 0 0 0 4px #ff2a2a; }
.cutin.ren .line b { color: #ff4a3a; text-shadow: 0 0 28px rgba(255, 42, 42, 0.5); }
.cutin.rui .panel::before { background-image: radial-gradient(circle, rgba(79, 141, 255, 0.35) 1.6px, transparent 2px); }
.cutin.rui .panel::after { box-shadow: inset 0 0 0 4px #4f8dff; }
.cutin.rui .line b { color: #8fb6ff; text-shadow: 0 0 28px rgba(79, 141, 255, 0.5); }
.cutin.show { animation: cutin 1.05s cubic-bezier(0.2, 0.9, 0.2, 1) forwards; }
.cutin.show.short { animation-duration: 0.85s; width: 46vw; height: 24vh; top: 16%; }
@keyframes cutin {
  0% { opacity: 1; transform: translateX(70%) skewX(-10deg); }
  14% { opacity: 1; transform: translateX(0) skewX(-4deg); }
  78% { opacity: 1; transform: translateX(-2%) skewX(-4deg); }
  100% { opacity: 0; transform: translateX(-30%) skewX(-12deg); }
}

/* ---------- results ---------- */
#screen-results::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, rgba(5, 7, 12, 0.92) 0%, rgba(5, 7, 12, 0.7) 45%, rgba(5, 7, 12, 0.05) 75%); }
.results { margin: auto var(--pad); width: min(560px, 92vw); display: grid; gap: 14px; }
.res-head { display: flex; align-items: center; gap: 22px; }
.rank { font-family: var(--display); font-weight: 400; font-style: italic; font-size: 150px; line-height: 0.85; color: var(--bone); }
.rank[data-rank="S"] { color: var(--fire); text-shadow: 0 0 50px rgba(255, 106, 26, 0.5); }
.rank[data-rank="A"] { color: #ffd2a8; }
.res-pos { font-family: var(--display); font-size: 40px; font-style: italic; }
.res-time { font-size: 13px; color: var(--dim); margin-top: 4px; }
.res-true { font-family: var(--mono); font-size: 12px; letter-spacing: 0.1em; padding: 10px 14px; color: var(--ink); background: var(--fire); }
.res-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.res-table td { padding: 6px 0; border-bottom: 1px solid rgba(244, 236, 224, 0.08); }
.res-table td:nth-child(2) { color: var(--dim); font-size: 11px; text-align: right; padding-right: 18px; }
.res-table td:nth-child(3) { text-align: right; font-size: 12px; width: 80px; white-space: nowrap; }
.res-total { display: flex; justify-content: space-between; align-items: baseline; }
.res-total span { font-size: 12px; color: var(--dim); }
.res-total b { font-family: var(--display); font-weight: 400; font-size: 48px; font-style: italic; }
.res-hint { font-size: 13px; color: var(--dim); min-height: 1em; }
.res-stars { font-size: 14px; color: var(--fire-hot); letter-spacing: 0.1em; }
.res-stars:empty, .res-total[hidden] { display: none; }
.rank[data-kind="stars"] { font-family: var(--mono); font-style: normal; font-size: 64px; line-height: 1; letter-spacing: 0.02em; }
#res-menu { grid-template-columns: repeat(3, 1fr); }
.title-best { font-size: 11px; color: var(--dim); min-height: 1em; }
.gate.called i { background: var(--fire); box-shadow: 0 0 10px var(--fire); animation: none; }
.gate.called { color: var(--fire-hot); }
.times { display: grid; gap: 3px; font-size: 12px; }
.times div { display: flex; gap: 12px; }
.times span { width: 44px; color: var(--dim); }
.times b { font-weight: 500; font-variant-numeric: tabular-nums; }

.hud-tr { position: absolute; right: var(--pad); top: var(--pad); display: grid; gap: 8px; justify-items: end; }
#minimap { width: 180px; height: 135px; }
.rival { font-size: 11px; display: flex; align-items: center; gap: 8px; color: var(--dim); }
.rival i { width: 8px; height: 8px; background: #ff2a2a; }
.rival b { color: var(--bone); font-weight: 500; font-variant-numeric: tabular-nums; }

.hud-br { position: absolute; right: var(--pad); bottom: var(--pad); display: grid; justify-items: end; gap: 10px; }
.speed { display: flex; align-items: baseline; gap: 8px; }
.speed b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(64px, 8vw, 104px); line-height: 0.9; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.speed span { font-size: 12px; color: var(--dim); }
.gauges { display: grid; gap: 8px; width: min(300px, 40vw); }
.gauge { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 10px; }
.gauge span { font-size: 10px; color: var(--dim); }
.gauge .bar { position: relative; height: 10px; background: rgba(244, 236, 224, 0.08); overflow: hidden; transform: skewX(-18deg); }
.gauge .bar i { position: absolute; inset: 0 auto 0 0; width: 0; }
.fire .bar i { background: linear-gradient(90deg, #b8380a, var(--fire) 60%, var(--fire-hot)); box-shadow: 0 0 14px rgba(255, 106, 26, 0.6); }
.fire .bar em { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 2px), var(--ink) calc(20% - 2px) 20%); }
.heat .bar { height: 4px; }
.heat .bar i { background: linear-gradient(90deg, #6b7a96, #e8eef8 60%, var(--siren-red)); }
#hud.firing .fire .bar i { animation: flick 0.08s steps(2) infinite; }
#hud.overheat .heat .bar i { background: var(--siren-red); animation: blink 0.25s steps(2) infinite; }
#hud.overheat .heat span { color: var(--siren-red); }

.hud-bc { position: absolute; left: 50%; bottom: var(--pad); transform: translateX(-50%); display: grid; justify-items: center; gap: 10px; }
.beat { position: relative; width: 260px; height: 22px; }
.beat .diamond { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; border: 1.5px solid var(--bone); transform: translate(-50%, -50%) rotate(45deg); transition: background 0.08s; }
.beat.hit .diamond { background: var(--fire); border-color: var(--fire); box-shadow: 0 0 18px var(--fire); }
.beat .tick { position: absolute; top: 50%; left: 50%; width: 2px; height: 14px; margin-top: -7px; background: var(--bone); opacity: 0.7; }
.drift { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--dim); opacity: 0; transition: opacity 0.15s; }
.drift.on { opacity: 1; }
.drift i { width: 22px; height: 5px; background: rgba(244, 236, 224, 0.15); transform: skewX(-18deg); }
.drift i.l1 { background: #9cc8ff; box-shadow: 0 0 10px #9cc8ff; }
.drift i.l2 { background: var(--fire); box-shadow: 0 0 10px var(--fire); }
.drift i.l3 { background: #fff3e0; box-shadow: 0 0 14px var(--fire-hot); }

.callout { position: absolute; left: 50%; top: 28%; transform: translateX(-50%); text-align: center; display: grid; gap: 4px; opacity: 0; }
.callout b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(44px, 7vw, 96px); line-height: 0.95; letter-spacing: 0.01em; white-space: nowrap; }
.callout span { font-size: 12px; color: var(--bone); }
.callout.show { animation: callout 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
.callout.fire b { color: var(--fire); text-shadow: 0 0 30px rgba(255, 106, 26, 0.6); }
.callout.warn b { color: var(--siren-red); }
.callout.cool b { color: #cfe3ff; }
.callout.small b { font-size: clamp(28px, 3.6vw, 48px); }

.slip { position: absolute; left: 50%; top: calc(var(--pad) + 4px); transform: translateX(-50%); font-size: 11px; padding: 6px 12px; border: 1px solid var(--faint); opacity: 0; transition: opacity 0.2s; }
.slip.on { opacity: 1; }
.slip.zero { border-color: var(--fire); color: var(--ink); background: var(--fire); }

.startlights { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); display: flex; gap: 14px; opacity: 0; transition: opacity 0.3s; }
#app[data-screen="countdown"] .startlights { opacity: 1; }
.startlights i { width: 30px; height: 30px; border-radius: 50%; background: #1a0b0b; border: 2px solid #2a1414; }
.startlights i.on { background: var(--siren-red); border-color: #ff8a80; box-shadow: 0 0 24px var(--siren-red); }
.startlights.go i { background: var(--fire); border-color: var(--fire-hot); box-shadow: 0 0 24px var(--fire); }

.debug { position: absolute; left: var(--pad); bottom: 44px; font-size: 10px; line-height: 1.6; color: var(--dim); white-space: pre; display: none; text-transform: none; letter-spacing: 0.02em; }
.debug.on { display: block; }
.toast { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); font-size: 11px; padding: 8px 14px; background: rgba(5, 7, 12, 0.75); border: 1px solid var(--faint); opacity: 0; transition: opacity 0.3s; }
.toast.show { opacity: 1; }
.ai-note { position: absolute; left: var(--pad); bottom: 10px; font-size: 9px; color: rgba(244, 236, 224, 0.45); letter-spacing: 0.06em; text-transform: none; }

/* ---------- subtitles ---------- */
.subtitle { position: absolute; z-index: 2; left: 50%; bottom: calc(var(--pad) + 76px); transform: translateX(-50%); display: grid; justify-items: center; gap: 2px; text-align: center; opacity: 0; pointer-events: none; max-width: 80vw; }
.subtitle b { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--fire); }
.subtitle b.ren { color: #ff4a3a; }
.subtitle b.rui { color: #8fb6ff; }
.subtitle b.cop { color: #d7dade; }
.subtitle span { font-family: var(--serif); font-style: italic; font-size: clamp(20px, 2.4vw, 30px); color: var(--bone); text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8); }
.subtitle em { font-style: normal; font-size: 13px; color: var(--dim); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8); }
.subtitle em:empty, .intro-card .sub:empty { display: none; }
.subtitle.show { animation: subtitle 2.6s ease forwards; }
@keyframes subtitle { 0% { opacity: 0; transform: translate(-50%, 6px); } 10% { opacity: 1; transform: translate(-50%, 0); } 85% { opacity: 1; } 100% { opacity: 0; } }
#app[data-screen="title"] .subtitle, #app[data-screen="season"] .subtitle, #app[data-screen="pause"] .subtitle { display: none; }

/* ---------- intro ---------- */
.letterbox { position: absolute; inset: 0; pointer-events: none; }
.letterbox i { position: absolute; left: 0; right: 0; height: 11vh; background: #000; transition: transform 0.6s cubic-bezier(0.6, 0, 0.2, 1); }
.letterbox i:first-child { top: 0; transform: translateY(-100%); }
.letterbox i:last-child { bottom: 0; transform: translateY(100%); }
#app[data-screen="intro"] .letterbox i { transform: none; }
.intro-title { position: absolute; left: var(--pad); top: 18vh; display: grid; gap: 8px; opacity: 0; pointer-events: none; }
.intro-title b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(56px, 9vw, 130px); line-height: 0.9; color: var(--bone); }
.intro-title span { font-size: 11px; color: var(--dim); }
.intro-title.show { animation: introtitle 2.3s ease forwards; }
@keyframes introtitle { 0% { opacity: 0; transform: translateX(-20px); } 20% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
.intro-card { position: absolute; left: var(--pad); bottom: calc(11vh + 28px); display: grid; gap: 6px; opacity: 0; pointer-events: none; }
.intro-card .num { font-size: 11px; color: var(--dim); }
.intro-card b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(64px, 10vw, 140px); line-height: 0.85; color: var(--fire); }
.intro-card.ren b { color: #ff4a3a; }
.intro-card.rui b { color: #9cc0ff; }
.intro-card .line { font-family: var(--serif); font-style: italic; font-size: clamp(22px, 2.6vw, 34px); color: var(--bone); }
.intro-card .sub { font-size: 13px; color: var(--dim); }
.intro-card.show { animation: introcard 2.1s ease forwards; }
@keyframes introcard { 0% { opacity: 0; transform: translateX(-30px) skewX(-6deg); } 14% { opacity: 1; transform: none; } 82% { opacity: 1; } 100% { opacity: 0; transform: translateX(10px); } }
.intro-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.skip { position: absolute; right: var(--pad); bottom: calc(11vh + 20px); font-size: 11px; color: var(--dim); background: none; border: 1px solid var(--faint); padding: 8px 12px; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
#app[data-screen="intro"] .skip { opacity: 1; pointer-events: auto; }

/* ---------- true ending ---------- */
.triptych { position: absolute; inset: 0; pointer-events: none; opacity: 0; display: grid; align-content: center; justify-items: center; gap: 18px; }
.triptych .strips { display: flex; gap: 1.2vw; width: 86vw; height: 46vh; transform: skewX(-8deg); }
.triptych .strip { flex: 1; overflow: hidden; position: relative; background: #07080c; box-shadow: inset 0 0 0 3px var(--fire); }
.triptych .strip.ren { box-shadow: inset 0 0 0 3px #ff2a2a; }
.triptych .strip.rui { box-shadow: inset 0 0 0 3px #4f8dff; }
.triptych .strip img { position: absolute; left: 50%; top: 50%; height: 125%; transform: translate(-50%, -46%) skewX(8deg); filter: contrast(1.15); }
.triptych .tri-title { display: grid; justify-items: center; gap: 6px; text-align: center; }
.triptych .tri-title b { font-family: var(--display); font-weight: 400; font-style: italic; font-size: clamp(48px, 8vw, 120px); line-height: 0.9; color: var(--fire); text-shadow: 0 0 40px rgba(255, 106, 26, 0.6); }
.triptych .tri-title span { font-size: 12px; color: var(--bone); }
.triptych.show { animation: triptych 3.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
.triptych.show .strip { animation: strip 3.2s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.triptych.show .strip:nth-child(2) { animation-delay: 0.08s; }
.triptych.show .strip:nth-child(3) { animation-delay: 0.16s; }
@keyframes triptych { 0% { opacity: 0; } 6% { opacity: 1; } 82% { opacity: 1; } 100% { opacity: 0; } }
@keyframes strip { 0% { transform: translateY(40%); opacity: 0; } 12% { transform: none; opacity: 1; } 100% { transform: none; opacity: 1; } }

.title-kv, .res-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; }
#screen-title, #screen-results { isolation: isolate; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes flick { 50% { filter: brightness(1.5); } }
@keyframes callout {
  0% { opacity: 0; transform: translateX(-50%) scale(1.35) skewX(-8deg); }
  12% { opacity: 1; transform: translateX(-50%) scale(1) skewX(-8deg); }
  70% { opacity: 1; transform: translateX(-50%) scale(0.98) skewX(-8deg); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.96) skewX(-8deg); }
}

/* ---------- language switch ---------- */
.langs { display: flex; gap: 2px; pointer-events: auto; }
.langs button { all: unset; cursor: pointer; font-size: 11px; padding: 7px 10px; color: rgba(244, 236, 224, 0.78); background: rgba(5, 7, 12, 0.6); letter-spacing: 0.04em; }
.langs button:hover { color: var(--bone); }
.langs button.on { color: var(--ink); background: var(--bone); }
.langs button:focus-visible, .menu button:focus-visible, .start:focus-visible { outline: 2px solid var(--fire); outline-offset: 2px; }
.title-langs { position: absolute; top: var(--pad); right: var(--pad); z-index: 1; }
.lang-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- touch ---------- */
/* Keyboard hints on keyboards, touch hints on touch screens. */
.touch-only, #app.touchmode .keys-only, #app.touchmode .key { display: none; }
#app.touchmode .touch-only { display: revert; }
#app.touchmode .start .touch-only { display: inline; }
.touch { position: absolute; inset: 0; z-index: 3; display: none; pointer-events: none; touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#app.touchmode[data-screen="race"] .touch, #app.touchmode[data-screen="countdown"] .touch { display: block; }
.t-steer { position: absolute; left: 0; bottom: 0; width: 42vw; height: 58vh; pointer-events: auto; touch-action: none; }
.t-bar { position: absolute; left: calc(var(--pad) + env(safe-area-inset-left)); bottom: var(--pad); width: min(260px, 32vw); height: 64px; }
.t-bar::before { content: ""; position: absolute; inset: 0; border: 1px solid var(--faint); background: rgba(5, 7, 12, 0.35); transform: skewX(-12deg); }
.t-bar i { position: absolute; top: 50%; margin-top: -10px; width: 0; height: 0; border: 10px solid transparent; opacity: 0.6; }
.t-bar i.l { left: 14px; border-right-color: var(--bone); border-left-width: 0; }
.t-bar i.r { right: 14px; border-left-color: var(--bone); border-right-width: 0; }
.t-bar b { position: absolute; left: 50%; top: 50%; margin: -20px 0 0 -20px; width: 40px; height: 40px; background: var(--fire); box-shadow: 0 0 18px rgba(255, 106, 26, 0.6); clip-path: polygon(30% 0, 100% 0, 70% 100%, 0 100%); }
.t-buttons { position: absolute; right: calc(var(--pad) + env(safe-area-inset-right)); bottom: var(--pad); display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 10px; align-items: end; }
.t-btn { all: unset; pointer-events: auto; touch-action: none; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; color: var(--bone); background: rgba(5, 7, 12, 0.45); border: 1px solid var(--faint); transform: skewX(-12deg); }
.t-btn.down { color: var(--ink); background: var(--bone); }
.t-fire { grid-column: 2; grid-row: 1; width: 84px; height: 58px; color: var(--fire); border-color: var(--fire); }
.t-fire.down { background: var(--fire); color: var(--ink); }
.t-brake { grid-column: 1; grid-row: 2; width: 72px; height: 58px; }
.t-drift { grid-column: 2; grid-row: 2; width: 108px; height: 84px; font-size: 14px; }
.t-pause { all: unset; pointer-events: auto; position: absolute; left: 50%; top: calc(var(--pad) + 30px); transform: translateX(-50%); width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; gap: 6px; background: rgba(5, 7, 12, 0.45); border: 1px solid var(--faint); }
.t-pause i { width: 4px; height: 16px; background: var(--bone); }
/* Touch layout: speed and gauges move up so the thumbs have the bottom corners. */
#app.touchmode .hud-br { top: var(--pad); bottom: auto; right: calc(var(--pad) + env(safe-area-inset-right)); }
#app.touchmode .hud-tr { display: none; }
#app.touchmode .speed b { font-size: clamp(40px, 6vw, 72px); }
#app.touchmode .gauges { width: min(220px, 30vw); }
#app.touchmode .hud-tl { left: calc(var(--pad) + env(safe-area-inset-left)); }
#app.touchmode .subtitle { bottom: calc(var(--pad) + 110px); }
#app.touchmode .toast { bottom: auto; top: 30%; }

/* A phone held upright: ask for landscape (the race pauses). */
.rotate { position: absolute; inset: 0; z-index: 20; display: none; place-content: center; justify-items: center; gap: 18px; padding: 24px; text-align: center; background: var(--ink); font-size: 15px; pointer-events: auto; }
.rotate b { width: 46px; height: 80px; border: 2px solid var(--bone); border-radius: 8px; animation: rotate-hint 2.2s ease-in-out infinite; }
@keyframes rotate-hint { 0%, 30% { transform: none; } 60%, 100% { transform: rotate(-90deg); border-color: var(--fire); } }
@media (orientation: portrait) {
  #app.handheld .rotate { display: grid; }
}

@media (max-width: 760px) {
  .controls, .hud-tr { display: none; }
  .gauges { width: 46vw; }
  .season-rounds { grid-template-columns: repeat(2, 1fr); }
  .season-body { grid-template-columns: 1fr; }
  .season-events { max-height: 34vh; }
}
/* Short landscape screens (phones): tighter title, pause and results. */
@media (max-height: 520px) {
  .title { gap: 10px; max-width: 70vw; }
  .title h1 { font-size: clamp(48px, 15vh, 96px); display: flex; gap: 0.25em; }
  .title-row b { font-size: 24px; }
  .tagline { font-size: 13px; line-height: 1.5; }
  .tagline em { font-size: 16px; }
  .controls { gap: 3px; font-size: 10px; }
  .title-best:empty { display: none; }
  .pause { gap: 8px; }
  .pause h2 { font-size: 40px; }
  .menu button { padding: 9px 14px; font-size: 13px; }
  /* Rank, total and the true-ending badge on the left, the breakdown on the right. */
  #screen-results::before { background: linear-gradient(90deg, rgba(5, 7, 12, 0.94) 0%, rgba(5, 7, 12, 0.84) 62%, rgba(5, 7, 12, 0.2) 92%); }
  .results { gap: 6px 22px; width: min(640px, 80vw); grid-template-columns: minmax(150px, auto) 1fr; align-items: start;
    grid-template-areas: "eye eye" "head table" "stars table" "total table" "true table" "hint hint" "menu menu"; }
  .results > .eyebrow { grid-area: eye; }
  .res-head { grid-area: head; flex-direction: column; align-items: flex-start; gap: 4px; }
  .res-stars { grid-area: stars; font-size: 12px; }
  .res-total { grid-area: total; flex-direction: column; align-items: flex-start; gap: 0; }
  .res-true { grid-area: true; font-size: 10px; padding: 6px 8px; }
  .res-table { grid-area: table; font-size: 10.5px; }
  .res-hint { grid-area: hint; font-size: 11px; }
  #res-menu { grid-area: menu; }
  .season { gap: 6px; margin: 6px var(--pad) 24px; align-self: center; }
  .season-head .eyebrow { display: none; }
  .season-head h2 { font-size: 26px; }
  .season-rounds button { padding: 5px 10px; }
  .season-rounds b { font-size: 16px; }
  .season-events { max-height: calc(100vh - 168px); }
  .season-events li { padding: 6px 10px; font-size: 12px; }
  .season-card { gap: 7px; padding: 10px 14px; }
  .season-card h3 { font-size: 24px; }
  .season-card p { font-size: 12px; line-height: 1.5; }
  .season-card .targets { font-size: 10px; gap: 2px; }
  .season-card .start { padding: 8px 12px; font-size: 12px; }
  .season-foot { font-size: 10px; }
  .season-back { padding: 5px 10px; }
  .rank { font-size: 88px; }
  .rank[data-kind="stars"] { font-size: 40px; }
  .res-pos { font-size: 24px; }
  .res-table td { padding: 2px 0; }
  .res-table td:nth-child(2) { font-size: 10px; padding-right: 10px; }
  .res-table td:nth-child(3) { width: 56px; font-size: 11px; }
  .res-total b { font-size: 32px; }
  .intro-card b { font-size: clamp(48px, 16vh, 100px); }
}
@media (prefers-reduced-motion: reduce) {
  .callout.show { animation-duration: 1.4s; }
}

/* ?playlog: the local play log for testers to copy (E4 play tests). */
.playlog { position: fixed; top: 16px; left: 16px; z-index: 50; max-width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 14px 16px; background: rgba(5, 7, 12, 0.94); border: 1px solid var(--faint); font-size: 12px; user-select: text; pointer-events: auto; }
.playlog pre { margin: 10px 0 12px; font-family: var(--mono); font-size: 12px; line-height: 1.5; text-transform: none; white-space: pre; color: var(--dim); }
.playlog nav { display: flex; gap: 8px; }
.playlog button { font: inherit; color: var(--ink); background: var(--bone); border: 0; padding: 6px 12px; cursor: pointer; }
