/* ==========================================================================
   Shared stylesheet.
   No framework, no build step, no external fonts, no network requests.

   Design constraints, taken from the product's own accessibility research:
   - System sans-serif only. Never a serif. (Stroke Association, 2012)
   - Body type never below 20px.
   - Line length capped at ~70ch, and ~60ch on the aphasia-accessible pages.
   - Line height 1.5-1.8. Paragraph spacing >= 2x font size. (WCAG 1.4.12)
   - Left aligned, ragged right. Never justified. Never centred for prose.
   - Sentence case. No ALL CAPS, ever, including buttons and labels.
   - Underline is used for links only, never for emphasis.
   - Every text/background pair is >= 7:1 (WCAG AAA) except where noted.
   - No text over images, gradients, blur or translucency.
   - Touch targets >= 44px, primary actions >= 56px, generous spacing.

   Contrast ratios for every pair used here are computed by check.py and are
   listed in the comments beside each token.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Colour tokens
   -------------------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  /* Light theme (default). Ratios are against --page unless stated. */
  --page:          #ffffff;
  --recessed:      #eff1f5;  /* card / table-header surface */
  --ink:           #111111;  /* 18.88:1 on page, 17.42:1 on recessed */
  --ink-2:         #3a3a3c;  /* 11.35:1 on page, 10.47:1 on recessed */
  --accent:        #004e89;  /* 8.57:1 on page,  7.91:1 on recessed */
  --accent-ink:    #ffffff;  /* 8.57:1 on accent */
  --accent-strong: #003a66;  /* 11.69:1 on page — hover / active link */
  --alert:         #8e1b1b;  /* 9.04:1 on page,  8.34:1 on recessed */
  --alert-ink:     #ffffff;  /* 9.04:1 on alert */
  --line:          #1c1c1e;  /* 17.01:1 — strong borders */
  --line-soft:     #6e6e73;  /* 5.07:1 — hairlines only, never text */
  --focus:         #004e89;

  /* Type scale. 20px body floor. */
  --size-body:     1.25rem;   /* 20px */
  --size-lead:     1.5rem;    /* 24px */
  --size-small:    1.125rem;  /* 18px — used only for footnote/caption rows */
  --size-h1:       2.75rem;   /* 44px */
  --size-h2:       2rem;      /* 32px */
  --size-h3:       1.5rem;    /* 24px */
  --size-h4:       1.25rem;   /* 20px */

  /* Spacing scale, 4px grid. */
  --s2:  0.5rem;
  --s3:  0.75rem;
  --s4:  1rem;
  --s5:  1.25rem;
  --s6:  1.5rem;
  --s7:  2rem;
  --s8:  2.5rem;
  --s9:  3rem;
  --s10: 4rem;

  --radius: 12px;
  --measure: 70ch;
  --measure-narrow: 60ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page:          #0a0a0b;
    --recessed:      #1c1c1e;  /* card surface */
    --ink:           #f5f5f7;  /* 18.18:1 on page, 15.63:1 on recessed */
    --ink-2:         #c7c7cc;  /* 11.75:1 on page, 10.10:1 on recessed */
    --accent:        #9cc6f0;  /* 11.07:1 on page,  9.51:1 on recessed */
    --accent-ink:    #0a0a0b;  /* 11.07:1 on accent */
    --accent-strong: #c6dff7;  /* 14.35:1 on page */
    --alert:         #f2a8a4;  /* 10.28:1 on page,  8.84:1 on recessed */
    --alert-ink:     #0a0a0b;  /* 10.28:1 on alert */
    --line:          #e8e8ed;  /* 16.21:1 */
    --line-soft:     #8e8e93;  /* 6.07:1 — hairlines only, never text */
    --focus:         #9cc6f0;
  }
}

/* --------------------------------------------------------------------------
   2. Reset and base
   -------------------------------------------------------------------------- */

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

html {
  /* Never a fixed root size: this multiplies whatever the reader has set. */
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: var(--s7);
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Noto Sans", sans-serif;
  font-size: var(--size-body);
  line-height: 1.6;
  font-weight: 400;
  text-align: left;
  overflow-wrap: break-word;
}

/* Prose measure. Everything that holds sentences is capped. */
p, li, dd, dt, blockquote, figcaption, details, .measure { max-width: var(--measure); }

h1, h2, h3, h4 {
  line-height: 1.25;
  margin: 0 0 var(--s5);
  max-width: 26ch;
  font-weight: 700;
  letter-spacing: -0.01em;
}
h1 { font-size: var(--size-h1); margin-top: 0; }
h2 { font-size: var(--size-h2); margin-top: var(--s10); }
h3 { font-size: var(--size-h3); margin-top: var(--s8); }
h4 { font-size: var(--size-h4); margin-top: var(--s7); text-transform: none; }

p { margin: 0 0 var(--s6); }

/* Paragraph spacing >= 2x font size where paragraphs are adjacent. */
p + p { margin-top: 0; }

ul, ol { margin: 0 0 var(--s6); padding-left: var(--s6); max-width: var(--measure); }
li { margin-bottom: var(--s3); }
li > ul, li > ol { margin-top: var(--s3); }

strong, b { font-weight: 700; }
em, i { font-style: italic; }

/* Links: underlined, never colour-only, thick enough to see. */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
a:hover, a:active { color: var(--accent-strong); text-decoration-thickness: 3px; }

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
}

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

hr {
  border: 0;
  border-top: 2px solid var(--line-soft);
  margin: var(--s9) 0;
  max-width: var(--measure);
}

abbr[title] { text-decoration: none; border-bottom: 2px dotted var(--line-soft); }

code, kbd, samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
  background: var(--recessed);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   3. Layout
   -------------------------------------------------------------------------- */

.skip-link {
  position: absolute;
  left: var(--s4);
  top: var(--s4);
  z-index: 100;
  transform: translateY(-200%);
  background: var(--accent);
  color: var(--accent-ink);
  padding: var(--s4) var(--s6);
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus { transform: translateY(0); color: var(--accent-ink); }

.wrap {
  width: 100%;
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 var(--s5);
}

.site-header {
  border-bottom: 2px solid var(--line);
  padding: var(--s5) 0;
}

.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s5);
  align-items: baseline;
  justify-content: space-between;
}

.home-link {
  font-size: var(--size-h3);
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  padding: var(--s2) 0;
  display: inline-block;
}
.home-link:hover { color: var(--ink); text-decoration: underline; text-decoration-thickness: 3px; }

.site-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s6);
  margin: 0;
  padding: 0;
  max-width: none;
}
.site-nav li { margin: 0; }
.site-nav a {
  display: inline-block;
  padding: var(--s3) 0;
  min-height: 44px;
  color: var(--ink);
}
.site-nav a[aria-current="page"] {
  font-weight: 700;
  text-decoration-thickness: 4px;
  color: var(--accent);
}

main { display: block; padding: var(--s9) 0 var(--s10); }

.site-footer {
  border-top: 2px solid var(--line);
  padding: var(--s8) 0 var(--s9);
  color: var(--ink-2);
}
.site-footer h2 { font-size: var(--size-h4); margin-top: 0; }
.site-footer ul { list-style: none; padding: 0; }
/* WCAG 2.2 target size: give footer links a real box, not a bare text line. */
.site-footer a { color: var(--accent); display: inline-block; padding: var(--s2) 0; }
.footer-cols {
  display: grid;
  gap: var(--s7);
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}
.footer-note { margin-top: var(--s7); font-size: var(--size-small); }

/* --------------------------------------------------------------------------
   4. Components
   -------------------------------------------------------------------------- */

.lead { font-size: var(--size-lead); line-height: 1.5; max-width: var(--measure-narrow); }

.eyebrow {
  font-size: var(--size-small);
  font-weight: 700;
  color: var(--ink-2);
  margin: 0 0 var(--s3);
  letter-spacing: 0.02em;
}

/* Cards and callouts. Separated by border, never by shadow or blur. */
.card {
  background: var(--recessed);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s6);
  margin: 0 0 var(--s6);
  max-width: var(--measure);
}
.card > :last-child { margin-bottom: 0; }
.card > :first-child { margin-top: 0; }
.card h2, .card h3, .card h4 { margin-top: 0; }

.callout {
  border-left: 8px solid var(--accent);
  background: var(--recessed);
  border-radius: var(--radius);
  padding: var(--s6);
  margin: var(--s7) 0;
  max-width: var(--measure);
}
.callout > :last-child { margin-bottom: 0; }
.callout > :first-child { margin-top: 0; }
.callout--alert { border-left-color: var(--alert); }

blockquote {
  margin: var(--s7) 0;
  padding: 0 0 0 var(--s6);
  border-left: 8px solid var(--line-soft);
}
blockquote p:last-child { margin-bottom: 0; }
blockquote cite { display: block; margin-top: var(--s4); font-style: normal; color: var(--ink-2); font-size: var(--size-small); }

/* Buttons */
.btn {
  display: inline-block;
  min-height: 56px;
  padding: var(--s4) var(--s7);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--recessed);
  color: var(--ink);
  font-size: var(--size-body);
  font-weight: 700;
  text-decoration: none;
  line-height: 1.5;
}
.btn:hover { color: var(--ink); text-decoration: underline; text-decoration-thickness: 3px; }
.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
@media (prefers-color-scheme: dark) {
  .btn--primary:hover { color: var(--accent-ink); }
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s5);
  margin: var(--s7) 0;
  padding: 0;
  list-style: none;
  max-width: var(--measure);
}
.btn-row li { margin: 0; }

/* Grid of equal cards */
.grid {
  display: grid;
  gap: var(--s6);
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  margin: var(--s7) 0;
  padding: 0;
  list-style: none;
  max-width: none;
}
.grid > li, .grid > div { margin: 0; max-width: none; }
.grid .card { max-width: none; height: 100%; }

/* Tables. Always scrollable on small screens, always with a caption. */
.table-scroll {
  overflow-x: auto;
  margin: var(--s6) 0 var(--s8);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 34rem;
  font-size: var(--size-body);
}
caption {
  text-align: left;
  padding: var(--s5) var(--s5) var(--s3);
  font-weight: 700;
  color: var(--ink);
}
th, td {
  text-align: left;
  padding: var(--s4) var(--s5);
  border-bottom: 2px solid var(--line-soft);
  vertical-align: top;
}
thead th { background: var(--recessed); border-bottom: 3px solid var(--line); }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
th[scope="row"] { font-weight: 700; }

/* The core interaction diagram: words -> three sentences -> spoken */
.flow {
  display: grid;
  gap: var(--s6);
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  margin: var(--s7) 0 var(--s8);
  padding: 0;
  list-style: none;
  max-width: none;
  counter-reset: flowstep;
}
.flow > li {
  margin: 0;
  max-width: none;
  background: var(--recessed);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s6);
}
.flow h3 { margin-top: 0; font-size: var(--size-h4); }
.flow h3 .step-num {
  display: inline-block;
  min-width: 2.2rem;
  color: var(--ink-2);
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4);
  list-style: none;
  padding: 0;
  margin: 0 0 var(--s5);
  max-width: none;
}
.tiles li {
  margin: 0;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4) var(--s5);
  font-size: var(--size-lead);
  font-weight: 700;
  background: var(--page);
  min-height: 56px;
  display: flex;
  align-items: center;
}

.sentences {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--s5);
  max-width: none;
}
.sentences li {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--page);
  padding: var(--s4) var(--s5);
  margin: 0 0 var(--s4);
  font-size: var(--size-lead);
}
.sentences li.is-chosen {
  border-width: 4px;
  border-color: var(--accent);
  font-weight: 700;
}
.sentences .picked-note {
  display: block;
  font-size: var(--size-small);
  font-weight: 400;
  color: var(--ink-2);
  margin-top: var(--s2);
}
.literal-row {
  border: 4px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4) var(--s5);
  font-weight: 700;
  font-size: var(--size-body);
  background: var(--page);
}

.spoken {
  font-size: var(--size-h3);
  font-weight: 700;
  border: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--s5);
  background: var(--page);
  margin: 0 0 var(--s5);
}

/* Definition-style question and answer blocks */
.faq { margin: var(--s7) 0; max-width: var(--measure); }
.faq h3 { margin-top: var(--s8); }
.faq h3:first-child { margin-top: 0; }

/* Steps list with big numbers */
ol.steps { counter-reset: step; list-style: none; padding: 0; }
ol.steps > li {
  counter-increment: step;
  margin-bottom: var(--s7);
  padding-left: 3.5rem;
  position: relative;
  min-height: 2.5rem;
}
ol.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--line);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--ink);
  background: var(--page);
}

/* Yes / no / partial marks in comparison tables — never colour alone. */
.mark { font-weight: 700; white-space: nowrap; }

/* Source lists */
.sources { font-size: var(--size-small); }
.sources li { margin-bottom: var(--s4); }

/* Page table of contents */
.toc {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s6);
  margin: 0 0 var(--s8);
  max-width: var(--measure);
  background: var(--recessed);
}
.toc h2 { font-size: var(--size-h4); margin: 0 0 var(--s4); }
.toc > :first-child { margin-top: 0; }
.toc ul { margin: 0; }
.toc a { display: inline-block; padding: var(--s2) 0; min-height: 44px; }

/* Aphasia-accessible page: shorter lines, bigger type, more air. */
.aphasia-easy { font-size: 1.5rem; line-height: 1.7; }
.aphasia-easy p, .aphasia-easy li { max-width: var(--measure-narrow); }
.aphasia-easy h2 { font-size: 2.25rem; margin-top: var(--s10); }
.aphasia-easy h3 { font-size: 1.75rem; }
.aphasia-easy li { margin-bottom: var(--s5); }
.aphasia-easy .card { padding: var(--s7); }
/* The larger .aphasia-easy heading rules must not leak into the contents box,
   which is navigation furniture rather than page content. Higher specificity
   than `.aphasia-easy h2`, so it wins regardless of source order. */
.aphasia-easy .toc h2 { font-size: var(--size-h4); margin-top: 0; }

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

/* --------------------------------------------------------------------------
   5. Motion and print
   -------------------------------------------------------------------------- */

@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;
  }
}

@media print {
  body { background: #ffffff; color: #000000; font-size: 12pt; }
  .site-nav, .skip-link, .btn-row { display: none; }
  a { color: #000000; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 10pt; }
}

/* --------------------------------------------------------------------------
   6. Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 40rem) {
  :root {
    --size-h1: 2.125rem;   /* 34px */
    --size-h2: 1.75rem;    /* 28px */
    --size-h3: 1.375rem;   /* 22px */
  }
  .site-header .wrap { display: block; }
  .site-nav { margin-top: var(--s4); }
  .aphasia-easy { font-size: 1.375rem; }
  .aphasia-easy h2 { font-size: 1.875rem; }
}
