/* Road Fighter web door — themeable chrome.
   Themes are variable sets on <html data-theme>; Audiowide is the
   display face, Rajdhani the body/UI face, in every theme — the
   canvas HUD uses the same pair (see FONT_DISPLAY / FONT_BODY
   in src/main.ts), so menus, HUD and 3D readouts all speak one
   voice. Fallbacks are metric-matched (Arial Narrow) so text
   never reflows while the webfonts load.
   Animations are ON by default (data-anim="on"): panel pops, the
   staggered button entrances, the title breathe and the separator
   flow only go quiet when the player turns them off — a saved off
   choice wins, and reduced-motion still forces them off. */

:root {
  color-scheme: dark;
  --font-display: "Audiowide", "Rajdhani", "Arial Narrow", sans-serif;
  --font-body: "Rajdhani", "Arial Narrow", sans-serif;
}
html[data-theme="heat"] {
  --bg: #0d0a08; --panel: rgba(13, 10, 8, 0.87); --field: #1a130e;
  --edge: #33241a; --accent: #ff4d00; --on-accent: #1c0d02;
  --text: #f7efe8; --dim: #b3a08e; --warn: #ffc21f;
  --sep1: #ff2d00; --sep2: #ff8c1a; --sep3: #ffc21f;
}
html[data-theme="midnight"] {
  --bg: #0b0e14; --panel: rgba(11, 14, 20, 0.82); --field: #12161f;
  --edge: #232a38; --accent: #22d3ee; --on-accent: #0b0e14;
  --text: #e8ecf3; --dim: #94a3b8; --warn: #f1c40f;
  --sep1: #22d3ee; --sep2: #818cf8; --sep3: #22d3ee;
}
html[data-theme="sunset"] {
  --bg: #160b08; --panel: rgba(22, 11, 8, 0.86); --field: #241209;
  --edge: #3a2015; --accent: #ff8c1a; --on-accent: #1c0d02;
  --text: #f7ece2; --dim: #c9a18c; --warn: #ffd23e;
  --sep1: #ff2d78; --sep2: #ff8c1a; --sep3: #ffd23e;
}
html[data-theme="toxic"] {
  --bg: #071207; --panel: rgba(7, 18, 7, 0.86); --field: #0d1f0d;
  --edge: #1d3319; --accent: #a3e635; --on-accent: #101c02;
  --text: #e9f5e3; --dim: #94b08a; --warn: #fde047;
  --sep1: #a3e635; --sep2: #22d3ee; --sep3: #a3e635;
}
html[data-theme="violet"] {
  --bg: #0e0a1c; --panel: rgba(14, 10, 28, 0.87); --field: #171231;
  --edge: #2a2350; --accent: #818cf8; --on-accent: #0d0a24;
  --text: #eceaf7; --dim: #a49ec9; --warn: #fbbf24;
  --sep1: #818cf8; --sep2: #c084fc; --sep3: #22d3ee;
}
html[data-theme="paper"] {
  color-scheme: light;
  --bg: #f2efe9; --panel: rgba(255, 255, 255, 0.9); --field: #ffffff;
  --edge: #d8d2c4; --accent: #d90429; --on-accent: #ffffff;
  --text: #191c22; --dim: #5d6470; --warn: #b45309;
  --sep1: #d90429; --sep2: #ff8c1a; --sep3: #d90429;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  display: flex;
  justify-content: center;
  padding: 16px;
}
#app { position: relative; width: 960px; max-width: 100%; aspect-ratio: 4 / 3; }
/* The aspect-ratio holds the stage's height when the 2D canvas is
   hidden in 3D mode — without it the stage collapses to 0 and the
   voxel view (inset: 0) has nothing to fill. */
canvas {
  display: block;
  width: 100%;
  border-radius: 12px;
  background: #1e7d32;
}
.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--panel);
  border-radius: 12px;
  text-align: center;
  padding: 20px;
}
html[data-anim="on"] .panel { animation: panelpop 0.3s ease-out; }
@keyframes panelpop {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}
/* ---- Feel pass (v1.2.0): entrances, idle life, celebrations ----
   Transform + opacity ONLY — never box-shadow, filter or layout —
   so every animation stays on the GPU. All of it is gated on
   data-anim="on", and the reduced-motion block below kills it. */
/* Staggered pop-in: the menu/lobby/result buttons arrive one
   after another, then the help lines fade up behind them. */
html[data-anim="on"] .panel .buttons button { animation: btnpop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
html[data-anim="on"] .panel .buttons button:nth-child(1) { animation-delay: 0.05s; }
html[data-anim="on"] .panel .buttons button:nth-child(2) { animation-delay: 0.12s; }
html[data-anim="on"] .panel .buttons button:nth-child(3) { animation-delay: 0.19s; }
@keyframes btnpop {
  from { opacity: 0; transform: scale(0.85) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
html[data-anim="on"] #menu .controls div { animation: fadeup 0.4s ease-out both; }
html[data-anim="on"] #menu .controls div:nth-child(1) { animation-delay: 0.16s; }
html[data-anim="on"] #menu .controls div:nth-child(2) { animation-delay: 0.2s; }
html[data-anim="on"] #menu .controls div:nth-child(3) { animation-delay: 0.24s; }
html[data-anim="on"] #menu .controls div:nth-child(4) { animation-delay: 0.28s; }
html[data-anim="on"] #menu .controls div:nth-child(5) { animation-delay: 0.32s; }
html[data-anim="on"] #menu .controls div:nth-child(6) { animation-delay: 0.36s; }
html[data-anim="on"] #menu .controls div:nth-child(7) { animation-delay: 0.4s; }
html[data-anim="on"] #menu .controls div:nth-child(8) { animation-delay: 0.44s; }
@keyframes fadeup {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
/* Idle life: the title breathes (scale + opacity only) and the
   GAS pedal carries a slow expanding ring — the menu never sits
   dead, and the driver's thumb always knows where GAS is. */
html[data-anim="on"] #menu h1 { animation: titlein 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both, titlebreathe 3.2s ease-in-out 0.6s infinite; }
@keyframes titlein {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes titlebreathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.02); opacity: 0.96; }
}
#touch-controls #tc-gas { position: relative; }
#touch-controls #tc-gas::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
html[data-anim="on"] #touch-controls #tc-gas::after { animation: gasring 2.2s ease-out infinite; }
@keyframes gasring {
  0% { opacity: 0.55; transform: scale(0.92); }
  70% { opacity: 0; transform: scale(1.25); }
  100% { opacity: 0; transform: scale(1.25); }
}
/* Win / lose: the result title pops (win) or shakes its head
   (lose), and the whole stage does one quick pulse on a win.
   The classes are added by main.ts in showResult(). */
html[data-anim="on"] #result.celebrate-win #result-title { animation: winpop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes winpop {
  0% { opacity: 0; transform: scale(0.6); }
  60% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}
html[data-anim="on"] #result.celebrate-lose #result-title { animation: losepop 0.5s ease-out both; }
@keyframes losepop {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
html[data-anim="on"] #app.celebrate { animation: screenpulse 0.6s ease-out; }
@keyframes screenpulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.02); }
  100% { transform: scale(1); }
}
/* ---- Particle layer ---- */
/* #fx-layer covers the stage (2D canvas and 3D voxel stage alike)
   and never takes input. Pieces fly out along --dx/--dy and fade;
   transform + opacity only. */
#fx-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
  border-radius: 12px;
}
.fx-particle {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  pointer-events: none;
  animation: fx-fly 0.7s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
.fx-confetti { width: 8px; height: 14px; margin: -7px 0 0 -4px; border-radius: 2px; }
@keyframes fx-fly {
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.2); opacity: 0; }
}
.hidden { display: none; }
h1 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 44px; letter-spacing: 2px; }
.tag { margin: 0; color: var(--dim); }
.version { margin: 0; color: var(--dim); font-size: 12px; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
button {
  font-family: inherit;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button { transition: transform 0.06s ease-out; -webkit-tap-highlight-color: transparent; }
button:active:not(:disabled) { transform: scale(0.97); }
/* Drive buttons answer deeper (0.94) — the thumb feels the press
   at once. .pressed is the same state for pointer-held buttons,
   added by main.ts alongside .active. */
#touch-controls button:active:not(:disabled),
#touch-controls button.pressed { transform: scale(0.94); }
button:hover:not(:disabled) { filter: brightness(1.1); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.controls { color: var(--dim); font-size: 14px; line-height: 1.9; }
.controls b { color: var(--text); }
.lobby-row { display: flex; gap: 8px; }
input {
  font-family: inherit;
  padding: 12px;
  font-size: 15px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: var(--field);
  color: var(--text);
  text-transform: uppercase;
}
#input-name { text-transform: none; }
.lobby-players { font-size: 15px; line-height: 1.8; }
.hint { color: var(--dim); font-size: 13px; max-width: 520px; }
#status { min-height: 22px; color: var(--warn); text-align: center; }

/* Themed separator: a static gradient bar by default; the flow
   animation only runs when animations are on, and the whole bar
   can be switched off in Customize. Colours come from the theme. */
.sep {
  height: 2px;
  width: min(420px, 82%);
  border-radius: 2px;
  background: linear-gradient(90deg, var(--sep1), var(--sep2), var(--sep3), var(--sep1));
  background-size: 200% 100%;
}
html[data-anim="on"] .sep { animation: sepflow 6s linear infinite; }
html[data-sep="off"] .sep { display: none; }
@keyframes sepflow { to { background-position: 200% 0; } }

/* ---- Customize sheet ---- */
#btn-settings {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--edge);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}
/* Sound mute toggle: same round button, riding under Customize.
   The label (🔊/🔇) is set by sfx.js from the saved choice. */
#btn-sound {
  position: fixed;
  top: 66px;
  right: 14px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--edge);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  font-size: 19px;
}
#sheet {
  position: fixed;
  top: 68px;
  right: 14px;
  width: 302px;
  max-width: calc(100vw - 28px);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 16px;
  z-index: 41;
  display: none;
  text-align: left;
}
#sheet.open { display: block; }
html[data-anim="on"] #sheet.open { animation: panelpop 0.25s ease-out; }
#sheet h2 { margin: 0 0 10px; font-family: var(--font-display); font-weight: 400; font-size: 18px; letter-spacing: 1px; }
#sheet .sep { width: 100%; margin-bottom: 6px; }
#sheet h3 { margin: 12px 0 6px; font-size: 12.5px; font-weight: 700; color: var(--dim); }
.pick-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.pick-grid button {
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--edge);
  padding: 8px 10px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.pick-grid button.active { border-color: var(--accent); outline: 1px solid var(--accent); }
.chip {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--c1) 50%, var(--c2) 50%);
  border: 1px solid rgba(128, 128, 128, 0.5);
}
.row-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0 2px;
  font-size: 14px;
  cursor: pointer;
}
.row-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 40px; height: 22px; border-radius: 999px; flex: none;
  background: var(--edge); position: relative; transition: background 0.15s;
}
.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text); transition: transform 0.15s;
}
.row-toggle input:checked + .switch { background: var(--accent); }
.row-toggle input:checked + .switch::before { transform: translateX(18px); }
.row-toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
#btn-done { width: 100%; margin-top: 14px; }

/* ---- Custom cursors ----
   The native cursor is hidden only while a custom one is active
   (text inputs keep their I-beam). Every custom cursor carries
   its own contrast — a white core with a dark rim — so it stays
   readable on any theme. Movement is transform-only (composited),
   and the hover grow is a transform on the inner wrapper. */
html:not([data-cursor="native"]) body,
html:not([data-cursor="native"]) button,
html:not([data-cursor="native"]) .panel,
html:not([data-cursor="native"]) .row-toggle { cursor: none; }
/* Blanket backstop: every element hides its native cursor while
   a custom one is active — text inputs keep their I-beam. */
html:not([data-cursor="native"]) *:not(input):not(textarea) { cursor: none !important; }
#cursor {
  position: fixed;
  left: 0; top: 0;
  width: 38px; height: 38px;
  margin: -19px 0 0 -19px;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.15s;
  will-change: transform;
  display: none;
}
#cursor.on { opacity: 1; }
#cursor-in { position: absolute; inset: 0; transition: transform 0.15s; }
#cursor.hovering #cursor-in { transform: scale(1.35); }
/* Orb: accent ring, white core, dark rim */
html[data-cursor="orb"] #cursor-in::before {
  content: ""; position: absolute; inset: 2px; border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.6), 0 0 12px var(--accent);
}
html[data-cursor="orb"] #cursor-in::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.65);
}
/* Crosshair: accent bars with dark outline, white centre dot */
html[data-cursor="crosshair"] #cursor-in::before {
  content: ""; position: absolute; left: 3px; right: 3px; top: 50%;
  height: 2px; margin-top: -1px; background: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}
html[data-cursor="crosshair"] #cursor-in::after {
  content: ""; position: absolute; top: 3px; bottom: 3px; left: 50%;
  width: 2px; margin-left: -1px; background: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}
html[data-cursor="crosshair"] #cursor-in {
  background: radial-gradient(circle, #fff 0 2.5px, rgba(0, 0, 0, 0.65) 3.5px, transparent 4.5px);
}
/* Chevron: accent arrow head, tip on the pointer, dark drop edge */
html[data-cursor="chevron"] #cursor-in::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 24px; height: 24px;
  background: linear-gradient(135deg, var(--sep2), var(--accent));
  clip-path: polygon(0 0, 100% 62%, 58% 74%, 76% 100%, 60% 100%, 44% 78%, 0 100%);
  filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.8));
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 3D voxel view: the voxel canvas overlays the stage exactly where
   the 2D canvas sits, and the toggle + zoom controls ride top-left.
   The voxel module owns showing/hiding the stage; the game canvas
   is hidden in 3D. The HUD readout sits bottom-left in 3D only. */
#voxel-stage {
  position: absolute;
  inset: 0;
  display: none;
  border-radius: 12px;
  overflow: hidden;
  z-index: 4;
}
#voxel-stage canvas {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 12px;
  background: #0b0e14;
}
#voxel-bar {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 7;
  display: flex;
  gap: 6px;
  align-items: center;
}
#voxel-bar button {
  width: auto;
  margin: 0;
  padding: 8px 12px;
  font-size: 13px;
  background: rgba(18, 22, 31, 0.8);
  color: #e8ecf3;
  border: 1px solid #232a38;
}
#voxel-bar button:hover { background: rgba(255, 215, 106, 0.85); color: #0b0e14; }
#voxel-bar button:disabled { background: rgba(58, 67, 86, 0.8); color: #8b96a8; }
#voxel-zoom { display: flex; gap: 6px; }
#voxel-zoom[hidden] { display: none; }
#voxel-hud {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 6;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: pre-line;
  border-radius: 8px;
  pointer-events: none;
}

/* ---- Touch drive controls (phones) ----
   Fixed to the bottom of the screen so both thumbs reach them, in
   2D and in 3D alike — the bar lives outside the canvas and the
   voxel stage, so orbiting the 3D camera never fights the pedals.
   Hidden unless the device has a coarse pointer (touch) AND the
   race is running; the frame loop toggles .hidden, the CSS gates
   on <html data-touch="coarse"> which main.ts sets at load. */
#touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
#touch-controls.hidden { display: none; }
html:not([data-touch="coarse"]) #touch-controls { display: none; }
#touch-controls .tc-cluster {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  pointer-events: none;
  flex-shrink: 0;
}
#touch-controls button {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 26px;
  background: rgba(18, 22, 31, 0.82);
  color: var(--text);
  border: 2px solid var(--edge);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
#touch-controls button.active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
#touch-controls #tc-gas {
  width: 88px;
  height: 88px;
  font-size: 20px;
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
#touch-controls #tc-brake { font-size: 15px; }
#touch-controls #tc-gear {
  width: 56px;
  height: 56px;
  font-size: 13px;
  border-radius: 16px;
}
#touch-controls #tc-pause {
  /* Out of the bottom row: the full drive set (steer + 3 pedals)
     is 458px wide at full size and squeezes on a 390px phone.
     Pause rides top-right under the settings button instead —
     it is a rare tap, the pedals are the thumbs' job. */
  position: fixed;
  top: 56px;
  right: 8px;
  width: 48px;
  height: 48px;
  font-size: 18px;
  border-radius: 14px;
}
/* Narrow phones: smaller pedals so the bar fits 360px screens
   with nothing squeezed (336px of buttons + 20px padding). */
@media (max-width: 560px) {
  #touch-controls { padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
  #touch-controls .tc-cluster { gap: 8px; }
  #touch-controls button { width: 64px; height: 64px; font-size: 24px; }
  #touch-controls #tc-gas { width: 72px; height: 72px; font-size: 18px; }
  #touch-controls #tc-gear { width: 48px; height: 48px; font-size: 12px; }
}

/* ---- Phone layout: the menu panel scrolls internally instead
   of clipping, type steps down, nothing runs off the sides. ---- */
@media (max-width: 560px) {
  body { padding: 8px; }
  h1 { font-size: 29px; letter-spacing: 1px; }
  .panel { gap: 9px; padding: 12px 10px; overflow-y: auto; justify-content: flex-start; }
  .controls { font-size: 12.5px; line-height: 1.55; }
  button { padding: 10px 14px; font-size: 14px; }
  #btn-settings { top: 8px; right: 8px; width: 40px; height: 40px; }
  /* Under the pause button (top 56, 48 tall) — never on top of it. */
  #btn-sound { top: 110px; right: 8px; width: 40px; height: 40px; }
  #sheet { top: 56px; right: 8px; }
  .lobby-row { flex-wrap: wrap; justify-content: center; }
  input { max-width: 100%; }
}

/* ---- Handheld console mode ----
   The phone IS the handheld: the game becomes the LCD (dark bezel,
   scanlines, glass glare) and the phone's lower half becomes the
   cream plastic body — D-pad left, pedals right, START/SELECT pills
   centred below, speaker grille bottom-right. The same touch
   buttons drive the game; only their arrangement changes. On by
   default on touch devices (the pre-paint script), off on desktop,
   a saved choice wins — the 🎮 button and the Customize sheet flip
   it. In flat mode #handheld-body contributes no box
   (display: contents) so the floating bottom bar works exactly as
   before; only its brand/speaker children hide. */
#lcd { position: relative; width: 100%; aspect-ratio: 4 / 3; }
#lcd-fx {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
  border-radius: 12px;
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.10) 0%, rgba(255, 255, 255, 0.02) 28%, transparent 45%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.14) 0 1px, transparent 1px 3px),
    radial-gradient(120% 90% at 50% 50%, transparent 62%, rgba(0, 0, 0, 0.22) 100%);
}
#handheld-body { display: contents; }
.hh-brand, .hh-speaker { display: none; }
.hh-hint { display: none; }
/* D-pad up/down + the cross centre only exist on the console. */
#touch-controls #tc-up, #touch-controls #tc-down,
#touch-controls .tc-dpad-center, #touch-controls #hh-select { display: none; }
#touch-controls .tc-pills { display: contents; }

html[data-handheld="on"] body { padding: 0; align-items: center; }
html[data-handheld="on"] #app {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  aspect-ratio: auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #ddd6c2, #cfc7ad);
  border-radius: 0;
  overflow: hidden;
}
@media (pointer: fine) {
  html[data-handheld="on"] #app {
    border-radius: 28px;
    margin: 12px 0;
    height: calc(100dvh - 24px);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  }
}
html[data-handheld="on"] #status { display: none; }
/* The LCD: dark bezel around the screen area. The screen children
   sit inset 10px inside it, so the bezel is even on all sides. */
html[data-handheld="on"] #lcd {
  flex: none;
  width: auto;
  margin: 12px 12px 0;
  background: #17171a;
  border-radius: 18px;
}
html[data-handheld="on"] #lcd canvas#game {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  border-radius: 6px;
}
html[data-handheld="on"] #voxel-stage { inset: 10px; border-radius: 6px; }
html[data-handheld="on"] #voxel-stage canvas { border-radius: 6px; }
html[data-handheld="on"] #voxel-bar { top: 18px; left: 18px; }
html[data-handheld="on"] #voxel-hud { left: 18px; bottom: 18px; }
html[data-handheld="on"] #lcd-fx { display: block; inset: 10px; border-radius: 6px; }
html[data-handheld="on"] #lcd .panel { inset: 10px; border-radius: 6px; z-index: 8; }
html[data-handheld="on"] #fx-layer { inset: 10px; border-radius: 6px; }
/* The menu drops its long manual on the small LCD — the console
   IS the controls. A one-line hint replaces it. */
html[data-handheld="on"] #menu .controls { display: none; }
html[data-handheld="on"] #menu .hh-hint {
  display: block;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.6;
  max-width: 340px;
  margin: 0;
}
/* The console body: brand top, controls middle, speaker bottom. */
html[data-handheld="on"] #handheld-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  justify-content: space-between;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  gap: 10px;
}
html[data-handheld="on"] .hh-brand {
  display: block;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 3px;
  color: #3a352a;
}
html[data-handheld="on"] .hh-brand span {
  display: block;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 4px;
  color: #6d6754;
  margin-top: 2px;
}
html[data-handheld="on"] .hh-speaker {
  display: block;
  margin: 4px 4px 0 auto;
  width: 118px;
  height: 52px;
  background-image: radial-gradient(circle, #8f8871 1.6px, transparent 1.8px);
  background-size: 11px 11px;
  transform: rotate(-18deg);
  opacity: 0.8;
}
/* The touch bar becomes the console's controls: D-pad + pedals on
   one row, START/SELECT pills centred below. The hardware is
   always visible in handheld mode — never hidden mid-race. */
html[data-handheld="on"] #touch-controls {
  position: static;
  z-index: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "dpad pedals" "pills pills";
  gap: 14px 8px;
  padding: 0;
  align-items: center;
  justify-items: center;
  pointer-events: none;
}
html[data-handheld="on"] #touch-controls.hidden { display: grid; }
html[data-handheld="on"] #touch-controls .tc-steer {
  grid-area: dpad;
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 3px;
  align-items: center;
  justify-items: center;
}
html[data-handheld="on"] #touch-controls .tc-pedals { grid-area: pedals; }
html[data-handheld="on"] #touch-controls .tc-pills {
  grid-area: pills;
  display: flex;
  gap: 14px;
  justify-content: center;
}
html[data-handheld="on"] #touch-controls #tc-up { display: block; grid-row: 1; grid-column: 2; }
html[data-handheld="on"] #touch-controls #tc-left { grid-row: 2; grid-column: 1; }
html[data-handheld="on"] #touch-controls #tc-right { grid-row: 2; grid-column: 3; }
html[data-handheld="on"] #touch-controls #tc-down { display: block; grid-row: 3; grid-column: 2; }
html[data-handheld="on"] #touch-controls .tc-dpad-center {
  display: block;
  grid-row: 2;
  grid-column: 2;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #26262b;
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.18);
}
/* D-pad arms: dark plastic squares, not the round pedal buttons. */
html[data-handheld="on"] #touch-controls .tc-steer button {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 18px;
  background: #26262b;
  color: #d8d2c0;
  border: 1px solid #17171a;
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.18), 0 3px 0 rgba(0, 0, 0, 0.35);
}
html[data-handheld="on"] #touch-controls .tc-steer button.active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
/* Pedals shrink to fit the console row beside the D-pad. */
html[data-handheld="on"] #touch-controls .tc-pedals button { width: 56px; height: 56px; }
html[data-handheld="on"] #touch-controls #tc-gas { width: 64px; height: 64px; font-size: 16px; }
html[data-handheld="on"] #touch-controls #tc-gear { width: 44px; height: 44px; font-size: 11px; }
html[data-handheld="on"] #touch-controls #tc-brake { font-size: 13px; }
/* START/SELECT: grey pills, like the real hardware. The pause
   button's ⏸ glyph becomes the START label on the console. */
html[data-handheld="on"] #touch-controls #hh-select { display: block; }
html[data-handheld="on"] #touch-controls .tc-pills button {
  width: 76px;
  height: 28px;
  border-radius: 14px;
  font-size: 11px;
  letter-spacing: 1px;
  background: #8f8871;
  color: #3a352a;
  border: 1px solid #a39a80;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
html[data-handheld="on"] #touch-controls #tc-pause {
  /* The base rule fixes pause top-right of the viewport; on the
     console it is a static START pill in the pills row. The
     two-ID selector is needed to beat that base rule. */
  position: static;
  width: 76px;
  height: 28px;
  font-size: 0;
}
html[data-handheld="on"] #touch-controls #tc-pause::after {
  content: "START";
  font-size: 11px;
  letter-spacing: 1px;
}
/* Narrow phones: smaller controls so the D-pad + pedals row fits
   a 360px screen with room to spare. */
@media (max-width: 400px) {
  html[data-handheld="on"] #touch-controls .tc-steer {
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
  }
  html[data-handheld="on"] #touch-controls .tc-steer button,
  html[data-handheld="on"] #touch-controls .tc-dpad-center { width: 42px; height: 42px; }
  html[data-handheld="on"] #touch-controls .tc-pedals button { width: 48px; height: 48px; }
  html[data-handheld="on"] #touch-controls #tc-gas { width: 56px; height: 56px; font-size: 15px; }
  html[data-handheld="on"] #touch-controls #tc-gear { width: 40px; height: 40px; font-size: 10px; }
}

/* ---- Handheld visual fixes (from the rig screenshots) ----
   1. The voxel bar bleeds through the translucent menu and covers
      the 2D HUD's left line, so on the console it hides while any
      panel is open and rides top-CENTRE while racing (over the
      road divider, clear of both HUDs). The gear + sheet still
      reach the Handheld toggle from the menu.
   2. The floating sound button sat on the right road; on the
      console it moves to the body's free bottom-left corner.
   3. The small LCD's menu drops its tag + version lines and
      tightens up, so the title, the three mode buttons and the
      controls hint all fit without scrolling.
   4. The tall body gets its period slogan between the brand and
      the controls, breaking up the empty plastic. */
html[data-handheld="on"] #lcd:has(.panel:not(.hidden)) #voxel-bar { display: none; }
html[data-handheld="on"] #voxel-bar { left: 50%; transform: translateX(-50%); top: 18px; }
html[data-handheld="on"] #btn-sound { top: auto; bottom: 12px; left: 12px; right: auto; }
html[data-handheld="on"] #lcd .panel { gap: 8px; }
html[data-handheld="on"] #menu h1 { font-size: 24px; }
html[data-handheld="on"] #menu .tag, html[data-handheld="on"] #menu .version { display: none; }
.hh-slogan { display: none; }
html[data-handheld="on"] .hh-slogan {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #6d6754;
  text-align: center;
}
html[data-handheld="on"] .hh-slogan::before,
html[data-handheld="on"] .hh-slogan::after {
  content: "";
  height: 1px;
  width: 44px;
  background: #a39a80;
}
