/*
 * base.css — fonts, design tokens, reset, base typography, utilities.
 * Snap-fit design system (R0). Spec: /DESIGN.md.
 *
 * Fonts (self-hosted, latin subset, variable WOFF2, SIL OFL 1.1; sources and licences in assets/fonts/FONTS.md):
 *   Archivo        wght 100-900, wdth 62-125   assets/fonts/archivo-var-latin.woff2   (display)
 *   Source Sans 3  wght 200-900, roman + italic assets/fonts/source-sans-3-var-latin*.woff2 (body)
 *
 * Breakpoints (min-width, used literally in media queries): 640 / 768 / 1024 / 1280.
 */

/* ---------- Fonts ---------- */
@font-face {
  font-family: Archivo;
  src: url("../fonts/archivo-var-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-var-latin.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-var-latin-italic.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

/*
 * Metric-matched local fallbacks (Arial), tuned 2026-11-16 (R8) by measuring rendered text widths.
 * Archivo Fallback has two faces so heavy text gets real Arial Bold advances, not synthesised bold:
 *   600-900: size-adjust is Archivo (800, wdth 112%) over Arial Bold on the page h1 strings (ratio 1.158),
 *            because the h1 is the LCP element. Smaller bold labels (wdth 106%) run about 14% wide until the swap.
 *            Stretch 118% and wider (the Home hero h1 at 125%) has its own face, ratio 1.298.
 *   100-599: Archivo 500 over Arial regular (ratio 1.007).
 * Ascent and descent are Archivo's hhea 878 / 210 per 1000 upm divided by size-adjust.
 * Source Sans 3 Fallback: measured ratio 0.934 against the 94% used, so it stays.
 */
@font-face {
  font-family: "Archivo Fallback";
  src: local("Arial");
  font-weight: 100 599;
  size-adjust: 100.7%;
  ascent-override: 87.2%;
  descent-override: 20.9%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Archivo Fallback";
  src: local("Arial Bold"), local("Arial-BoldMT");
  font-weight: 600 900;
  font-stretch: 50% 117%;
  size-adjust: 115.8%;
  ascent-override: 75.8%;
  descent-override: 18.1%;
  line-gap-override: 0%;
}

/* The Home hero h1 is set at wdth 125%, so it needs its own size-adjust (measured the same way). */
@font-face {
  font-family: "Archivo Fallback";
  src: local("Arial Bold"), local("Arial-BoldMT");
  font-weight: 600 900;
  font-stretch: 118% 200%;
  size-adjust: 129.8%;
  ascent-override: 67.6%;
  descent-override: 16.2%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Source Sans 3 Fallback";
  src: local("Arial");
  size-adjust: 94%;
  ascent-override: 108.9%;
  descent-override: 42.6%;
  line-gap-override: 0%;
}

/* ---------- Tokens (light, constant + light theme) ---------- */
:root {
  color-scheme: light dark;

  /* Logo stops. Blue and purple exist only inside the seam and the logo. */
  --brand-cyan: #05b0c3;
  --brand-blue: #4470be;
  --brand-purple: #7b3fbf;
  --brand-magenta: #b000be;

  /* Named palette (DESIGN 1.1) */
  --paper: #f1f3f6;
  --ink: #172033;
  --graphite: #4a5468;
  --pegboard: #c9d1dc;
  --signal-cyan: #05b0c3;
  --signal-magenta: #b000be;
  --block-face: #fbfcfd;
  --block-face-raised: #fff;
  --ink-plate: #172033;
  --ink-plate-text: #f1f3f6;

  /* The only gradient: a 3px seam where parts have locked together. */
  --gradient-seam: linear-gradient(
    90deg,
    #05b0c3 0%,
    #4470be 37%,
    #7b3fbf 65%,
    #b000be 100%
  );
  --seam-w: 3px;
  --ledge: 3px;

  /* Legacy gradient names, remapped */
  --gradient-brand: var(--gradient-seam);
  --gradient-brand-strong: var(--gradient-seam);
  --gradient-text: currentcolor;

  /* Semantic colours (M0 names kept) */
  --color-bg: var(--paper);
  --color-surface: var(--block-face);
  --color-surface-raised: var(--block-face-raised);
  --color-border: var(--pegboard); /* decorative only */
  --color-border-strong: var(--graphite); /* UI boundaries, >= 3:1 */
  --color-text: var(--ink);
  --color-text-muted: var(--graphite);
  --color-link: var(--ink);
  --color-accent: var(--signal-magenta);
  --color-accent-2: var(--signal-cyan);
  --color-focus: var(--signal-magenta);
  --color-success: #1f7a4d;
  --color-error: #b42318;
  --color-on-brand: #172033; /* text on cyan fills; constant in both themes */
  --color-ink: #172033;
  --color-header-bg: rgb(241 243 246 / 92%);
  --color-selection: rgb(5 176 195 / 35%);
  --peg-color: var(--pegboard);

  /* Depth: hard ledges, no blur. */
  --ledge-color: rgb(74 84 104 / 35%);
  --shadow-s: 0 1px 0 var(--pegboard);
  --shadow-m: 0 3px 0 var(--ledge-color);
  --shadow-l: 0 6px 0 var(--ledge-color);

  /* Type */
  --font-display: archivo, "Archivo Fallback", system-ui, sans-serif;
  --font-body: "Source Sans 3", "Source Sans 3 Fallback", system-ui, sans-serif;

  /*
   * Fluid scale, 375px to 1280px viewport: clamp(min, intercept + slope*vw, max)
   * where slope = (max - min) / (1280 - 375) * 100 and intercept = min - slope * 3.75.
   * Sizes px (mobile to desktop): 13/13, 14/15, 17/18, 19/21, 22/24, 28/36, 36/48, 44/72, 48/96.
   */
  --step--2: 0.8125rem;
  --step--1: clamp(0.875rem, 0.8491rem + 0.1105vw, 0.9375rem);
  --step-0: clamp(1.0625rem, 1.0366rem + 0.1105vw, 1.125rem);
  --step-1: clamp(1.1875rem, 1.1357rem + 0.221vw, 1.3125rem);
  --step-2: clamp(1.375rem, 1.3232rem + 0.221vw, 1.5rem);
  --step-3: clamp(1.75rem, 1.5428rem + 0.884vw, 2.25rem);
  --step-4: clamp(2.25rem, 1.9392rem + 1.326vw, 3rem);
  --step-5: clamp(2.75rem, 2.0249rem + 3.0939vw, 4.5rem);
  --step-6: clamp(3rem, 1.7569rem + 5.3039vw, 6rem);

  --fw-regular: 400;
  --fw-medium: 600; /* body semibold */
  --fw-semibold: 600;
  --fw-label: 600;
  --fw-title: 650;
  --fw-heading: 750;
  --fw-bold: 750;
  --fw-black: 800;

  --wdth-normal: 100%;
  --wdth-label: 106%;
  --wdth-wide: 112%;
  --wdth-xwide: 125%;

  --lh-tight: 1.05;
  --lh-heading: 1.1;
  --lh-snug: 1.25;
  --lh-body: 1.6;
  --tracking-tight: -0.02em;
  --tracking-label: 0.01em;
  --tracking-wide: 0.18em;

  --measure: 66ch;
  --measure-lead: 58ch;
  --measure-h1: 20ch;
  --measure-h2: 28ch;

  /* Space (8px rhythm) */
  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs: 0.75rem;
  --space-s: 1rem;
  --space-m: 1.5rem;
  --space-l: 2rem;
  --space-xl: 3rem;
  --space-2xl: 4rem;
  --space-3xl: 6rem;
  --module: 4rem;
  --peg: 1.5rem;
  --section-pad: clamp(4rem, 3rem + 4.4vw, 7rem);
  --gutter: 1rem;

  /* Layout */
  --container-max: 76rem;
  --container-narrow: 44rem;
  --container-wide: 90rem;
  --header-h: var(--module);
  --header-h-scrolled: var(--module);

  /* Radii */
  --radius-s: 4px;
  --radius-m: 12px;
  --radius-l: 20px;
  --radius-pill: 999px;

  /* Z-index */
  --z-base: 0;
  --z-raised: 10;
  --z-header: 100;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;

  /* Motion */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-snap: cubic-bezier(0.3, 1.45, 0.55, 1);
  --dur-micro: 160ms;
  --dur-fast: 220ms;
  --dur-snap: 260ms;
  --dur-reveal: 400ms;
  --dur-hero: 1000ms;
  --snap-step: 110ms;
  --stagger-step: 60ms;
  --reveal-distance: 12px;
}

@media (min-width: 640px) {
  :root {
    --gutter: 1.5rem;
  }
}

@media (min-width: 1024px) {
  :root {
    --gutter: 2rem;
  }
}

/* ---------- Dark tokens ("Night board") ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121a2b;
    --ink: #e7ebf2;
    --graphite: #a6b0c3;
    --pegboard: #2c3852;
    --signal-magenta: #e05aea;
    --block-face: #1a2438;
    --block-face-raised: #212c43;
    --ink-plate: #0c1220;
    --ink-plate-text: #e7ebf2;
    --color-success: #5bd69a;
    --color-error: #ff8a80;
    --color-header-bg: rgb(18 26 43 / 92%);
    --color-selection: rgb(5 176 195 / 40%);
    --ledge-color: rgb(0 0 0 / 45%);
    --shadow-s: 0 1px 0 var(--pegboard);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #121a2b;
  --ink: #e7ebf2;
  --graphite: #a6b0c3;
  --pegboard: #2c3852;
  --signal-magenta: #e05aea;
  --block-face: #1a2438;
  --block-face-raised: #212c43;
  --ink-plate: #0c1220;
  --ink-plate-text: #e7ebf2;
  --color-success: #5bd69a;
  --color-error: #ff8a80;
  --color-header-bg: rgb(18 26 43 / 92%);
  --color-selection: rgb(5 176 195 / 40%);
  --ledge-color: rgb(0 0 0 / 45%);
}

:root[data-theme="light"] {
  color-scheme: light;
}

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
  overflow-x: clip; /* un-revealed [data-reveal] offsets must not widen the layout viewport */
}

body {
  min-block-size: 100vh;
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--lh-body);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

img,
picture,
svg,
video,
canvas {
  display: block;
  max-inline-size: 100%;
}

img,
video {
  block-size: auto;
}

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

button {
  cursor: pointer;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* ---------- Typography ---------- */
h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  line-height: var(--lh-heading);
}

h1 {
  max-inline-size: var(--measure-h1);
  font-size: var(--step-4);
  font-weight: var(--fw-black);
  font-stretch: var(--wdth-wide);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
}

h2 {
  max-inline-size: var(--measure-h2);
  font-size: var(--step-3);
  font-weight: var(--fw-heading);
  font-stretch: var(--wdth-wide);
  letter-spacing: var(--tracking-tight);
}

h3 {
  font-size: var(--step-2);
  font-weight: var(--fw-title);
  font-stretch: var(--wdth-label);
  line-height: var(--lh-snug);
}

h4 {
  font-size: var(--step-1);
  font-weight: var(--fw-title);
  font-stretch: var(--wdth-label);
  line-height: var(--lh-snug);
}

p,
li {
  max-inline-size: var(--measure);
}

strong,
b {
  font-weight: var(--fw-semibold);
}

@supports (text-wrap: balance) {
  h1,
  h2,
  h3,
  h4 {
    text-wrap: balance;
  }
}

@supports (text-wrap: pretty) {
  p,
  li {
    text-wrap: pretty;
  }
}

a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-color: var(--graphite);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: var(--signal-magenta);
  text-decoration-thickness: 2px;
}

::selection {
  background: var(--color-selection);
}

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

/* ---------- Utilities ---------- */
.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* <main> is focused programmatically by the skip link; show no ring unless keyboard-driven. */
main:focus:not(:focus-visible),
main[tabindex="-1"]:not(:focus-visible) {
  outline: none;
}

/* ---------- Reduced motion (mandatory, from CLAUDE.md) ---------- */
/* stylelint-disable declaration-no-important -- the one place CLAUDE.md requires !important */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
/* stylelint-enable declaration-no-important */
