/* ==========================================================================
   Tokens — the whole visual system, defined once.

   Nothing below this file should invent a colour, a spacing value or a radius.
   Ad hoc values drift into six almost-identical greys and five slightly
   different paddings, which reads as sloppiness even when nobody can name why.

   Direction: this is a pregnancy medical archive read by anxious people,
   frequently at 3am on a phone. It should feel calm, clinical and warm —
   closer to a good hospital leaflet than to a lifestyle blog. Deliberately not
   any of the three looks AI design defaults to: no cream-and-terracotta, no
   near-black with an acid accent, no zero-radius broadsheet hairlines.
   ========================================================================== */

:root {
  /* --- ink ------------------------------------------------------------- */
  --ink: #17282f;          /* deep petrol slate, not near-black */
  --ink-soft: #465b64;
  --ink-faint: #6c828c;
  --ink-invert: #f4f8f9;

  /* --- ground ---------------------------------------------------------- */
  --bg: #f6f9fa;           /* cool off-white, never cream */
  --surface: #ffffff;
  --surface-sunk: #eef3f5;
  --line: #dce6ea;
  --line-strong: #c3d3d9;

  /* --- brand ----------------------------------------------------------- */
  --brand: #0f6b6b;        /* deep teal: clinical trust */
  --brand-deep: #0a4d4d;
  --brand-soft: #e4f1f0;
  --brand-line: #a8d2cf;

  /* --- accent ---------------------------------------------------------- */
  --accent: #a8506f;       /* muted plum, warmth without candy pink */
  --accent-deep: #7f3a53;
  --accent-soft: #fbeef2;

  /* --- semantic --------------------------------------------------------
     Reserved for meaning. Never spent as decoration, or they stop signalling. */
  --warn: #8a5d00;
  --warn-soft: #fdf3e0;
  --warn-line: #e6c98a;
  --ok: #1d6b45;
  --ok-soft: #e6f3ec;

  /* --- type ------------------------------------------------------------
     Three faces in the guide's model: a system workhorse for UI, a serif for
     long-form body, one display face for headings. */
  --font-ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-display: 'Chivo', var(--font-ui);

  --step--1: clamp(0.82rem, 0.8rem + 0.1vw, 0.88rem);
  --step-0: clamp(1rem, 0.97rem + 0.16vw, 1.09rem);
  --step-1: clamp(1.19rem, 1.13rem + 0.3vw, 1.36rem);
  --step-2: clamp(1.42rem, 1.32rem + 0.5vw, 1.7rem);
  --step-3: clamp(1.69rem, 1.53rem + 0.8vw, 2.13rem);
  --step-4: clamp(2.01rem, 1.77rem + 1.2vw, 2.66rem);
  --step-5: clamp(2.4rem, 2.03rem + 1.8vw, 3.32rem);

  --lh-tight: 1.15;
  --lh-snug: 1.35;
  --lh-prose: 1.68;

  /* --- space ----------------------------------------------------------- */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;
  --s-9: 6rem;

  /* --- form ------------------------------------------------------------ */
  --r-sm: 6px;
  --r: 12px;
  --r-lg: 20px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgb(23 40 47 / 6%), 0 1px 3px rgb(23 40 47 / 4%);
  --shadow: 0 2px 4px rgb(23 40 47 / 5%), 0 6px 16px rgb(23 40 47 / 7%);
  --shadow-lg: 0 4px 8px rgb(23 40 47 / 6%), 0 16px 40px rgb(23 40 47 / 10%);

  --measure: 68ch;
  --wide: 1180px;
  --mid: 900px;

  /* --- motion ----------------------------------------------------------
     Nothing animates linearly. Ease-out for things arriving, ease-in-out for
     things moving between states. */
  --ease-out: cubic-bezier(0.16, 0.84, 0.44, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --t-fast: 140ms;
  --t: 240ms;
  --t-slow: 420ms;
}

/* --- webfonts -----------------------------------------------------------
   Self-hosted and preloaded in the head. `swap` so the archive is readable
   before the fonts arrive — nothing here should wait on a typeface. */

@font-face {
  font-family: 'Source Serif 4';
  src: url('/assets/fonts/source-serif-4-normal-400-1.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Source Serif 4';
  src: url('/assets/fonts/source-serif-4-normal-600-2.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Chivo';
  src: url('/assets/fonts/chivo-normal-700-1.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Chivo';
  src: url('/assets/fonts/chivo-normal-900-2.woff2') format('woff2');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   Site styles. Every value comes from tokens.css.
   ========================================================================== */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--lh-prose);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  color: var(--ink);
  margin: 0 0 var(--s-3);
  text-wrap: balance;
}

h1 { font-size: var(--step-5); letter-spacing: -0.02em; }
h2 { font-size: var(--step-3); letter-spacing: -0.01em; }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }
h5, h6 { font-size: var(--step-0); }

p, ul, ol, blockquote, table, figure { margin: 0 0 var(--s-5); }

a { color: var(--brand-deep); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-deep); }

/* A visible focus ring everywhere, on the element the keyboard is actually on. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* --- layout -------------------------------------------------------------- */

.wrap { width: min(calc(100% - var(--s-5) * 2), var(--wide)); margin-inline: auto; }
.wrap-mid { width: min(calc(100% - var(--s-5) * 2), var(--mid)); margin-inline: auto; }

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--brand);
  color: var(--ink-invert);
  padding: var(--s-3) var(--s-4);
  border-radius: 0 0 var(--r) 0;
  z-index: 50;
  font-family: var(--font-ui);
}
.skip:focus { left: 0; }

/* --- header -------------------------------------------------------------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-3) 0;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: var(--step-1);
  color: var(--brand-deep);
  text-decoration: none;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
}
.brand:hover { color: var(--accent-deep); }
.brand svg { width: 1.6em; height: 1.6em; flex: none; }

.nav { margin-left: auto; }
.nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
}
.nav a {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-pill);
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}
.nav a:hover { background: var(--brand-soft); color: var(--brand-deep); }
.nav a[aria-current='page'] { background: var(--brand); color: var(--ink-invert); }

/* --- breadcrumbs --------------------------------------------------------- */

.crumbs {
  font-family: var(--font-ui);
  font-size: var(--step--1);
  color: var(--ink-faint);
  padding: var(--s-4) 0 0;
}
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.crumbs li { display: flex; align-items: center; gap: var(--s-2); }
.crumbs li + li::before { content: '/'; color: var(--line-strong); }
.crumbs a { color: var(--ink-soft); text-decoration: none; }
.crumbs a:hover { color: var(--brand-deep); text-decoration: underline; }
.crumbs [aria-current='page'] { color: var(--ink-faint); }

/* --- main ---------------------------------------------------------------- */

main { display: block; padding-bottom: var(--s-9); }

.page-head { padding: var(--s-6) 0 var(--s-5); max-width: var(--measure); }
.page-head p { color: var(--ink-soft); font-size: var(--step-1); margin: 0; }
.page-head h1 { margin-bottom: var(--s-4); }

.eyebrow {
  font-family: var(--font-ui);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 var(--s-3);
}

/* --- hero ---------------------------------------------------------------- */

.hero {
  background: linear-gradient(168deg, var(--brand-soft) 0%, var(--bg) 62%);
  border-bottom: 1px solid var(--line);
  padding: var(--s-8) 0 var(--s-7);
}
.hero h1 { max-width: 18ch; }
.hero__lede {
  font-size: var(--step-2);
  color: var(--ink-soft);
  max-width: 46ch;
  margin: 0 0 var(--s-6);
}
.hero__actions { display: flex; flex-wrap: wrap; gap: var(--s-3); }

.btn {
  display: inline-block;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: var(--step-0);
  padding: var(--s-3) var(--s-5);
  border-radius: var(--r-pill);
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}
.btn--primary { background: var(--brand); color: var(--ink-invert); box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--brand-deep); color: var(--ink-invert); transform: translateY(-2px); box-shadow: var(--shadow); }
.btn--primary:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn--ghost { background: var(--surface); color: var(--brand-deep); border-color: var(--brand-line); }
.btn--ghost:hover { background: var(--brand-soft); transform: translateY(-2px); }
.btn--ghost:active { transform: translateY(0); }

/* --- cards --------------------------------------------------------------- */

.grid {
  display: grid;
  gap: var(--s-5);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  padding: 0;
  margin: 0 0 var(--s-6);
  list-style: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  transition: transform var(--t) var(--ease-out), box-shadow var(--t) var(--ease-out),
    border-color var(--t) var(--ease-out);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand-line); }
.card h2, .card h3 { font-size: var(--step-1); margin: 0; }
.card h2 a, .card h3 a { color: var(--ink); text-decoration: none; }
.card:hover h2 a, .card:hover h3 a { color: var(--brand-deep); }
.card p { color: var(--ink-soft); font-size: var(--step--1); margin: 0; line-height: var(--lh-snug); }
.card__meta {
  font-family: var(--font-ui);
  font-size: var(--step--1);
  color: var(--ink-faint);
  margin-top: auto;
  padding-top: var(--s-3);
}

.card--section { border-left: 4px solid var(--brand-line); }
.card--section .count {
  font-family: var(--font-ui);
  font-weight: 600;
  color: var(--brand-deep);
  font-size: var(--step--1);
}

/* --- staggered reveal ----------------------------------------------------
   Animated *from* the hidden state with keyframes, never held hidden by a
   class that JavaScript removes. A script error, a blocked file or a
   non-rendering tab must not be able to leave the content invisible.
   The delay is set by a small set of classes rather than an inline style,
   because a `style-src 'self'` CSP blocks inline style attributes. */

@media (prefers-reduced-motion: no-preference) {
  .reveal { animation: rise var(--t-slow) var(--ease-out) both; }
  .d1 { animation-delay: 60ms; }
  .d2 { animation-delay: 120ms; }
  .d3 { animation-delay: 180ms; }
  .d4 { animation-delay: 240ms; }
  .d5 { animation-delay: 300ms; }
  .d6 { animation-delay: 360ms; }
  .d7 { animation-delay: 420ms; }
  .d8 { animation-delay: 480ms; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* --- prose --------------------------------------------------------------- */

.prose { max-width: var(--measure); }
.prose > * + * { margin-top: var(--s-5); }
.prose h2 { margin-top: var(--s-7); padding-top: var(--s-2); }
.prose h3 { margin-top: var(--s-6); }
.prose h4 { margin-top: var(--s-5); font-family: var(--font-ui); font-weight: 600; }
.prose ul, .prose ol { padding-left: var(--s-5); }
.prose li + li { margin-top: var(--s-2); }
.prose img { border-radius: var(--r); margin-inline: auto; }
.prose figure { margin-inline: 0; }
.prose figcaption {
  font-family: var(--font-ui);
  font-size: var(--step--1);
  color: var(--ink-faint);
  text-align: center;
  margin-top: var(--s-2);
}
.prose blockquote {
  border-left: 3px solid var(--brand-line);
  padding-left: var(--s-5);
  margin-left: 0;
  color: var(--ink-soft);
  font-style: italic;
}
.prose strong { font-weight: 600; }

/* Wide content must scroll inside its own box; the page body never does. */
.prose table, .table-scroll { display: block; overflow-x: auto; max-width: 100%; }

/* --- tables -------------------------------------------------------------- */

.table-scroll { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }

table.data {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-ui);
  font-size: var(--step--1);
  min-width: 34rem;
}
table.data caption {
  caption-side: top;
  text-align: left;
  padding: var(--s-4) var(--s-4) var(--s-3);
  color: var(--ink-soft);
  font-size: var(--step--1);
}
table.data th, table.data td {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data thead th {
  background: var(--surface-sunk);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--brand-soft); }
table.data a { font-weight: 600; }

.badge {
  display: inline-block;
  font-size: var(--step--1);
  font-weight: 600;
  padding: 2px var(--s-2);
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.badge--review { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--gap { background: var(--accent-soft); color: var(--accent-deep); }

/* --- notices -------------------------------------------------------------
   Semantic colour carrying meaning before the text is read. */

.notice {
  border-radius: var(--r);
  padding: var(--s-5);
  margin: 0 0 var(--s-6);
  border: 1px solid var(--line);
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: var(--step--1);
  line-height: var(--lh-snug);
}
.notice h2, .notice h3, .notice p:first-child strong { font-family: var(--font-ui); font-size: var(--step-0); margin: 0 0 var(--s-2); }
.notice p { margin: 0 0 var(--s-2); }
.notice p:last-child { margin-bottom: 0; }
.notice--warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.notice--warn h2, .notice--warn h3 { color: var(--warn); }
.notice--warn a { color: var(--warn); }
.notice--info { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-deep); }
.notice--info h2, .notice--info h3 { color: var(--brand-deep); }

/* --- related ------------------------------------------------------------- */

.related {
  margin-top: var(--s-8);
  padding-top: var(--s-6);
  border-top: 1px solid var(--line);
}
.related h2 { font-size: var(--step-2); }

.linklist { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: var(--s-6); }
.linklist li { break-inside: avoid; margin-bottom: var(--s-2); }
.linklist a { font-family: var(--font-ui); font-size: var(--step--1); }
@media (width < 40rem) { .linklist { columns: 1; } }

/* --- footer -------------------------------------------------------------- */

.site-footer {
  background: var(--ink);
  color: var(--ink-invert);
  padding: var(--s-8) 0 var(--s-6);
  font-family: var(--font-ui);
  font-size: var(--step--1);
}
.site-footer a { color: var(--brand-soft); text-decoration: none; }
.site-footer a:hover { color: var(--surface); text-decoration: underline; }
.site-footer h2 {
  color: var(--ink-invert);
  font-size: var(--step-0);
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--s-3);
}
.footer-grid {
  display: grid;
  gap: var(--s-6);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  margin-bottom: var(--s-6);
}
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin-bottom: var(--s-2); }
.site-footer__base {
  border-top: 1px solid rgb(244 248 249 / 15%);
  padding-top: var(--s-5);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  justify-content: space-between;
  color: #a9bfc7;
}
.site-footer__base p { margin: 0; max-width: 62ch; }

/* --- utility ------------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stack-lg > * + * { margin-top: var(--s-7); }
.lede { font-size: var(--step-1); color: var(--ink-soft); max-width: var(--measure); }
.muted { color: var(--ink-faint); }
.ui { font-family: var(--font-ui); }

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