/* ===== DESIGN TOKENS ===== */
:root {
  --bg: #fbfaf7;
  --bg-elevated: #ffffff;
  --ink: #15212e;
  --ink-soft: #3a4a5c;
  --ink-muted: #6b7785;
  --rule: #e3e0d8;
  --upstream: #1f3a52;
  --midmarket: #4a7396;
  --downstream: #7aa6cc;
  --feedback: #16a085;
  --accent: #c8392c;

  --font-serif: 'Newsreader', Georgia, serif;
  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --max-w: 920px;
  --nav-h: 56px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
}

/* ===== NAV ===== */
.nav-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(251,250,247,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
  z-index: 100;
}
.nav-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-title { display: flex; flex-direction: column; gap: 2px; }
.nav-paper {
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600; color: var(--ink);
  letter-spacing: 0.02em;
}
.nav-sub {
  font-family: var(--font-sans);
  font-size: 11px; color: var(--ink-muted);
}
.nav-progress {
  width: 120px; height: 3px;
  background: var(--rule); border-radius: 2px; overflow: hidden;
}
.nav-progress-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.15s;
}

/* ===== CHAPTER RAIL ===== */
.chapter-rail {
  position: fixed; left: 24px; top: 50%;
  transform: translateY(-50%);
  z-index: 90;
}
.chapter-rail ol {
  list-style: none; padding: 0;
}
.chapter-rail li {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; cursor: pointer;
  opacity: 0.4; transition: opacity 0.3s;
}
.chapter-rail li.active { opacity: 1; }
.chapter-rail .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--rule); transition: background 0.3s, transform 0.3s;
  flex-shrink: 0;
}
.chapter-rail li.active .dot {
  background: var(--accent); transform: scale(1.4);
}
.chapter-rail .label {
  font-family: var(--font-sans);
  font-size: 11px; color: var(--ink-muted);
  white-space: nowrap;
}
.chapter-rail li.active .label { color: var(--ink); font-weight: 500; }

@media (max-width: 1100px) {
  .chapter-rail { display: none; }
}

/* ===== CHAPTER LAYOUT ===== */
.chapter {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 7rem 24px 3rem;
}
.chapter:first-of-type { padding-top: 2rem; }

.chapter-num {
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.chapter h2 {
  font-size: 2.2rem; font-weight: 600;
  line-height: 1.2; margin-bottom: 1rem;
  color: var(--ink);
}
.lede {
  font-size: 1.1rem; line-height: 1.75;
  color: var(--ink-soft);
  max-width: 720px;
  margin-bottom: 2rem;
}

/* ===== PLAIN CARD ===== */
.plain-card {
  background: var(--bg);
  border-left: 4px solid #d4a843;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0 8px 8px 0;
  max-width: 720px;
}
.plain-label {
  font-family: var(--font-sans);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: #b8942e;
  margin-bottom: 8px;
}
.plain-card p {
  font-size: 0.95rem; line-height: 1.65;
  color: var(--ink-soft);
  margin-bottom: 0.6rem;
}
.plain-card p:last-child { margin-bottom: 0; }

/* ===== EQUATION BLOCK ===== */
.equation-block {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}
.equation-block .eq-label {
  font-family: var(--font-sans);
  font-size: 11px; color: var(--ink-muted);
  margin-bottom: 8px;
}

/* ===== INTERACTIVE SECTION ===== */
.interactive-section {
  margin: 2.5rem 0;
}
.interactive-section .hint {
  font-family: var(--font-sans);
  font-size: 12px; color: var(--ink-muted);
  margin-top: 8px;
  font-style: italic;
}
.controls-row {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-bottom: 1rem; align-items: flex-end;
}
.control-group {
  flex: 1 1 200px; min-width: 180px;
}
.control-group label {
  display: block;
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.control-group input[type="range"] {
  width: 100%; accent-color: var(--accent);
}
.control-group .value-display {
  font-family: var(--font-mono);
  font-size: 13px; color: var(--accent);
  font-weight: 500;
}
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 700px) {
  .chart-grid { grid-template-columns: 1fr; }
}
.chart-box {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  min-height: 320px;
}

/* ===== CALLOUT ===== */
.callout {
  border-left: 4px solid var(--accent);
  background: rgba(200, 57, 44, 0.04);
  padding: 1rem 1.25rem;
  margin: 2rem 0;
  border-radius: 0 8px 8px 0;
  max-width: 720px;
}
.callout p {
  font-size: 0.95rem; line-height: 1.6;
  color: var(--ink-soft);
  font-style: italic;
}

/* ===== CHAPTER FOOT LINK ===== */
.chapter-foot {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-sans);
  font-size: 14px; font-weight: 500;
  color: var(--upstream);
  text-decoration: none;
  margin-top: 2rem;
  transition: color 0.2s, gap 0.2s;
}
.chapter-foot:hover { color: var(--accent); gap: 12px; }
.chapter-foot .arrow { transition: transform 0.2s; }
.chapter-foot:hover .arrow { transform: translateX(4px); }

/* ===== COVER ===== */
.cover { padding-top: calc(var(--nav-h) + 3rem); text-align: left; }
.cover-inner { max-width: 720px; }
.cover-eyebrow {
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.cover-title {
  font-size: 2.8rem; font-weight: 600;
  line-height: 1.15; margin-bottom: 0.75rem;
}
.cover-title em { color: var(--accent); }
.cover-subtitle {
  font-size: 1.15rem; color: var(--ink-soft);
  margin-bottom: 1rem;
}
.cover-byline {
  font-family: var(--font-sans);
  font-size: 14px; color: var(--ink-muted);
  margin-bottom: 2rem; line-height: 1.6;
}
.cover-byline .muted { color: var(--ink-muted); }

.cover-abstract {
  background: var(--bg);
  border-left: 4px solid #d4a843;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0 2.5rem;
  border-radius: 0 8px 8px 0;
}
.cover-abstract-label {
  font-family: var(--font-sans);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: #b8942e;
  margin-bottom: 10px;
}
.cover-abstract p {
  font-size: 0.95rem; line-height: 1.7;
  color: var(--ink-soft);
  margin-bottom: 0.75rem;
}
.cover-abstract p:last-child { margin-bottom: 0; }

.cover-pillars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 2rem;
}
@media (max-width: 700px) {
  .cover-pillars { grid-template-columns: 1fr; }
  .cover-title { font-size: 2rem; }
}
.pillar {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.25rem;
}
.pillar-num {
  font-family: var(--font-serif);
  font-size: 1.4rem; font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.pillar-title {
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.pillar-text {
  font-size: 0.85rem; line-height: 1.55;
  color: var(--ink-muted);
}

/* ===== STRATEGY CARDS (ch5) ===== */
.strategy-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px; margin: 1rem 0;
}
.strategy-card {
  background: var(--bg-elevated);
  border: 2px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}
.strategy-card:hover { border-color: var(--midmarket); }
.strategy-card.selected {
  border-color: var(--accent);
  background: rgba(200,57,44,0.04);
}
.strategy-card .card-icon { font-size: 1.5rem; margin-bottom: 4px; }
.strategy-card .card-title {
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 600; color: var(--ink);
}
.strategy-card .card-desc {
  font-size: 0.78rem; color: var(--ink-muted);
  margin-top: 4px; line-height: 1.4;
}

/* ===== READOUT CARDS ===== */
.readout-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px; margin: 1rem 0;
}
.readout-card {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem;
  text-align: center;
}
.readout-card .readout-label {
  font-family: var(--font-sans);
  font-size: 11px; font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.readout-card .readout-value {
  font-family: var(--font-mono);
  font-size: 1.5rem; font-weight: 500;
  color: var(--ink);
  margin-top: 4px;
}

/* ===== SVG DIAGRAM ===== */
.arch-diagram {
  width: 100%; max-width: 720px;
  margin: 1.5rem auto;
}

/* ===== BUTTONS ===== */
.btn-action {
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600;
  padding: 8px 18px;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-action:hover { background: var(--accent); color: white; }
.btn-action.active {
  background: var(--accent); color: white;
}

/* ===== TABLE ===== */
.results-table {
  width: 100%; border-collapse: collapse;
  margin: 1rem 0; font-size: 0.9rem;
}
.results-table th {
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 600;
  text-align: left; padding: 8px 12px;
  border-bottom: 2px solid var(--rule);
  color: var(--ink-soft);
}
.results-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
}
.results-table td.num {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ===== UTILITIES ===== */
.prose { max-width: 720px; }
.prose p { margin-bottom: 1rem; color: var(--ink-soft); line-height: 1.75; }
.prose strong { color: var(--ink); }

@media (max-width: 600px) {
  .chapter { padding: 5rem 16px 2rem; }
  .cover { padding-top: calc(var(--nav-h) + 2rem); }
  .cover-title { font-size: 1.8rem; }
  .chapter h2 { font-size: 1.6rem; }
}
