/* ===== 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;
  --gold: #b8860b;
  --cayley: #16a085;
  --householder: #c8392c;
  --blend: #8e44ad;
  --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: 'Newsreader', Georgia, serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
}

/* ===== Fonts ===== */
.mono, .nav-paper, .nav-sub, .slider-label, .readout-val, .chapter-num, .plain-label, .callout-label, .pillar-num, .cover-eyebrow, .cover-abstract-label {
  font-family: 'Inter', -apple-system, sans-serif;
}
code, .mono-block {
  font-family: 'JetBrains Mono', monospace;
}

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

/* ===== Chapter Rail ===== */
.chapter-rail {
  position: fixed;
  left: 24px; top: 50%;
  transform: translateY(-50%);
  z-index: 90;
  list-style: none;
}
.chapter-rail ol { list-style: none; }
.chapter-rail li {
  display: flex; align-items: center;
  margin-bottom: 14px;
  cursor: pointer;
  transition: all .2s;
}
.chapter-rail .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--ink-muted);
  background: transparent;
  transition: all .25s;
  flex-shrink: 0;
}
.chapter-rail li.active .dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,57,44,.15);
}
.chapter-rail .label {
  font-size: 11px; color: var(--ink-muted);
  margin-left: 8px;
  max-width: 120px;
  opacity: 0; transform: translateX(-4px);
  transition: all .2s;
  white-space: nowrap;
}
.chapter-rail li:hover .label,
.chapter-rail li.active .label {
  opacity: 1; transform: translateX(0);
}

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

/* ===== Chapters ===== */
.chapter {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 7rem 2rem 4rem;
}
.chapter-head { margin-bottom: 2rem; }
.chapter-num {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .5rem;
}
h2 {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: .75rem;
  color: var(--ink);
}
.lede {
  font-size: 1.1rem;
  font-style: italic;
  color: var(--ink-soft);
  max-width: 680px;
  line-height: 1.65;
}

/* ===== Plain-English Card ===== */
.plain-card {
  background: #faf6e9;
  border-left: 4px solid var(--gold);
  padding: 1.5rem 1.75rem;
  margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.plain-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: .75rem;
}
.plain-card p {
  font-size: .95rem;
  line-height: 1.65;
  margin-bottom: .65rem;
  color: var(--ink-soft);
}
.plain-card p:last-child { margin-bottom: 0; }

/* ===== Callout ===== */
.callout {
  border-left: 4px solid var(--accent);
  background: rgba(200,57,44,.04);
  padding: 1.5rem 1.75rem;
  margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.callout-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .5rem;
}
.callout-body {
  font-size: .95rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* ===== Equation Block ===== */
.equation-block {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}
.equation-block .eq-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: .5rem;
  text-align: left;
  font-family: 'Inter', sans-serif;
}

/* ===== Prose ===== */
.prose { margin: 1.5rem 0; }
.prose p { margin-bottom: 1rem; color: var(--ink-soft); line-height: 1.7; }
.prose strong { color: var(--ink); }

/* ===== Interactive Section ===== */
.interactive-section {
  margin: 2.5rem 0;
  padding: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.interactive-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: .5rem;
}
.interactive-section .hint {
  font-size: .85rem;
  color: var(--ink-muted);
  margin-bottom: 1.25rem;
}

/* ===== Slider Controls ===== */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.slider-group {
  display: flex; flex-direction: column;
}
.slider-group label {
  font-size: .82rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: .25rem;
}
.slider-group input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--rule);
  outline: none;
}
.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--upstream);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.slider-group input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--upstream);
  cursor: pointer;
  border: 2px solid #fff;
}

/* ===== Readout Cards ===== */
.readout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}
.readout-card {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: .75rem 1rem;
  text-align: center;
}
.readout-label {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: .25rem;
}
.readout-val {
  font-size: 1.15rem;
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink);
}

/* ===== Chart Containers ===== */
.viz-container {
  width: 100%;
  min-height: 380px;
  margin-top: 1rem;
}
.viz-container.tall { min-height: 480px; }
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 680px) {
  .chart-grid { grid-template-columns: 1fr; }
}

/* ===== Toggle Buttons ===== */
.toggle-btn {
  display: inline-block;
  padding: .5rem 1.25rem;
  border: 2px solid var(--upstream);
  border-radius: 4px;
  background: transparent;
  color: var(--upstream);
  font-family: 'Inter', sans-serif;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  margin-right: .5rem;
  margin-bottom: .5rem;
}
.toggle-btn:hover { background: var(--upstream); color: #fff; }
.toggle-btn.active { background: var(--upstream); color: #fff; }

/* ===== Chapter Foot Link ===== */
.chapter-foot {
  display: block;
  text-align: center;
  margin-top: 3rem;
  padding: 1.25rem;
  border-top: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink-soft);
  transition: all .25s;
}
.chapter-foot:hover {
  color: var(--accent);
}
.next-hint {
  font-size: .95rem;
  font-weight: 500;
  transition: all .2s;
}
.next-arrow {
  display: inline-block;
  transition: transform .2s;
}
.chapter-foot:hover .next-arrow {
  transform: translateX(6px);
}

/* ===== Cover ===== */
.cover {
  padding-top: 10rem;
  text-align: center;
  min-height: 100vh;
}
.cover-inner {
  max-width: 720px;
  margin: 0 auto;
}
.cover-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
}
.cover-title {
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1.15;
  margin-bottom: .75rem;
}
.cover-title em {
  color: var(--accent);
  font-style: italic;
}
.cover-subtitle {
  font-size: 1.15rem;
  color: var(--ink-soft);
  font-style: italic;
  margin-bottom: 1.5rem;
}
.cover-byline {
  font-size: .9rem;
  color: var(--ink-soft);
  margin-bottom: .25rem;
  line-height: 1.6;
}
.muted { color: var(--ink-muted); }

.cover-abstract {
  text-align: left;
  margin-top: 2.5rem;
  padding: 1.5rem 1.75rem;
  background: #faf6e9;
  border-left: 4px solid var(--gold);
  border-radius: 0 6px 6px 0;
}
.cover-abstract-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: .75rem;
}
.cover-abstract p {
  font-size: .95rem;
  line-height: 1.65;
  margin-bottom: .75rem;
  color: var(--ink-soft);
}
.cover-abstract p:last-child { margin-bottom: 0; }

.cover-pillars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-top: 2.5rem;
  text-align: left;
}
.pillar {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.25rem;
}
.pillar-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .35rem;
}
.pillar-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: .35rem;
}
.pillar-text {
  font-size: .82rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

.cover-cta {
  margin-top: 3rem;
}
.primary-btn {
  display: inline-block;
  padding: .75rem 2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.primary-btn:hover { background: #a52f24; }
.cover-meta {
  margin-top: .75rem;
  font-size: .82rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .cover { padding-top: 7rem; }
  .cover-title { font-size: 1.9rem; }
  .cover-pillars { grid-template-columns: 1fr; }
  .chapter { padding: 5rem 1.25rem 3rem; }
  h2 { font-size: 1.6rem; }
  .controls-grid { grid-template-columns: 1fr; }
  .interactive-section { padding: 1.25rem; }
  .nav-progress { width: 100px; }
}

/* ===== SVG Diagram Styles ===== */
.arch-diagram { width: 100%; max-width: 700px; margin: 1.5rem auto; }
.arch-diagram text { font-family: 'Inter', sans-serif; }

/* ===== Property Grid ===== */
.property-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}
.property-card {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.25rem;
}
.property-icon {
  font-size: 1.5rem;
  margin-bottom: .5rem;
}
.property-name {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: .35rem;
}
.property-detail {
  font-size: .88rem;
  color: var(--ink-soft);
  line-height: 1.55;
}
.property-tech {
  margin-top: .5rem;
  font-size: .78rem;
  color: var(--ink-muted);
}

/* ===== Tables in Prose ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: .85rem;
}
.data-table th {
  background: var(--upstream);
  color: #fff;
  font-weight: 600;
  padding: .6rem .75rem;
  text-align: left;
  font-family: 'Inter', sans-serif;
}
.data-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-soft);
}
.data-table tr:nth-child(even) { background: rgba(0,0,0,.02); }
.data-table .best { font-weight: 700; color: var(--feedback); }
