/* =========================================================================
   BASE — reset, document rhythm, global a11y affordances.
   ========================================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 6rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color var(--d-state) var(--e-soft),
              color var(--d-state) var(--e-soft);
}

h1, h2, h3, h4, p, figure, blockquote, ul, ol, dl { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; height: auto; }
button, input, textarea, select { font: inherit; color: inherit; }
strong, b { font-weight: 600; }

/* Fine-grained emphasis: the editorial serif is only ever an accent. */
em, .edit {
  font-family: var(--font-edit);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0;
}

::selection { background: var(--accent); color: var(--on-accent); }

/* ---- Focus: never removed, always visible in both themes -------------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-1);
}

.skip-link {
  position: absolute;
  left: var(--s-4);
  top: -100%;
  z-index: var(--z-overlay);
  padding: var(--s-3) var(--s-5);
  background: var(--accent);
  color: var(--on-accent);
  font: 600 var(--t-small)/1 var(--font-ui);
  border-radius: var(--r-2);
  transition: top var(--d-micro) var(--e-out);
}
.skip-link:focus-visible { top: var(--s-4); }

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

/* ---- Layout primitives ------------------------------------------------ */
.shell {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.section {
  position: relative;
  padding-block: var(--section-y);
  border-top: 1px solid var(--border-subtle);
}
.section:first-of-type { border-top: 0; }

/* Rhythm. A section that answers the one before it sits close to it and drops
   the rule; a section that opens a new movement gets the full separation. */
.section--joined { padding-top: var(--section-y-close); border-top: 0; }
.section--tight  { padding-top: var(--section-y-tight); }

/* Paper grain. Static by design — an animated grain is decoration that
   costs a repaint every frame and buys nothing. */
.grain {
  position: fixed; inset: 0;
  z-index: var(--z-overlay);
  pointer-events: none;
  opacity: 0.038;
  mix-blend-mode: overlay;
  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");
}

/* =========================================================================
   REDUCED MOTION — global kill switch. Reveal states are forced to their
   final value by .js-reveal defaults, so nothing is left invisible.
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Navigation between pages ------------------------------------------
   Same-origin MPA view transitions. Clicking a case study now crosses over
   instead of blinking white, which is the single cheapest way to make a
   hand-written static site feel built rather than assembled. Browsers
   without support navigate exactly as before. */
@view-transition { navigation: auto; }

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) {
    animation: vt-out var(--d-exit) var(--e-soft) both;
  }
  ::view-transition-new(root) {
    animation: vt-in var(--d-enter) var(--e-expo) both;
  }
  @keyframes vt-out { to { opacity: 0; transform: translateY(-8px); } }
  @keyframes vt-in  { from { opacity: 0; transform: translateY(12px); } }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
}

/* The header is the one thing that must not move across the transition. */
.nav__mark { view-transition-name: site-mark; }
