: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;
  --gold: #b48939;
  --violet: #7c4dff;
  --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.14rem;
  line-height: 1.72;
  background: linear-gradient(180deg, #f8f5f0 0%, #f3efe7 100%);
  -webkit-font-smoothing: antialiased;
}

.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 {
  max-width: 1160px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 5rem;
}

.back-link,
.primary-link,
.ghost-link,
.toolbar-button,
.epoch-chip,
.toc__link {
  font-family: var(--sans);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover,
.back-link:focus-visible,
.toc__link:hover,
.toc__link:focus-visible {
  color: var(--ink);
}

.hero {
  padding: 0.5rem 0 2rem;
}

.hero__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.9fr);
  gap: 1.25rem;
  margin-top: 1.4rem;
  align-items: start;
}

.hero__copy,
.hero-card,
.interactive-figure,
.diagram-board,
.aside,
.takeaway-card,
.compare-card,
.train-status,
.preview-panel,
.names-panel,
.step-panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.hero__copy,
.hero-card,
.takeaway-card,
.compare-card,
.aside,
.preview-panel,
.names-panel,
.step-panel {
  padding: 1.3rem 1.4rem;
}

.kicker,
.eyebrow,
.hero-card__eyebrow,
.note-label,
.arch-label,
.arch-note,
.preview-label,
.chart-y-label,
.chart-x-label,
.chip-label {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.hero h1 {
  margin: 0.45rem 0 0.9rem;
  max-width: 12ch;
  font-size: clamp(2.8rem, 7vw, 4.8rem);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: -0.045em;
}

.abstract {
  max-width: 34ch;
  margin: 0 0 0.9rem;
  font-size: 1.18rem;
  color: var(--ink);
}

.abstract--secondary {
  color: var(--muted);
  font-size: 1.02rem;
}

.hero__meta,
.hero__actions,
.hero-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.hero__meta {
  margin-top: 1.1rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.88rem;
}

.hero__actions {
  margin-top: 1.15rem;
}

.primary-link,
.ghost-link,
.toolbar-button,
.epoch-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.78rem 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.epoch-chip {
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
}

.primary-link,
.toolbar-button--accent,
.epoch-chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.primary-link:hover,
.ghost-link:hover,
.toolbar-button:hover,
.epoch-chip:hover {
  transform: translateY(-1px);
}

.toolbar-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.hero-card__formula {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
}

.hero-card__copy {
  margin: 0;
  font-size: 1rem;
  color: var(--ink);
}

.hero-notes {
  flex-direction: column;
  margin-top: 1rem;
  gap: 0.8rem;
}

.hero-notes div {
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}

.note-label {
  display: block;
  margin-bottom: 0.25rem;
}

.toc {
  position: sticky;
  top: 0.75rem;
  z-index: 20;
  margin: 1.6rem 0 2.8rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 249, 0.94);
  box-shadow: 0 10px 24px rgba(32, 39, 51, 0.05);
}

.toc ul {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem 0.9rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc__link {
  display: block;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.toc__link.is-active {
  color: var(--ink);
  font-weight: 800;
}

section {
  margin-top: 4.2rem;
  scroll-margin-top: 5.8rem;
}

section h2 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 4.5vw, 3rem);
  line-height: 1.02;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.num {
  color: var(--muted);
  margin-right: 0.28em;
}

section h3 {
  margin: 0.25rem 0 0.6rem;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.18;
}

p {
  max-width: 66ch;
  margin: 0 0 1rem;
}

code,
pre {
  font-family: var(--mono);
}

code {
  padding: 0.08em 0.35em;
  border-radius: 0.45rem;
  background: rgba(32, 39, 51, 0.06);
  font-size: 0.88em;
}

.math-block {
  margin: 1rem 0;
  overflow-x: auto;
}

.katex-display {
  margin: 0 !important;
}

/* ── Comparison cards ── */

.compare-grid,
.takeaway-grid {
  display: grid;
  gap: 1rem;
}

.compare-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 1.4rem;
}

.compare-card--highlight {
  border-color: rgba(60, 104, 207, 0.28);
  background: #fbfcff;
}

.aside {
  margin-top: 1.2rem;
  padding: 1.3rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--paper-soft);
  color: var(--muted);
}

.aside strong {
  color: var(--ink);
}

/* ── Step-by-step comparison (Section I) ── */

.step-compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.4rem 0;
}

.step-sequence {
  display: grid;
  gap: 6px;
  margin-top: 0.7rem;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-num {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 16px;
  text-align: right;
}

.step-desc {
  font-family: var(--sans);
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}

.step-caption {
  margin: 0.6rem 0 0;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── Interactive figures ── */

.diagram-board,
.interactive-figure {
  margin: 1.6rem 0 0;
  overflow: hidden;
}

.figure-controls,
.figure-toolbar {
  font-family: var(--sans);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.1rem;
  background: var(--paper-soft);
  border-bottom: 1px solid var(--line);
}

.epoch-chips {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chip-label {
  margin-right: 0.15rem;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--blue);
}

figcaption {
  padding: 0 1rem 1rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
}

/* ── Character cells ── */

.slider-label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 200px;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--muted);
}

.slider-label--compact {
  min-width: 120px;
  flex: 0 1 180px;
}

.corruption-grid {
  display: grid;
  gap: 0.6rem;
  padding: 1.2rem 1.1rem;
}

.corrupt-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.corrupt-name {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  width: 80px;
  text-align: right;
}

.char-row {
  display: flex;
  gap: 3px;
}

.char-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 36px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.char-cell--char {
  background: rgba(60, 104, 207, 0.10);
  color: var(--ink);
}

.char-cell--mask {
  background: rgba(211, 91, 67, 0.12);
  color: var(--coral);
}

.char-cell--pad {
  background: rgba(32, 39, 51, 0.04);
  color: rgba(32, 39, 51, 0.25);
}

.char-cell--empty {
  background: rgba(32, 39, 51, 0.03);
  color: rgba(32, 39, 51, 0.18);
}

.char-cell--correct {
  background: rgba(30, 119, 112, 0.12);
  color: var(--teal);
}

.char-cell--wrong {
  background: rgba(211, 91, 67, 0.15);
  color: var(--coral);
}

.char-cell--reveal {
  background: rgba(124, 77, 255, 0.14);
  color: var(--violet);
  transform: scale(1.08);
}

/* ── Dataset listing ── */

.dataset-listing {
  margin-top: 1.4rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper-soft);
}

.dataset-listing .names-list {
  margin-top: 0.5rem;
}

/* ── Architecture diagram ── */

.diagram-board {
  padding: 1.5rem;
}

.arch-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.arch-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.arch-row {
  display: flex;
  gap: 3px;
}

.arch-arrow-down {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.arch-arrow-down span {
  font-size: 0.78rem;
}

.arch-block {
  padding: 0.8rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  font-family: var(--sans);
  font-size: 0.9rem;
  text-align: center;
}

.arch-block--accent {
  border-color: rgba(60, 104, 207, 0.24);
  background: #f5f7fd;
}

.arch-note {
  display: block;
  margin-top: 0.3rem;
}

/* ── Training ── */

.train-status {
  padding: 0.55rem 0.85rem;
  border-radius: 14px;
}

.train-status span {
  display: block;
  font-family: var(--sans);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.train-status strong {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 0.92rem;
}

.training-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.8fr);
  gap: 1rem;
  padding: 1rem;
}

.chart-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfbfd;
  overflow: hidden;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 220px;
}

.chart-axes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.chart-y-label {
  position: absolute;
  top: 8px;
  left: 10px;
}

.chart-x-label {
  position: absolute;
  bottom: 6px;
  right: 10px;
}

.preview-panel {
  display: grid;
  gap: 0.75rem;
}

.preview-block {
  display: grid;
  gap: 0.3rem;
}

.preview-label {
  font-family: var(--sans);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.preview-name-label {
  font-family: var(--mono);
  font-size: 0.92rem;
}

.control-stack {
  display: grid;
  gap: 0.36rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--muted);
}

.control-stack span {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--ink);
}

/* ── Sampling ── */

.sampling-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(220px, 0.7fr);
  gap: 1rem;
  padding: 1rem;
}

.timeline-wrap {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfbfd;
  padding: 1rem;
  overflow-x: auto;
}

.timeline {
  display: grid;
  gap: 4px;
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.timeline-step {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 60px;
  text-align: right;
}

.names-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.names-placeholder {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.88rem;
}

.name-pill {
  display: inline-flex;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--mono);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
}

.name-pill--small {
  padding: 0.28rem 0.6rem;
  font-size: 0.82rem;
}

/* ── Takeaways ── */

.takeaway-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 1.4rem;
}

.article-footer {
  margin-top: 2.8rem;
  padding-top: 1.3rem;
  border-top: 1px solid var(--line-strong);
  color: var(--muted);
}

/* ── QA Section ── */

.char-cell--question {
  background: rgba(60, 104, 207, 0.12);
  color: var(--blue);
}

.char-cell--sep {
  background: rgba(32, 39, 51, 0.08);
  color: var(--muted);
  font-weight: 700;
}

.char-cell--answer {
  background: rgba(30, 119, 112, 0.12);
  color: var(--teal);
}

.qa-format-demo {
  margin: 1.4rem 0;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  display: grid;
  gap: 0.7rem;
}

.qa-format-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.qa-format-label {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  min-width: 72px;
  text-align: right;
}

.qa-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.qa-key-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--sans);
  font-size: 0.76rem;
  color: var(--muted);
}

.qa-key-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.qa-key-swatch--q { background: rgba(60, 104, 207, 0.15); }
.qa-key-swatch--sep { background: rgba(32, 39, 51, 0.10); }
.qa-key-swatch--mask { background: rgba(211, 91, 67, 0.15); }
.qa-key-swatch--ans { background: rgba(30, 119, 112, 0.15); }

.qa-select {
  appearance: auto;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
}

.qa-summary-table {
  margin-top: 1.6rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper-soft);
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.compare-table th,
.compare-table td {
  padding: 0.6rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.compare-table th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.compare-table td:first-child {
  font-weight: 600;
  color: var(--muted);
}

/* ── Responsive ── */

@media (max-width: 1080px) {
  .hero__grid,
  .compare-grid,
  .step-compare,
  .training-shell,
  .sampling-shell {
    grid-template-columns: 1fr;
  }

  .toc ul {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 1.04rem;
  }

  .article {
    padding: 1rem 0.9rem 4rem;
  }

  .hero h1 {
    font-size: clamp(2.4rem, 14vw, 3.6rem);
  }

  .toc {
    position: static;
  }

  .toc ul,
  .takeaway-grid,
  .compare-grid,
  .step-compare {
    grid-template-columns: 1fr;
  }

  .hero__actions,
  .figure-toolbar,
  .figure-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .epoch-chips {
    flex-wrap: wrap;
  }

  .char-cell {
    width: 26px;
    height: 30px;
    font-size: 0.8rem;
  }

  .slider-label--compact {
    min-width: 100%;
  }
}
