/* ==========================================================================
   Prashant Singh — "Noise → Signal"
   Base layer: tokens, type, global chrome (cursor, grain, nav, preloader)
   ========================================================================== */

:root {
  --ink: #07070a;
  --ink-2: #0d0d12;
  --ink-3: #15151c;
  --paper: #eeeae2;
  --paper-2: #e2ddd2;
  --mute: #8c8980;
  --mute-2: #5a5853;
  --line: rgba(238, 234, 226, 0.12);
  --line-strong: rgba(238, 234, 226, 0.24);
  --ember: #ff5c28;
  --ember-soft: rgba(255, 92, 40, 0.16);
  --signal: #7cf7d4;

  /* themable surface — GSAP flips these on the About chapter */
  --bg: var(--ink);
  --fg: var(--paper);
  --fg-mute: var(--mute);
  --rule: var(--line);

  --f-display: "Inter Tight", system-ui, sans-serif;
  --f-serif: "Instrument Serif", Georgia, serif;
  --f-mono: "JetBrains Mono", ui-monospace, monospace;

  --gutter: clamp(16px, 4vw, 56px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
}

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

html { -webkit-text-size-adjust: 100%; }
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--f-display);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color 0.0s;
}
body.is-loading { overflow: hidden; height: 100vh; }

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
::selection { background: var(--ember); color: var(--ink); }

.mono {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.serif { font-family: var(--f-serif); font-style: italic; font-weight: 400; letter-spacing: -0.01em; }
.ember { color: var(--ember); }
.signal { color: var(--signal); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* split-text helpers */
.line-mask { display: block; overflow: hidden; padding-bottom: 0.06em; margin-bottom: -0.06em; }
.word { display: inline-block; }
.char { display: inline-block; }

/* ---------- grain ---------- */
.grain {
  position: fixed; inset: -50%;
  width: 200%; height: 200%;
  pointer-events: none; z-index: 90;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.9s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-4%, 3%); }
  40% { transform: translate(3%, -5%); }
  60% { transform: translate(-6%, -2%); }
  80% { transform: translate(5%, 4%); }
  100% { transform: translate(0, 0); }
}

/* ---------- cursor ---------- */
.cursor { position: fixed; top: 0; left: 0; z-index: 100; pointer-events: none; mix-blend-mode: difference; }
.cursor__dot,
.cursor__ring { position: fixed; top: 0; left: 0; border-radius: 50%; transform: translate(-50%, -50%); }
.cursor__dot { width: 6px; height: 6px; background: #fff; }
.cursor__ring {
  width: 38px; height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  display: grid; place-items: center;
  transition: width 0.45s var(--ease-out), height 0.45s var(--ease-out), background-color 0.3s, border-color 0.3s;
}
.cursor__label {
  font-family: var(--f-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: #000; opacity: 0; transition: opacity 0.2s;
}
.cursor.is-hover .cursor__ring { width: 84px; height: 84px; background: #fff; border-color: #fff; }
.cursor.is-hover .cursor__label { opacity: 1; }
.cursor.is-hover .cursor__dot { opacity: 0; }
.cursor.is-down .cursor__ring { width: 28px; height: 28px; }
@media (hover: none), (pointer: coarse) { .cursor { display: none; } }

/* ---------- preloader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 80;
  background: var(--ink);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--gutter);
  color: var(--paper);
}
.loader__top, .loader__bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.loader__log {
  font-family: var(--f-mono); font-size: 12px; line-height: 1.9; color: var(--mute);
  min-height: 9.5em;
}
.loader__log .ok { color: var(--signal); }
.loader__log .hl { color: var(--paper); }
.loader__count {
  font-size: clamp(96px, 22vw, 340px);
  font-weight: 800; letter-spacing: -0.06em; line-height: 0.8;
  font-variant-numeric: tabular-nums;
}
.loader__count sup { font-size: 0.18em; font-weight: 500; letter-spacing: 0; vertical-align: top; color: var(--ember); margin-left: 0.1em; }
.loader__bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--ember); transform-origin: left; transform: scaleX(0); }

/* ---------- nav ---------- */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px var(--gutter);
  mix-blend-mode: difference;
  color: #fff;
}
.nav__logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.02em; font-size: 15px; }
.nav__mark {
  width: 30px; height: 30px; border: 1px solid currentColor; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--f-serif); font-style: italic; font-size: 16px; font-weight: 400;
}
.nav__links { display: flex; gap: 32px; }
.nav__links a { position: relative; overflow: hidden; display: inline-block; height: 1.3em; line-height: 1.3em; }
.nav__links a span { display: block; transition: transform 0.5s var(--ease-out); }
.nav__links a span + span { position: absolute; top: 100%; left: 0; }
.nav__links a:hover span { transform: translateY(-100%); }
.nav__status { display: flex; align-items: center; gap: 10px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--signal); position: relative; }
.pulse::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--signal);
  animation: pulse 2s var(--ease-out) infinite;
}
@keyframes pulse { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(3.2); opacity: 0; } }

/* chapter rail (left edge) */
.rail {
  position: fixed; left: var(--gutter); bottom: 28px; z-index: 60;
  display: flex; align-items: center; gap: 14px;
  mix-blend-mode: difference; color: #fff;
}
.rail__track { width: 120px; height: 1px; background: rgba(255,255,255,0.25); position: relative; overflow: hidden; }
.rail__fill { position: absolute; inset: 0; background: #fff; transform-origin: left; transform: scaleX(0); }
.rail__label { min-width: 13ch; height: 1.4em; overflow: hidden; position: relative; }
.rail__label span { display: block; }
.rail__time { position: fixed; right: var(--gutter); bottom: 28px; z-index: 60; mix-blend-mode: difference; color: #fff; }

@media (max-width: 820px) {
  .nav__links { display: none; }
  .rail__track { width: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
  .pulse::after { animation: none; }
}
