/* ============================================================
   Base — reset, typography, atmosphere, accessibility
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + var(--s-5));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.65;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ---- atmosphere -------------------------------------------
   Two fixed layers, both pointer-inert, both compositor-safe:
   a wine glow anchored top-left, and a fine grain that keeps
   the near-black field from reading as dead flat.
   ----------------------------------------------------------- */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
body::before {
  background:
    radial-gradient(70ch 52ch at 12% -8%,  var(--glow-a), transparent 68%),
    radial-gradient(60ch 48ch at 96% 4%,   var(--glow-b), transparent 66%),
    radial-gradient(90ch 60ch at 50% 118%, var(--glow-c), transparent 72%);
}
body::after {
  opacity: var(--noise-opacity);
  mix-blend-mode: var(--noise-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* keep all real content above the atmosphere */
.nav, .page, .footer { position: relative; z-index: 1; }

/* ---- headings --------------------------------------------- */
h1, h2, h3, h4 {
  margin: 0;
  font-weight: 550;
  line-height: 1.12;
  letter-spacing: var(--track-tight);
  text-wrap: balance;
}

p { margin: 0; }

/* ---- links ------------------------------------------------
   Underline is drawn, not toggled — the rule grows from the
   left edge so the hover reads as a deliberate mark.
   ----------------------------------------------------------- */
a { color: inherit; text-decoration: none; }

.link {
  position: relative;
  color: var(--accent-text);
  padding-bottom: 1px;
}
.link::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 100%; height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur-base) var(--ease-out);
}
.link:hover::after,
.link:focus-visible::after { transform: scaleX(1); }

/* ---- the mono metadata voice ------------------------------
   Signature move of this system: every date, count, label and
   tag is mono, 11px, wide-tracked, uppercase.
   ----------------------------------------------------------- */
.label {
  font-family: var(--mono);
  font-size: var(--t-label);
  line-height: 1.4;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}
.label--accent { color: var(--accent-text); }

/* ---- media ------------------------------------------------ */
img { max-width: 100%; height: auto; display: block; }

/* ---- selection -------------------------------------------- */
::selection { background: var(--selection-bg); color: var(--selection-ink); }

/* ---- focus ------------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link {
  color: var(--selection-ink);
  position: absolute;
  left: var(--s-4);
  top: -100px;
  z-index: 100;
  padding: var(--s-3) var(--s-5);
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: var(--t-small);
  border-radius: var(--r-sm);
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--s-4); }

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

/* ---- bilingual switching ----------------------------------
   Language spans are swapped by data-lang on <html>.
   ----------------------------------------------------------- */
:root[data-lang="en"] .lang-cn,
:root[data-lang="cn"] .lang-en { display: none; }

/* CJK wants opposite tracking to the Latin display treatment */
:root[data-lang="cn"] body { letter-spacing: 0; line-height: 1.78; }

/* ---- scroll reveal ----------------------------------------
   Progressive enhancement, deliberately inverted: content is
   visible by default and only becomes hideable once the reveal
   script has run and set data-reveal on <html>. If JS never
   loads or throws, nothing is ever hidden.
   transform + opacity only — stays on the compositor.
   ----------------------------------------------------------- */
:root[data-reveal="on"] .reveal {
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity   var(--dur-slow) var(--ease-out),
    transform var(--dur-slow) var(--ease-out);
}
/* Stagger steps as classes — a strict style-src CSP forbids the
   inline style attribute a JS-set custom property would need. */
:root[data-reveal="on"] .reveal--1 { transition-delay:  70ms; }
:root[data-reveal="on"] .reveal--2 { transition-delay: 140ms; }
:root[data-reveal="on"] .reveal--3 { transition-delay: 210ms; }
:root[data-reveal="on"] .reveal--4 { transition-delay: 280ms; }
:root[data-reveal="on"] .reveal--5 { transition-delay: 350ms; }
:root[data-reveal="on"] .reveal.is-in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  :root[data-reveal="on"] .reveal { opacity: 1; transform: none; transition: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
