:root {
  color-scheme: dark;
  font-family: "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
  text-rendering: optimizeLegibility;

  --ink: #f2f0e8;
  --muted: #99a19f;
  --panel: #191f22;
  --edge: #30383a;
  --amber: #ffbd4a;
  --green: #65e391;
  --speed-colour: #65e391;
  --focus-colour: var(--amber);
  --page: #101417;
  --glow: #354137;
  --panel-secondary: #202a25;
  --track-background: #101a1d;
  --track-road: #252e32;
  --track-dash: #c4d0ce;
  --track-center: #566165;
  --track-start: #e2c789;
  --track-tree: #091013;
  --track-post: #697676;
  --track-text: #aab8b5;
  --track-amber-off: #473728;
  --track-green-off: #294536;
  --track-red-off: #4a2929;
  --track-car: #f4d06f;
  --track-window: #b8e1eb;
  --track-car-detail: #070b0d;
  --metric-background: #151a1d;
  --feedback-background: #202a26;
  --control-background: #22292b;
  --header-border: #293032;
  --brand-ink: #192019;
  --mono: "Cascadia Mono", Consolas, monospace;
  --display: "Bahnschrift", "Arial Narrow", Impact, sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --ink: #202723;
  --muted: #626e69;
  --panel: #ffffff;
  --edge: #d2d9d5;
  --page: #f0f3ee;
  --glow: #d2dbc8;
  --panel-secondary: #eef2eb;
  --track-background: #e4ebe6;
  --track-road: #606a68;
  --track-dash: #e4ebe6;
  --track-center: #98a29c;
  --track-start: #ffcf76;
  --track-tree: #26312e;
  --track-post: #798782;
  --track-text: #42504a;
  --track-amber-off: #5e4d36;
  --track-green-off: #34583e;
  --track-red-off: #654141;
  --track-car: #e7ae40;
  --track-window: #d8f1f5;
  --track-car-detail: #26312e;
  --metric-background: #f4f6f3;
  --feedback-background: #edf5ed;
  --control-background: #f1f3f0;
  --header-border: #d4dbd5;
  --brand-ink: #202723;
  --green: #18743f;
  --speed-colour: #18743f;
  --focus-colour: #8d6213;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 70% -12%, var(--glow) 0, transparent 34rem),
    var(--page);
}

button {
  min-height: 44px;
  border: 1px solid var(--edge);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid var(--focus-colour);
  outline-offset: 3px;
}

.game {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
}

.masthead {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--header-border);
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  background: var(--panel);
  font-size: 12px;
}

.setting-button[aria-pressed="true"] {
  border-color: var(--focus-colour);
  color: var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  color: var(--brand-ink);
  background: var(--amber);
  font-size: 20px;
}

.brand-accent {
  color: var(--focus-colour);
}

.build-tag,
.eyebrow,
.strip-hint,
.metric-label,
.key-hint,
.footer-note {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.11em;
}

.build-tag,
.strip-hint {
  color: var(--muted);
}

.strip-panel,
.race-panel,
.controls-panel,
.opponent-telemetry,
.tournament-panel,
.performance-panel,
.roadmap-panel {
  margin-top: 18px;
  padding: 20px 24px;
  border: 1px solid var(--edge);
  border-radius: 14px;
  background: var(--panel);
}

.duel-status {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--amber);
  background: var(--panel-secondary);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
}

.duel-complete {
  border-left-color: var(--green);
}

.opponent-telemetry {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 9px;
}

.opponent-telemetry > span:not(.opponent-name) {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.opponent-telemetry small,
.opponent-name {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.opponent-telemetry strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.opponent-telemetry strong span + span {
  margin-left: 0.25em;
  font-size: 10px;
}

.opponent-name {
  align-self: center;
  color: var(--focus-colour);
}

.series-options {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.series-options .button {
  min-width: 44px;
  min-height: 36px;
  border-radius: 6px;
  background: var(--control-background);
}

.series-options .button[aria-pressed="true"] {
  border-color: var(--focus-colour);
  color: var(--focus-colour);
}

.tournament-status {
  margin: 12px 0;
  color: var(--ink);
}

.strip-heading,
.race-topline,
.controls-heading,
.buttons {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.telemetry {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eyebrow {
  margin: 0;
  color: var(--focus-colour);
}

.strip-panel {
  background:
    linear-gradient(120deg, var(--panel-secondary), var(--panel) 52%, var(--panel-secondary));
}

.strip-heading {
  margin-bottom: 8px;
}

.track-stage {
  position: relative;
  overflow: hidden;
  border-radius: 9px;
  background: #101417;
}

#strip-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

.touch-control-dock {
  display: none;
  position: absolute;
  left: 50%;
  width: min(480px, calc(100% - 16px));
  bottom: 8px;
  z-index: 2;
  grid-template-columns: 0.95fr 0.95fr 1.3fr 0.95fr;
  gap: 6px;
  transform: translateX(-50%);
}

.touch-control {
  display: grid;
  min-width: 0;
  min-height: 48px;
  place-items: center;
  padding: 4px 2px;
  border: 1px solid rgb(233 222 190 / 55%);
  border-radius: 7px;
  color: #f2f0e8;
  background: rgb(13 19 21 / 90%);
  font-family: var(--mono);
  font-size: clamp(8px, 2.1vw, 11px);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-control-throttle {
  border-color: #65e391;
  color: #a6f4c0;
}

.touch-control:active {
  transform: scale(0.97);
  filter: brightness(1.2);
}

.scene-scoreboard {
  position: absolute;
  top: 3%;
  z-index: 1;
  width: min(29%, 320px);
  max-height: 47%;
  overflow: auto;
  padding: clamp(7px, 1vw, 14px);
  border: 1px solid rgb(233 222 190 / 42%);
  border-radius: 7px;
  background: rgb(13 19 21 / 88%);
  color: #f2f0e8;
  font-family: var(--mono);
  text-shadow: 0 1px 2px #000;
  scrollbar-color: #697676 transparent;
}

.standings-board {
  left: 1.5%;
}

.personal-bests-board {
  right: 1.5%;
}

.race-speed-comparison {
  position: absolute;
  top: 3%;
  left: 50%;
  z-index: 1;
  max-width: 38%;
  padding: 7px 10px;
  transform: translateX(-50%);
  border: 1px solid rgb(233 222 190 / 42%);
  border-radius: 7px;
  background: rgb(13 19 21 / 88%);
  color: #f2f0e8;
  font-family: var(--mono);
  font-size: clamp(8px, 0.9vw, 11px);
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
}

.scene-race-result {
  position: absolute;
  top: 18%;
  left: 50%;
  z-index: 1;
  width: min(90%, 540px);
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid rgb(233 222 190 / 42%);
  border-radius: 9px;
  background: rgb(13 19 21 / 92%);
  color: #f2f0e8;
  font-family: var(--display);
  font-size: clamp(20px, 3.2vw, 34px);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  text-shadow: 0 2px 8px #000;
  white-space: pre-line;
}

.scene-race-result[hidden] {
  display: none;
}

.scene-scoreboard-title {
  margin: 0 0 7px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: clamp(8px, 0.9vw, 11px);
  letter-spacing: 0.08em;
}

.scene-scoreboard pre {
  overflow: visible;
  margin: 0;
  color: inherit;
  font-family: var(--mono);
  font-size: clamp(7px, 0.8vw, 10px);
  line-height: 1.55;
  white-space: pre-wrap;
}

html[data-theme="light"] .scene-scoreboard {
  border-color: rgb(32 39 35 / 45%);
  background: rgb(240 243 238 / 92%);
  color: #202723;
  text-shadow: none;
}

html[data-theme="light"] .scene-scoreboard-title {
  color: #8d6213;
}

html[data-theme="light"] .race-speed-comparison {
  border-color: rgb(32 39 35 / 45%);
  background: rgb(240 243 238 / 92%);
  color: #202723;
  text-shadow: none;
}

html[data-theme="light"] .scene-race-result {
  border-color: rgb(32 39 35 / 45%);
  background: rgb(240 243 238 / 95%);
  color: #202723;
  text-shadow: none;
}

.race-topline {
  gap: 16px;
}

h1,
h2 {
  margin: 4px 0 0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.015em;
}

h1 {
  font-size: clamp(24px, 4vw, 34px);
}

h2 {
  font-size: 28px;
}

.button-stage {
  border-color: var(--amber);
  border-radius: 8px;
  color: #171714;
  background: var(--amber);
  font-weight: 700;
}

.button-stage {
  min-width: 145px;
  padding: 0 20px;
}

.launch-settings {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-top: 16px;
}

.launch-rpm-control {
  width: min(360px, 100%);
}

.launch-setting-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 3px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.launch-setting-label output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

#launch-rpm {
  display: block;
  width: 100%;
  min-height: 24px;
  margin: 0;
  accent-color: var(--focus-colour);
  cursor: pointer;
}

#engine-power,
#vehicle-mass,
#clutch-capacity,
#tire-grip,
#gear-count,
#final-drive,
#tire-radius {
  display: block;
  width: 100%;
  min-height: 24px;
  margin: 0;
  accent-color: var(--focus-colour);
  cursor: pointer;
}

.tuning-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--metric-background);
}

.tuning-control {
  min-width: 0;
}

.vehicle-presets,
.traction-chart-control {
  grid-column: 1 / -1;
  min-width: 0;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-buttons .button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: var(--control-background);
  font-size: 12px;
}

.preset-buttons .button[aria-pressed="true"] {
  border-color: var(--focus-colour);
  color: var(--focus-colour);
}

.preset-buttons .button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

#traction-chart {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--edge);
  border-radius: 6px;
}

.gear-ratio-row {
  display: grid;
  align-content: end;
  gap: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.gear-chart-control {
  grid-column: 1 / -1;
  min-width: 0;
}

#gear-chart {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--edge);
  border-radius: 6px;
  touch-action: none;
  cursor: crosshair;
}

#gear-chart:focus-visible {
  outline: 2px solid var(--focus-colour);
  outline-offset: 2px;
}

.gear-ratio-row input {
  width: 100%;
  min-height: 30px;
  padding: 4px 8px;
  border: 1px solid var(--edge);
  border-radius: 5px;
  color: var(--ink);
  background: var(--control-background);
  font: inherit;
}

.gear-ratio-row input:focus-visible,
#gear-count:focus-visible {
  outline: 2px solid var(--focus-colour);
  outline-offset: 2px;
}

.throttle-control {
  width: min(500px, 100%);
  margin-top: 12px;
}

.throttle-track {
  height: 9px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--control-background);
}

.throttle-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--focus-colour);
  transition: width 45ms linear;
}

.throttle-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.button-mode {
  min-width: 205px;
  padding: 0 12px;
  background: var(--control-background);
}

.button-mode[aria-pressed="true"] {
  border-color: var(--focus-colour);
  color: var(--focus-colour);
}

.feedback {
  display: flex;
  min-height: 42px;
  align-items: center;
  margin: 14px 0;
  padding: 0 12px;
  border-left: 3px solid var(--green);
  border-radius: 0 5px 5px 0;
  color: var(--ink);
  background: var(--feedback-background);
  font-size: 14px;
}

.telemetry {
  display: grid;
  grid-template-columns: 1.2fr repeat(6, 1fr);
  gap: 12px;
}

.metric {
  display: grid;
  min-height: 70px;
  align-content: center;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--metric-background);
}

.metric-label {
  color: var(--muted);
}

.metric-value {
  font-family: var(--display);
  font-size: 25px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-speed .metric-value {
  color: var(--speed-colour);
  font-size: 32px;
}

.metric-value small {
  margin-left: 5px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
}

.tire-state {
  color: var(--green);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.tire-state.spinning {
  color: var(--amber);
}

.rpm-range {
  position: relative;
  margin-top: 1px;
  height: 5px;
  overflow: hidden;
  border-radius: 2px;
  background: #323a3a;
}

.rpm-range #rpm-fill {
  display: block;
  width: 14.3%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 60ms linear;
}

.rpm-range i {
  position: absolute;
  top: 0;
  height: 100%;
  pointer-events: none;
}

.rpm-range #rpm-shift-zone {
  left: 91.4%;
  width: 2.9%;
  background: #65e391;
  opacity: 0.95;
}

.rpm-range #rpm-needle {
  left: 14.3%;
  width: 2px;
  background: #ffffff;
  transform: translateX(-1px);
  transition: left 60ms linear;
}

.shift-cue {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.04em;
}

.shift-cue.shift-now {
  color: #198348;
  font-weight: 700;
}

.shift-cue.shift-perfect {
  color: #65e391;
  font-weight: 800;
}

.shift-cue.shift-soon {
  color: var(--focus-colour);
  font-weight: 700;
}

.shift-cue.limiter {
  color: #a3221d;
  font-weight: 700;
}

.controls-panel {
  margin-bottom: 16px;
}

.controls-heading {
  align-items: end;
}

.controls-note {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: right;
}

.buttons {
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 10px;
  margin-top: 14px;
}

.button {
  border-radius: 8px;
}

.button:not(.button-stage) {
  padding: 0 14px;
  background: var(--control-background);
}

.button-transbrake {
  padding: 0 14px;
  user-select: none;
  touch-action: none;
}

.button-transbrake[aria-pressed="true"] {
  border-color: var(--focus-colour);
  color: var(--focus-colour);
}

.button-throttle {
  min-width: 164px;
  user-select: none;
  touch-action: none;
}

.button-clutch {
  min-width: 150px;
  user-select: none;
  touch-action: none;
}

.button-throttle:active {
  border-color: var(--green);
  color: var(--green);
}

.button-clutch[aria-pressed="true"] {
  border-color: var(--focus-colour);
  color: var(--focus-colour);
}

.button-shift {
  min-width: 134px;
}

.button-reset {
  min-width: 105px;
  color: var(--muted);
}

.key-hint {
  margin-right: 6px;
  color: var(--focus-colour);
  font-size: 9px;
}

.button-stage:hover {
  background: #ffd074;
}

.button-mode:hover,
.button-throttle:hover,
.button-clutch:hover,
.button-transbrake:hover,
.button-shift:hover,
.button-reset:hover {
  border-color: #667273;
}

.rules-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.rules-note strong {
  color: var(--ink);
  font-weight: 600;
}

.performance-panel,
.roadmap-panel {
  margin-top: 18px;
}

.feature-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.formula-source,
.coming-soon-note {
  color: var(--muted);
  font-size: 12px;
}

.formula-source {
  text-decoration-color: var(--focus-colour);
  text-underline-offset: 3px;
}

.formula-source:focus-visible,
.feature-button:focus-visible {
  outline: 2px solid var(--focus-colour);
  outline-offset: 3px;
}

.estimate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
}

.estimate-card {
  display: grid;
  min-height: 72px;
  align-content: center;
  gap: 7px;
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--metric-background);
}

.estimate-value {
  color: var(--ink);
  font-family: var(--display);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.estimate-highlight {
  border-color: var(--focus-colour);
}

.estimate-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.coming-soon-note {
  margin: 0 0 3px;
  text-align: right;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.feature-button {
  display: grid;
  min-height: 62px;
  align-content: center;
  gap: 5px;
  padding: 9px 12px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  background: var(--control-background);
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.feature-button span {
  font-size: 13px;
  font-weight: 650;
}

.feature-button small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.feature-button:disabled {
  cursor: not-allowed;
  opacity: 0.78;
}

.feature-button.feature-available {
  border-color: var(--focus-colour);
}

.feature-available small {
  color: var(--green);
}

.footer-note {
  padding: 4px 0 22px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 700px) {
  .game {
    width: min(100% - 24px, 560px);
  }

  .masthead {
    min-height: 62px;
  }

  .build-tag,
  .strip-hint {
    font-size: 8px;
  }

  .strip-panel,
  .race-panel,
  .controls-panel,
  .opponent-telemetry,
  .tournament-panel,
  .performance-panel,
  .roadmap-panel {
    padding: 16px;
  }

  .launch-settings {
    align-items: stretch;
    flex-direction: column;
  }

  .launch-rpm-control {
    width: 100%;
  }

  .button-mode {
    min-height: 40px;
    align-self: flex-start;
  }

  .feature-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .coming-soon-note {
    text-align: left;
  }

  .opponent-telemetry {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .opponent-name {
    grid-column: 1 / -1;
  }

  .scene-scoreboard {
    top: 2%;
    width: 46%;
    max-height: 52%;
    padding: 5px;
  }

  .scene-scoreboard-title {
    margin-bottom: 3px;
    font-size: 8px;
  }

  .scene-scoreboard pre {
    font-size: 7px;
    line-height: 1.35;
  }

  .race-speed-comparison {
    display: none;
  }

  .scene-race-result {
    display: block;
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    max-width: none;
    padding: 9px 12px;
    transform: none;
    border-width: 1px 0 0;
    border-radius: 0;
    font-size: clamp(15px, 4vw, 19px);
    line-height: 1.25;
    text-shadow: none;
  }

  .touch-control-dock {
    display: grid;
    position: relative;
    right: auto;
    bottom: auto;
    left: auto;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 6px;
    transform: none;
    border-top: 1px solid rgb(233 222 190 / 28%);
    background: rgb(13 19 21 / 92%);
    gap: 5px;
  }

  @media (max-width: 560px) {
    .masthead {
      align-items: flex-start;
      flex-direction: column;
      justify-content: center;
      gap: 8px;
      padding: 12px 0;
    }

    .header-tools {
      width: 100%;
      flex-wrap: wrap;
    }

    .build-tag {
      margin-left: auto;
    }
  }

  .telemetry {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 64px;
    padding: 8px;
  }

  .metric-value {
    font-size: 22px;
  }

  .metric-speed .metric-value {
    font-size: 27px;
  }
}

@media (hover: none), (pointer: coarse) {
  .touch-control-dock {
    display: grid;
  }
}

@media (max-width: 400px) {
  .brand {
    gap: 6px;
    font-size: 16px;
  }

  .brand-mark {
    width: 26px;
    height: 26px;
  }

  .build-tag {
    max-width: 112px;
    text-align: right;
  }

  .buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .buttons .button {
    min-width: 0;
    padding: 0 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
