:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --ink: #090b0d;
  --panel: rgba(12, 15, 18, 0.9);
  --panel-strong: rgba(15, 18, 22, 0.97);
  /* Borders are the only thing identifying several controls, and these were too
     faint to be non-text contrast (WCAG 1.4.11 wants 3:1). Measured against the
     header fill, --line was 1.32:1 and --line-strong put the sound toggle's border
     at 2.71:1. At 0.24 / 0.42 the icon button reaches ~3.6:1 and the panel edges
     survive a bright frame of the 3D scene behind them. No layout impact. */
  --line: rgba(230, 235, 240, 0.2);
  --line-strong: rgba(230, 235, 240, 0.36);
  --text: #f4f5f6;
  --muted: #9ba2aa;
  --acid: #ef233c;
  --green: #62d985;
  --red: #ff5c69;
  --cyan: #55ccdf;
  --carbon: #101318;
  --carbon-raised: #171b20;
  --font: "Barlow", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --condensed: "Barlow Condensed", "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
}

/* ---- Loading screen ---- */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
  transition: opacity 280ms ease, visibility 280ms ease;
}
.loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-lockup { display: grid; justify-items: center; gap: 24px; width: min(280px, calc(100vw - 48px)); text-align: center; }
.loader-logo { display: block; width: clamp(180px, 22vw, 260px); height: auto; }
.loader-bar {
  position: relative;
  width: 100%;
  height: 2px;
  background: rgba(255,255,255,0.2);
}
.loader-bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: #08bce8;
  transform: scaleX(.06);
  transform-origin: left center;
  will-change: transform;
}
.loader-car { position: absolute; top: 50%; left: 6%; display: block; width: 100px; height: auto; filter: drop-shadow(0 0 4px rgba(8, 188, 232, .38)); transform: translate(-50%, -92%); will-change: left; pointer-events: none; user-select: none; }
@media (prefers-reduced-motion: reduce) {
  .loading-screen { transition: none; }
}
.loader-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.loader-error { max-width: 300px; margin: 2px 0 0; color: rgba(247, 249, 252, .82); font: 600 13px/1.45 var(--font); }
.loader-retry { min-width: 112px; padding: 10px 20px; border: 1px solid #08bce8; border-radius: 999px; color: #f7f9fc; background: transparent; font: 700 12px/1 var(--font); letter-spacing: .08em; text-transform: uppercase; }
body.is-booting > :not(.loading-screen):not(script) { visibility: hidden; pointer-events: none; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--ink);
  font-family: var(--font);
  user-select: none;
}
button, input, select, a {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; opacity: 0.58; }
[hidden] { display: none !important; }

#scene-root, #scene-root canvas {
  position: fixed;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}
body.no-webgl #scene-root {
  background:
    linear-gradient(rgba(5,8,12,0.28), rgba(5,8,12,0.64)),
    url("../assets/loading-circuit.webp") center / cover no-repeat;
}

.track-grade {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.62), transparent 16%, transparent 84%, rgba(0, 0, 0, 0.62)),
    linear-gradient(180deg, rgba(7, 9, 11, 0.36), transparent 30%, rgba(7, 9, 11, 0.76)),
    radial-gradient(circle at 50% 38%, transparent 0, transparent 38%, rgba(0, 0, 0, 0.32) 82%);
}
.track-grade::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.14;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 100% 4px, 80px 100%;
}

.game-shell {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: max(14px, var(--sat)) max(16px, var(--sar)) max(14px, var(--sab)) max(16px, var(--sal));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  pointer-events: none;
}
