/* ==========================================================================
   Base — reset, typography defaults, focus, accessibility primitives.
   ========================================================================== */

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

* {
  margin: 0;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--paper);
  /* Safety net: nothing may cause horizontal scroll on any device.
     `clip` (not hidden) so it never breaks position: sticky/fixed. */
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Real kerning + common/contextual ligatures everywhere. Harmless where
     the font lacks the feature; a clear lift where it doesn't. */
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
}

/* ---- Media ---- */
img,
picture,
video,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ---- Headings ---- */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

/* Serif display headings: let large glyphs settle into their optical size
   and keep discretionary ligatures for editorial finish. */
h1,
h2,
.statement,
.lede {
  font-optical-sizing: auto;
}

/* Long-form prose reads better with hanging punctuation where supported
   (Safari today; ignored elsewhere — never a regression). */
.lede,
.statement,
.prose p {
  hanging-punctuation: first last;
}

h1 {
  font-size: var(--text-h1);
  line-height: var(--leading-tight);
}

h2 {
  font-size: var(--text-h2);
  line-height: var(--leading-tight);
}

h3 {
  font-size: var(--text-h3);
}

h4 {
  font-size: var(--text-h4);
}

p {
  text-wrap: pretty;
}

/* ---- Links ---- */
a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color var(--dur-fast) var(--ease-out);
}

a:hover {
  color: var(--accent);
}

/* ---- Forms inherit typography ---- */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

/* ---- Focus — always visible, never removed ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

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

/* ---- Accessibility primitives ---- */
.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;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--gray-900);
  color: #fff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transform: translateY(-300%);
  transition: transform var(--dur-fast) var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
  color: #fff;
}

/* ---- Scroll progress indicator ---- */
.scroll-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 60;
  pointer-events: none;
  /* No track: at 0% scroll a track renders as a stray stub in the corner.
     Only the fill (which grows from the left) should ever be visible. */
  background: transparent;
  /* Ride above the view-transition layer so it never flickers between pages. */
  view-transition-name: scroll-progress;
}

.scroll-progress span {
  display: block;
  height: 100%;
  /* A warm→accent sweep gives the bar a sense of travel, not just fill. */
  background: linear-gradient(90deg, var(--warm), var(--accent) 65%);
  transform: scaleX(0);
  transform-origin: 0 50%;
  will-change: transform;
}

/* Lenis: let the library own scroll; disable native smooth so they don't fight. */
html.lenis,
html.lenis body {
  height: auto;
}

.lenis.lenis-smooth {
  scroll-behavior: auto !important;
}

.lenis.lenis-stopped {
  overflow: clip;
}

/* ---- Reduced motion: honor the preference globally ---- */
@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;
  }
}
