:root {
  --paper: #F4EAD8;
  --paper-deep: #E9DBBE;
  --ink: #23241C;
  --petrol: #14303A;
  --petrol-soft: #2C4A4E;
  --orange: #D9481F;
  --red: #CF2233;
  --amber: #E9A13B;
  --sand: #DFC79A;
  --cream: #F8F0DC;
  --bezel: #2B3A33;
  --bezel-2: #35463D;
  --screen: #0B1712;
  --phos: #86E0A8;
  --phos-dim: #3F8F65;
  --amber-lit: #FFB45E;
  --dockH: 0px;
  --dockW: 0px;
  --safeB: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Archivo', system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
[hidden] { display: none !important; }

#game {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: var(--paper);
}
#game canvas { display: block; }

#paper {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.55;
  mix-blend-mode: multiply;
  background-repeat: repeat;
  background-size: 128px 128px;
}
#paper::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 160px rgba(56, 39, 20, 0.16), inset 0 0 20px rgba(56, 39, 20, 0.08);
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
#ui::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 18, 0.38);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 0;
  pointer-events: none;
}
body.arcade-open #ui::before { opacity: 1; }

/* ------------------------------------------------------------- header */
#posterHead {
  position: absolute;
  top: 0;
  left: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 0 0 18px;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.3s ease;
  max-width: calc(100% - 150px);
}
body.arcade-open #posterHead { opacity: 0.28; }

#title {
  position: relative;
  display: inline-block;
  font-family: 'Jost', sans-serif;
  font-weight: 500;
  font-size: clamp(24px, 3.5vw, 52px);
  line-height: 0.94;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--cream);
  background: var(--petrol);
  padding: 4px 8px 5px;
  border-radius: 2px;
  text-shadow: 1.5px 1px 0 rgba(233, 161, 59, 0.55);
  white-space: nowrap;
}
#title em {
  font-style: normal;
  color: var(--orange);
  text-shadow: 1.5px 1px 0 rgba(20, 48, 58, 0.45);
}
#title::before {
  display: none;
}

#hud {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 8px;
  padding: 6px 11px 7px;
  background: rgba(248, 240, 220, 0.9);
  border: 1.5px solid var(--petrol);
  border-radius: 2px;
  box-shadow: 3px 3px 0 rgba(20, 48, 58, 0.14);
  width: max-content;
  max-width: 100%;
}
.hud-cell { display: flex; align-items: baseline; gap: 5px; }
.hud-cell .lbl {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--petrol);
  opacity: 0.78;
}
.hud-cell .val {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 500;
  font-size: 26px;
  line-height: 0.9;
  letter-spacing: 0.02em;
  color: var(--petrol);
  font-variant-numeric: tabular-nums;
}
.hud-cell .val.small { font-size: 16px; }
.hud-cell .unit {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
  color: var(--orange);
}
.batt {
  width: 74px;
  height: 13px;
  border: 1.5px solid var(--petrol);
  position: relative;
  background: rgba(20, 48, 58, 0.06);
}
.batt-fill {
  position: absolute;
  inset: 1.5px;
  width: calc(100% - 3px);
  background: var(--orange);
  transform-origin: left center;
  transition: transform 0.15s linear, background 0.2s;
}
.batt-ticks {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 9px, rgba(20, 48, 58, 0.55) 9px 10px);
}
.hud-cell.low .batt-fill { background: var(--red, #CF2233); animation: lowbatt 0.9s steps(2) infinite; }
@keyframes lowbatt { 50% { opacity: 0.35; } }
.hud-best { display: none; }
@media (min-width: 900px) { .hud-best { display: flex; } }

#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 14px;
  margin-top: 8px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--petrol);
  text-transform: uppercase;
}
#legend span { display: flex; align-items: center; gap: 4px; opacity: 0.86; }
#legend b {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 4px 1px;
  border: 1px solid rgba(20, 48, 58, 0.5);
  border-radius: 2px;
  background: rgba(248, 240, 220, 0.55);
}
@media (hover: none), (pointer: coarse) { #legend { display: none; } }

#topTools {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 16px;
  display: flex;
  gap: 7px;
  z-index: 3;
  pointer-events: auto;
  transition: opacity 0.3s ease;
}
body.arcade-open #topTools { opacity: 0; pointer-events: none; }
.stamp {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--petrol);
  background: rgba(248, 240, 220, 0.9);
  border: 1.5px solid var(--petrol);
  border-radius: 2px;
  padding: 6px 8px 5px;
  box-shadow: 2px 2px 0 rgba(20, 48, 58, 0.16);
  min-width: 30px;
}
.stamp:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 rgba(20, 48, 58, 0.16); }
#btnRanks { color: var(--orange); }

/* ------------------------------------------------------------- ignition */
.ignition {
  position: absolute;
  left: 50%;
  top: 80%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 24px 7px;
  background: var(--orange);
  color: var(--cream);
  border: 2px solid var(--petrol);
  border-radius: 2px;
  box-shadow: 5px 5px 0 rgba(20, 48, 58, 0.26);
  z-index: 5;
  pointer-events: auto;
  animation: pulseStamp 2.4s ease-in-out infinite;
}
.ignition .ig-big {
  font-family: 'Jost', sans-serif;
  font-weight: 600;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.13em;
}
.ignition .ig-small {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.14em;
  opacity: 0.9;
}
@keyframes pulseStamp {
  0%, 100% { box-shadow: 5px 5px 0 rgba(20, 48, 58, 0.26); }
  50% { box-shadow: 5px 5px 0 rgba(20, 48, 58, 0.26), 0 0 0 7px rgba(217, 72, 31, 0.16); }
}
body.driving .ignition, body.arcade-open .ignition, body.ended .ignition { display: none; }

/* ------------------------------------------------------------- touch */
.touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--dockH) + var(--safeB) + 12px);
  display: none;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 6;
  pointer-events: none;
}
@media (hover: none), (pointer: coarse) {
  .touch { display: flex; }
}
body[data-dock="side"] .touch { right: var(--dockW); }
body[data-dock="float"] .touch { right: calc(var(--cockpitW, 380px) + 28px); }
body[data-dock="side"] #topTools { right: calc(var(--dockW) + 12px); }
body[data-dock="side"] .bezel-main { flex-direction: column; }
body[data-dock="side"] .left-col { width: auto; flex: 0 0 auto; flex-direction: row; align-items: center; gap: 10px; }
body[data-dock="side"] .vents { width: 52px; height: auto; flex-direction: column; flex: 0 0 52px; }
body[data-dock="side"] .dials { flex: 0 0 auto; justify-content: flex-start; gap: 8px; }
body[data-dock="side"] .dial canvas { width: 42px; height: 42px; }
body[data-dock="side"] .screen-col { flex: 1; min-height: 0; }
body[data-dock="side"] .cockpit:not(.open) .bezel-main { flex: 0 0 auto; }
body[data-dock="side"] .cockpit:not(.open) .screen-wrap { flex: 0 0 auto; aspect-ratio: 8 / 5; width: 100%; }
body[data-dock="side"] .cockpit:not(.open) .screen-col { flex: 0 0 auto; }
body[data-dock="side"] .cockpit.open .bezel-main { flex-direction: row; }
body[data-dock="side"] .cockpit.open .left-col { width: 118px; flex: 0 0 118px; flex-direction: column; gap: 6px; }
body[data-dock="side"] .cockpit.open .vents { width: auto; height: 8px; flex-direction: row; flex: none; }
body[data-dock="side"] .cockpit.open .dials { flex: 1; justify-content: space-around; }
body.arcade-open .touch, body.ended .touch, body.paused .touch { display: none !important; }
.touch-cluster { display: flex; flex-direction: column; gap: 8px; pointer-events: auto; align-items: flex-start; }
.tlabel {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 7px;
  letter-spacing: 0.16em;
  color: var(--cream);
  background: rgba(20, 48, 58, 0.72);
  border: 1px solid rgba(248, 240, 220, 0.5);
  border-radius: 2px;
  padding: 3px 5px 2px;
  margin-bottom: 1px;
}
.touch-cluster.right { align-items: flex-end; }
.touch-cluster.right .tlabel { align-self: flex-end; }
.tbtn {
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--petrol);
  background: rgba(248, 240, 220, 0.82);
  border: 2px solid var(--petrol);
  border-radius: 3px;
  box-shadow: 3px 3px 0 rgba(20, 48, 58, 0.2);
  touch-action: none;
}
.tbtn:active, .tbtn.held {
  background: var(--amber);
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 rgba(20, 48, 58, 0.2);
}
.tbtn.boost { color: var(--cream); background: rgba(217, 72, 31, 0.9); border-color: var(--cream); width: 66px; }
.tbtn.boost:active, .tbtn.boost.held { background: var(--orange); }
.tbtn.brake { width: 58px; }

/* ------------------------------------------------------------- cockpit */
#cockpitLayer {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}
.cockpit {
  position: absolute;
  left: 0;
  top: 0;
  width: 380px;
  height: 250px;
  padding: 0;
  pointer-events: auto;
  transition: width 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform, width, height;
  z-index: 32;
}
body.arcade-open .cockpit { z-index: 70; }
.bezel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--bezel);
  border: 2px solid var(--cream);
  border-radius: 17px;
  box-shadow: 0 7px 0 rgba(20, 48, 58, 0.2), inset 0 0 0 1px rgba(11, 18, 16, 0.55), inset 0 2px 0 rgba(248, 240, 220, 0.1);
  position: relative;
  overflow: hidden;
}
.bezel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 18% 0%, rgba(248, 240, 220, 0.07), transparent 55%),
    repeating-linear-gradient(0deg, rgba(11, 18, 16, 0.16) 0 1px, transparent 1px 3px);
  opacity: 0.5;
}
.bezel-main {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 9px;
  position: relative;
  z-index: 1;
}
.left-col {
  width: 88px;
  flex: 0 0 88px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.vents { display: flex; gap: 4px; height: 8px; }
.vents i {
  flex: 1;
  height: 7px;
  border-radius: 4px;
  background: #16221D;
  box-shadow: inset 0 1px 0 rgba(248, 240, 220, 0.08);
}
.dials {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 4px;
  min-height: 0;
}
.dial { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dial canvas { width: 44px; height: 44px; display: block; }
.dial span {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 7px;
  letter-spacing: 0.12em;
  color: rgba(248, 240, 220, 0.6);
}
.screen-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.screen-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0A1410;
  border: 2px solid #66786C;
  border-radius: 9px;
  padding: 4px;
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.85), 0 0 0 1px #131E19;
  position: relative;
  overflow: hidden;
}
#screen {
  display: block;
  background: var(--screen);
  border-radius: 4px;
  touch-action: none;
  box-shadow: 0 0 18px rgba(79, 208, 134, 0.16);
}
.screen-glass {
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.55);
}
.screen-scan {
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.14) 0 1px, transparent 1px 3px);
  opacity: 0.45;
}
.iconbar {
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  flex: 0 0 25px;
}
.icon-btn {
  width: 25px;
  height: 23px;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid rgba(248, 240, 220, 0.28);
  border-radius: 3px;
  color: rgba(248, 240, 220, 0.82);
}
.icon-btn svg { width: 100%; height: 100%; fill: currentColor; }
.icon-btn:active { background: var(--orange); color: var(--cream); border-color: var(--cream); }
.icon-btn.on { color: var(--amber-lit); border-color: rgba(233, 161, 59, 0.8); }
.icon-btn.batt-icon { color: rgba(248, 240, 220, 0.8); cursor: default; }
.icon-btn.batt-icon svg rect#battIconFill { fill: var(--amber); }

.arcade-close {
  display: none;
  position: absolute;
  right: 0;
  top: -31px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--cream);
  background: var(--orange);
  border: 2px solid var(--cream);
  border-radius: 2px;
  padding: 6px 9px 5px;
  box-shadow: 2px 2px 0 rgba(11, 18, 16, 0.4);
}
.cockpit.open .arcade-close { display: block; }
.cockpit.open .bezel {
  border-width: 3px;
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 12px 0 rgba(11, 18, 16, 0.3), inset 0 0 0 1px rgba(11, 18, 16, 0.6), inset 0 2px 0 rgba(248, 240, 220, 0.12);
}
.cockpit.open .screen-wrap { animation: crt-on 0.34s ease-out; }
.bezel-foot { display: none; }
body[data-dock="side"] .cockpit:not(.open) .bezel-foot {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 2px 0;
  border-top: 1px solid rgba(248, 240, 220, 0.18);
  background: repeating-linear-gradient(0deg, transparent 0 11px, rgba(11, 18, 16, 0.22) 11px 13px);
}
.bf-grille { display: none; }
.bf-grille i { height: 6px; border-radius: 3px; background: #15211C; box-shadow: inset 0 1px 0 rgba(248, 240, 220, 0.06); }
.bf-mark { display: flex; align-items: baseline; gap: 9px; }
.bf-name {
  font-family: 'Jost', sans-serif;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.24em;
  color: rgba(248, 240, 220, 0.68);
}
.bezel-foot em {
  font-family: 'IBM Plex Mono', monospace;
  font-style: normal;
  font-size: 6px;
  letter-spacing: 0.18em;
  color: rgba(248, 240, 220, 0.35);
}
.bf-vents { display: flex; gap: 4px; }
.bf-vents i { height: 5px; flex: 1; border-radius: 3px; background: #16221D; box-shadow: inset 0 1px 0 rgba(248, 240, 220, 0.07); }
@keyframes crt-on {
  0% { filter: brightness(2.4) saturate(0.2); }
  45% { filter: brightness(1.5) saturate(0.7); }
  100% { filter: none; }
}
.cockpit.open .left-col { width: 118px; flex-basis: 118px; }
.cockpit.open .dial canvas { width: 52px; height: 52px; }
@media (max-width: 380px) {
  #title { font-size: 20px; }
  #btnRanks { display: none; }
  #hud { gap: 3px 7px; }
  .hud-cell .val { font-size: 19px; }
  .hud-cell .val.small { font-size: 12px; }
  .batt { width: 38px; }
}

@media (max-width: 620px) {
  .cockpit.open .left-col { display: none; }
  .cockpit.open .bezel { padding: 10px; }
  .cockpit.open .screen-col { gap: 5px; }
  .cockpit.open .iconbar { height: 27px; flex-basis: 27px; }
  .cockpit.open .icon-btn { width: 28px; height: 25px; }
}

body.arcade-open .touch { opacity: 0; }

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 24, 22, 0.58);
  backdrop-filter: blur(2px);
  overflow: auto;
  touch-action: pan-y;
  pointer-events: auto;
  animation: overlayIn 0.22s ease;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.card {
  position: relative;
  width: min(700px, 94vw);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 26px 26px 22px;
  background: var(--paper);
  border: 2px solid var(--petrol);
  border-radius: 3px;
  box-shadow: 10px 10px 0 rgba(20, 48, 58, 0.28);
  color: var(--petrol);
  touch-action: pan-y;
}
.card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(20, 48, 58, 0.22);
  pointer-events: none;
}
.card > * { position: relative; z-index: 1; }
.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--orange);
  margin-bottom: 8px;
}
.card h2 {
  font-family: 'Jost', sans-serif;
  font-weight: 500;
  font-size: clamp(26px, 4vw, 40px);
  letter-spacing: 0.04em;
  line-height: 1;
  margin-bottom: 14px;
}
.card h3 {
  font-family: 'Jost', sans-serif;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}
.card-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.14em;
  background: transparent;
  border: 1px solid rgba(20, 48, 58, 0.45);
  border-radius: 2px;
  padding: 5px 7px;
  color: var(--petrol);
}
.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 22px;
  margin: 6px 0 16px;
}
.help-grid span {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.16em;
  color: var(--orange);
  margin-bottom: 3px;
}
.help-grid p { font-size: 13px; line-height: 1.45; }
.help-note {
  font-size: 12px;
  line-height: 1.5;
  color: rgba(20, 48, 58, 0.82);
  border-top: 1px solid rgba(20, 48, 58, 0.25);
  padding-top: 12px;
}
.ranks-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 24px;
  margin-bottom: 16px;
}
.ranks-grid ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
}
.ranks-grid li {
  counter-increment: rank;
  display: flex;
  gap: 7px;
  padding: 4px 0;
  border-bottom: 1px dotted rgba(20, 48, 58, 0.25);
  align-items: baseline;
}
.ranks-grid li::before {
  content: counter(rank) ".";
  color: var(--orange);
  width: 16px;
  flex: 0 0 16px;
}
.ranks-grid li a {
  color: var(--petrol);
  text-decoration: none;
  border-bottom: 1px solid rgba(217, 72, 31, 0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ranks-grid li b {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ranks-grid li.empty { color: rgba(20, 48, 58, 0.5); font-size: 10px; }
.ranks-grid li.empty::before { content: ""; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn-primary, .btn-ghost {
  font-family: 'Archivo', sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 2px;
  padding: 12px 20px 11px;
  border: 2px solid var(--petrol);
}
.btn-primary {
  background: var(--orange);
  color: var(--cream);
  box-shadow: 4px 4px 0 rgba(20, 48, 58, 0.26);
}
.btn-primary:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(20, 48, 58, 0.26); }
.btn-ghost { background: transparent; color: var(--petrol); }
.pause-card { width: min(440px, 92vw); }
.pause-card p { font-size: 13px; line-height: 1.5; margin-bottom: 4px; }
.result-card { width: min(560px, 94vw); }
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px 0 18px;
}
.result-grid > div {
  border: 1px solid rgba(20, 48, 58, 0.3);
  padding: 9px 10px;
  background: rgba(233, 219, 190, 0.35);
}
.result-grid span {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 7px;
  letter-spacing: 0.14em;
  color: rgba(20, 48, 58, 0.7);
  margin-bottom: 3px;
}
.result-grid strong {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.result-board { margin-top: 4px; }
.result-board ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
}
.result-board li {
  counter-increment: rank;
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px dotted rgba(20, 48, 58, 0.25);
}
.result-board li::before { content: counter(rank) "."; color: var(--orange); width: 16px; flex: 0 0 16px; }
.result-board li a {
  color: var(--petrol);
  text-decoration: none;
  border-bottom: 1px solid rgba(217, 72, 31, 0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-board li b { margin-left: auto; font-weight: 600; }
.result-board li.empty { color: rgba(20, 48, 58, 0.5); font-size: 10px; }
.result-board li.empty::before { content: ""; }

#toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 100px);
  transform: translate(-50%, -10px);
  background: var(--petrol);
  color: var(--cream);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 8px 12px 7px;
  border-radius: 2px;
  border: 1px solid rgba(248, 240, 220, 0.4);
  box-shadow: 3px 3px 0 rgba(20, 48, 58, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 75;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.arcade-open #toast { top: calc(env(safe-area-inset-top, 0px) + 20px); }

/* ------------------------------------------------------------- small screens */
@media (max-width: 380px) {
  #title { font-size: 20px; }
  #btnRanks { display: none; }
  #hud { gap: 3px 7px; }
  .hud-cell .val { font-size: 19px; }
  .hud-cell .val.small { font-size: 12px; }
  .batt { width: 38px; }
}

@media (max-width: 620px) {
  #posterHead {
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 0 0 12px;
    max-width: calc(100% - 100px);
  }
  #hud { gap: 3px 10px; padding: 5px 8px 5px; margin-top: 7px; }
  .hud-cell .val { font-size: 21px; }
  .hud-cell .val.small { font-size: 13px; }
  .hud-cell .lbl { font-size: 7px; }
  .batt { width: 48px; height: 11px; }
  .hud-cell .batt + .val { display: none; }
  .hud-cell:nth-child(3) .lbl { display: none; }
  .hud-cell:nth-child(3) .unit { font-size: 7px; }
  #topTools { top: calc(env(safe-area-inset-top, 0px) + 10px); right: 10px; }
  .stamp { padding: 5px 6px 4px; font-size: 8px; }
  .card { padding: 22px 18px 18px; }
  .help-grid { grid-template-columns: 1fr; gap: 11px; }
  .ranks-grid { grid-template-columns: 1fr; gap: 14px; }
  .result-grid { gap: 6px; }
  .result-grid strong { font-size: 15px; }
  .ignition { padding: 8px 20px 6px; }
  .ignition .ig-big { font-size: 20px; }
  .card-close { top: 10px; right: 10px; }
}
@media (max-height: 480px) {
  #legend { display: none; }
  #title { font-size: 22px; }
  .hud-cell .val { font-size: 18px; }
  .hud-cell .val.small { font-size: 12px; }
  #audit { display: none; }
}

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