@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400..700;1,9..144,400..600&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --border: #e0ddd6;
  --text: #1f1d1a;
  --muted: #6b6558;
  --accent: #8a3b2e;
  --accent-bg: #f3e6e1;
  --ok: #2f6b3a;
  --ok-bg: #e5f1e6;
  --warn: #9a6b00;
  --warn-bg: #fbf0d8;
  --bad: #9a2e2e;
  --bad-bg: #fbe6e5;
  --code-bg: #2b2a28;
  --code-text: #f1efe9;

  /* Default (unthemed) accent — overridden per paper below. Each paper's
     theme is a genuinely different palette, not a hue-rotate, because each
     paper is about a different kind of thing: WP53 is audit-red because it's
     about review and reconciliation; WP04 is rail-green/gold because it's
     about money moving; WP44 is phosphor-green because it's about a decades-
     old terminal protocol. See README "Theming a paper" for the pattern. */
  --theme-accent: var(--accent);
  --theme-accent-2: var(--warn);
  --theme-bg: var(--accent-bg);
  --theme-hero-from: #efe9df;
  --theme-hero-to: #e3dbcc;
  --theme-hero-ink: #3a2a1f;

  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* WP53 — "The Expense Report Was Never About Expenses". Audit-red: this is
   the lab's native palette (the --accent/--accent-bg above), kept as-is here
   so the shared UI (buttons, badges) and this paper's theme are visually the
   same thing, not a coincidence. */
[data-theme="wp53"] {
  --theme-accent: #8a3b2e;
  --theme-accent-2: #b8552f;
  --theme-bg: #f3e6e1;
  --theme-hero-from: #f6ece6;
  --theme-hero-to: #ecd9cd;
  --theme-hero-ink: #5a2a1c;
}

/* WP04 — "Why Africa Needs Stablecoin Rails...". Rail-green and transfer-
   gold: a corridor, a toll, a coin moving through it. */
[data-theme="wp04"] {
  --theme-accent: #1f7a5c;
  --theme-accent-2: #c9972c;
  --theme-bg: #e7f3ee;
  --theme-hero-from: #eaf6f0;
  --theme-hero-to: #d3ece0;
  --theme-hero-ink: #163c2d;
}

/* WP44 — "The Interface Tax". Phosphor-green terminal: the thing the paper
   is about is a 1990s signalling protocol read over a dial-up-era screen. */
[data-theme="wp44"] {
  --theme-accent: #16a34a;
  --theme-accent-2: #0d7a37;
  --theme-bg: #e6f5ea;
  --theme-hero-from: #0f2418;
  --theme-hero-to: #16331f;
  --theme-hero-ink: #baf2c9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Fraunces only where it's doing editorial work (the hero's display title,
   stat numbers, pull-quote-style text) — a plain panel heading like
   "National & per-user USSD hours" stays in the system sans so the
   ampersand stays an ampersand: Fraunces' swash "&" reads as a different
   glyph entirely at body-heading sizes. */
h1, h3, .display {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h2 { text-wrap: balance; }
.hero h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mono, code, .code-block, pre.ascii, .wp-tag, .badge, .param-citation,
.param-note, .status-line, .hero-eyebrow, .stat-label {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
}

.topbar {
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar h1 { margin: 0 0 4px; font-size: 1.5rem; }
.tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }

.layout {
  display: flex;
  min-height: calc(100vh - 86px);
}

.sidebar {
  width: 270px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px 0;
  flex-shrink: 0;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--text);
}
.sidebar-item:hover { background: var(--accent-bg); }
.sidebar-item.active { background: var(--accent-bg); font-weight: 600; border-left: 3px solid var(--accent); }
.sidebar-item .wp-tag { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 400; }
.sidebar-loading, .placeholder { padding: 20px; color: var(--muted); }

/* Small theme swatch next to each sidebar entry — a quiet preview that each
   paper is its own thing before you've even opened it. */
.sidebar-swatch {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.sidebar-item[data-theme="wp53"] .sidebar-swatch { background: #8a3b2e; }
.sidebar-item[data-theme="wp04"] .sidebar-swatch { background: #1f7a5c; }
.sidebar-item[data-theme="wp44"] .sidebar-swatch { background: #16a34a; }

.main {
  flex: 1;
  padding: 0 0 60px;
  max-width: 980px;
}
.main-inner { padding: 0 32px; }

/* ---------- hero (Overview tab only) ---------- */
.hero {
  background: linear-gradient(135deg, var(--theme-hero-from), var(--theme-hero-to));
  padding: 56px 32px 40px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  min-height: 300px;
}
.hero-copy { position: relative; z-index: 1; flex: 1 1 360px; }
.hero-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--theme-accent);
  opacity: 0.85;
  margin: 0 0 12px;
}
.hero h2 {
  margin: 0 0 16px;
  /* Pudding's own lesson, tested directly against their "YOU WILL DIE"
     piece: the headline finding should read as large as a magazine cover,
     not a page title — this is the single biggest lever for "feels like a
     dev tool" vs. "feels like something worth reading." */
  font-size: clamp(2rem, 4.2vw, 3.1rem);
  line-height: 1.05;
  color: var(--theme-hero-ink);
  max-width: 14ch;
}
.hero-hook {
  margin: 0;
  font-size: 1.15rem;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  color: var(--theme-hero-ink);
  opacity: 0.9;
  max-width: 42ch;
  line-height: 1.5;
}
.hero-art { position: absolute; inset: 0; z-index: 0; opacity: 0.9; pointer-events: none; }
.hero-art svg { width: 100%; height: 100%; display: block; }

/* The single biggest number in the paper, set as large as the headline —
   see renderHero()'s comment for why this exists at all. */
.hero-stat {
  position: relative;
  z-index: 1;
  text-align: right;
  flex: 0 0 auto;
}
.hero-stat-num {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: clamp(2.6rem, 6vw, 4.6rem);
  line-height: 0.95;
  color: var(--theme-accent);
  font-variant-numeric: tabular-nums;
}
.hero-stat-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--theme-hero-ink);
  opacity: 0.7;
  max-width: 20ch;
  margin-top: 4px;
  margin-left: auto;
  line-height: 1.4;
}

/* The narrative, read before anything else — see renderOverview()'s comment.
   Larger, more generous body copy than the methodology index below it: this
   is the part a reader is meant to actually read, not scan. */
.story {
  /* .panel (the parent) already carries 32px of horizontal padding — this
     only adds vertical space, so the two don't stack into a double indent. */
  padding: 32px 0 8px;
  max-width: 68ch;
}
.story p { font-size: 1.05rem; line-height: 1.7; margin: 0 0 20px; color: var(--text); }
.story strong {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
  display: block;
  margin: 28px 0 8px;
}
.methodology-heading {
  margin: 8px 0 2px;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.hook-source {
  display: block;
  margin-top: 4px;
  font-size: 0.74rem;
  font-family: "JetBrains Mono", monospace;
  font-style: normal;
  opacity: 0.65;
}

.overview-lede {
  font-size: 0.95rem;
  color: var(--muted);
  max-width: 62ch;
  margin: 0 0 22px;
}

.method-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.method-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--theme-accent);
  border-radius: 6px;
  padding: 12px 16px;
  background: var(--panel);
}
.method-card strong { font-size: 0.96rem; }
.method-card .param-citation { display: block; margin-top: 4px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 0 0 20px;
  padding: 0 32px;
  flex-wrap: wrap;
  background: var(--panel);
}
.tab-btn {
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--theme-accent); border-bottom-color: var(--theme-accent); font-weight: 600; }

.panel { animation: none; padding: 0 32px; }
.panel > h2:first-child { margin-top: 4px; }

.badge {
  display: inline-block;
  font-size: 0.66rem;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
  white-space: nowrap;
}
.badge-paper { background: var(--ok-bg); color: var(--ok); }
.badge-free { background: var(--warn-bg); color: var(--warn); }
.badge-status-verified { background: var(--ok-bg); color: var(--ok); }
.badge-status-verified-but-correlational { background: var(--warn-bg); color: var(--warn); }
.badge-status-not-implementable { background: var(--bad-bg); color: var(--bad); }
.badge-status-lab-illustrative { background: var(--theme-bg); color: var(--theme-accent); }

.param-row { margin-bottom: 16px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.param-label-row { display: flex; align-items: center; justify-content: space-between; }
.param-label-row label { font-weight: 600; font-size: 0.88rem; }
.param-slider-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.param-slider-row input[type="range"] { flex: 1; accent-color: var(--theme-accent); }
.slider-value { min-width: 54px; text-align: right; font-weight: 500; }
.param-note, .param-citation { font-size: 0.78rem; color: var(--muted); margin: 4px 0 0; }
.param-citation { font-style: italic; }

.run-btn {
  background: var(--theme-accent);
  color: #fff;
  border: none;
  padding: 11px 22px;
  border-radius: 6px;
  font-size: 0.92rem;
  cursor: pointer;
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}
.run-btn:hover { opacity: 0.88; }

.caveat-box {
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  color: var(--warn);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin: 10px 0;
}

/* ---------- result: big stat cards, not a plain definition list ---------- */
.result-card {
  margin-top: 16px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.result-card > strong {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 500;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 18px 24px;
}
.result-grid dt { font-size: 0.72rem; color: var(--muted); font-family: "JetBrains Mono", monospace; }
.result-grid dd {
  margin: 4px 0 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 1.7rem;
  color: var(--theme-accent);
  line-height: 1.1;
}

.fun-panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--theme-accent);
  border-radius: 10px;
  background: var(--theme-bg);
}
.fun-panel strong { font-size: 1rem; }
.fun-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.fun-list li { font-size: 0.95rem; }
.fun-light-heading { margin: 14px 0 0; font-size: 0.88rem; font-style: italic; color: var(--text); font-family: "Fraunces", Georgia, serif; }
.fun-light-list { margin-top: 8px; }
.fun-caveat { margin: 8px 0 0; font-size: 0.72rem; color: var(--muted); }

table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 0.85rem; }
th, td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
th { background: var(--theme-bg); font-family: "JetBrains Mono", monospace; font-weight: 500; font-size: 0.78rem; }

.code-block, pre.ascii {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.8rem;
  white-space: pre;
}

.history-table { margin-top: 18px; }
.history-table h4 { margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }

blockquote {
  border-left: 3px solid var(--theme-accent);
  margin: 10px 0;
  padding: 2px 14px;
  color: var(--muted);
  font-style: italic;
  font-family: "Fraunces", Georgia, serif;
}

.status-line { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.copy-btn { font-size: 0.75rem; padding: 4px 10px; margin-bottom: 8px; cursor: pointer; font-family: "JetBrains Mono", monospace; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .hero, .overview-body, .tabs, .panel { padding-left: 18px; padding-right: 18px; }
}
