:root {
  color-scheme: dark;
  --bg: #151613;
  --panel: #1d1e19;
  --line: #37362b;
  --text: #f7efdb;
  --muted: #bcb19b;
  --gold: #f6b643;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 300px;
  background: radial-gradient(ellipse at 25% 18%, #242019 0%, transparent 56%), var(--bg);
  color: var(--text);
  font: 15px/1.45 "Arial", sans-serif;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.shell { width: min(1296px, calc(100% - 88px)); margin-inline: auto; }
.topbar { border-bottom: 1px solid var(--line); background: #151613ef; }
.topbar-inner { min-height: 62px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 900; letter-spacing: .19em; }
.brand-icon {
  display: inline-block;
  width: 27px;
  height: 25px;
  background: var(--gold);
  clip-path: polygon(0 74%, 35% 20%, 47% 39%, 62% 17%, 100% 74%, 81% 74%, 62% 45%, 47% 68%, 36% 50%, 19% 74%);
}
.back { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.back span { color: var(--gold); font-size: 18px; }
.back:hover { color: var(--text); }

.masthead { display: flex; align-items: end; justify-content: space-between; gap: 22px; margin-block: 38px 28px; }
.eyebrow { display: flex; align-items: center; gap: 9px; margin: 0; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .19em; }
.eyebrow i { width: 7px; height: 7px; background: currentColor; transform: rotate(45deg); flex: none; }
h1, h2, p { margin-top: 0; }
h1 {
  margin: 8px 0 9px;
  font-size: clamp(44px, 6.05vw, 88px);
  line-height: .99;
  font-weight: 950;
  letter-spacing: -.082em;
  font-stretch: condensed;
}
h1 em { color: var(--gold); font-style: normal; }
.intro { margin: 0; color: var(--muted); }
.route { display: flex; align-items: center; gap: 11px; padding: 12px 15px; background: #29251c; border: 1px solid #53452e; border-radius: 8px; white-space: nowrap; }
.route-icon { color: var(--gold); font-size: 26px; line-height: 1; }
.route small, .route strong { display: block; }
.route small { color: var(--muted); font-size: 9px; letter-spacing: .15em; }
.route strong { font-size: 14px; }
.route-distance { margin-left: 6px; padding-left: 14px; border-left: 1px solid #645337; color: var(--gold); font-size: 13px; font-weight: 700; }

.race-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(245px, 285px); gap: 18px; padding-bottom: 35px; }
.race-main { min-width: 0; }
.stage {
  position: relative;
  isolation: isolate;
  display: grid;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  min-height: 390px;
  aspect-ratio: 1.8;
  border: 1px solid #604b32;
  border-radius: 12px;
  background: #754624;
}
#track, .cover, .overlay { position: absolute; width: 100%; height: 100%; inset: 0; }
#track { display: block; }
.cover {
  pointer-events: none;
  background: linear-gradient(90deg, #1b130eec 0%, #241812ae 26%, #32221526 64%, transparent 84%),
    linear-gradient(0deg, #1a130cbb, transparent 35%, transparent 70%, #24160f54),
    url("./assets/desert-rally.jpg") 56% 54% / cover no-repeat;
  opacity: 0;
  transition: opacity .22s ease;
}
[data-phase="menu"] .cover { opacity: 1; }
[data-graphics="ready"] .cover {
  background: linear-gradient(90deg, #21150ed4 0%, #21150e69 40%, transparent 78%),
    linear-gradient(0deg, #24180c44, transparent 24%);
}
.graphics-status { margin: 12px 0 0 !important; max-width: 29ch; }
.primary:disabled { opacity: .63; }
.hud { position: absolute; z-index: 2; top: 15px; left: 15px; display: flex; gap: 6px; }
.hud > div {
  min-width: 74px;
  padding: 8px 11px 7px;
  border: 1px solid #f4d9ac38;
  border-radius: 6px;
  background: #1e1714db;
}
.hud span { display: block; color: #decfb9; font-size: 9px; font-weight: 700; letter-spacing: .13em; }
.hud strong { display: block; font-size: 19px; line-height: 1.28; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud small { color: #decfb9; font-size: 12px; font-weight: 400; }
.stage-actions { position: absolute; z-index: 3; top: 15px; right: 15px; display: flex; gap: 6px; }
.icon-button {
  width: 37px;
  height: 37px;
  border: 1px solid #f4d9ac4f;
  border-radius: 6px;
  background: #1e1714d9;
  display: grid;
  place-items: center;
}
.icon-button:hover:not(:disabled) { color: var(--gold); border-color: var(--gold); }
.icon-button:disabled { opacity: .48; }
.expand-mark { width: 15px; height: 15px; border: 2px solid currentColor;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 66%, 33% 66%, 33% 100%, 66% 100%, 66% 66%, 100% 66%, 100% 33%, 66% 33%, 66% 0, 33% 0, 33% 33%, 0 33%);
}
[aria-pressed="true"] .expand-mark { color: var(--gold); }
.pause-mark { width: 11px; height: 13px; border-inline: 3px solid currentColor; }
.sound-mark { position: relative; width: 17px; height: 16px; }
.sound-mark::before { content: ""; position: absolute; inset: 1px 6px 1px 0; background: currentColor; clip-path: polygon(0 35%, 36% 35%, 100% 0, 100% 100%, 36% 65%, 0 65%); }
.sound-mark::after { content: ""; position: absolute; right: 1px; top: 7px; width: 7px; height: 1px; background: currentColor; transform: rotate(-45deg); }
[aria-pressed="true"] .sound-mark::after { width: 7px; height: 11px; top: 2px; transform: none; border-right: 2px solid currentColor; border-radius: 50%; background: none; }

.overlay { z-index: 1; display: flex; align-items: center; padding: 0 6%; background: #21170fc9; }
[data-phase="menu"] .overlay { background: transparent; }
.overlay-content { padding-block: 50px; }
.overlay h2 { margin: 6px 0 3px; font-size: clamp(39px, 5.25vw, 75px); font-weight: 900; letter-spacing: -.077em; line-height: 1.07; text-shadow: 0 1px 24px #21130bcc; }
.overlay p:not(.eyebrow) { color: #f0dfc6; font-size: 15px; margin: 0 0 19px; }
.primary {
  min-height: 46px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  gap: 20px;
  border: 1px solid #ffd47d;
  border-radius: 6px;
  background: var(--gold);
  color: #21190c;
  font-size: 14px;
  font-weight: 800;
}
.primary:hover { background: #ffd179; }
.primary span[aria-hidden] { font-size: 20px; line-height: 1; }
.secondary { margin-left: 9px; min-height: 46px; padding: 0 12px; border: 1px solid #c6a677; background: #231b158f; border-radius: 6px; }
.secondary:hover { color: var(--gold); border-color: var(--gold); }
.countdown { display: grid; place-items: center; position: absolute; inset: 0; z-index: 2; pointer-events: none; color: #fff0bd; font-size: clamp(64px, 9vw, 126px); font-weight: 900; font-style: italic; text-shadow: 0 5px 20px #2a150d; }
.notice { position: absolute; z-index: 2; top: 20%; left: 50%; transform: translateX(-50%); padding: 4px 10px; border-radius: 5px; background: #26190de5; color: #ffe6ab; font-size: 13px; text-align: center; white-space: nowrap; }
.notice:empty { display: none; }

.telemetry {
  position: absolute;
  z-index: 2;
  inset: auto 15px 15px;
  display: flex;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
}
.speed, .boost { border: 1px solid #f4d9ac38; border-radius: 6px; background: #1e1714dd; }
.speed { padding: 3px 11px 2px; display: flex; align-items: baseline; gap: 5px; min-width: 90px; }
.speed strong { font-size: 28px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.speed span { font-size: 11px; color: #e4ceb0; }
.boost { width: 133px; padding: 7px 9px; }
.boost > span { display: flex; align-items: center; gap: 5px; color: #e4ceb0; font-size: 9px; letter-spacing: .04em; font-weight: 800; }
.boost > span b { font-size: 15px; line-height: 1; color: var(--gold); }
.boost > span strong { margin-left: auto; font-variant-numeric: tabular-nums; }
.boost-track { height: 4px; margin-top: 5px; border-radius: 4px; background: #594433; overflow: hidden; }
.boost-track i { display: block; width: 100%; height: 100%; background: var(--gold); transform-origin: left; }
.course-progress { display: flex; align-items: center; gap: 12px; margin: 12px 0 0; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.course-meter { flex: 1; position: relative; height: 4px; background: #4a3e2b; border-radius: 5px; }
.course-meter i { position: absolute; inset: 0; background: var(--gold); border-radius: 5px; transform: scaleX(0); transform-origin: left; }
.course-meter b { position: absolute; left: var(--mark); top: -1px; height: 6px; width: 2px; background: #94795a; }

.sidebar { display: flex; flex-direction: column; gap: 11px; min-width: 0; }
.panel { padding: 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.panel h2 { margin: 0 0 11px; font-size: 16px; line-height: 1.2; letter-spacing: -.025em; font-weight: 800; }
.vehicle-picker { display: grid; gap: 7px; }
.vehicle {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: 58px;
  text-align: left;
  padding: 7px 8px;
  gap: 8px;
  border: 1px solid #454031;
  border-radius: 6px;
  background: #25241d;
}
.vehicle:not(:disabled):hover { border-color: #ae8747; }
.vehicle[aria-pressed="true"] { border-color: #b4863a; background: #342a1b; }
.vehicle-art { position: relative; display: block; width: 42px; height: 28px; flex: 0 0 42px; color: #c99f5c; }
.vehicle-art::before, .vehicle-art::after { content: ""; position: absolute; bottom: 2px; z-index: 1; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #d2a15a; background: #242017; }
.vehicle-art::before { left: 5px; }
.vehicle-art::after { right: 4px; }
.vehicle-art i, .vehicle-art b { display: block; position: absolute; background: currentColor; }
.suv-art i { inset: 4px 4px 7px; clip-path: polygon(0 46%, 11% 9%, 68% 9%, 84% 47%, 99% 56%, 100% 100%, 0 100%); }
.suv-art b { inset: 8px 10px 13px; background: #302818; clip-path: polygon(0 0, 73% 0, 91% 100%, 0 100%); }
.atv-art i { inset: 9px 1px 6px; clip-path: polygon(0 46%, 17% 33%, 41% 57%, 59% 48%, 64% 13%, 90% 31%, 100% 79%, 78% 100%, 14% 100%); }
.atv-art b { inset: 4px 10px 11px 23px; clip-path: polygon(0 0, 100% 1%, 100% 20%, 60% 20%, 92% 100%, 66% 100%, 26% 20%, 0 20%); }
.vehicle-info { min-width: 0; flex: 1; }
.vehicle-info strong, .vehicle-info small { display: block; }
.vehicle-info strong { font-size: 14px; }
.vehicle-info small { font-size: 11px; color: var(--muted); line-height: 1.2; }
.radio-mark { width: 12px; height: 12px; flex: 0 0 12px; border: 1px solid #7d6b50; border-radius: 50%; display: grid; place-items: center; }
[aria-pressed="true"] .radio-mark { border-color: var(--gold); }
[aria-pressed="true"] .radio-mark::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); }
.keyboard-help { margin: 0; }
.keyboard-help > div { min-height: 28px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.keyboard-help > div + div { margin-top: 3px; }
.keyboard-help dt { display: flex; gap: 4px; }
.keyboard-help dd { color: var(--muted); margin: 0; font-size: 12px; }
kbd {
  display: inline-grid;
  min-width: 25px;
  height: 23px;
  padding: 0 4px;
  place-items: center;
  border: 1px solid #524b3c;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #2c2a21;
  color: var(--text);
  font: 600 13px/1 "Arial", sans-serif;
}
kbd.wide-key { font-size: 10px; }
.record-panel { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.record-panel h2 { margin: 0; font-size: 14px; }
.record-panel h2 span { color: var(--gold); margin-right: 3px; }
.record-panel p { margin: 0; color: var(--gold); font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.touch, .touch-help { display: none; }
body.is-expanded { overflow: hidden; }
.race-main.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--bg);
}
.is-expanded > .stage { flex: 1; min-height: 0; aspect-ratio: auto; }

@media (max-width: 1020px) {
  .shell { width: calc(100% - 44px); }
  .race-layout { grid-template-columns: minmax(0, 1fr) 237px; gap: 13px; }
  .masthead { margin-top: 30px; }
  .stage { min-height: 380px; }
}
@media (max-width: 750px) {
  .shell { width: calc(100% - 28px); }
  .topbar-inner { min-height: 49px; }
  .brand { font-size: 12px; gap: 6px; }
  .brand-icon { width: 23px; }
  .masthead { display: block; margin-block: 21px 14px; }
  h1 { font-size: clamp(38px, 9.2vw, 62px); margin: 7px 0 5px; }
  .intro { font-size: 12px; }
  .route { width: max-content; margin-top: 12px; padding: 5px 8px; gap: 7px; }
  .route-icon { font-size: 20px; }
  .route small { display: none; }
  .route strong, .route-distance { font-size: 11px; }
  .route-distance { padding-left: 8px; margin-left: 0; }
  .race-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .stage { min-height: 293px; aspect-ratio: 1.65; }
  .cover { background-position: 59% 53%; }
  .hud { top: 8px; left: 8px; gap: 4px; }
  .hud > div { min-width: 50px; padding: 4px 6px; }
  .hud span { font-size: 8px; letter-spacing: .06em; }
  .hud strong { font-size: 14px; }
  .hud small { font-size: 10px; }
  .stage-actions { top: 8px; right: 8px; gap: 4px; }
  .icon-button { width: 34px; height: 34px; }
  .telemetry { inset: auto 8px 8px; }
  .speed { min-width: 72px; padding-inline: 6px; }
  .speed strong { font-size: 22px; }
  .boost { width: 101px; }
  .overlay { padding-inline: 16px; }
  .overlay p:not(.eyebrow) { font-size: 12px; margin-bottom: 12px; }
  .primary, .secondary { min-height: 41px; font-size: 13px; }
  .course-progress { margin-top: 7px; }
  .sidebar { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
  .garage-panel { grid-column: 1 / -1; }
  .vehicle-picker { grid-template-columns: 1fr 1fr; }
  .record-panel { align-items: start; flex-direction: column; justify-content: start; }
}
@media (pointer: coarse), (max-width: 750px) {
  .race-main:has(.stage:not([data-phase="menu"]):not([data-phase="finished"])) .touch {
    display: flex;
    justify-content: space-between;
    gap: 9px;
    margin-top: 8px;
    touch-action: none;
  }
  .touch > div { display: flex; gap: 4px; }
  .touch button {
    touch-action: none;
    user-select: none;
    width: clamp(41px, 12vw, 59px);
    height: 46px;
    display: grid;
    place-items: center;
    border: 1px solid #65543b;
    border-radius: 6px;
    background: #2b241a;
    font-size: 21px;
    font-weight: 700;
  }
  .touch .gas { color: var(--gold); border-color: #a77f40; }
  .touch .is-held { background: var(--gold); color: #241a10; }
}
@media (pointer: coarse) {
  .keyboard-help { display: none; }
  .touch-help { display: block; color: var(--muted); margin: 0; font-size: 12px; }
}
@media (max-width: 370px) {
  .stage-actions .icon-button { width: 30px; height: 32px; }
  .vehicle { gap: 4px; padding: 6px; }
  .vehicle-art { transform: scale(.82); transform-origin: left; width: 34px; flex-basis: 34px; }
  .vehicle-info strong { font-size: 12px; }
  .vehicle-info small { font-size: 10px; }
  .overlay button { padding-inline: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .is-expanded .touch { margin-top: 5px; }
  .is-expanded .touch button { height: 34px; }
  .is-expanded .course-progress { margin-top: 4px; }
}
