/* ===== GraphBit Interactive Companion — Stylesheet ===== */

: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: #c9a227;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --content-max: 920px;
  --nav-h: 56px;
  --rail-w: 160px;
}

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

/* ===== TOP NAV ===== */
.top-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(251,250,247,0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.nav-brand {
  font-family: var(--sans); font-weight: 700; font-size: 15px;
  color: var(--accent);
}
.nav-links { display: flex; gap: 16px; }
.nav-links a {
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  color: var(--ink-muted); text-decoration: none;
  transition: color .2s;
}
.nav-links a:hover { color: var(--accent); }
.nav-arxiv {
  font-family: var(--mono); font-size: 11px; color: var(--ink-muted);
  text-decoration: none; border: 1px solid var(--rule); border-radius: 4px;
  padding: 3px 8px; transition: border-color .2s, color .2s;
}
.nav-arxiv:hover { border-color: var(--accent); color: var(--accent); }

/* ===== CHAPTER RAIL ===== */
.chapter-rail {
  position: fixed; left: 20px; top: 50%; transform: translateY(-50%);
  z-index: 90; width: var(--rail-w);
  display: flex; flex-direction: column; gap: 6px;
}
.rail-link {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none;
  font-family: var(--sans); font-size: 11px; color: var(--ink-muted);
  transition: color .2s; cursor: pointer;
}
.rail-link:hover { color: var(--ink-soft); }
.rail-link.active { color: var(--accent); font-weight: 600; }
.rail-num {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--rule); transition: background .2s, transform .2s;
  display: inline-block;
}
.rail-link.active .rail-num { background: var(--accent); transform: scale(1.4); }
.rail-label { white-space: nowrap; }
@media (max-width: 1100px) { .chapter-rail { display: none; } }

/* ===== MAIN CONTENT ===== */
.content {
  max-width: calc(var(--content-max) + var(--rail-w) + 80px);
  margin: 0 auto;
}

/* ===== CHAPTER LAYOUT ===== */
.chapter {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 7rem 24px 3rem;
  padding-left: calc(var(--rail-w) + 48px);
}
@media (max-width: 1100px) { .chapter { padding-left: 24px; } }

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

/* ===== PLAIN ENGLISH CARD ===== */
.plain-card {
  background: var(--bg); border-left: 4px solid var(--gold);
  padding: 1.5rem 1.8rem; margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.plain-card p {
  font-size: 0.95rem; line-height: 1.7; 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: 6px; padding: 1.2rem 1.5rem; margin: 1.8rem 0;
  overflow-x: auto;
}
.equation-block h4 {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--upstream); margin-bottom: 8px;
}
.equation-block p {
  font-size: 0.95rem; line-height: 1.7; color: var(--ink-soft);
  margin-bottom: 0.6rem;
}
.equation-block p:last-child { margin-bottom: 0; }
.equation-block ul {
  margin: 0.5rem 0 0.8rem 1.2rem;
  font-size: 0.95rem; line-height: 1.7; color: var(--ink-soft);
}
.equation-block li { margin-bottom: 0.3rem; }

/* ===== RESULTS TABLE ===== */
.results-table {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
  font-family: var(--sans); font-size: 13px;
}
.results-table th {
  text-align: left; padding: 8px 10px;
  border-bottom: 2px solid var(--rule);
  font-weight: 600; color: var(--ink); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.results-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--rule);
  color: var(--ink-soft);
}
.results-table .highlight-row { background: rgba(200,57,44,0.04); }
.results-table .highlight-row td { color: var(--ink); font-weight: 600; }

/* ===== INTERACTIVE SECTION ===== */
.interactive-section {
  margin: 2.5rem 0; padding: 1.5rem;
  background: var(--bg-elevated); border: 1px solid var(--rule);
  border-radius: 8px;
}
.interactive-section h4 {
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  color: var(--upstream); margin-bottom: 12px;
}
.viz-hint {
  font-family: var(--sans); font-size: 12px; color: var(--ink-muted);
  margin: 8px 0 12px; font-style: italic;
}
.chart-container { width: 100%; min-height: 300px; }

/* ===== CONTROLS ===== */
.controls-row {
  display: flex; flex-wrap: wrap; gap: 1.2rem;
  margin-bottom: 1.2rem; align-items: flex-end;
}
.control-group {
  display: flex; flex-direction: column; gap: 4px; min-width: 160px;
}
.control-group label {
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  color: var(--ink-soft);
}
.control-group input[type="range"] {
  width: 100%; height: 4px; -webkit-appearance: none; appearance: none;
  background: var(--rule); border-radius: 2px; outline: none;
}
.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}

/* ===== STRATEGY CARDS ===== */
.strategy-cards {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 1rem;
}
.strategy-card {
  flex: 1; min-width: 160px; padding: 14px 16px;
  background: var(--bg); border: 2px solid var(--rule); border-radius: 6px;
  cursor: pointer; text-align: center;
  font-family: var(--sans); font-size: 13px; color: var(--ink-soft);
  transition: border-color .2s, color .2s, background .2s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.strategy-card:hover { border-color: var(--midmarket); }
.strategy-card.active {
  border-color: var(--accent); color: var(--accent);
  background: rgba(200,57,44,0.04);
}
.strategy-icon { font-size: 1.4rem; }
.strategy-label { font-weight: 600; font-size: 14px; }
.strategy-desc { font-size: 11px; color: var(--ink-muted); }

/* ===== FRAMEWORK CARDS (ch5) ===== */
.framework-cards {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 1rem;
}
.fw-card {
  padding: 8px 14px; background: var(--bg); border: 2px solid var(--rule);
  border-radius: 6px; cursor: pointer; text-align: center;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  color: var(--ink-soft); transition: border-color .2s, color .2s, background .2s;
}
.fw-card:hover { border-color: var(--midmarket); }
.fw-card.active {
  border-color: var(--accent); color: var(--accent);
  background: rgba(200,57,44,0.04);
}

/* ===== TOGGLE BUTTONS ===== */
.toggle-btn {
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  padding: 8px 16px; border: 2px solid var(--rule); border-radius: 6px;
  background: var(--bg); color: var(--ink-soft); cursor: pointer;
  transition: border-color .2s, background .2s, color .2s;
  white-space: nowrap;
}
.toggle-btn:hover { border-color: var(--midmarket); }
.toggle-btn.active {
  border-color: var(--accent); color: var(--accent);
  background: rgba(200,57,44,0.04);
}

/* ===== DAG DIAGRAM ===== */
.dag-container { display: flex; flex-direction: column; gap: 1rem; }
.dag-svg-wrap {
  width: 100%; min-height: 340px;
  display: flex; justify-content: center; align-items: center;
}
.dag-svg-wrap svg { max-width: 100%; }
.node-detail-panel {
  background: var(--bg); border: 1px solid var(--rule);
  border-radius: 6px; padding: 1rem 1.2rem; min-height: 80px;
}
.node-detail-panel h4 {
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  color: var(--upstream); margin-bottom: 6px;
}
.node-detail-panel p { font-size: 0.9rem; color: var(--ink-soft); line-height: 1.6; }
.node-detail-placeholder {
  font-size: 0.85rem; color: var(--ink-muted); font-style: italic;
}

/* ===== CALLOUT ===== */
.callout {
  background: rgba(200,57,44,0.04);
  border-left: 4px solid var(--accent);
  padding: 1.2rem 1.5rem; margin: 2rem 0;
  border-radius: 0 6px 6px 0;
}
.callout p { font-size: 0.95rem; color: var(--ink-soft); line-height: 1.65; }
.callout em { color: var(--accent); font-style: italic; }

/* ===== CHAPTER FOOT LINK ===== */
.chapter-foot { margin-top: 2rem; }
.chapter-foot a {
  font-family: var(--sans); font-size: 14px; font-weight: 500;
  color: var(--ink-muted); text-decoration: none;
  transition: color .2s;
}
.chapter-foot a:hover { color: var(--accent); }

/* ===== SUB CHART HEADLINE ===== */
.sub-chart-headline {
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  color: var(--upstream); margin: 1.5rem 0 8px;
}

/* ===== CLOSING PROSE ===== */
.closing-prose {
  margin-top: 2rem; padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.closing-prose p {
  font-size: 1rem; line-height: 1.75; color: var(--ink-soft);
}

/* ===== COVER PAGE ===== */
.chapter-cover {
  padding-top: calc(var(--nav-h) + 4rem);
  text-align: center;
  max-width: 800px;
}
.chapter-cover .chapter-inner { max-width: 720px; margin: 0 auto; }
.eyebrow {
  font-family: var(--sans); font-size: 12px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--accent);
  margin-bottom: 16px;
}
.chapter-cover h1 {
  font-family: var(--serif); font-size: 2.6rem; font-weight: 700;
  line-height: 1.15; margin-bottom: 20px;
}
.chapter-cover h1 em { color: var(--accent); }
.byline {
  font-family: var(--sans); font-size: 14px; color: var(--ink-soft);
  margin-bottom: 2.5rem; line-height: 1.6;
}
.cover-abstract {
  background: var(--bg); border-left: 4px solid var(--gold);
  padding: 1.5rem 2rem; margin: 2rem auto;
  border-radius: 0 6px 6px 0; text-align: left;
}
.cover-abstract p {
  font-size: 0.95rem; line-height: 1.7; color: var(--ink-soft);
  margin-bottom: 0.7rem;
}
.cover-abstract p:last-child { margin-bottom: 0; }
.cover-abstract b { color: var(--ink); }

.pillar-cards {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
  margin: 2.5rem auto 0; max-width: 720px;
}
@media (max-width: 600px) { .pillar-cards { grid-template-columns: 1fr; } }
.pillar-card {
  background: var(--bg-elevated); border: 1px solid var(--rule);
  border-radius: 8px; padding: 1.2rem 1rem; text-align: left;
}
.pillar-num {
  font-family: var(--serif); font-size: 1.5rem; font-weight: 700;
  color: var(--accent); margin-bottom: 6px;
}
.pillar-card h3 {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 6px;
}
.pillar-card p {
  font-size: 0.85rem; line-height: 1.55; color: var(--ink-muted);
}
.pillar-card b { color: var(--ink-soft); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .chapter-cover h1 { font-size: 1.8rem; }
  .chapter { padding-top: 5rem; }
  .chapter h2 { font-size: 1.6rem; }
  .controls-row { flex-direction: column; }
  .strategy-cards { flex-direction: column; }
  .top-nav { padding: 0 12px; }
  .nav-links { gap: 8px; }
}
