/*
 * Article page styles. Consumes /tokens.css for all visual variables.
 * Tuned for long-form reading: a single comfortable measure, generous
 * vertical rhythm, a clear hero, and quiet chrome.
 *
 * Reading-experience variables (below) are owned by this file, scoped to
 * the article page. The body is set in a serif so the page reads as a
 * publication rather than an app; long-form text and the page surface are
 * softened off pure white/black to avoid optical halation. Headings and
 * chrome stay full contrast.
 */

:root {
  --family-serif: 'Source Serif 4', Georgia, Cambria, 'Times New Roman', serif;
}
:root,
:root[data-theme='dark'] {
  --article-surface: #0d0d0d;
  --article-ink: #dddddd;
}
:root[data-theme='light'] {
  --article-surface: #fafafa;
  --article-ink: #1f1f1f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--article-surface);
  color: var(--text-primary);
  font-family: var(--family-sans);
  font-size: var(--text-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.skip-link {
  position: absolute; left: -9999px; top: 8px;
  background: var(--accent-default); color: var(--accent-on-accent);
  padding: 8px 12px; border-radius: var(--radius-md);
  z-index: 100;
}
.skip-link:focus { left: 8px; }

a {
  color: var(--accent-default);
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--accent-default) 45%, transparent);
  text-underline-offset: 3px;
}
a:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}

button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent-default); outline-offset: 2px; }

/* ---------- Site header ---------- */
.site-header {
  display: flex; align-items: center; gap: var(--space-5);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; background: var(--article-surface);
  z-index: 10;
}
.site-header .brand {
  display: inline-flex; align-items: center; gap: var(--space-3);
  color: var(--text-primary); text-decoration: none;
  font-weight: 700; font-size: var(--text-md);
  letter-spacing: -0.01em;
}
.site-header .brand-mark { width: 22px; height: 22px; }
.site-header .site-nav { display: flex; gap: var(--space-5); margin-left: auto; }
.site-header .site-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
}
.site-header .site-nav a:hover { color: var(--text-primary); }
.header-tools { display: flex; align-items: center; gap: var(--space-1); }
.theme-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 8px;
  border-radius: var(--radius-md); font-size: 16px; line-height: 1;
}
.theme-toggle:hover { background: var(--bg-overlay); color: var(--text-primary); }
.font-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 6px 9px;
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 800; line-height: 1;
}
.font-toggle:hover { background: var(--bg-overlay); color: var(--text-primary); }
.font-toggle[aria-pressed='true'] {
  background: var(--accent-subtle); color: var(--accent-default);
}

/* ---------- Layout ---------- */
main {
  margin: 0 auto;
  padding: var(--space-8) var(--space-5) var(--space-7);
}

/* Every direct band of the article shares one measure. 660px at the 19px
   serif body lands around 65 characters per line, the reading sweet spot. */
.article-hero,
.correction-banner,
.prose,
.corrections,
.references {
  max-width: 660px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Article hero ---------- */
.article-hero {
  margin-bottom: var(--space-7);
}
.article-hero .eyebrow {
  color: var(--accent-default);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: var(--text-xs);
  font-weight: 700;
  margin: 0 0 var(--space-4);
}
.article-hero h1 {
  font-size: clamp(2.25rem, 1.6rem + 2.4vw, 3.25rem);
  line-height: 1.08;
  letter-spacing: -0.022em;
  font-weight: 800;
  margin: 0 0 var(--space-4);
}
.article-hero .dek {
  font-size: var(--text-xl);
  line-height: 1.45;
  color: var(--text-secondary);
  margin: 0 0 var(--space-5);
  font-weight: 400;
}
.article-meta {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}
.article-meta span[aria-hidden] { opacity: 0.5; }

/* Hero image: wider than the prose measure, centered, 16:9 cropped to
   match the Flutter ArticleDetailScreen so different source aspect
   ratios still produce a consistent hero shape. */
.article-hero-image {
  max-width: var(--viz-max);
  margin: 0 auto var(--space-7);
  padding: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--accent-subtle);
}
.article-hero-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Byline */
.article-byline {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-5) 0 var(--space-4);
}
.byline-photo {
  width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; flex: none;
}
.byline-text { display: flex; flex-direction: column; }
.byline-name {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
}
.byline-title {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* ---------- Correction banner ---------- */
.correction-banner {
  margin-bottom: var(--space-6);
  padding: var(--space-4);
  background: var(--bg-inset);
  border-left: 4px solid var(--status-warning);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.correction-banner strong { margin-right: 6px; }

/* ---------- Prose column ---------- */
/* Body is serif (a reading face); headings stay in the sans (Inter) so
   the serif/sans contrast signals "this is writing." Body ink is softened
   off pure white to avoid halation; headings keep full contrast. */
.prose {
  font-family: var(--family-serif);
  font-size: 1.1875rem;          /* ~19px reading size */
  line-height: 1.7;
  color: var(--article-ink);
}
.prose > :first-child { margin-top: 0; }
.prose p {
  margin: 0 0 var(--space-5);
}
/* Lead paragraph gets a touch more presence. */
.prose > p:first-of-type {
  font-size: 1.3125rem;
  line-height: 1.55;
  color: var(--article-ink);
}
.prose h2 {
  font-family: var(--family-sans);
  font-size: var(--text-2xl);
  line-height: 1.2;
  letter-spacing: -0.012em;
  font-weight: 700;
  color: var(--text-primary);
  margin: var(--space-8) 0 var(--space-4);
  padding-top: var(--space-2);
}
.prose h3 {
  font-family: var(--family-sans);
  font-size: var(--text-xl);
  line-height: 1.3;
  font-weight: 700;
  color: var(--text-primary);
  margin: var(--space-7) 0 var(--space-3);
}
.prose strong { font-weight: 700; color: var(--text-primary); }
.prose em { font-style: italic; }
.prose hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-7) 0;
}
.prose blockquote {
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-5);
  border-left: 3px solid var(--accent-default);
  color: var(--text-secondary);
  background: var(--bg-inset);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-lg);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  font-family: var(--family-mono);
  font-size: 0.86em;
  background: var(--bg-inset);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.prose pre {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--text-sm);
}
.prose pre code { background: none; padding: 0; font-size: 0.95em; }
.prose ul, .prose ol { padding-left: var(--space-5); margin: 0 0 var(--space-5); }
.prose li { margin-bottom: var(--space-2); }
.prose li::marker { color: var(--text-tertiary); }
.prose img { max-width: 100%; height: auto; border-radius: var(--radius-md); }
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-5) 0;
  font-size: var(--text-sm);
}
.prose th, .prose td {
  border: 1px solid var(--border-subtle);
  padding: var(--space-2) var(--space-3);
  text-align: left;
}
.prose th { background: var(--bg-surface); font-weight: 700; }

/* ---------- Visualization figure ---------- */
.viz,
.viz-container {
  /* Vertical drags over a chart pan the page; horizontal gestures and
     taps still reach the chart so tooltips and hover affordances work.
     Pairs with the chart fragments not calling preventDefault on wheel
     or touchmove. */
  touch-action: pan-y;
  margin: var(--space-7) auto;
  max-width: var(--viz-max);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.viz svg,
.viz img,
.viz-container img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.viz figcaption,
.viz-container figcaption {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--space-3);
  text-align: center;
  line-height: 1.5;
}
.viz-missing {
  margin: var(--space-6) auto;
  max-width: 720px;
  padding: var(--space-4);
  border: 1px dashed var(--status-warning);
  border-radius: var(--radius-md);
  color: var(--status-warning);
  font-size: var(--text-sm);
  text-align: center;
}

/* ---------- Callout ---------- */
.callout {
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-5);
  border-left: 4px solid var(--accent-default);
  background: var(--bg-inset);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.callout.note { border-left-color: var(--status-info); }
.callout.warning { border-left-color: var(--status-warning); }
.callout.methodology { border-left-color: var(--accent-default); }
.callout.correction { border-left-color: var(--status-warning); }

/* ---------- Footnote markers ---------- */
.footnote-ref {
  display: inline-block;
  vertical-align: super;
  font-size: 0.7em;
  color: var(--accent-default);
  text-decoration: none;
  font-weight: 600;
}

/* ---------- Series prev/next navigation ---------- */
.series-nav {
  max-width: 660px;
  margin: var(--space-8) auto 0;
  display: flex;
  gap: var(--space-4);
}
.series-nav-spacer { flex: 1; }
.series-nav-link {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color 140ms ease, transform 140ms ease,
    box-shadow 140ms ease;
}
.series-nav-link:hover {
  border-color: var(--accent-default);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.series-nav-link:focus-visible {
  outline: 2px solid var(--accent-default);
  outline-offset: 2px;
}

/* Circular arrow chip. */
.series-nav-chip {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent-default);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 140ms ease, color 140ms ease;
}
.series-nav-link:hover .series-nav-chip {
  background: var(--accent-default);
  color: #ffffff;
}

.series-nav-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.series-nav-link.next .series-nav-text { align-items: flex-end; }
.series-nav-dir {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--accent-default);
}
.series-nav-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .series-nav-link { transition: border-color 140ms ease; }
  .series-nav-link:hover { transform: none; box-shadow: none; }
  .tts-reading { transition: none; }
}
@media (max-width: 560px) {
  .series-nav { flex-direction: column; }
  .series-nav-link.next .series-nav-text { align-items: flex-start; }
  .series-nav-spacer { display: none; }
}

/* ---------- Corrections + references ---------- */
.corrections,
.references {
  margin-top: var(--space-8);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-6);
}
.corrections h2,
.references h2 {
  font-size: var(--text-xl);
  margin: 0 0 var(--space-4);
}
.corrections .empty {
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.correction {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}
.correction-head {
  display: flex; gap: var(--space-3);
  font-size: var(--text-xs); color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.14em;
  margin-bottom: var(--space-2);
}
.correction .severity { color: var(--accent-default); font-weight: 700; }
.correction-material .severity { color: var(--status-warning); }
.correction .summary { margin: 0 0 var(--space-2); }
.correction details summary {
  cursor: pointer; color: var(--text-secondary); font-size: var(--text-sm);
}
.references ol {
  padding-left: var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}
.references li { margin-bottom: var(--space-2); }

/* ---------- Treeline band ---------- */
.treeline-band {
  height: 20px;
  margin-top: var(--space-6);
  background-image: linear-gradient(to right,
    transparent, var(--accent-subtle), transparent);
  border-radius: 2px;
  opacity: 0.7;
}
.footer-band { height: 40px; opacity: 0.4; margin-top: 0; }

/* ---------- Site footer ---------- */
.site-footer {
  margin-top: var(--space-9);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}
.site-footer .legal {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  padding: var(--space-5);
  background: var(--bg-inset);
}

/* ---------- Reading toolbar ---------- */
/* Mirrors lib/features/article_detail/view/reading_toolbar.dart: an
   elevated card above the prose with pill controls. Dyslexic font pill
   is always visible; TTS pills are revealed by hydrate.js when the Web
   Speech API is available. */
.reading-toolbar {
  max-width: 660px;
  margin: 0 auto var(--space-6);
  padding: var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}
.reading-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font: 600 var(--text-sm)/1 var(--family-sans);
  cursor: pointer;
}
.reading-pill:hover {
  color: var(--text-primary);
  border-color: var(--border-default);
}
.reading-pill[hidden] { display: none; }
.reading-pill-ic {
  width: 16px; height: 16px;
  fill: currentColor; flex: none;
}
.reading-pill-primary {
  background: var(--accent-default);
  color: var(--accent-on-accent);
  border-color: var(--accent-default);
}
.reading-pill-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-on-accent);
}
.reading-pill[aria-pressed='true'] {
  background: var(--accent-subtle);
  color: var(--accent-default);
  border-color: var(--accent-default);
}
.reading-pill .tts-ic-pause { display: none; }
.reading-pill.is-playing .tts-ic-play { display: none; }
.reading-pill.is-playing .tts-ic-pause { display: inline; }
.tts-status {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* ---------- Legacy tts-bar (kept for any cached/stale HTML) ---------- */
.tts-bar {
  max-width: 660px;
  margin: 0 auto var(--space-6);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.tts-bar[hidden] { display: none; }
.tts-play {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--accent-default); color: var(--accent-on-accent);
  border: none; cursor: pointer;
  padding: 9px 15px; border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 600;
}
.tts-play:hover { background: var(--accent-hover); }
.tts-stop {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: none;
  background: var(--bg-inset); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  cursor: pointer;
}
.tts-stop:hover { color: var(--text-primary); }
.tts-stop[hidden] { display: none; }
.tts-ic { width: 18px; height: 18px; fill: currentColor; flex: none; }
.tts-ic-pause { display: none; }
.tts-play.is-playing .tts-ic-play { display: none; }
.tts-play.is-playing .tts-ic-pause { display: inline; }
.tts-status {
  font-size: var(--text-sm); color: var(--text-tertiary);
  margin-left: auto;
}
/* The block being read aloud, highlighted as speech moves through it. */
.tts-reading {
  background: var(--accent-subtle);
  box-shadow: 0 0 0 6px var(--accent-subtle);
  border-radius: var(--radius-sm);
  transition: background-color 200ms ease;
}

/* ---------- Dyslexia-friendly reading font ---------- */
/* OpenDyslexic (SIL Open Font License), self-hosted from /fonts. Applied
   to the article reading surfaces only when the reader opts in via the
   header toggle; site chrome stays in Inter. */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('/fonts/opendyslexic-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('/fonts/opendyslexic-700.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('/fonts/opendyslexic-400-italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
:root[data-font='dyslexic'] .prose,
:root[data-font='dyslexic'] .prose h2,
:root[data-font='dyslexic'] .prose h3,
:root[data-font='dyslexic'] .article-hero h1,
:root[data-font='dyslexic'] .article-hero .dek,
:root[data-font='dyslexic'] .article-hero .eyebrow,
:root[data-font='dyslexic'] .corrections,
:root[data-font='dyslexic'] .references {
  font-family: 'OpenDyslexic', var(--family-sans);
}
:root[data-font='dyslexic'] .prose {
  /* OpenDyslexic has a large body and runs wide; trim the size and open
     up the spacing so the line measure and rhythm still hold. */
  font-size: 1.0625rem;
  line-height: 1.85;
  letter-spacing: 0.01em;
  word-spacing: 0.04em;
}
:root[data-font='dyslexic'] .prose > p:first-of-type { font-size: 1.1875rem; }
:root[data-font='dyslexic'] .article-hero h1 { letter-spacing: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 767px) {
  main { padding: var(--space-6) var(--space-4) var(--space-6); }
  .prose { font-size: 1.0625rem; }
  .prose > p:first-of-type { font-size: 1.1875rem; }
  .site-header { padding: var(--space-3) var(--space-4); }
  .site-header .site-nav { display: none; }
  .viz, .viz-container { padding: var(--space-3); }
}
