/* ============================================================
   BASE — reset, environment, shared primitives
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, h2, h3, h4, p, figure, blockquote, ul, ol, dl, dd { margin: 0; }
ul[class], ol[class] { list-style: none; padding: 0; }
img, picture, svg, video { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

html {
  scroll-behavior: auto;         /* Lenis owns smooth scrolling */
  background: var(--obsidian);
}

body {
  margin: 0;
  font-family: var(--f-sans);
  font-size: var(--step-0);
  line-height: 1.55;
  font-weight: 400;
  color: var(--world-fg);
  background: var(--world-bg);
  transition: background-color var(--world-shift) var(--e-glide),
              color          var(--world-shift) var(--e-glide);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Lock scroll while the loader / menu / transition owns the screen */
body.is-locked { overflow: hidden; height: 100vh; }

::selection { background: var(--gold); color: var(--obsidian); }

:focus-visible {
  outline: 2px solid var(--world-accent);
  outline-offset: 4px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---- Skip link ------------------------------------------- */
.skip {
  position: fixed; top: 0; left: 0; z-index: 999;
  padding: 0.85em 1.4em;
  background: var(--gold); color: var(--obsidian);
  font-family: var(--f-mono); font-size: var(--step--1);
  letter-spacing: 0.08em; text-transform: uppercase;
  transform: translateY(-120%);
  transition: transform var(--t-ui) var(--e-out);
}
.skip:focus { transform: translateY(0); }

/* ============================================================
   FILM GRAIN + LIGHT FIELD
   The environment is never completely still.
   ============================================================ */
.grain {
  position: fixed; inset: -150%;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.34;
  background-image: var(--grain-src);
  background-size: 220px 220px;
  mix-blend-mode: overlay;
  will-change: transform;
  animation: grain-drift 900ms steps(1) infinite;
}
/* Cream worlds need a softer, warmer grain than black ones */
body[data-chrome='light'] .grain { opacity: 0.20; mix-blend-mode: multiply; }

@keyframes grain-drift {
  0%   { transform: translate3d(0,0,0); }
  12%  { transform: translate3d(-3%, 2%, 0); }
  25%  { transform: translate3d(4%, -3%, 0); }
  37%  { transform: translate3d(-2%, -4%, 0); }
  50%  { transform: translate3d(3%, 3%, 0); }
  62%  { transform: translate3d(-4%, 1%, 0); }
  75%  { transform: translate3d(2%, -2%, 0); }
  87%  { transform: translate3d(-1%, 4%, 0); }
  100% { transform: translate3d(0,0,0); }
}

/* Soft luminous field that trails the pointer across dark chapters */
.lightfield {
  position: fixed; inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-cine) var(--e-glide);
  background: radial-gradient(
    38vmax 38vmax at var(--lf-x, 50%) var(--lf-y, 40%),
    color-mix(in srgb, var(--forest-glow) 46%, transparent) 0%,
    color-mix(in srgb, var(--forest-deep) 18%, transparent) 42%,
    transparent 72%);
}
body[data-chrome='dark'] .lightfield { opacity: 0.75; }

/* ============================================================
   TYPOGRAPHY PRIMITIVES
   ============================================================ */
.display {
  font-family: var(--f-display);
  font-weight: 500;
  line-height: 0.86;
  letter-spacing: -0.022em;
  font-variation-settings: 'opsz' 96;
}
.display--xl { font-size: var(--display-xl); }
.display--lg { font-size: var(--display-lg); }
.display--md { font-size: var(--display-md); }

.meta {
  font-family: var(--f-mono);
  font-size: var(--step--2);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 400;
}
.meta--accent { color: var(--accent); }

.lede {
  font-size: var(--step-2);
  line-height: 1.34;
  font-weight: 400;
  letter-spacing: -0.012em;
  max-width: 22ch;
}

.prose { max-width: 58ch; }
.prose p + p { margin-top: 1.15em; }
.prose p { color: var(--muted); font-size: var(--step-1); line-height: 1.62; }

/* Gold hairline used as a section punctuation mark */
.hair {
  height: var(--rule);
  background: var(--hair);
  transform-origin: left center;
  border: 0;
}
.hair--gold { background: color-mix(in srgb, var(--accent) 70%, transparent); }

/* ============================================================
   CHAPTER SHELL
   ============================================================ */

/* Any section that declares a world paints itself from that world,
   rather than inheriting from <body>. The body colour is driven by
   scroll and can lag a fast jump; a chapter must never depend on it. */
[data-world] {
  background-color: var(--bg);
  color: var(--fg);
}

.chapter {
  position: relative;
  background: var(--bg);
  color: var(--fg);
  padding-block: var(--chapter-pad);
  padding-inline: var(--bleed);
  isolation: isolate;
}

.chapter__index {
  display: flex; align-items: baseline; gap: 1.2em;
  margin-bottom: clamp(2.5rem, 6vh, 5rem);
}
.chapter__num {
  font-family: var(--f-mono);
  font-size: var(--step--2);
  letter-spacing: 0.2em;
  color: var(--accent);
}
.chapter__label {
  font-family: var(--f-mono);
  font-size: var(--step--2);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}
.chapter__index .hair { flex: 1; }

/* ============================================================
   REVEAL PRIMITIVES (paired with js/reveal.js)
   Elements start hidden only when JS is present, so a
   no-JS visitor still gets the whole site.
   ============================================================ */
.js .r-mask   > * { transform: translateY(102%); }
.js .r-mask     { overflow: hidden; }
.js .r-fade     { opacity: 0; }
.js .r-clip     { clip-path: inset(0 0 100% 0); }

/* ============================================================
   MOTION PREFERENCES
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; opacity: 0.16; }
  .lightfield { display: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .js .r-mask > *, .js .r-fade, .js .r-clip {
    transform: none !important; opacity: 1 !important; clip-path: none !important;
  }
}
