/*
 * Reset, typography and primitives.
 *
 * Mobile-first throughout: the base rules ARE the phone layout, and every
 * media query below adds rather than subtracts. This is the deliberate
 * inversion of the old stylesheet, where the desktop layout was the base and
 * `max-width` queries took things away.
 */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  margin: 0 0 var(--sp-3);
  line-height: 1.2;
  letter-spacing: -.018em;
  font-weight: 650;
  text-wrap: balance;          /* ignored where unsupported; no fallback needed */
}
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

p { margin: 0 0 var(--sp-4); }
ul, ol { margin: 0 0 var(--sp-4); padding-left: 1.25em; }
/* Scoped to prose deliberately. As a bare `li + li` this leaked into every
   list on the site — the nav, the footer, the popular sidebar — pushing every
   item after the first down by 4px, which read as the FIRST item sitting
   higher than the rest. Component lists set their own spacing with gap. */
.prose li + li { margin-top: var(--sp-1); }

a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-dark); }

/* One focus treatment everywhere. Keyboard users get a clear ring; mouse
   users never see it. Never remove the outline without replacing it. */
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

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

code, kbd, samp, .mono { font-family: var(--font-mono); font-size: .9em; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-6) 0;
}

small, .small { font-size: var(--fs-sm); }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

/* Visible only to screen readers — used for skip links and icon-only controls. */
.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 {
  position: absolute; left: var(--sp-2); top: -3rem;
  background: var(--surface); color: var(--text);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  z-index: 100; transition: top .12s ease;
}
.skip-link:focus { top: var(--sp-2); }

/* ---- layout primitives ---- */
.wrap {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}
@media (min-width: 48rem) { .wrap { padding-inline: var(--sp-5); } }

.stack > * + * { margin-top: var(--sp-4); }
.prose { max-width: var(--measure); }
.prose img { border-radius: var(--radius); margin-block: var(--sp-5); }
.prose iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: var(--radius); }

/* Wide content must scroll inside itself rather than pushing the page sideways. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/*
 * Suppress decorative motion when the OS asks for it.
 *
 * Note the blanket `*` with !important: it is the right default, but it also
 * flattens FUNCTIONAL animations — anything conveying state or time rather
 * than decoration. A progress bar caught by this completes in 0.01ms and,
 * being `forwards`, holds at 100% permanently: an indicator that permanently
 * claims "about to change". Such elements must re-assert their duration
 * explicitly (see .hero-progress-fill in components.css).
 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
