:root {
  color-scheme: dark;
  --ink: #f5f0e8;
  --muted: #c3bcb5;
  --charcoal: #101113;
  --line: #393738;
  --lacquer: #a9322a;
  --focus: #ffb3a2;
  --gutter: clamp(15px, 3.2vw, 54px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--charcoal); font: 400 15px/1.5 system-ui, sans-serif; }
h1, h2, p { margin: 0; }
a { color: inherit; }
button, select, input { font: inherit; }
button, select, input[type="number"] { color: var(--ink); background: #1c1c1e; border: 1px solid #5a5351; }
button { padding: 7px 13px; min-height: 40px; cursor: pointer; }
button:hover, select:hover { background: #302726; border-color: #877671; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.play-shell {
  --mast-height: 56px;
  position: relative;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top);
  background: #0b0c0e;
}
.mast {
  min-height: var(--mast-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: var(--charcoal);
}
.mast-brand, .mast-actions { display: flex; align-items: center; gap: clamp(7px, 1.15vw, 19px); }
.mast-actions { flex: none; gap: 4px; }
.mast-actions button { white-space: nowrap; background: transparent; border-color: transparent; font-size: .83rem; }
.mast-actions button:hover, .mast-actions button[aria-pressed="true"] { background: #282322; color: #ffd1c4; }
.dario { display: flex; align-items: center; min-height: 42px; }
.dario img { display: block; width: clamp(58px, 6vw, 94px); height: auto; }
.arcade-link { font-size: .82rem; text-underline-offset: .23em; color: var(--muted); }
#mast-title { padding-left: 14px; border-left: 1px solid #65544d; white-space: nowrap; font-size: .9rem; font-weight: 640; }
#mast-title i { margin-left: .2em; font: italic 1.05em Georgia, serif; color: var(--muted); }

.stage {
  position: relative;
  isolation: isolate;
  width: min(100%, calc((100svh - var(--mast-height) - env(safe-area-inset-top)) * 416 / 240));
  aspect-ratio: 416 / 240;
  margin-inline: auto;
  container-type: inline-size;
}
.stage:focus { outline: none; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.splash {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: center;
  background: linear-gradient(90deg, #101113f5 0%, #101113d9 22%, #10111365 46%, #10111312 65%, transparent 80%);
  pointer-events: none;
}
.splash-copy { width: max-content; max-width: 100%; margin: 0 0 1.45cqw 7.15cqw; color: var(--ink); }
.race-logo {
  display: grid;
  justify-items: start;
  margin: 0 0 clamp(12px, 2.65cqw, 36px);
  line-height: .85;
  white-space: nowrap;
  text-shadow: 0 .06em #211719;
}
.race-logo > span {
  padding-left: .075em;
  font: 850 clamp(15px, 4.05cqw, 64px)/.94 system-ui, sans-serif;
  letter-spacing: -.08em;
}
.race-logo strong {
  margin-left: -.075em;
  color: #ffc981;
  font: italic 1000 clamp(50px, 13.1cqw, 209px)/.82 'Arial Black', Arial, sans-serif;
  letter-spacing: -.105em;
  text-transform: uppercase;
  -webkit-text-stroke: .012em #ffb873;
  text-shadow: .014em .027em #952d2d, .035em .055em #4b2026, .051em .065em #211719;
}
.race-logo i {
  margin: .29em 0 0 .14em;
  color: #fff0e5;
  font: italic 400 clamp(15px, 3.65cqw, 57px)/1 Georgia, serif;
  letter-spacing: -.045em;
}
.entry { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#start { min-height: 44px; color: #fff7ee; background: var(--lacquer); border-color: #e1705d; font-size: clamp(.82rem, 1.36cqw, 1.09rem); font-weight: 700; padding-inline: clamp(12px, 1.8cqw, 25px); pointer-events: auto; }
#start:hover { background: #b53930; }
.keyboard-entry, #status { color: #fff1e5; font-size: .83rem; }
#status:empty { display: none; }

.drive-controls { display: none; }
.drive-steering, .drive-pedals { display: flex; gap: 6px; }
.drive-controls button { min-width: 49px; min-height: 49px; touch-action: none; user-select: none; -webkit-user-select: none; font-weight: 720; }
.drive-controls button[data-k="1"] { background: var(--lacquer); border-color: #e07460; }
.drive-controls button:active { background: #ede3d8; color: #171515; }

.race-guide {
  width: min(1200px, 100% - 2 * var(--gutter));
  margin-inline: auto;
  padding: clamp(25px, 3.4vw, 52px) 0 34px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 40px;
}
.race-guide h2 { font-size: 1.15rem; letter-spacing: -.015em; margin-bottom: .33em; }
.race-guide p, .controls-guide label { color: var(--muted); }
.race-guide b { color: var(--ink); font-weight: 620; }
.controls-guide p { margin-bottom: 9px; }
.controls-guide p > span { display: inline-block; margin-left: 6px; }
kbd { border: 1px solid #5a5351; padding: 1px 5px; color: var(--ink); }
select, input[type="number"] { padding: 6px 9px; }
.manual-drive { display: none; }
.manual-keys { margin-top: 9px; }
.manual-keys kbd:nth-child(2) { margin-left: 8px; }
.manual-drive button, .technical button { touch-action: none; }
.rotate-hint { display: none; }
.technical { grid-column: 1 / -1; border-top: 1px solid var(--line); color: var(--muted); }
.technical summary { padding-block: 12px; min-height: 44px; width: fit-content; cursor: pointer; color: var(--ink); }
.technical-settings, #projection-controls { margin: 3px 0 9px; display: flex; flex-wrap: wrap; gap: 7px 15px; align-items: center; }
.technical a { text-underline-offset: .23em; }
.technical input[type="number"] { width: 80px; }
.technical input[type="checkbox"], .technical input[type="range"] { accent-color: #e27560; }
.technical label { display: inline-flex; align-items: center; gap: 5px; }
.technical pre { white-space: pre-wrap; }
.lab-keys, .readouts { font-size: .8rem; margin-block: 8px; }
.readouts { display: flex; flex-wrap: wrap; gap: 5px 14px; }

.play-shell:is(:fullscreen, .expanded) { --mast-height: 46px; width: 100%; height: 100%; overflow: auto; }
.play-shell:is(:fullscreen, .expanded) :is(.dario, .arcade-link) { display: none; }
.play-shell:is(:fullscreen, .expanded) #mast-title { border: 0; padding-left: 0; }
.play-shell.expanded { position: fixed; inset: 0; z-index: 5; }
body:has(.play-shell.expanded) { overflow: hidden; }

@media (max-width: 660px) {
  #mast-title { display: none; }
  .mast { min-height: max(var(--mast-height), 50px); }
  .mast-brand { gap: 9px; }
  .mast-actions button { padding-inline: 6px; font-size: .73rem; }
  .race-guide { grid-template-columns: 1fr; }
}
@media (max-width: 365px) {
  .mast { padding-inline: 9px; }
  .arcade-link { display: none; }
}
@media (pointer: coarse) {
  .keyboard-entry { display: none; }
  .drive-controls { display: flex; justify-content: space-between; padding: 8px var(--gutter) max(8px, env(safe-area-inset-bottom)); gap: 8px; }
  .drive-controls button { padding-inline: clamp(7px, 2vw, 15px); }
  .manual-drive { display: flex; justify-content: space-between; gap: 8px; padding: 0 var(--gutter) 8px; }
}
@media (pointer: coarse) and (orientation: portrait) {
  .stage { width: 100%; }
  .rotate-hint { display: block; margin-top: .5em; font-size: .86rem; }
}
@media (pointer: coarse) and (orientation: landscape) {
  .drive-controls { position: absolute; left: 0; right: 0; z-index: 1; top: 49%; padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); pointer-events: none; }
  .drive-controls button { pointer-events: auto; background: #151415da; border-color: #fff3df83; font-size: .83rem; }
  .drive-controls button:active { background: #ede3d8; }
  .drive-controls button[data-k="1"]:not(:active) { background: #8d2a25e6; }
  .manual-drive { position: absolute; z-index: 1; top: calc(49% + 66px); inset-inline: 0; padding-inline: 8px; pointer-events: none; }
  .manual-drive button { pointer-events: auto; background: #151415da; }
}

/* The instrument strip and landscape touch controls occupy their own space. */
.play-shell {
  --hud-height: 92px;
  --side-pad: 0px;
  --play-width: min(calc(100% - var(--side-pad) * 2), calc((100svh - var(--mast-height) - var(--hud-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 416 / 240));
}
.stage { width: var(--play-width); }
.race-hud {
  width: var(--play-width);
  min-height: var(--hud-height);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 1.12fr .66fr 1fr 1.12fr;
  grid-template-rows: minmax(calc(var(--hud-height) - 2px), auto);
  background: #10181f;
  border: 1px solid #354250;
  font-variant-numeric: tabular-nums;
}
.race-hud > div {
  position: relative;
  min-width: 0;
  padding: 5px clamp(5px, 1.3vw, 18px) 7px;
  border-top: 3px solid #435d6b;
  border-inline-end: 1px solid #354250;
  background: linear-gradient(145deg,#253340 0%,#19252f 59%,#151f27 59%);
}
.race-hud > div:last-child { border-inline-end: 0; }
.race-hud .hud-speed { border-top-color: #ffa66d; }
.race-hud .hud-gear { border-top-color: #f5bd79; }
.race-hud .hud-time { border-top-color: #8bdaca; }
.hud-label,.hud-note {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(.56rem, 1.26vw, .83rem);
  font-weight: 750;
  letter-spacing: .07em;
  line-height: 1.25;
  text-transform: uppercase;
  color: #cedce2;
}
.hud-line { display: flex; align-items: baseline; gap: clamp(3px, .65vw, 9px); }
.hud-line strong,.hud-digits {
  display: block;
  font: 900 clamp(1.18rem,3vw,2.65rem)/1.06 'Cascadia Mono','Consolas',monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.055em;
  color: #fff0da;
  text-shadow: 0 2px #0b131b;
}
.hud-speed strong { font-size: clamp(1.48rem, 4.6vw, 3rem); }
.hud-unit,.hud-mode { color: #ffca8d; font-size: clamp(.54rem,1.16vw,.77rem); font-weight: 800; white-space: nowrap; }
.hud-gear strong { color: #ffd08c; }
.hud-mode { background:#473525; border:1px solid #78583c; padding:0 2px; line-height:1.3; }
.hud-digits[data-long="yes"] { font-size:clamp(1.02rem,2.4vw,2.3rem); }
.hud-time strong { color: #c4f2e2; }
.hud-note:empty { visibility:hidden; }
#hud-peak:empty,#hud-passes:empty { display:none; }
.hud-note { min-height: 1.25em; margin-top: 1px; letter-spacing: 0; color: #ffd18b; }
.hud-check.fresh { border-top-color: #d1f4e5; background: linear-gradient(145deg,#31534f,#1f383d); }
.hud-check.ahead .hud-note { color: #aaf0cb; }
.hud-check.behind .hud-note { color: #ffd0a1; }
.hud-revs {
  display:block; width:100%; height:5px; margin-top:2px; appearance:none;
  border:0; border-radius:0; color:#ffaf72; background:#384452;
}
.hud-revs::-webkit-progress-bar { background:#384452; }
.hud-revs::-webkit-progress-value { background:repeating-linear-gradient(110deg,transparent 0 8px,#111e29 8px 10px),linear-gradient(90deg,#5fc0b9,#ffca7d 65%,#f88e70); }
.hud-revs::-moz-progress-bar { background:repeating-linear-gradient(110deg,transparent 0 8px,#111e29 8px 10px),linear-gradient(90deg,#5fc0b9,#ffca7d 65%,#f88e70); }
@media (max-width:660px) {
  .play-shell { --mast-height:50px; --hud-height:70px; }
  .hud-line { flex-wrap:wrap; column-gap:4px; row-gap:0; }
  .hud-gear strong { font-size:1.47rem; }
  .hud-speed strong { font-size:clamp(1.62rem, 7vw, 2rem); }
  .hud-label { letter-spacing:.034em; }
  .hud-digits { letter-spacing:-.065em; }
}
@media (pointer: coarse) and (orientation:portrait) {
  .play-shell { --play-width:100%; }
  .drive-controls button { min-height:54px; }
}
@media (pointer:coarse) and (orientation:landscape) {
  .play-shell { --side-pad: 100px; --hud-height:74px; }
  .drive-controls { top: max(68px, calc(var(--mast-height) + 5svh)); }
  .drive-steering,.drive-pedals { display:grid; gap:6px; width:81px; }
  .drive-controls button { min-height:49px; padding-inline:4px; }
  .manual-drive { top: calc(max(68px, var(--mast-height) + 5svh) + 112px); }
  .manual-drive button { width:81px; padding-inline:3px; font-size:.7rem; }
  .hud-digits { font-size:clamp(1rem,2.85vw,1.55rem); }
  .hud-speed strong { font-size:clamp(1.35rem,3.9vw,2rem); }
}

/* R12 · Cabinet pause: keep the original 416×240 raster and HUD intact. */
.pause-panel {
  position:absolute; inset:0; z-index:3; display:grid; place-items:center;
  background:rgba(11,17,25,.82); text-align:center;
}
.pause-copy { display:grid; justify-items:center; gap:clamp(4px,1.2cqw,14px); padding:8px; max-width:100%; }
.pause-eyebrow { color:#9de2d5; font:800 clamp(9px,1.6cqw,16px)/1.2 monospace; letter-spacing:.09em; }
.pause-copy strong { color:#ffc981; font:italic 1000 clamp(24px,9cqw,96px)/.9 'Arial Black',Arial,sans-serif; letter-spacing:-.06em; text-shadow:2px 3px #8e392f; }
#pause-reason { font-size:clamp(11px,1.8cqw,18px); color:#fff0da; }
#resume { background:#a9322a; border-color:#e1705d; min-height:36px; padding:4px 12px; font-size:clamp(12px,2cqw,18px); font-weight:750; }
.pause-copy small { color:#c3bcb5; font:700 clamp(10px,1.5cqw,14px)/1 monospace; }
.pad-status { font-size:.82rem; color:#9de2d5 !important; }
@media(max-width:800px){.mast-brand .arcade-link{display:none}.mast-actions{gap:0}.mast-actions button{padding-inline:5px;font-size:.72rem}}
@media(max-width:430px){.mast-brand .dario img{width:48px}.mast{padding-inline:6px;gap:3px}.mast-actions button{padding-inline:3px;font-size:.68rem}.mast-actions button#full{white-space:normal;max-width:75px;line-height:1.15}.mast-actions button#sound{white-space:normal;max-width:76px;line-height:1.15}}
@media(max-height:360px) and (orientation:landscape){.pause-copy{gap:3px}.pause-copy strong{font-size:clamp(24px,6cqw,50px)}.pause-copy small{display:none}}
