:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: #eee8d7;
  background: #10191b;
  --case: #172526;
  --panel: #1d2b2b;
  --line: #3a4b48;
  --muted: #b1bcb0;
  --accent: #edce93;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button { color: inherit; font: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
.cabinet {
  width: min(100%, 500px);
  min-height: 100vh;
  min-height: 100svh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto minmax(254px, 1fr) auto auto;
  background: var(--case);
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(0px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
}

.masthead {
  padding: 0 4px 12px;
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.wordmark { display: flex; gap: 8px; align-items: center; }
.wordmark h1 { font-size: 1.72rem; line-height: 1.1; font-weight: 650; white-space: nowrap; }
.mark { display: grid; gap: 3px; transform: skewX(-26deg); }
.mark i { width: 14px; height: 2px; background: var(--accent); }
.mark i:nth-child(2) { width: 10px; }
.mark i:nth-child(3) { width: 6px; }
.roman { color: var(--muted); font: 0.65rem var(--mono); white-space: nowrap; }
html[lang="en"] .roman { display: none; }
.course { display: grid; gap: 2px; text-align: right; white-space: nowrap; }
.course span, .label { color: var(--muted); font-size: 0.7rem; }
.course strong { font-size: 0.85rem; font-weight: 550; }

.console {
  display: grid;
  grid-template-rows: auto 3px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #101b1d;
}
.telemetry { display: grid; grid-template-columns: 1fr 0.9fr 1fr; padding: 8px 12px; gap: 4px; }
.dial { display: grid; align-content: center; gap: 2px; }
.dial div { display: flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.dial b { font: 600 1.34rem/1 var(--mono); }
.dial small { color: var(--muted); font-size: 0.68rem; }
.time { border-inline: 1px solid #2d3c3c; text-align: center; }
.time div { justify-content: center; }
.time b { color: var(--accent); }
.time.urgent b { color: #ffad93; }
.distance, .distance div { justify-content: end; text-align: right; }
progress { width: 100%; height: 3px; border: 0; appearance: none; background: #344844; accent-color: var(--accent); }
progress::-webkit-progress-bar { background: #344844; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.screen { position: relative; isolation: isolate; background: #39767b; }
#track { display: block; width: 100%; height: 100%; position: absolute; inset: 0; }
.screen-top { position: absolute; inset: 8px 8px auto; display: flex; align-items: start; justify-content: space-between; z-index: 2; pointer-events: none; }
.cue, .pause { background: #192827; color: #f0e4ca; border: 1px solid #75827a; }
.cue { padding: 8px; border-radius: 4px; font-size: 0.8rem; }
.cue.turn { border-color: #b4986b; }
.cue.checkpoint { color: #ffe1a5; border-color: #d1ae74; }
.cue.incident { border-color: #cc9073; color: #ffe2c8; }
.pause { margin-left: auto; width: 44px; height: 44px; border-radius: 6px; display: grid; place-items: center; pointer-events: auto; }
.pause span { width: 12px; height: 14px; border-inline: 3px solid currentColor; }
.overlay {
  position: absolute;
  inset: auto 0 0;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  background: #172526;
  border-top: 1px solid #607069;
}
.brief h2 { font-size: 0.92rem; font-weight: 600; }
.brief p { color: var(--muted); margin-top: 4px; font-size: 0.73rem; }
.action {
  border: 1px solid #e0ba7f;
  border-radius: 6px;
  background: var(--accent);
  color: #23251e;
  padding: 8px 12px;
  font-size: 0.88rem;
  font-weight: 700;
  min-height: 44px;
  flex-shrink: 0;
}
.action span { margin-left: 4px; font: 1rem var(--mono); }
.countdown {
  position: absolute;
  inset: 18% 0 auto;
  text-align: center;
  font: 700 clamp(2.8rem, 12vw, 4.5rem)/1 var(--mono);
  color: #212d2e;
  text-shadow: 0 1px #f2daa3;
}

.deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(66px, 23%);
  column-gap: 4px;
  margin-top: 8px;
  padding: 8px 0 4px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  align-items: center;
}
.wheel-control, .pedal-control {
  display: grid;
  justify-items: center;
  align-items: end;
  gap: 4px;
}
.pedal-control { padding-inline-end: 8px; }
.control-hint { color: var(--muted); font-size: 0.73rem; text-align: center; }
#wheel {
  width: clamp(136px, 51vw, 216px);
  width: clamp(136px, 24svh, min(57vw, 216px));
  aspect-ratio: 1;
  position: relative;
  cursor: grab;
  border-radius: 50%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#wheel[data-grips="1"], #wheel[data-grips="2"] { cursor: grabbing; }
.wheel-face { position: absolute; inset: 0; transform: rotate(var(--angle, 0deg)); pointer-events: none; }
.rim {
  position: absolute;
  inset: 0;
  border: 18px solid #465350;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px #1a2222, 0 0 0 1px #101819;
  background: #142020;
}
.rim::after { content: ""; position: absolute; inset: -15px; border: 1px solid #63716b; border-radius: 50%; }
.spokes { position: absolute; inset: 15%; background: #69736a; clip-path: polygon(0 34%, 46% 44%, 54% 44%, 100% 34%, 100% 49%, 60% 63%, 60% 100%, 40% 100%, 40% 63%, 0 49%); }
.hub { position: absolute; inset: 37%; border-radius: 50%; border: 1px solid #7e8b80; background: #303d3c; box-shadow: 0 0 0 3px #2b3433; }
.hub::after { content: ""; position: absolute; inset: 43% 30%; background: #a1aa97; border-radius: 2px; }
.grip {
  position: absolute;
  top: calc(50% - 18px);
  width: 14px;
  height: 36px;
  background: repeating-linear-gradient(#80918a 0 2px, #4b5a54 2px 6px);
  border-radius: 6px;
}
.grip.left { left: 2px; }
.grip.right { right: 2px; }
[data-mode="tutorial"][data-input="touch"] .grip, #wheel[data-grips="2"] .grip {
  background: repeating-linear-gradient(#edce93 0 2px, #776c54 2px 6px);
}
.index { position: absolute; top: 2px; left: calc(50% - 4px); width: 8px; height: 11px; border-radius: 2px; background: var(--accent); }

#brake {
  width: clamp(62px, 19vw, 84px);
  height: 74px;
  height: clamp(66px, 11svh, 86px);
  background: #374441;
  border-radius: 12px 12px 8px 8px;
  border: 1px solid #798277;
  box-shadow: 0 4px #111c1d;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.77rem;
  font-weight: 600;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#brake i { width: 28px; height: 22px; border-block: 2px solid #b4baa8; background: linear-gradient(transparent 44%, #b4baa8 44% 56%, transparent 56%); }
#brake[data-held] { transform: translateY(3px); box-shadow: 0 1px #111c1d; background: #644a41; border-color: #ba9280; }
.plate {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.73rem;
  padding-inline: 4px;
}
#garage-return, #practice, #sound { min-height: 44px; border: 0; padding: 0 4px; background: transparent; color: var(--muted); font-size: inherit; }
#practice { margin-left: auto; padding-inline: 8px; }
#sound b { margin-left: 4px; font-weight: 550; color: #eee8d7; }
#language-switch { display: inline-grid; min-height: 44px; align-items: center; padding-inline: 8px; color: var(--accent); text-underline-offset: 3px; }
#language-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
button:hover { filter: brightness(1.07); }
button:disabled { cursor: default; }

@media (max-width: 360px) { .roman { display: none; } }
@media (orientation: landscape) and (max-height: 540px) and (min-width: 560px) {
  .cabinet {
    width: min(100%, 940px);
    min-height: 100vh;
    min-height: 100svh;
    grid-template: auto minmax(230px, 1fr) auto / minmax(0, 1fr) minmax(220px, 34%);
    column-gap: 8px;
  }
  .masthead, .plate { grid-column: 1 / -1; }
  .deck { margin-top: 0; padding: 4px 0; border-top: 0; }
  .overlay { min-height: 56px; padding-block: 4px; }
  #wheel { width: 136px; width: clamp(112px, 35svh, 148px); }
  #brake { width: 62px; height: 65px; }
}


.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.cabinet[data-mode="garage"] { grid-template-rows: auto 1fr auto; }
.cabinet[data-mode="garage"] .console,
.cabinet[data-mode="garage"] .deck { display: none; }
#garage-return { margin-left: auto; }
#garage-return:not([hidden]) + #practice { margin-left: 0; padding-inline: 4px; }

.garage {
  display: grid;
  grid-template-rows: minmax(144px, 1fr) auto;
  gap: 12px;
}
.garage-hero {
  position: relative;
  background: #253735;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#garage-preview {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  object-fit: cover;
}
.garage-heading {
  position: absolute;
  inset: 12px 12px auto;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  z-index: 1;
}
.garage-heading h2, .stage-choice select {
  padding: 6px 9px;
  background: #172526;
  color: #eee8d7;
  border-radius: 4px;
}
.garage-heading h2 { font-size: 0.88rem; font-weight: 650; }
.stage-choice select {
  min-height: 44px;
  max-width: 100%;
  border: 1px solid #718177;
  color: var(--accent);
  font-size: 0.82rem;
  cursor: pointer;
}
.stage-choice select:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.stage-brief {
  position: absolute;
  inset: auto 8px 8px;
  padding: 8px 10px;
  background: #172526;
  color: #eee8d7;
  border-radius: 4px;
  font-size: 0.74rem;
  text-align: center;
}
.garage-options {
  display: grid;
  gap: 12px;
  min-width: 0;
}
#vehicle-list { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.vehicle-option { display: block; position: relative; cursor: pointer; }
.vehicle-option input {
  position: absolute;
  inset: 50% 12px auto auto;
  margin: 0;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  accent-color: var(--accent);
}
.vehicle-tile {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 6px 38px 6px 8px;
  background: #1c2b2b;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.vehicle-option input:checked + .vehicle-tile {
  border-color: #c4a979;
  background: #2a3834;
}
.vehicle-option input:focus-visible + .vehicle-tile {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.vehicle-thumb { width: 62px; height: auto; display: block; }
.vehicle-copy, .vehicle-speed { display: grid; gap: 4px; }
.vehicle-copy strong { font-size: 0.93rem; font-weight: 650; }
.vehicle-copy small, .vehicle-speed small { color: var(--muted); font-size: 0.68rem; }
.vehicle-speed { text-align: right; white-space: nowrap; }
.vehicle-speed b { font: 650 1rem/1 var(--mono); }
.vehicle-option input:checked + .vehicle-tile .vehicle-speed b { color: var(--accent); }
#garage-start {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 48px;
  padding-inline: 16px;
}
#garage-start-label { margin: 0; font: inherit; }

@supports not (accent-color: #edce93) {
  .vehicle-option input { opacity: 0; }
  .vehicle-tile::after {
    content: "";
    position: absolute;
    inset: 50% 12px auto auto;
    transform: translateY(-50%);
    border: 1px solid #b1bcb0;
    border-radius: 50%;
    width: 17px;
    height: 17px;
  }
  .vehicle-option input:checked + .vehicle-tile::after {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: inset 0 0 0 4px #2a3834;
  }
}

@media (max-width: 360px) {
  .garage, .garage-options { gap: 8px; }
  .vehicle-tile { grid-template-columns: 50px minmax(0, 1fr) auto; min-height: 54px; }
  .vehicle-thumb { width: 50px; }
  html[lang="en"] .vehicle-tile { padding-block: 4px; }
}

@media (orientation: landscape) and (max-height: 540px) and (min-width: 560px) {
  .cabinet[data-mode="garage"] { grid-template-columns: 1fr; }
  .garage { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-rows: auto; align-items: center; }
  .garage-hero { aspect-ratio: 1.38; }
}

.route-strip {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--line);
  background: #1c2b2a;
}
.route-caption { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.route-caption span { color: #eee8d7; font-size: 0.72rem; }
.route-caption b { color: var(--muted); font-size: 0.68rem; font-weight: 500; }
#keyboard-guide { margin: 0; color: var(--muted); font-size: 0.72rem; text-align: center; }
#route-stages {
  list-style: none;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  position: relative;
  gap: 2px;
  margin: 0;
  padding: 0;
}
#route-stages::before {
  content: "";
  position: absolute;
  inset: 50% 7% auto;
  height: 1px;
  background: #657266;
}
#route-stages li {
  position: relative;
  min-width: 0;
  justify-self: center;
  border: 1px solid #778377;
  border-radius: 3px;
  background: #223331;
  padding: 3px 5px;
  color: #d4d5c3;
  font: 0.68rem var(--mono);
}
#route-stages li[data-locked="true"] { border-style: dashed; color: #9ba99d; }
#route-stages li[aria-current="step"] { border-color: var(--accent); background: var(--accent); color: #25312a; }

.clear-panel {
  position: absolute;
  z-index: 2;
  inset: auto 12px 12px;
  display: grid;
  justify-items: start;
  gap: 4px;
  padding: 12px 16px;
  border-left: 3px solid #edce93;
  background: #172526;
  color: #f0e4ca;
}
.clear-panel span { color: var(--accent); font: 650 0.75rem var(--mono); }
.clear-panel strong { font-size: 1.12rem; }
.clear-panel small { color: var(--muted); font-size: 0.72rem; }
.record-transfer { width: min(calc(100% - 32px), 420px); margin: 48px auto; }
.record-transfer p { line-height: 1.5; color: var(--muted); margin-block: 12px 24px; }
.record-transfer a { display: inline-grid; align-items: center; min-height: 44px; text-decoration: none; }

@media (prefers-reduced-motion: no-preference) {
  .clear-panel { animation: stage-clear-in 210ms ease-out both; }
  @keyframes stage-clear-in {
    from { opacity: 0; transform: translateY(6px); }
  }
}
