/* ============================================================
   Base — reset, element defaults, layout + type primitives
   ============================================================ */

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

html {
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  /* Containment for horizontal overflow.
     `clip` (unlike `hidden`) does NOT create a scroll container, which is what
     stops mobile browsers from allowing pinch-zoom-out to reveal off-screen
     content and never snapping back. Supported in all modern browsers. */
  overflow-x: clip;
  /* Stop iOS Safari from inflating fonts on landscape orientation change. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  line-height: var(--lh-normal);
  color: var(--fg-muted);
  font-size: var(--fs-body);
  overflow-x: clip;
  /* Defence in depth: don't let any descendant push the document wider than
     the viewport. Combined with `overflow-x: clip` above, this guarantees
     scrollWidth ≤ clientWidth on every page when implemented correctly. */
  min-width: 0;
}

/* Anything that holds raw content (images, embeds, code blocks) honours its
   container width by default. */
img, svg, video, iframe, embed, object, canvas { max-width: 100%; }

h1, h2, h3, h4, h5, h6 {
  color: var(--fg-strong);
  font-weight: 700;
  line-height: var(--lh-tight);
  margin: 0 0 var(--space-4) 0;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); font-weight: 600; line-height: var(--lh-snug); }
h4 { font-size: var(--fs-h4); font-weight: 600; }

p { margin: 0 0 var(--space-4) 0; line-height: var(--lh-relaxed); text-wrap: pretty; hyphens: auto; -webkit-hyphens: auto; }

a { color: var(--accent); text-decoration: none; transition: color var(--dur) var(--ease-out); }
a:hover { color: var(--accent-hover); text-decoration: underline; }

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

ul, ol { margin: 0 0 var(--space-4); padding-left: 1.2em; }

/* Focus ring: light context. */
:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--accent); border-radius: 4px; }
/* Focus ring: dark context (ink / slate sections, drawer, fiskwatch, KPD card).
   White halo blends with body copy on dark; use ink + a wider red ring. */
.section--ink :focus-visible,
.section--slate :focus-visible,
.drawer__panel :focus-visible,
.fiskwatch :focus-visible,
.kpd :focus-visible,
.kpdapp :focus-visible,
.case__hero :focus-visible,
.sal__result :focus-visible,
.bd__bulletin :focus-visible,
.bd__dir :focus-visible {
  box-shadow: 0 0 0 2px var(--ink-900), 0 0 0 5px var(--red-500);
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* skip link */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 1000;
  background: var(--red-700); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---- Layout ---- */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 32px; }
.container--mid { max-width: 1100px; }
.container--narrow { max-width: 760px; }
@media (max-width: 640px) { .container { padding: 0 20px; } }

.section { padding: clamp(48px, 6vw + 2rem, 80px) 0; }
.section--white { background: var(--white); }
.section--paper { background: var(--paper); }
.section--ink { background: var(--ink-900); color: rgba(255,255,255,.75); }
.section--slate { background: var(--slate-700); color: rgba(255,255,255,.85); }

/* ---- Type utilities ---- */
.eyebrow {
  font-size: var(--fs-eyebrow); font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--accent); margin: 0;
}
.eyebrow--muted { color: var(--ink-500); }
.eyebrow--subtle { color: var(--ink-400); }
.lead { font-size: clamp(16px, 0.6vw + 0.9rem, 19px); line-height: 1.55; color: var(--fg-muted); max-width: 65ch; }
.mono { font-family: var(--font-mono); }
.text-red { color: var(--red-700); }
.text-ink { color: var(--ink-900); }

/* ---- Wave motif (signature brand element) ---- */
.wave-divider { width: 100%; height: 24px; line-height: 0; }
.wave-divider svg { width: 100%; height: 100%; display: block; }
.wave-divider--flip { transform: scaleY(-1); }
.wave-accent { width: 96px; height: 12px; display: block; }

/* ---- Section heading (chapter numeral + wave accent) ---- */
.section-head { display: grid; grid-template-columns: auto 1fr; gap: 40px; align-items: baseline; }
.section-head__num {
  font-weight: 700; font-size: 56px; color: var(--red-700);
  line-height: 0.9; letter-spacing: -0.04em;
}
.section-head__title { margin: 0; font-size: var(--fs-h1); line-height: 1.05; color: var(--ink-900); }
.section-head__lead { margin: 20px 0 0; font-size: 17px; line-height: 1.6; color: var(--fg-muted); max-width: 720px; }
.section-head__accent { margin-top: 24px; }
.section-head--center { grid-template-columns: 1fr; text-align: center; max-width: 720px; margin: 0 auto; }
.section-head--center .section-head__accent { display: flex; justify-content: center; }
.section-head--dark .section-head__title { color: #fff; }
.section-head--dark .section-head__lead { color: rgba(255,255,255,.7); }
@media (max-width: 640px) {
  .section-head { grid-template-columns: 1fr; gap: 12px; }
  .section-head__num { font-size: 40px; }
}
