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

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

body {
  margin: 0;
  min-height: 100lvh;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-weight: 400;
  font-feature-settings: var(--font-features-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Numeric UI — aligned figures for metrics, specs, and counters.
   Tabular + slashed zero keeps stacked data from shifting. */
[data-stat],
.stat-value,
.metric-value,
dl dt,
time,
.tabular {
  font-variant-numeric: tabular-nums slashed-zero;
  font-feature-settings: var(--font-features-numeric);
}

/* Monospace runs always carry their own feature set. */
code, pre, kbd, samp,
[class*="mono"] {
  font-feature-settings: var(--font-features-text);
}

/* Keyboard focus — 2px ring + 2px offset (WCAG 2.2 SC 2.4.13 / 1.4.11). */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  :focus-visible { transition: none; }
}

h1, h2, h3, h4, p, figure, dl, dd, ul, ol {
  margin: 0;
  padding: 0;
}

ul, ol { list-style: none; }

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

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

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

/* Visually hidden — assistive copy of every animated text run */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link — off-screen until focused, then pinned top-left above the masthead */
.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 2000;
  padding: 0.7rem 1.1rem;
  background: var(--foreground);
  color: var(--background);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-chip);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  transform: translateY(-160%);
  transition: transform var(--duration-fast) var(--ease-plate);
}
.skip-link:focus-visible {
  transform: translateY(0);
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Text-reveal primitives — no overflow clip anywhere */
.reveal-flow {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.3em;
}
.reveal-unit {
  display: inline-block;
  will-change: transform, opacity;
}

/* Scroll lock while the menu sheet or modal is open.
   Only overflow is clamped — setting height:100% here collapses the document
   and makes the page jump back to the top when the overlay closes. The
   scrollbar gutter is reserved so locking does not shift the layout sideways. */
html.is-locked {
  overflow: hidden;
  scrollbar-gutter: stable;
}

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

/* Anchor jumps must clear the fixed masthead */
html {
  scroll-padding-top: 5rem;
}

/* Bespoke technical scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--background);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 0;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--foreground-muted);
}

/* Accessibility focus-visible styles */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}

/* Asset-failure banner — a failed load must be visible */
.asset-error {
  position: fixed;
  left: 0; right: 0; top: 0;
  z-index: 100;
  padding: 0.75rem 1.25rem;
  background: #ff6b00;
  color: #000;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------
   Entrance safety net.

   Elements that animate in are hidden ONLY after JS confirms it can run
   them (main.js adds .js-motion to <html>). Without that class they stay
   fully visible, so a module error, a blocked CDN, or a trigger that never
   fires can never leave text permanently transparent.
   ------------------------------------------------------------------ */
.js-motion [data-reveal] {
  opacity: 0;
  transform: translateY(0.75rem);
  transition:
    opacity 600ms var(--ease-entrance),
    transform 600ms var(--ease-entrance);
}
.js-motion [data-reveal].is-revealed {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .reveal-unit { transform: none !important; opacity: 1 !important; }
  .js-motion [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}
