/* ==========================================================================
   BASE — reset, element defaults, the page shell, and shared utilities.
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

/* Anything anchored from the nav has to clear the sticky bar. Declared once,
   here, rather than remembered on each section. */
:target,
[id] { scroll-margin-top: calc(var(--nav-h) + var(--sp-5)); }

@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;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--tr-tight);
  text-wrap: balance;
}

p { margin: 0; }

a { color: inherit; text-decoration: none; }

img, svg, video, iframe { display: block; max-width: 100%; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

input, select, textarea { font: inherit; color: inherit; }

ul { margin: 0; padding: 0; list-style: none; }

::selection { background: var(--c-rust); color: var(--c-cream); }

:focus-visible {
  outline: 2px solid var(--c-gold);
  outline-offset: 3px;
}

/* --- Grain ---------------------------------------------------------------
   One SVG turbulence layer over the whole page. It sits above the background
   and below every section, so it warms the charcoal without touching type. */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  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.82' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='220' height='220' filter='url(%23n)'/></svg>");
  mix-blend-mode: screen;
}

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

.page { position: relative; z-index: 2; }

/* --- Sections -------------------------------------------------------------
   A section is either on the charcoal ground or on the off-white one. The
   inverted variant re-points the semantic tokens rather than restating any
   colour, so every component inside it flips with no component-level rule. */
.section { padding-block: var(--section-y); }

.section--invert {
  --bg:          var(--c-cream);
  --bg-raised:   #FFFFFF;
  --bg-pressed:  #E7E0D2;
  --text:        var(--c-charcoal);
  --text-muted:  rgba(26, 25, 23, 0.72);
  --text-faint:  rgba(26, 25, 23, 0.52);
  --rule-color:  rgba(26, 25, 23, 0.16);
  --rule-color-strong: rgba(26, 25, 23, 0.34);
  --stripe:      rgba(26, 25, 23, 0.06);
  background: var(--c-cream);
  color: var(--c-charcoal);
}

/* --- Utilities ------------------------------------------------------------ */
.label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--accent-quiet);
}

.measure { max-width: var(--measure); }

.rule-top    { border-top: var(--rule); }
.rule-bottom { border-bottom: var(--rule); }

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

.skip-link {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: calc(var(--z-nav) + 1);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-cream);
  color: var(--c-charcoal);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease);
}
.skip-link:focus { transform: translateY(0); }

/* Attribute-hidden elements must win over any component display rule. */
[hidden] { display: none !important; }

/* --- Reveal on scroll -----------------------------------------------------
   site.js adds .is-in when an element enters the viewport. The resting state
   is defined here so that if JavaScript never runs, nothing is invisible:
   .reveal without the class is fully opaque until JS marks it .reveal-armed. */
.reveal-armed {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.reveal-armed.is-in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .reveal-armed { opacity: 1; transform: none; }
}
