/* === 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: #b8943e;
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.75;
  font-size: 17px;
}

/* === Top Nav === */
.nav-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: rgba(251,250,247,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
  height: 56px;
}
.nav-inner {
  max-width: 920px; margin: 0 auto; padding: 0 1.5rem;
  display: flex; align-items: center; height: 100%;
}
.nav-title { font-family: var(--sans); font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.nav-paper { font-weight: 600; color: var(--ink); }
.nav-sub { margin-left: 0.5rem; color: var(--ink-muted); font-weight: 400; }
.nav-progress {
  position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
  background: var(--rule);
}
.nav-progress-fill {
  height: 100%; width: 0%; background: var(--accent);
  transition: width 0.1s linear;
}

/* === Chapter Rail === */
.chapter-rail {
  position: fixed; left: 0; top: 50%; transform: translateY(-50%);
  z-index: 90; padding: 0 0 0 20px;
  display: flex; flex-direction: column; gap: 18px;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--rule); cursor: pointer;
  transition: background 0.3s, transform 0.3s;
  position: relative;
}
.dot.active { background: var(--accent); transform: scale(1.4); }
.dot .label {
  position: absolute; left: 20px; top: 50%; transform: translateY(-50%);
  font-family: var(--sans); font-size: 11px; color: var(--ink-muted);
  white-space: nowrap; opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
}
.dot:hover .label { opacity: 1; }

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

/* === Chapters === */
.chapter {
  max-width: 920px; margin: 0 auto;
  padding: 7rem 1.5rem 3rem;
  min-height: 60vh;
}
.chapter:first-of-type { padding-top: 2rem; }

.chapter-head { margin-bottom: 2rem; }
.chapter-num {
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.75rem;
}
h2 {
  font-family: var(--serif); font-size: 2.1rem; font-weight: 700;
  line-height: 1.2; margin-bottom: 1rem; color: var(--ink);
}
.lede {
  font-size: 1.1rem; color: var(--ink-soft); line-height: 1.7;
  max-width: 680px;
}

/* === Plain Card === */
.plain-card {
  background: var(--bg); border-left: 4px solid var(--gold);
  padding: 1.5rem 1.75rem; margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.plain-label {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 0.75rem;
}
.plain-card p {
  font-size: 0.95rem; line-height: 1.75; color: var(--ink-soft);
  margin-bottom: 0.75rem;
}
.plain-card p:last-child { margin-bottom: 0; }

/* === Prose === */
.prose { margin: 1.5rem 0; }
.prose p { margin-bottom: 1rem; line-height: 1.8; }
.prose p:last-child { margin-bottom: 0; }

/* === Equation Block === */
.equation-block {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.5rem 2rem;
  margin: 2rem 0;
  overflow-x: auto;
  text-align: center;
}

/* === Callout === */
.callout {
  background: rgba(200,57,44,0.04);
  border-left: 4px solid var(--accent);
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.callout-label {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.5rem;
}
.callout-body {
  font-style: italic; color: var(--ink-soft); line-height: 1.7;
  font-size: 0.95rem;
}

/* === Interactive Section === */
.interactive-section {
  margin: 2.5rem 0;
  padding: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.interactive-section h3 {
  font-family: var(--serif); font-size: 1.15rem; font-weight: 600;
  margin-bottom: 0.5rem; color: var(--ink);
}
.live-hint {
  font-family: var(--sans); font-size: 11px; color: var(--ink-muted);
  margin-bottom: 1rem;
}

/* === Controls === */
.ctrl {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.ctrl label {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  color: var(--ink-soft); min-width: 140px;
}
.ctrl input[type="range"] {
  flex: 1; height: 6px; -webkit-appearance: none; appearance: none;
  background: var(--rule); border-radius: 3px; outline: none;
}
.ctrl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  border-radius: 50%; background: var(--upstream);
  cursor: pointer; border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.ctrl .ctrl-val {
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  color: var(--ink); min-width: 50px; text-align: right;
}

/* === Chart containers === */
.viz-container { width: 100%; margin: 1rem 0; }
.viz-container.short { height: 280px; }
.viz-container.tall { height: 480px; }

/* === Grids === */
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.grid-3 {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

/* === Chapter foot link === */
.chapter-foot {
  display: block; margin-top: 3rem; padding: 1rem 0;
  border-top: 1px solid var(--rule);
  text-decoration: none; color: var(--ink-soft);
  font-family: var(--sans); font-size: 14px;
  transition: color 0.2s;
}
.chapter-foot:hover { color: var(--accent); }
.chapter-foot:hover .next-arrow { transform: translateX(6px); }
.next-hint { display: flex; align-items: center; gap: 0.5rem; }
.next-arrow { transition: transform 0.2s; font-size: 18px; }

/* === Cover === */
.cover { padding-top: 8rem; }
.cover-inner { max-width: 720px; }
.cover-eyebrow {
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 1.5rem;
}
.cover-title {
  font-size: 3rem; font-weight: 700; line-height: 1.15;
  margin-bottom: 1.5rem;
}
.cover-title em { color: var(--accent); font-style: italic; }
.cover-byline {
  font-family: var(--sans); font-size: 13px; color: var(--ink-muted);
  margin-bottom: 2.5rem; line-height: 1.6;
}
.cover-byline .muted { color: var(--ink-muted); }

.cover-abstract {
  background: var(--bg);
  border-left: 4px solid var(--gold);
  padding: 1.5rem 1.75rem;
  margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.cover-abstract-label {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 0.75rem;
}
.cover-abstract p {
  font-size: 0.95rem; line-height: 1.75; color: var(--ink-soft);
  margin-bottom: 0.75rem;
}
.cover-abstract p:last-child { margin-bottom: 0; }

.cover-pillars {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 1.25rem; margin-top: 2.5rem;
}
.pillar {
  background: var(--bg-elevated); border: 1px solid var(--rule);
  border-radius: 8px; padding: 1.25rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.pillar:hover {
  border-color: var(--midmarket);
  box-shadow: 0 2px 12px rgba(31,58,82,0.08);
}
.pillar-num {
  font-family: var(--serif); font-size: 1.5rem; font-weight: 700;
  color: var(--accent); margin-bottom: 0.5rem;
}
.pillar-title {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 0.5rem;
}
.pillar-text {
  font-size: 0.85rem; color: var(--ink-muted); line-height: 1.6;
}

/* === Strategy cards === */
.strategy-cards {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem; margin-bottom: 1rem;
}
.strat-card {
  background: var(--bg); border: 2px solid var(--rule);
  border-radius: 8px; padding: 1rem; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.strat-card:hover { border-color: var(--midmarket); }
.strat-card.selected {
  border-color: var(--upstream);
  background: rgba(31,58,82,0.04);
}
.strat-name {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 0.25rem;
}
.strat-desc {
  font-size: 0.8rem; color: var(--ink-muted); line-height: 1.5;
}

/* === Readouts === */
.readouts {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem; margin: 1rem 0;
}
.readout {
  background: var(--bg); border-radius: 6px; padding: 0.75rem;
  text-align: center;
}
.readout-label {
  font-family: var(--sans); font-size: 11px; font-weight: 500;
  color: var(--ink-muted); margin-bottom: 0.25rem;
}
.readout-val {
  font-family: var(--mono); font-size: 1.25rem; font-weight: 600;
  color: var(--ink);
}

/* === Button row === */
.btn-row {
  display: flex; gap: 0.75rem; margin: 1rem 0;
}
.primary-btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  background: var(--upstream); color: white;
  border: none; padding: 0.6rem 1.25rem;
  border-radius: 6px; cursor: pointer;
  transition: background 0.2s;
}
.primary-btn:hover { background: var(--accent); }
.ghost-btn {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--rule); padding: 0.6rem 1.25rem;
  border-radius: 6px; cursor: pointer;
  transition: border-color 0.2s;
}
.ghost-btn:hover { border-color: var(--ink-muted); }

/* === Property grid (for compositional elements) === */
.property-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem; margin: 1.5rem 0;
}
.prop-card {
  background: var(--bg); border: 1px solid var(--rule);
  border-radius: 8px; padding: 0.75rem;
  cursor: pointer; text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.prop-card:hover {
  border-color: var(--midmarket);
  box-shadow: 0 2px 8px rgba(31,58,82,0.06);
}
.prop-card.selected {
  border-color: var(--upstream);
  background: rgba(31,58,82,0.04);
}
.prop-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.prop-name {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  color: var(--ink);
}

/* === Flow diagram === */
.flow-diagram {
  display: flex; align-items: center; justify-content: center;
  gap: 0; margin: 2rem 0; flex-wrap: wrap;
}
.flow-node {
  background: var(--bg-elevated); border: 2px solid var(--upstream);
  border-radius: 10px; padding: 1rem 1.25rem;
  text-align: center; min-width: 140px;
  cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s;
}
.flow-node:hover, .flow-node.active {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(200,57,44,0.12);
}
.flow-node-label {
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  color: var(--ink); margin-bottom: 0.25rem;
}
.flow-node-sub {
  font-size: 0.75rem; color: var(--ink-muted);
}
.flow-arrow {
  font-size: 1.5rem; color: var(--ink-muted); margin: 0 0.25rem;
}
.flow-detail {
  margin-top: 1.5rem; padding: 1.25rem;
  background: var(--bg); border-radius: 8px;
  border: 1px solid var(--rule);
}
.flow-detail-title {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--upstream); margin-bottom: 0.5rem;
}
.flow-detail-body {
  font-size: 0.9rem; color: var(--ink-soft); line-height: 1.7;
}

/* === Closing === */
.closing {
  max-width: 920px; margin: 0 auto; padding: 4rem 1.5rem 2rem;
  border-top: 1px solid var(--rule);
}
.closing-statement {
  font-size: 1.3rem; font-style: italic; color: var(--ink-soft);
  line-height: 1.6; text-align: center; margin-bottom: 2.5rem;
}
.numbers-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem; margin-bottom: 2.5rem;
}
.big-num { text-align: center; }
.num-val {
  font-family: var(--mono); font-size: 2.5rem; font-weight: 700;
  color: var(--accent); display: block;
}
.num-desc {
  font-family: var(--sans); font-size: 12px; color: var(--ink-muted);
  margin-top: 0.25rem;
}
.site-footer {
  text-align: center; padding: 2rem 0;
  font-family: var(--sans); font-size: 12px; color: var(--ink-muted);
}

/* === Responsive === */
@media (max-width: 768px) {
  .cover-title { font-size: 2rem; }
  .cover-pillars { grid-template-columns: 1fr; }
  .property-grid { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .readouts { grid-template-columns: 1fr; }
  .strategy-cards { grid-template-columns: 1fr; }
  .flow-diagram { flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); }
  .numbers-row { grid-template-columns: 1fr; }
  h2 { font-size: 1.6rem; }
}
