:root {
  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'Manrope', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'IBM Plex Mono', 'SFMono-Regular', monospace;
  --bg: #f6f3ed;
  --paper: #fffdf9;
  --paper-soft: #f9f6f0;
  --ink: #202733;
  --muted: #626d79;
  --line: rgba(32, 39, 51, 0.12);
  --line-strong: rgba(32, 39, 51, 0.18);
  --blue: #3c68cf;
  --coral: #d35b43;
  --teal: #1e7770;
  --shadow: 0 10px 28px rgba(32, 39, 51, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.75;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ─── Progress ─── */
.progress-bar { position: fixed; inset: 0 0 auto; height: 3px; z-index: 50; }
.progress-bar__fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--teal), var(--blue)); }

/* ─── Article shell ─── */
.article { max-width: 780px; margin: 0 auto; padding: 2rem 1.5rem 6rem; }

/* ─── Back link ─── */
.back-link {
  font-family: var(--sans); font-size: 0.85rem; color: var(--muted);
  text-decoration: none; display: inline-block; margin-bottom: 0.5rem;
}
.back-link:hover { color: var(--ink); }

/* ─── Hero ─── */
.hero { margin-bottom: 2rem; }
.kicker {
  margin: 0; font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted);
}
.hero h1 {
  margin: 0.3rem 0 0.8rem; font-size: clamp(2.4rem, 6vw, 3.6rem);
  line-height: 1; font-weight: 700; letter-spacing: -0.04em;
}
.abstract { max-width: 52ch; margin: 0 0 0.6rem; font-size: 1.1rem; }
.abstract--secondary { color: var(--muted); font-size: 0.98rem; }
.hero__meta {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin-top: 1rem;
  font-family: var(--sans); font-size: 0.82rem; color: var(--muted);
}

/* ─── TOC ─── */
.toc {
  position: sticky; top: 0.5rem; z-index: 20;
  margin: 0 0 3rem; padding: 0.7rem 1rem;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(255, 253, 249, 0.95); backdrop-filter: blur(8px);
}
.toc ul {
  display: flex; flex-wrap: wrap; gap: 0.3rem 1rem;
  margin: 0; padding: 0; list-style: none;
}
.toc__link {
  font-family: var(--sans); font-size: 0.78rem; text-decoration: none;
  color: var(--muted); white-space: nowrap;
}
.toc__link.is-active { color: var(--ink); font-weight: 800; }

/* ─── Sections ─── */
.step-section {
  position: relative;
  margin-top: 4rem;
  padding: 3rem 2.5rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.03);
}

.step-badge {
  position: absolute;
  top: -16px;
  left: 32px;
  background: var(--coral);
  color: white;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.4rem 1.2rem;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(217, 98, 43, 0.25);
}

section h2 { margin: 0 0 0.8rem; font-size: 1.8rem; line-height: 1.15; letter-spacing: -0.02em; }
section h3 { margin: 2rem 0 0.6rem; font-size: 1.25rem; }
.num { color: var(--muted); font-weight: 400; }
p { margin: 0 0 1rem; max-width: 62ch; }
ul, ol { max-width: 62ch; }
li { margin-bottom: 0.5rem; }
code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--paper-soft); padding: 0.1em 0.35em;
  border-radius: 4px; border: 1px solid var(--line);
}

/* ─── Eyebrow ─── */
.eyebrow {
  margin: 0 0 0.2rem; font-family: var(--sans); font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700;
}

/* ─── Two-column cards ─── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.5rem 0; }
.col-card {
  padding: 1.2rem; border: 1px solid var(--line); border-radius: 14px;
  background: var(--paper); box-shadow: var(--shadow);
}
.col-card h3 { margin: 0.3rem 0 0.6rem; font-size: 1.1rem; }
.col-card p { font-size: 0.95rem; }
.col-card--accent { border-color: var(--teal); background: rgba(30, 119, 112, 0.03); }

/* ─── Math blocks (rendered by JS into these containers) ─── */
.math-block { margin: 1rem 0; overflow-x: auto; }

/* ─── Callout ─── */
.callout {
  margin: 1.5rem 0; padding: 1rem 1.2rem;
  border-left: 3px solid var(--teal); background: rgba(30, 119, 112, 0.04);
  border-radius: 0 10px 10px 0; font-size: 0.98rem;
}
.callout--think {
  border-left-color: var(--blue); background: rgba(60, 104, 207, 0.04);
}
.callout strong { font-family: var(--sans); font-size: 0.88rem; }

/* ─── Problem list ─── */
.problem-list { margin: 1.2rem 0; display: flex; flex-direction: column; gap: 0.6rem; }
.problem-card {
  display: flex; gap: 0.8rem; align-items: flex-start;
  padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); font-size: 0.95rem;
}
.problem-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--coral); color: #fff; font-family: var(--sans);
  font-size: 0.8rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.problem-card div p { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.9rem; }

/* ─── Pipeline ─── */
.pipeline {
  display: flex; align-items: center; justify-content: center;
  gap: 0.4rem; flex-wrap: wrap;
  margin: 1.5rem 0; padding: 1.2rem;
  border: 1px solid var(--line); border-radius: 14px; background: var(--paper);
}
.pipe-step {
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
}
.pipe-icon {
  width: 48px; height: 48px; border: 2px solid var(--line-strong); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.88rem; font-weight: 600;
}
.pipe-step--hl .pipe-icon { border-color: var(--teal); color: var(--teal); background: rgba(30, 119, 112, 0.06); }
.pipe-step--hl .pipe-label { color: var(--teal); }
.pipe-step { transition: all 200ms; }
.pipe-label { font-family: var(--sans); font-size: 0.72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.pipe-arrow { font-size: 1.2rem; color: var(--muted); }

/* ─── Domain switcher ─── */
.domain-switcher { display: flex; gap: 0.4rem; margin: 1rem 0; flex-wrap: wrap; }
.domain-btn {
  appearance: none; font-family: var(--sans); font-size: 0.82rem; font-weight: 600;
  padding: 0.45rem 0.9rem; border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--paper); color: var(--muted); cursor: pointer;
  transition: all 150ms;
}
.domain-btn:hover { border-color: var(--ink); color: var(--ink); }
.domain-btn--active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ─── Doc list ─── */
.doc-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 1rem 0; }
.doc-card {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); font-size: 0.95rem;
  transition: border-color 200ms, background 200ms;
}
.doc-card.is-retrieved { border-color: var(--teal); background: rgba(30, 119, 112, 0.05); }
.doc-tag {
  flex-shrink: 0; font-family: var(--mono); font-size: 0.78rem; font-weight: 600;
  color: var(--blue); background: rgba(60, 104, 207, 0.08);
  padding: 0.15rem 0.45rem; border-radius: 6px;
}

/* ─── Code block ─── */
.code-block {
  margin: 1.2rem 0; padding: 0.9rem 1.1rem;
  border-radius: 10px; background: #1e2028; color: #e0ddd5; overflow-x: auto;
}
.code-block pre { margin: 0; }
.code-block code {
  font-family: var(--mono); font-size: 0.85rem; background: none;
  border: none; padding: 0; color: inherit; line-height: 1.6;
}
.cm { color: #7a8694; }

/* ─── Step tag ─── */
.step-tag {
  display: inline-block; font-family: var(--sans); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: #fff;
  background: var(--teal); padding: 0.15rem 0.5rem; border-radius: 4px;
  margin-right: 0.3rem; vertical-align: middle; position: relative; top: -1px;
}

/* ─── Embed demo ─── */
.embed-demo { margin: 1rem 0; }
.embed-demo__row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); font-size: 0.9rem;
}
.embed-demo__label {
  font-family: var(--sans); font-size: 0.82rem; font-weight: 600; color: var(--coral);
  white-space: nowrap;
}
.embed-demo__row code {
  font-family: var(--mono); font-size: 0.85rem;
}

/* ─── Figure / canvas ─── */
.figure { margin: 1.5rem 0; text-align: center; }
.figure canvas { max-width: 100%; border-radius: 10px; cursor: grab; border: 1px solid var(--line); }
.figure canvas:active { cursor: grabbing; }
figcaption { margin-top: 0.5rem; font-family: var(--sans); font-size: 0.78rem; color: var(--muted); }

/* ─── Query box ─── */
.query-box {
  display: flex; align-items: baseline; gap: 0.5rem;
  margin: 1rem 0; padding: 0.7rem 1rem;
  border: 1.5px solid var(--coral); border-radius: 10px;
  background: rgba(211, 91, 67, 0.04); font-size: 0.98rem;
}
.query-label {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--coral); flex-shrink: 0;
}

/* ─── Data table ─── */
.data-table {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
  font-family: var(--sans); font-size: 0.85rem;
}
.data-table th {
  text-align: left; padding: 0.5rem 0.7rem;
  border-bottom: 2px solid var(--line-strong);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.data-table td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line); }
.data-table tr.is-retrieved td { background: rgba(30, 119, 112, 0.05); }
.retrieved-yes { color: var(--teal); font-weight: 700; }
.retrieved-no { color: var(--muted); }

/* ─── Prompt builder ─── */
.prompt-builder {
  margin: 1.2rem 0; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--paper);
}
.prompt-part { padding: 0.7rem 1rem; }
.prompt-part--ctx { background: rgba(30, 119, 112, 0.04); border-bottom: 1px solid var(--line); }
.prompt-part--q { background: rgba(211, 91, 67, 0.04); }
.prompt-tag {
  display: inline-block; font-family: var(--sans); font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; padding: 0.12rem 0.4rem;
  border-radius: 4px; margin-bottom: 0.3rem;
}
.prompt-tag--ctx { background: var(--teal); color: #fff; }
.prompt-tag--q { background: var(--coral); color: #fff; }
.prompt-part div { font-family: var(--mono); font-size: 0.85rem; line-height: 1.6; }
.prompt-doc { margin: 0.15rem 0; }
.prompt-doc-num { color: var(--muted); }

/* ─── Generation box ─── */
.gen-box {
  margin: 1.2rem 0; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--paper);
}
.gen-prompt {
  padding: 0.6rem 1rem; background: var(--paper-soft);
  font-family: var(--mono); font-size: 0.78rem; color: var(--muted);
  border-bottom: 1px solid var(--line); max-height: 5rem; overflow: hidden;
  white-space: pre-wrap; line-height: 1.5;
}
.gen-output { padding: 0.9rem 1rem; min-height: 2.5rem; font-size: 1rem; line-height: 1.7; }
.gen-controls { padding: 0.6rem 1rem; border-top: 1px solid var(--line); display: flex; gap: 0.5rem; }

.btn {
  appearance: none; font-family: var(--sans); font-size: 0.82rem; font-weight: 700;
  padding: 0.5rem 1rem; border-radius: 999px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; cursor: pointer;
  transition: transform 150ms;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn--ghost { background: transparent; color: var(--ink); }

.gen-token { display: inline; }
.gen-token--context { background: rgba(30, 119, 112, 0.15); border-radius: 3px; padding: 0 0.1rem; }
.hl-ctx { background: rgba(30, 119, 112, 0.15); border-radius: 3px; padding: 0.05rem 0.25rem; }

/* ─── Attention heatmap ─── */
.attn-heatmap { margin: 1rem 0; overflow-x: auto; }
.attn-row { display: flex; }
.attn-cell {
  width: 60px; height: 30px; display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,0.3); color: #fff; font-family: var(--mono);
  font-size: 0.68rem; flex-shrink: 0;
}
.attn-label {
  width: 72px; height: 30px; display: flex; align-items: center;
  font-family: var(--mono); font-size: 0.72rem; color: var(--ink); font-weight: 600; flex-shrink: 0;
}
.attn-header {
  width: 60px; height: 24px; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.68rem; color: var(--muted); font-weight: 600; flex-shrink: 0;
}

/* ─── Examples (with/without RAG) ─── */
.example {
  margin-top: 0.6rem; padding: 0.6rem 0.8rem; border-radius: 8px;
  font-size: 0.9rem; font-style: italic;
}
.example--bad { background: rgba(211, 91, 67, 0.05); border: 1px solid rgba(211, 91, 67, 0.12); }
.example--good { background: rgba(30, 119, 112, 0.05); border: 1px solid rgba(30, 119, 112, 0.12); }
.verdict {
  display: block; margin-top: 0.3rem; font-style: normal;
  font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.verdict--bad { color: var(--coral); }
.verdict--good { color: var(--teal); }

/* ─── Walkthrough ─── */
.walkthrough {
  margin: 1.2rem 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--paper); overflow: hidden;
}
.wt-step { display: flex; gap: 0.8rem; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line); }
.wt-step:last-child { border-bottom: none; }
.wt-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink); color: #fff; font-family: var(--sans);
  font-size: 0.8rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.wt-body { flex: 1; min-width: 0; }
.wt-body h4 {
  margin: 0 0 0.3rem; font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.wt-doc {
  font-family: var(--mono); font-size: 0.82rem; padding: 0.2rem 0.4rem;
  border-radius: 4px; background: var(--paper-soft); border: 1px solid var(--line);
  margin: 0.2rem 0;
}
.wt-doc.is-retrieved { border-color: var(--teal); background: rgba(30, 119, 112, 0.05); }
.wt-prompt {
  font-family: var(--mono); font-size: 0.82rem; padding: 0.5rem 0.7rem;
  border-radius: 8px; background: #1e2028; color: #e0ddd5;
  white-space: pre-wrap; line-height: 1.5;
}
.wt-answer {
  padding: 0.5rem 0.7rem; border-radius: 8px;
  background: rgba(30, 119, 112, 0.05); border: 1px solid rgba(30, 119, 112, 0.12);
  font-size: 0.95rem;
}

/* ─── Failure list ─── */
.failure-list { margin: 1rem 0; }
.failure { margin-bottom: 1rem; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.failure h4 { margin: 0 0 0.3rem; font-size: 1rem; color: var(--coral); }
.failure p { margin: 0; font-size: 0.92rem; color: var(--muted); }

/* ─── Final equation ─── */
.final-eq {
  margin: 2rem 0; padding: 1.5rem; text-align: center;
  border: 1px solid var(--line); border-radius: 14px; background: var(--paper);
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .two-col { grid-template-columns: 1fr; }
  .pipeline { justify-content: flex-start; }
}
