/* ==========================================================================
   Neutral Base — design tokens
   Mirrors DESIGN.md frontmatter verbatim. If a value changes here, change it
   there too; the detector reads DESIGN.md and compares it against the CSS.

   Fonts (all free, none on the saturated list):
   @import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;700&family=Literata:opsz,wght@7..72,400;7..72,600&family=JetBrains+Mono:wght@400;500&display=swap');
   ========================================================================== */

:root {
  /* ── Type families ─────────────────────────────────────────────────────── */
  --font-sans: Archivo, "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-serif: Literata, Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", SFMono-Regular, Consolas, monospace;

  /* ── Type ramp ─────────────────────────────────────────────────────────── */
  --size-11: 0.6875rem;   /* functional floor */
  --size-12: 0.75rem;
  --size-13: 0.8125rem;
  --size-14: 0.875rem;
  --size-16: 1rem;
  --size-18: 1.125rem;
  --size-20: 1.25rem;
  --size-24: 1.5rem;
  --size-28: 1.75rem;
  --size-32: 2rem;
  --size-40: 2.5rem;
  --size-48: 3rem;
  --size-56: 3.5rem;
  --size-72: 4.5rem;      /* ceiling 6rem, one- or two-word headlines only */
  --size-display: clamp(2.75rem, 5vw, 4.5rem);

  /* ── Leading & tracking ────────────────────────────────────────────────── */
  --leading-display: 1.04;
  --leading-heading: 1.2;
  --leading-body: 1.6;
  --leading-prose: 1.7;
  --leading-ui: 1.4;

  --track-display: -0.025em;  /* floor -0.04em */
  --track-heading: -0.015em;
  --track-body: 0;
  --track-label: 0.04em;      /* short uppercase labels only */

  /* ── Measure ───────────────────────────────────────────────────────────── */
  --measure-prose: 68ch;      /* stay inside 65–75ch */
  --measure-ui: 60ch;

  /* ── Spacing ───────────────────────────────────────────────────────────── */
  --space-3xs: 2px;
  --space-2xs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 72px;
  --space-4xl: 112px;
  --space-5xl: 160px;

  --gutter-min: 24px;   /* body text never touches the viewport edge */
  --pad-min: 12px;      /* inside any bordered / filled box */
  --tap-min: 44px;      /* touch target floor */

  /* ── Radii ─────────────────────────────────────────────────────────────── */
  --radius-none: 0;
  --radius-xs: 3px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;    /* cards: 12–16px */
  --radius-xl: 16px;
  --radius-pill: 999px; /* small controls only */

  /* ── Motion ────────────────────────────────────────────────────────────── */
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-instant: 90ms;
  --dur-fast: 160ms;
  --dur-base: 240ms;
  --dur-slow: 420ms;
  --dur-reveal: 640ms;

  /* ── Light theme (default) ─────────────────────────────────────────────── */
  --surface: oklch(98.5% 0.004 250);          /* #f8fafd */
  --surface-sunken: oklch(96.2% 0.006 250);   /* #eff3f6 */
  --surface-raised: oklch(100% 0 250);        /* #ffffff */
  --rule: oklch(90% 0.008 250);               /* #dadee3 */

  --text: oklch(18.5% 0.02 250);              /* #0c131b · 17.9:1 */
  --text-body: oklch(32% 0.016 250);          /* #2d343b · 12.1:1 */
  --text-muted: oklch(48% 0.014 250);         /* #585e65 ·  6.3:1 */
  --text-faint: oklch(55.5% 0.013 250);       /* #6d747b ·  4.6:1 */

  --accent: oklch(56% 0.135 45);              /* #b35627 ·  4.7:1 */
  --accent-strong: oklch(48% 0.13 42);        /* #973e16 ·  6.6:1 */
  --accent-soft: oklch(72% 0.11 48);          /* #dd8f66 */
  --accent-pale: oklch(94.5% 0.035 50);       /* #ffe7d8 */
  --on-accent: oklch(98.5% 0.004 250);

  --positive: oklch(50% 0.11 155);            /* #1e7546 */
  --caution: oklch(56% 0.115 75);             /* #9b690b */
  --critical: oklch(50.5% 0.17 25);           /* #b12c2e */

  /* Elevation: an edge OR a shadow, never both. Every shadow has a Y offset
     and is neutral — a zero-offset coloured halo is decoration, not depth. */
  --elev-flat: none;
  --elev-edge: inset 0 0 0 1px oklch(90% 0.008 250);
  --elev-raised:
    0 1px 2px oklch(18.5% 0.02 250 / 0.06),
    0 2px 6px oklch(18.5% 0.02 250 / 0.06);
  --elev-lifted:
    0 2px 4px oklch(18.5% 0.02 250 / 0.07),
    0 8px 20px oklch(18.5% 0.02 250 / 0.09);
  --elev-overlay:
    0 8px 12px oklch(18.5% 0.02 250 / 0.10),
    0 24px 56px oklch(18.5% 0.02 250 / 0.16);

  color-scheme: light;
}

/* ── Dark theme ──────────────────────────────────────────────────────────
   Defined twice on purpose: once for the system preference (guarded so an
   explicit light choice still wins) and once for an explicit dark choice.
   Never give a colour its only definition inside one of these blocks. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: oklch(17.5% 0.016 250);        /* #0b1117 */
    --surface-sunken: oklch(14% 0.016 250);   /* #050a10 */
    --surface-raised: oklch(22.5% 0.016 250); /* #161c23 */
    --rule: oklch(31% 0.014 250);             /* #2b3137 */

    --text: oklch(96.5% 0.006 250);           /* #f0f4f7 · 17.1:1 */
    --text-body: oklch(88.5% 0.008 250);      /* #d5dade · 13.4:1 */
    --text-muted: oklch(73.5% 0.01 250);      /* #a5aaaf ·  8.1:1 */
    --text-faint: oklch(63.5% 0.012 250);     /* #858b92 ·  5.5:1 */

    --accent: oklch(76% 0.12 50);             /* #ee9a69 ·  8.5:1 */
    --accent-strong: oklch(72% 0.11 48);      /* #dd8f66 */
    --accent-soft: oklch(56% 0.135 45);
    --accent-pale: oklch(30% 0.05 45);
    --on-accent: oklch(17.5% 0.016 250);

    --positive: oklch(76% 0.1 155);           /* #7bc495 */
    --caution: oklch(80% 0.11 80);
    --critical: oklch(74% 0.13 25);           /* #f28881 */

    --elev-edge: inset 0 0 0 1px oklch(31% 0.014 250);
    --elev-raised:
      0 1px 2px oklch(0% 0 0 / 0.40),
      0 2px 6px oklch(0% 0 0 / 0.30);
    --elev-lifted:
      0 2px 4px oklch(0% 0 0 / 0.45),
      0 8px 20px oklch(0% 0 0 / 0.35);
    --elev-overlay:
      0 8px 12px oklch(0% 0 0 / 0.50),
      0 24px 56px oklch(0% 0 0 / 0.45);

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --surface: oklch(17.5% 0.016 250);
  --surface-sunken: oklch(14% 0.016 250);
  --surface-raised: oklch(22.5% 0.016 250);
  --rule: oklch(31% 0.014 250);

  --text: oklch(96.5% 0.006 250);
  --text-body: oklch(88.5% 0.008 250);
  --text-muted: oklch(73.5% 0.01 250);
  --text-faint: oklch(63.5% 0.012 250);

  --accent: oklch(76% 0.12 50);
  --accent-strong: oklch(72% 0.11 48);
  --accent-soft: oklch(56% 0.135 45);
  --accent-pale: oklch(30% 0.05 45);
  --on-accent: oklch(17.5% 0.016 250);

  --positive: oklch(76% 0.1 155);
  --caution: oklch(80% 0.11 80);
  --critical: oklch(74% 0.13 25);

  --elev-edge: inset 0 0 0 1px oklch(31% 0.014 250);
  --elev-raised: 0 1px 2px oklch(0% 0 0 / 0.40), 0 2px 6px oklch(0% 0 0 / 0.30);
  --elev-lifted: 0 2px 4px oklch(0% 0 0 / 0.45), 0 8px 20px oklch(0% 0 0 / 0.35);
  --elev-overlay: 0 8px 12px oklch(0% 0 0 / 0.50), 0 24px 56px oklch(0% 0 0 / 0.45);

  color-scheme: dark;
}

/* ==========================================================================
   Base — the floor, applied. Delete nothing here without a reason.
   ========================================================================== */

body {
  background: var(--surface);
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: var(--size-16);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Page inset: body text never runs flush to the viewport edge. */
.container {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--gutter-min);
}
@media (min-width: 768px) {
  .container { padding-inline: var(--space-xl); }
}

/* Measure. Every text column stays inside 65–75ch. */
p, li, blockquote, dd { max-width: var(--measure-prose); }

/* Headings: roman, tightened optically, and — the structural rule — carrying
   more space above than below, so each one binds to what it introduces. */
h1, h2, h3, h4 {
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 600;
  text-wrap: balance;
  margin-block: var(--space-2xl) var(--space-md);
}
h1 { font-size: var(--size-40); line-height: 1.1;  letter-spacing: -0.02em; }
h2 { font-size: var(--size-28); line-height: 1.2;  letter-spacing: -0.015em; }
h3 { font-size: var(--size-20); line-height: 1.3;  letter-spacing: -0.005em; }
h4 { font-size: var(--size-16); line-height: 1.4; }
h1:first-child, h2:first-child, h3:first-child { margin-block-start: 0; }

.display {
  font-size: var(--size-display);
  font-weight: 600;
  line-height: var(--leading-display);
  letter-spacing: var(--track-display);
  text-wrap: balance;
  color: var(--text);
}

.prose { font-family: var(--font-serif); font-size: 1.0625rem; line-height: var(--leading-prose); }
.lead  { font-size: var(--size-20); line-height: 1.55; color: var(--text); max-width: var(--measure-prose); }
.caption { font-size: var(--size-12); line-height: 1.45; color: var(--text-muted); }

/* The only place uppercase belongs: a short label. */
.label-micro {
  font-size: var(--size-11);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-muted);
}

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.9375em; }
:where(table, .tabular) { font-variant-numeric: tabular-nums; }

/* ── Components ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: var(--tap-min);
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius-md);
  font: 500 var(--size-14)/var(--leading-ui) var(--font-sans);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out-quart),
              color var(--dur-fast) var(--ease-out-quart);
}
.btn-primary { background: var(--accent-strong); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); }
.btn-secondary {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--rule);
}
.btn-secondary:hover { background: var(--surface-sunken); }
.btn:disabled { color: var(--text-faint); cursor: not-allowed; }

.input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 10px 12px;
  background: var(--surface-raised);
  color: var(--text-body);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font: 400 var(--size-16)/var(--leading-ui) var(--font-sans);
}
.input::placeholder { color: var(--text-faint); }  /* still clears 4.5:1 */

/* One card. Edge, no shadow. Cards do not nest. */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--elev-flat);
}
.card .card { border: 0; padding: 0; background: none; }  /* refuse to nest */

.tag {
  display: inline-block;
  padding: 3px 7px;
  background: var(--surface-sunken);
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  font-size: var(--size-11);
  font-weight: 600;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
}

hr { border: 0; border-top: 1px solid var(--rule); margin-block: var(--space-2xl); }

/* ── The surfaces you did not draw ───────────────────────────────────────── */

::selection { background: var(--accent-pale); color: var(--text); }
:root { caret-color: var(--accent); accent-color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in oklch, var(--accent) 45%, transparent);
  transition: text-decoration-color var(--dur-fast) var(--ease-out-quart);
}
a:hover { text-decoration-color: var(--accent); }

::marker { color: var(--text-faint); }

* { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* ── Motion ──────────────────────────────────────────────────────────────── */

/* Content ships visible; motion enhances the entrance, it does not gate
   existence. A failed reveal must never produce a blank page. */
.reveal {
  animation: rise var(--dur-reveal) var(--ease-out-expo) both;
}
@keyframes rise {
  from { opacity: 0; transform: translate3d(0, 12px, 0); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .reveal { animation: none; opacity: 1; transform: none; }
}
