: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: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  overflow: hidden;
  background: #000;
  transition: opacity 0.32s ease;
}
.loading-screen.hidden { opacity: 0; pointer-events: none; }
.loader-title {
  position: relative;
  z-index: 1;
  font: 700 28px/1 Arial, Helvetica, sans-serif;
  letter-spacing: -.04em;
  color: #fff;
}
.loader-bar {
  position: relative;
  z-index: 1;
  width: min(260px, calc(100vw - 48px));
  height: 2px;
  background: rgba(255,255,255,0.2);
  overflow: hidden;
}
.loader-bar i {
  display: block;
  width: 0%;
  height: 100%;
  background: #fff;
  transition: width 0.24s cubic-bezier(0.33, 1, 0.68, 1);
}
.loader-bar.indeterminate i {
  width: 34%;
  background: #fff;
  will-change: transform;
  transition: none;
  animation: loader-slide 1.35s infinite cubic-bezier(0.65, 0, 0.35, 1);
}
@keyframes loader-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(305%); }
}
@media (prefers-reduced-motion: reduce) {
  .loader-bar i { transition: none; }
  .loader-bar.indeterminate i { animation-duration: 3s; }
}
.loader-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
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;
}
