*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--wall-2);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--hair-strong) transparent;
}
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-stopped { overflow: hidden; }
html.is-loading { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-stretch: 100%;
  font-weight: 400;
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--ivory);
  background: transparent;
  overflow-x: clip;
}
html::before { /* fixed backdrop as an element: background-attachment: fixed misbehaves on iOS */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(120% 90% at 72% 38%, var(--wall) 0%, var(--wall-2) 70%);
}
img, video, canvas, svg { display: block; max-width: 100%; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration-color: var(--hair-strong); text-underline-offset: 0.2em; }
a:hover { text-decoration-color: var(--noodle); }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--noodle); outline-offset: 3px; border-radius: 2px; }
section:focus { outline: none; }
::selection { background: var(--noodle); color: var(--on-accent); }

.num, dd, .counter-n, .stat-num { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: fixed; left: 1rem; top: -4rem; z-index: 100; padding: 0.6rem 1rem;
  background: var(--noodle); color: var(--on-accent); font-weight: 700; text-decoration: none;
}
.skip:focus { top: 1rem; }

/* Fixed 3D stage */
/* Height is the LARGE viewport (lvh): when iOS Safari's toolbar collapses mid-scroll the canvas must not resize, or the renderer
   reallocates its buffers and the camera re-frames on every toolbar frame (stutter + a visible zoom). Falls back to 100%. */
#stage { position: fixed; inset: 0 0 auto 0; width: 100%; height: 100%; height: 100lvh; z-index: 0; }
#stage { transition: opacity 0.8s ease; }
.no-stage #stage { opacity: 0; pointer-events: none; } /* stays laid out so a slow stage can size itself, then fades in */
@media (prefers-reduced-motion: reduce) { #stage { transition: none; } }
.no-stage body::before, .stage-fading body::before {
  content: ""; position: fixed; inset: 0; z-index: 0;
  background:
    linear-gradient(rgba(var(--veil-rgb), 0.78), rgba(var(--veil-rgb), 0.9)),
    url("../media/poster-act-b2.jpg") center 32% / cover no-repeat;
  background:
    linear-gradient(rgba(var(--veil-rgb), 0.78), rgba(var(--veil-rgb), 0.9)),
    image-set(url("../media/poster-act-b2.webp") type("image/webp"), url("../media/poster-act-b2.jpg") type("image/jpeg")) center 32% / cover no-repeat;
}
.scrim { /* sits above the canvas, below the content: keeps the text side legible, the scene continuous */
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(var(--veil-rgb), 0.65) 0%, rgba(var(--veil-rgb), 0.38) 30%, rgba(var(--veil-rgb), 0) 55%);
}
.no-stage .scrim { display: none; }

main { position: relative; z-index: 1; }
.panel { text-shadow: 0 1px 14px rgba(var(--veil-rgb), 0.6); }

/* Type */
.display {
  font-stretch: 112%;
  font-weight: 780;
  font-size: var(--fs-h2);
  line-height: 1.02;
  letter-spacing: -0.012em;
  text-wrap: balance;
  margin-bottom: 1.4rem;
}
p + p { margin-top: 1rem; }
.caption, figcaption { font-size: var(--fs-caption); line-height: 1.5; color: var(--caption); }
.lede { font-size: clamp(1.0625rem, 1.25vw, 1.25rem); color: var(--ivory); max-width: 36rem; text-wrap: pretty; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 3rem; padding: 0 1.5rem; border-radius: 999px;
  font-weight: 650; font-stretch: 100%; text-decoration: none; font-size: 1rem;
  transition: background-color 0.25s, color 0.25s, transform 0.25s var(--ease-out), box-shadow 0.25s;
}
.btn--primary { background: var(--noodle); color: var(--on-accent); box-shadow: 0 10px 40px -12px rgba(var(--noodle-rgb), 0.55); }
.btn--primary:hover { filter: brightness(1.08) saturate(1.05); transform: translateY(-1px); }
.btn--ghost { box-shadow: inset 0 0 0 1px var(--hair-strong); }
.btn--ghost:hover { box-shadow: inset 0 0 0 1px var(--ivory); }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 2rem; }

/* Top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: var(--sat) max(var(--gutter), env(safe-area-inset-right, 0px)) 0 max(var(--gutter), env(safe-area-inset-left, 0px));
  background: rgba(var(--veil-rgb), 0.62);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  transition: box-shadow 0.4s;
}
.topbar.is-scrolled { box-shadow: 0 1px 0 var(--hair); }
.wordmark { font-stretch: 125%; font-weight: 760; letter-spacing: -0.01em; text-decoration: none; font-size: 1rem; white-space: nowrap; }
.topbar nav { display: flex; gap: clamp(0.85rem, 2.4vw, 1.9rem); font-size: 0.875rem; }
.topbar nav a { color: var(--dim); text-decoration: none; transition: color 0.2s; white-space: nowrap; padding: 0.4rem 0; display: inline-flex; align-items: center; min-height: 2.75rem; }
.topbar nav a:hover { color: var(--ivory); }
@media (max-width: 420px) {
  .wordmark { font-size: 0.875rem; }
  .topbar nav { gap: 0.9rem; font-size: var(--fs-caption); }
  .topbar nav a:nth-child(2) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .btn { transition: none; }
}
/* Persistent honesty badge: quiet, out of the way of the text */
.stage-badge {
  position: fixed; right: var(--gutter); bottom: 1.1rem; z-index: 15; margin: 0; pointer-events: none;
  font-size: var(--fs-micro); line-height: 1; color: rgba(var(--ivory-rgb), 0.85);
  padding: 0.4rem 0.7rem; border-radius: 999px; background: rgba(var(--veil-rgb), 0.6);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: opacity 0.5s;
}
.no-stage .stage-badge, .is-loading .stage-badge, body[data-chapter="film"] .stage-badge, body[data-chapter="limits"] .stage-badge { opacity: 0; }
/* The hero carries its own reconstruction note, and its joint-state card sits where the badge would: hide the badge there. */
body[data-chapter="hero"] .stage-badge { opacity: 0; }
@media (max-width: 820px), (orientation: portrait) and (max-width: 1100px) {
  .stage-badge {
    right: auto; left: var(--gutter); top: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 0.7rem); font-size: 0.6875rem;
  }
  body[data-chapter="hero"] .stage-badge { opacity: 0; }
  body[data-chapter="sandbox"] .stage-badge { bottom: auto; top: calc(var(--topbar-h) + 0.6rem); }
}

/* Chapter progress rail (desktop) */
.rail { position: fixed; top: 0; right: 0; bottom: 0; width: 2px; z-index: 16; pointer-events: none; background: rgba(var(--ivory-rgb), 0.07); }
.rail i { position: absolute; inset: 0; background: var(--noodle); transform-origin: 50% 0; transform: scaleY(var(--p, 0)); opacity: 0.9; }
.rail b { position: absolute; right: 0; width: 6px; height: 1px; background: rgba(var(--ivory-rgb), 0.4); }
.is-loading .rail, .no-stage .rail { opacity: 0; }
@media (max-width: 820px), (orientation: portrait) and (max-width: 1100px) { .rail { display: none; } }
@media (prefers-reduced-motion: reduce) { .stage-badge { transition: none; } }

/* Hardware-acceleration note: a quiet pill, bottom-left, dismissible */
.gl-note {
  position: fixed; left: var(--gutter); bottom: calc(env(safe-area-inset-bottom, 0px) + 1.1rem); z-index: 30;
  display: flex; align-items: flex-start; gap: 0.35rem; max-width: min(34rem, calc(100vw - 2 * var(--gutter)));
  padding: 0.6rem 0.4rem 0.6rem 1.1rem; border-radius: 1.4rem;
  background: rgba(var(--veil-rgb), 0.86); box-shadow: 0 0 0 1px var(--hair-strong), 0 12px 40px -12px var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.gl-note p { margin: 0; font-size: var(--fs-caption); line-height: 1.45; color: var(--ivory); padding-top: 0.15rem; }
.gl-note button { flex: none; width: 2.25rem; height: 2.25rem; display: grid; place-items: center; border-radius: 50%; }
.gl-note button:hover { background: rgba(var(--ivory-rgb), 0.12); }
.gl-note svg { width: 1rem; height: 1rem; fill: none; stroke: var(--ivory); stroke-width: 1.8; stroke-linecap: round; }

/* ---- Portrait tablets: the honesty badge rides under the top bar (clear scene), not over the bottom text panels ---- */
@media (min-width: 600px) and (max-width: 820px) and (min-height: 700px), (orientation: portrait) and (min-width: 821px) and (max-width: 1100px) {
  .stage-badge { top: calc(var(--topbar-h) + 0.7rem); bottom: auto; font-size: 0.8125rem; padding: 0.5rem 0.85rem; }
}
