:root,
[data-theme="light"] {
  --bg: #faf9f5;
  --surface: #ffffff;
  --surface-alt: #f3f1ea;
  --border: #e4e0d5;
  --border-strong: #c7c1b2;
  --ink: #171717;
  --ink-body: #374151;
  --ink-muted: #6b7280;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --green: #047857;
  --green-soft: #d1fae5;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --rose: #be123c;
  --rose-soft: #ffe4e6;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --grid: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-alt: #1e2530;
  --border: #2c3545;
  --border-strong: #445268;
  --ink: #f3f5f8;
  --ink-body: #cbd5e1;
  --ink-muted: #8e9cb0;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.16);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.14);
  --rose: #fb7185;
  --rose-soft: rgba(251, 113, 133, 0.14);
  --violet: #c084fc;
  --violet-soft: rgba(192, 132, 252, 0.14);
  --grid: #273142;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

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

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.muted { color: var(--ink-muted); font-size: 13.5px; }
.muted-inline { color: var(--ink-muted); }

/* Sticky Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1020px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.brand-divider { color: var(--border-strong); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

select, input[type="text"] {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13.5px;
  outline: none;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
  transition: all 0.14s ease;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
[data-theme="dark"] .btn-primary { color: #0b101b; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--ink-body); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 10px 18px; font-size: 14.5px; }

/* Single Readable Editorial Column */
.page {
  max-width: 1020px;
  margin: 0 auto;
  padding: 36px 24px 80px;
}

/* 1. Cold-Reader Intro */
.intro-hero {
  margin-bottom: 40px;
}

.eyebrow {
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 8px;
}

.intro-hero h1 {
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 850;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin-bottom: 14px;
}

.lede {
  font-size: 18px;
  color: var(--ink-body);
  line-height: 1.6;
  max-width: 840px;
  margin-bottom: 20px;
}

.thesis-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.thesis-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

.thesis-text {
  font-size: 16px;
  color: var(--ink);
  line-height: 1.55;
}

.cast-drawer {
  margin-top: 10px;
  font-size: 14px;
}

.cast-drawer summary {
  cursor: pointer;
  color: var(--ink-muted);
  font-weight: 600;
  user-select: none;
}

.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.cast-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.cast-name {
  font-weight: 750;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Section Headers */
.section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.section-head h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.015em;
}

/* 2. 4-Act Grid & Scoreboard */
.acts-section {
  margin-bottom: 44px;
}

.acts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 780px) {
  .acts-grid { grid-template-columns: 1fr; }
}

.act-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.act-card.act-red { border-top-color: var(--rose); }
.act-card.act-green { border-top-color: var(--green); }
.act-card.act-violet { border-top-color: var(--violet); }
.act-card.act-amber { border-top-color: var(--amber); }

.act-kicker {
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.act-card h3 {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 8px;
}

.act-card p {
  font-size: 14.5px;
  color: var(--ink-body);
  line-height: 1.55;
  margin-bottom: 12px;
}

.act-pill {
  font-size: 12.5px;
  font-weight: 750;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--ink);
}

.scoreboard-wrap {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 16px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.scoreboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.scoreboard-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
}

.scoreboard-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--ink-body);
}

.scoreboard-table tr:last-child td {
  border-bottom: none;
}

.method-footer {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--ink-muted);
  line-height: 1.6;
}

/* Bottleneck Relay Chain */
.spine-section {
  margin-bottom: 42px;
}

.chain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 12px;
}

.chain-node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.chain-node:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.chain-step-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.chain-bottleneck-label {
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  color: var(--amber);
  margin-top: 10px;
}

.chain-bottleneck-val {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
  line-height: 1.35;
}

/* 3. Two Story Charts */
.charts-section {
  margin-bottom: 44px;
}

.two-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 820px) {
  .two-charts { grid-template-columns: 1fr; }
}

.chart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.chart-title {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 3px;
}

.chart-caption {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.45;
  margin-bottom: 12px;
}

.chart-svg-wrap svg {
  width: 100%;
  height: 205px;
  display: block;
  overflow: visible;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--ink-body);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

/* 4. Chronological Chapters Feed */
.chapters-section {
  margin-bottom: 44px;
}

.chapters-feed {
  display: grid;
  gap: 24px;
}

.chapter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 28px;
  box-shadow: var(--shadow);
}

.chapter-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.chapter-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chapter-title {
  font-size: 22px;
  font-weight: 820;
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin-bottom: 8px;
}

.chapter-summary {
  font-size: 16px;
  color: var(--ink-body);
  line-height: 1.6;
  margin-bottom: 16px;
}

/* Cheap vs Bottleneck Bar inside Each Chapter */
.shift-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

@media (max-width: 680px) {
  .shift-strip { grid-template-columns: 1fr; }
}

.shift-pill {
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}

.shift-pill.cheap { background: var(--green-soft); }
.shift-pill.scarce { background: var(--amber-soft); }

.shift-kicker {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.shift-pill.cheap .shift-kicker { color: var(--green); }
.shift-pill.scarce .shift-kicker { color: var(--amber); }

/* Key Clashes inside Chapter */
.chapter-subhead {
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.clashes-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.clash-row {
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.45;
}

.clash-row-title {
  font-weight: 750;
  color: var(--ink);
  margin-bottom: 3px;
}

.clash-cause-effect {
  color: var(--ink-body);
}

.arrow-inline {
  color: var(--amber);
  font-weight: 800;
  padding: 0 4px;
}

/* Expandable Actor Table inside Each Chapter */
.actors-Accordion {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.actors-Accordion summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent);
  user-select: none;
}

.mini-table-wrap {
  overflow-x: auto;
  margin-top: 10px;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.mini-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.mini-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.v-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 750;
  padding: 1px 7px;
  border-radius: 99px;
  margin-right: 5px;
}
.v-Worked { background: var(--green-soft); color: var(--green); }
.v-Backfired { background: var(--rose-soft); color: var(--rose); }
.v-Squeezed { background: var(--violet-soft); color: var(--violet); }
.v-Mixed { background: var(--amber-soft); color: var(--amber); }

/* 5. Frontier Console */
.frontier-card {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 24px 28px;
  box-shadow: var(--shadow);
}

.frontier-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.frontier-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.steer-details {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}

.steer-details summary {
  cursor: pointer;
  font-weight: 650;
  color: var(--ink-body);
}

.steer-body {
  margin-top: 12px;
}

.shock-input {
  width: 100%;
  margin-bottom: 10px;
}

.directives-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
}

.dir-item {
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 7px 10px;
}

.dir-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.dir-item input {
  width: 100%;
  font-size: 12.5px;
  padding: 5px 8px;
}

.live-box {
  margin-top: 16px;
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 14px 16px;
}

.live-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  margin-bottom: 10px;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.live-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.live-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 12px;
}

.live-chip.done {
  border-color: var(--green);
  color: var(--green);
  font-weight: 700;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: min(420px, 92vw);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
