/* ============================================================
   Benchmark Radar — interactive companion site
   Editorial long-form design system (cream / navy / warm red)
   ============================================================ */

: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: #b98a2f;
  --cream: #f6f1e3;
  --serif: 'Newsreader', Georgia, serif;
  --sans: 'Inter', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Fixed nav ---------- */

.nav-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: rgba(251, 250, 247, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.nav-inner {
  max-width: 1160px; margin: 0 auto; padding: 0.65rem 1.4rem;
  display: flex; flex-direction: column; gap: 4px;
}
.nav-title { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.nav-paper { font-family: var(--sans); font-weight: 600; font-size: 0.82rem; letter-spacing: 0.02em; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sub { font-family: var(--sans); font-size: 0.7rem; color: var(--ink-muted); white-space: nowrap; }
.nav-progress { height: 2px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.nav-progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.15s linear; }

/* ---------- Left chapter rail ---------- */

.chapter-rail {
  position: fixed; left: 18px; top: 50%; transform: translateY(-50%);
  z-index: 900;
}
.chapter-rail ol { list-style: none; }
.chapter-rail li {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 0; cursor: pointer;
}
.chapter-rail .dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--ink-muted); background: transparent;
  flex-shrink: 0; transition: all 0.2s;
}
.chapter-rail li.active .dot { background: var(--accent); border-color: var(--accent); transform: scale(1.35); }
.chapter-rail .label {
  font-family: var(--sans); font-size: 0.66rem; color: var(--ink-muted);
  opacity: 0; transition: opacity 0.2s; white-space: nowrap;
}
.chapter-rail li:hover .label, .chapter-rail li.active .label { opacity: 1; }
@media (max-width: 1100px) { .chapter-rail { display: none; } }

/* ---------- Chapters ---------- */

.chapter {
  max-width: 920px; margin: 0 auto; padding: 7rem 1.4rem 3.5rem;
  border-bottom: 1px solid var(--rule);
}
.chapter:last-of-type { border-bottom: none; }

.eyebrow {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent);
  margin-bottom: 0.9rem;
}
.chapter h2 {
  font-size: clamp(1.9rem, 4vw, 2.7rem); font-weight: 600;
  line-height: 1.14; letter-spacing: -0.012em; margin-bottom: 1.1rem;
}
.lede {
  font-size: 1.22rem; line-height: 1.6; color: var(--ink-soft);
  font-style: italic; margin-bottom: 2rem; max-width: 46rem;
}
.chapter p { margin-bottom: 1.15rem; max-width: 46rem; }
.chapter p.wide { max-width: none; }
.chapter strong { font-weight: 700; }
.chapter em { font-style: italic; }
.chapter .num { font-family: var(--mono); font-size: 0.88em; }

/* ---------- Plain-English card ---------- */

.plain-card {
  background: var(--cream);
  border-left: 4px solid var(--gold);
  padding: 1.35rem 1.55rem 0.6rem;
  margin: 2.1rem 0;
  border-radius: 0 6px 6px 0;
}
.plain-label {
  font-family: var(--sans); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold);
  margin-bottom: 0.7rem;
}
.plain-card p { font-size: 1.02rem; line-height: 1.58; color: var(--ink-soft); }

/* ---------- Equation block ---------- */

.equation-block {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.3rem 1.6rem;
  margin: 1.8rem 0;
  overflow-x: auto;
}
.equation-block .eq-title {
  font-family: var(--sans); font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--midmarket);
  margin-bottom: 0.6rem;
}
.equation-block .katex-display { margin: 0.4rem 0; }

.var-table {
  font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft);
  margin-top: 0.8rem; border-collapse: collapse;
}
.var-table td { padding: 2px 12px 2px 0; vertical-align: top; }
.var-table td:first-child { font-family: var(--mono); color: var(--upstream); white-space: nowrap; }

/* ---------- Interactive section ---------- */

.interactive-section {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.4rem 1.5rem 1.1rem;
  margin: 2.2rem 0;
  box-shadow: 0 1px 3px rgba(21, 33, 46, 0.05);
}
.interactive-label {
  font-family: var(--sans); font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--upstream);
  margin-bottom: 1rem; display: flex; align-items: center; gap: 8px;
}
.interactive-label::before {
  content: ''; display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}
.live-hint {
  font-family: var(--sans); font-size: 0.72rem; color: var(--ink-muted);
  font-style: italic; margin-bottom: 0.9rem;
}

.control-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem 1.4rem; margin-bottom: 1.1rem;
}
.control { display: block; }
.control label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--sans); font-size: 0.74rem; font-weight: 600;
  color: var(--ink-soft); margin-bottom: 4px;
}
.control label .val { font-family: var(--mono); font-weight: 500; color: var(--upstream); font-size: 0.76rem; }
input[type="range"] {
  width: 100%; height: 4px; -webkit-appearance: none; appearance: none;
  background: linear-gradient(to right, var(--midmarket), var(--downstream));
  border-radius: 2px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--bg-elevated); border: 2.5px solid var(--accent);
  cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--bg-elevated); border: 2.5px solid var(--accent); cursor: grab;
}
input[type="text"] {
  width: 100%; font-family: var(--sans); font-size: 0.92rem; color: var(--ink);
  padding: 0.55rem 0.8rem; border: 1.5px solid var(--rule); border-radius: 6px;
  background: var(--bg); outline: none;
}
input[type="text"]:focus { border-color: var(--midmarket); }

.chart-grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.chart-grid.g2 { grid-template-columns: 1fr 1fr; }
.chart-grid.g2x2 { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
@media (max-width: 760px) { .chart-grid.g2, .chart-grid.g2x2 { grid-template-columns: 1fr; } }
.chart-cell { min-height: 300px; }
.chart-cell .js-plotly-plot { min-height: 300px; }

.readout-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem; margin: 0.9rem 0;
}
.readout {
  background: var(--bg); border: 1px solid var(--rule); border-radius: 7px;
  padding: 0.7rem 0.9rem;
}
.readout .ro-label { font-family: var(--sans); font-size: 0.64rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 3px; }
.readout .ro-value { font-family: var(--mono); font-size: 1.28rem; font-weight: 500; color: var(--upstream); }
.readout .ro-value.red { color: var(--accent); }
.readout .ro-value.green { color: var(--feedback); }
.readout .ro-sub { font-family: var(--sans); font-size: 0.68rem; color: var(--ink-muted); margin-top: 2px; }

/* ---------- Buttons / toggles ---------- */

.btn-row { display: flex; flex-wrap: wrap; gap: 0.55rem; margin: 0.8rem 0; }
.btn {
  font-family: var(--sans); font-size: 0.76rem; font-weight: 600;
  padding: 0.42rem 0.95rem; border-radius: 999px;
  border: 1.5px solid var(--rule); background: var(--bg-elevated);
  color: var(--ink-soft); cursor: pointer; transition: all 0.15s;
}
.btn:hover { border-color: var(--midmarket); color: var(--upstream); }
.btn.active { background: var(--upstream); border-color: var(--upstream); color: #fff; }
.btn.accent.active { background: var(--accent); border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.switch-row { display: flex; flex-wrap: wrap; gap: 1.1rem; align-items: center; margin: 0.7rem 0; }
.switch { display: flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .track {
  width: 34px; height: 19px; border-radius: 999px; background: var(--rule);
  position: relative; transition: background 0.18s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2.5px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  transition: left 0.18s; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.switch input:checked + .track { background: var(--feedback); }
.switch input:checked + .track::after { left: 17px; }
.switch input.failed:checked + .track { background: var(--accent); }
.switch .sw-label { font-family: var(--sans); font-size: 0.76rem; font-weight: 600; color: var(--ink-soft); }

/* ---------- Callout ---------- */

.callout {
  border-left: 4px solid var(--accent);
  background: #fdf3f1;
  padding: 1.15rem 1.5rem;
  margin: 2.2rem 0;
  border-radius: 0 6px 6px 0;
}
.callout-label {
  font-family: var(--sans); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent);
  margin-bottom: 0.5rem;
}
.callout p { font-size: 1.04rem; color: var(--ink-soft); margin-bottom: 0.5rem; }
.callout p:last-child { margin-bottom: 0; }
.callout em { color: var(--accent); font-weight: 600; }

/* ---------- Chapter foot link ---------- */

.chapter-foot {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--sans); font-size: 0.82rem; font-weight: 600;
  color: var(--ink-muted); text-decoration: none; margin-top: 1.6rem;
  transition: color 0.2s;
}
.chapter-foot .arrow { transition: transform 0.2s; font-size: 1rem; }
.chapter-foot:hover { color: var(--accent); }
.chapter-foot:hover .arrow { transform: translateX(6px); }

/* ---------- Cover ---------- */

.cover { padding-top: 8.5rem; border-bottom: 1px solid var(--rule); }
.cover-inner { max-width: 920px; }
.cover-eyebrow {
  font-family: var(--sans); font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent);
  margin-bottom: 1.3rem;
}
.cover-title {
  font-size: clamp(2.4rem, 5.5vw, 3.7rem); font-weight: 600;
  line-height: 1.08; letter-spacing: -0.015em; margin-bottom: 1.2rem;
}
.cover-title em { color: var(--accent); }
.cover-subtitle {
  font-size: 1.3rem; font-style: italic; color: var(--ink-soft);
  margin-bottom: 1.4rem;
}
.cover-byline { font-family: var(--sans); font-size: 0.86rem; line-height: 1.75; color: var(--ink-soft); margin-bottom: 2.4rem; }
.cover-byline .muted { color: var(--ink-muted); font-size: 0.78rem; }

.cover-abstract {
  background: var(--cream); border-left: 4px solid var(--gold);
  border-radius: 0 8px 8px 0; padding: 1.7rem 2rem 1.2rem; margin-bottom: 2.6rem;
}
.cover-abstract-label {
  font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.17em; text-transform: uppercase; color: var(--gold);
  margin-bottom: 1rem;
}
.cover-abstract p { font-size: 1.06rem; line-height: 1.66; color: var(--ink-soft); margin-bottom: 1.05rem; }
.cover-abstract p:last-child { margin-bottom: 0.4rem; }

.cover-pillars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2.5rem; }
@media (max-width: 760px) { .cover-pillars { grid-template-columns: 1fr; } }
.pillar {
  background: var(--bg-elevated); border: 1px solid var(--rule);
  border-radius: 9px; padding: 1.2rem 1.25rem;
}
.pillar-num {
  font-family: var(--serif); font-style: italic; font-size: 1.5rem;
  color: var(--downstream); font-weight: 600; margin-bottom: 0.4rem;
}
.pillar-title { font-family: var(--sans); font-size: 0.88rem; font-weight: 700; color: var(--upstream); margin-bottom: 0.45rem; line-height: 1.3; }
.pillar-text { font-size: 0.88rem; line-height: 1.5; color: var(--ink-soft); }

/* ---------- SVG diagram (ch2) ---------- */

.arch-svg-wrap { overflow-x: auto; }
.arch-detail {
  background: var(--bg); border: 1px solid var(--rule); border-radius: 7px;
  padding: 0.9rem 1.1rem; margin-top: 0.9rem; min-height: 92px;
  font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); line-height: 1.55;
}
.arch-detail .ad-title { font-weight: 700; color: var(--upstream); font-size: 0.85rem; margin-bottom: 0.3rem; }
.arch-node { cursor: pointer; }
.arch-node rect { transition: all 0.15s; }
.arch-node:hover rect { stroke-width: 2.5; }
.arch-node.selected rect { stroke: var(--accent); stroke-width: 2.5; }

.flow-line {
  stroke-dasharray: 6 5; animation: dashflow 1.2s linear infinite;
}
@keyframes dashflow { to { stroke-dashoffset: -11; } }

/* ---------- Search results (ch4, ch9) ---------- */

.result-list { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
.result-item {
  border: 1px solid var(--rule); border-radius: 7px;
  background: var(--bg); padding: 0.7rem 0.95rem; cursor: pointer;
  transition: border-color 0.15s;
}
.result-item:hover { border-color: var(--midmarket); }
.result-item.open { border-color: var(--upstream); }
.result-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.8rem; }
.result-name { font-family: var(--sans); font-weight: 700; font-size: 0.86rem; color: var(--upstream); }
.result-score { font-family: var(--mono); font-size: 0.82rem; color: var(--accent); white-space: nowrap; }
.result-desc { font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; line-height: 1.45; }
.result-words { font-family: var(--sans); font-size: 0.7rem; margin-top: 5px; line-height: 1.7; }
.w-chip {
  display: inline-block; font-family: var(--mono); font-size: 0.66rem;
  padding: 1px 7px; border-radius: 999px; margin-right: 4px; margin-bottom: 2px;
}
.w-hit { background: #e2f3ee; color: #0d7a63; border: 1px solid #9ed4c6; }
.w-miss { background: #f3e3e1; color: #a03328; border: 1px solid #e0b6b1; text-decoration: line-through; }
.result-detail {
  display: none; margin-top: 0.6rem; border-top: 1px dashed var(--rule); padding-top: 0.55rem;
  font-family: var(--mono); font-size: 0.7rem; color: var(--ink-soft); line-height: 1.7;
}
.result-item.open .result-detail { display: block; }
.result-detail table { border-collapse: collapse; width: 100%; font-size: 0.68rem; }
.result-detail th { text-align: left; font-family: var(--sans); color: var(--ink-muted); font-weight: 600; padding: 2px 8px 2px 0; border-bottom: 1px solid var(--rule); }
.result-detail td { padding: 2px 8px 2px 0; border-bottom: 1px solid var(--rule); }
.term-pill { color: var(--upstream); font-weight: 700; }

/* ---------- Table (generic data table) ---------- */

.data-table {
  width: 100%; border-collapse: collapse; font-family: var(--sans);
  font-size: 0.78rem; color: var(--ink-soft); margin: 1rem 0;
}
.data-table th {
  text-align: left; font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-muted); font-weight: 700;
  padding: 0.45rem 0.7rem; border-bottom: 2px solid var(--rule);
}
.data-table td { padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.data-table td.mono, .data-table th.mono { font-family: var(--mono); }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--cream); }
.data-table tr.sel { background: var(--cream); }

/* ---------- Misc ---------- */

.small-note { font-family: var(--sans); font-size: 0.7rem; color: var(--ink-muted); line-height: 1.5; margin-top: 0.6rem; }
.footer {
  max-width: 920px; margin: 0 auto; padding: 2.5rem 1.4rem 4rem;
  font-family: var(--sans); font-size: 0.74rem; color: var(--ink-muted); line-height: 1.7;
}
.footer a { color: var(--midmarket); }
