*, *::before, *::after { box-sizing: border-box; }

html {
  color-scheme: dark;
  scrollbar-width: none;
}
html::-webkit-scrollbar { display: none; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background var(--d3) var(--ease-io), color var(--d3) var(--ease-io);
}

img, video, canvas { display: block; max-width: 100%; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 400; }
p { margin: 0; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ============================================================
   GL CANVAS — sits behind the DOM, full viewport
   ============================================================ */
#gl {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* Everything else rides above it */
.page { position: relative; z-index: 1; }

/* ============================================================
   FILM GRAIN — Brand Standard §8, ~28 grain
   ============================================================ */
body::after {
  content: "";
  position: fixed;
  inset: -50%;
  z-index: 900;
  pointer-events: none;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 700ms steps(3) infinite;
  transition: opacity var(--d3) var(--ease-io);
}
@keyframes grain {
  0%   { transform: translate3d(0,0,0); }
  33%  { transform: translate3d(-2%,1.5%,0); }
  66%  { transform: translate3d(1.5%,-2%,0); }
  100% { transform: translate3d(0,0,0); }
}

/* ============================================================
   TYPE PRIMITIVES
   ============================================================ */
.mono {
  font-family: var(--font-mono);
  font-size: var(--text-mono);
  letter-spacing: var(--track-mono);
  text-transform: uppercase;
  font-weight: 500;
}
.mono--accent { color: var(--accent); }
.mono--muted  { color: var(--muted); }

.display {
  font-family: var(--display-face);
  font-weight: 700;
  text-transform: uppercase;
  line-height: 0.88;
  letter-spacing: -0.005em;
  font-size: var(--text-display);
}
.display .hot { color: var(--accent); }

.kinetic {
  font-family: var(--font-kinetic);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 0.86;
  font-variation-settings: "wdth" 100;
  will-change: font-variation-settings;
}

/* Masked line reveal — every headline in the build uses this */
.lm { display: block; overflow: hidden; }
/* No will-change here. Every headline on the page uses this mask, so
   the hint promoted twenty-odd elements to their own compositor layer
   and kept them there for the life of the page — long after a one-shot
   reveal had finished. GSAP promotes each line for the duration of its
   own tween, which is when it is actually needed. */
.lm > span {
  display: block;
  transform: translate3d(0, 108%, 0);
}

/* Blade rule */
.blade {
  position: relative;
  height: 1px;
  background: var(--line);
  overflow: hidden;
}
.blade::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 16%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: blade 3.4s var(--ease-io) infinite;
}
@keyframes blade {
  from { transform: translate3d(-120%,0,0); }
  to   { transform: translate3d(720%,0,0); }
}

.shell {
  width: 100%;
  min-width: 0;          /* a grid/flex parent must not stretch it to content */
  max-width: 1720px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Full-bleed marquees and the world wipes intentionally reach past the
   viewport. Clip horizontally at the page so they can, without ever
   giving the document a sideways scrollbar. */
.page { overflow-x: clip; }

/* ============================================================
   CURSOR
   ============================================================ */
.cursor {
  position: fixed;
  top: 0; left: 0;
  width: 28px; height: 28px;
  margin: -14px 0 0 -14px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  z-index: 950;
  pointer-events: none;
  mix-blend-mode: difference;
  will-change: transform;
}
.cursor__dot {
  position: fixed;
  top: 0; left: 0;
  width: 4px; height: 4px;
  margin: -2px 0 0 -2px;
  background: var(--accent);
  border-radius: 50%;
  z-index: 951;
  pointer-events: none;
  will-change: transform;
}
@media (hover: none) { .cursor, .cursor__dot { display: none; } }

/* ============================================================
   NAV
   ============================================================ */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  /* The burger is position:fixed to the same right gutter, so the world
     links have to stop short of it. Without this reserve the burger sat
     directly on top of OFF+GRID — the link was rendered and clickable
     underneath, just completely covered. */
  padding: 0.9rem var(--gutter);
  padding-inline-end: calc(var(--gutter) + 7.5rem);
  mix-blend-mode: difference;
}
.nav__mark {
  height: 18px;
  opacity: 0;
  transform: translate3d(0,-8px,0);
}
.nav__worlds { display: flex; gap: 0.35rem; align-items: center; }
.nav__world {
  padding: 0.4rem 0.7rem;
  border: 1px solid transparent;
  transition: border-color var(--d2) var(--ease-out), color var(--d2) var(--ease-out);
}
.nav__world[aria-current="true"] { border-color: var(--accent); color: var(--accent); }
.nav__world:hover { color: var(--accent); }

/* Below this the four world links cannot sit beside the mark and the
   burger, and they were simply running off the side of the screen —
   up to 130px past the edge on a 375 viewport, invisible only because
   body clips overflow-x. All four are in the burger menu, which is
   the whole reason it exists, so they come out of the bar here.

   The end padding goes back to normal at the same time: it was only
   ever reserving room so the fixed burger could not sit on top of the
   Off+Grid link, and with no links there is nothing to cover. */
@media (max-width: 820px) {
  .nav__worlds { display: none; }
  .nav { padding-inline-end: var(--gutter); }

  /* The bar is fixed with no backdrop, so the page scrolls straight
     under it — on a phone the wordmark was sitting on top of the
     standings rows and the driver names, unreadable over both.

     `mix-blend-mode: difference` was the whole defence, and it only
     works while whatever is behind happens to be flat and dark. It
     cannot cope with a light chapter or a photograph, and this page
     alternates both. So below 820px the blend comes off and the bar
     gets a real scrim instead — a gradient rather than a solid, so
     it still reads as an overlay rather than a header bar. */
  .nav {
    mix-blend-mode: normal;
    background: linear-gradient(
      180deg,
      color-mix(in srgb, var(--nav-scrim) 92%, transparent) 0%,
      color-mix(in srgb, var(--nav-scrim) 72%, transparent) 55%,
      transparent 100%);
    padding-block: 0.9rem 1.6rem;
  }
}

/* The scrim has to be whatever the page is actually sitting on. Pages
   that flip tone as you scroll (girl.html) re-point this; everything
   else stays on the world's own ground. */
:root { --nav-scrim: var(--ground); }

/* Live session bar — only in lightsout */
.livebar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 820;
  display: none;
  align-items: center;
  gap: 1.5rem;
  padding: 0.55rem var(--gutter);
  background: var(--accent);
  color: var(--accent-ink);
}
[data-state="lightsout"] .livebar { display: flex; }
.livebar__pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-ink);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; transform: scale(0.7); } }

/* ============================================================
   WORLD SWITCH WIPE — sits above everything while it plays
   ============================================================ */
.wipe {
  position: fixed;
  inset: 0;
  z-index: 990;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}
.wipe.on { opacity: 1; visibility: visible; }

/* ============================================================
   DEV HUD — flip race states live
   ============================================================ */
.hud {
  position: fixed;
  left: var(--gutter);
  bottom: 1rem;
  z-index: 930;
  display: flex;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}
.hud button {
  padding: 0.4rem 0.6rem;
  background: var(--ground);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.hud button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
[data-state="lightsout"] .hud { bottom: 3rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .lm > span { transform: none !important; }
  body::after { display: none; }
}

/* ============================================================
   NEXT-UP DIAL — the corner widget

   On every page, always true, always turning. It sits above the
   bottom HUD strip rather than beside it, so neither has to move
   when the race state changes.
   ============================================================ */
.nextup {
  position: fixed; z-index: 820;
  right: var(--gutter); bottom: 4.2rem;
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.5rem 0.85rem 0.5rem 0.55rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--ground) 84%, transparent);
  backdrop-filter: blur(9px);
  color: var(--muted);
  transition: color var(--d2) var(--ease-out), border-color var(--d2) var(--ease-out),
              transform var(--d2) var(--ease-out);
}
.nextup:hover, .nextup:focus-visible {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  transform: translateY(-2px);
}
[data-state="lightsout"] .nextup { bottom: 6.2rem; }

.nextup__dial {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  flex: none;
  color: var(--accent);
}
.nextup__dial .circuit { width: 100%; height: 100%; overflow: visible; }

.nextup__meta { display: grid; gap: 0.1rem; line-height: 1.25; }
.nextup__round { color: var(--accent); font-size: 0.5625rem; }
.nextup__name { color: var(--ink); font-size: 0.6875rem; }
.nextup__clock { font-size: 0.625rem; font-variant-numeric: tabular-nums; }

/* Race weekend: the whole dial changes register. */
.nextup[data-state="live"] { border-color: var(--accent); }
.nextup[data-state="live"] .nextup__clock { color: var(--accent); }

/* The gallery is a full-bleed drag surface with its own chrome. */
.wall ~ .nextup, body:has(#wall) .nextup { display: none; }

@media (max-width: 720px) {
  .nextup { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .nextup { transition: none; }
}
