:root {
  --bg: #f5f1e8;
  --paper: #fffdf8;
  --ink: #1a1a1a;
  --muted: #69645e;
  --accent-a: #c44e52;
  --accent-b: #4c72b0;
  --rule: #ddd5c8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #efe7da 0%, var(--bg) 35%, #f2efe8 100%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.5;
}

.hero {
  max-width: 950px;
  margin: 0 auto;
  padding: 64px 20px 36px;
}

.kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  margin: 6px 0 10px;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.05;
}

.dek {
  margin: 0 0 24px;
  max-width: 700px;
  color: #2d2b29;
  font-size: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 280px));
  gap: 14px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat .value {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 700;
}

.story {
  max-width: 950px;
  margin: 0 auto;
  padding: 8px 20px 46px;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px 18px 10px;
  margin: 0 0 16px;
}

.scrolly-wrap {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(240px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.sticky-figure {
  position: sticky;
  top: 14px;
  align-self: start;
  background: #fcfaf5;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px;
}

.chart-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chart-nav-btn {
  border: 1px solid #c7beaf;
  background: #f7f2e8;
  color: #2b2824;
  border-radius: 16px;
  padding: 4px 9px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.chart-nav-btn.is-active {
  background: #2f2f2f;
  color: #fff;
  border-color: #2f2f2f;
}

.figure-hint {
  margin: 8px 2px 2px;
  color: #5a554d;
  font-size: 13px;
}

.chapters {
  display: grid;
  gap: 12px;
}

.chapter {
  border-left: 3px solid #d8d1c5;
  padding-left: 12px;
  opacity: 0.55;
  transition: opacity 0.25s ease, border-color 0.25s ease;
  min-height: 42vh;
}

.chapter.is-active {
  opacity: 1;
  border-color: #6f6a62;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.1;
}

.panel p {
  margin: 0 0 10px;
  color: #3f3b36;
  max-width: 760px;
}

figure {
  margin: 0;
}

img {
  width: 100%;
  height: auto;
  display: block;
}

.coef-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.coef-btn {
  border: 1px solid #bcb3a4;
  border-radius: 20px;
  background: #f8f4eb;
  color: #2b2824;
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.coef-btn.is-active {
  background: #2f2f2f;
  color: #fff;
  border-color: #2f2f2f;
}

#coef-plot {
  display: none;
  width: 100%;
  height: auto;
  background: #fcfaf5;
  border: 1px solid var(--rule);
  border-radius: 8px;
}

#coef-fallback {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fcfaf5;
  margin-bottom: 8px;
}

.footer {
  max-width: 950px;
  margin: 0 auto;
  padding: 0 20px 34px;
  color: var(--muted);
  font-size: 14px;
}

.footnote {
  font-size: 13px;
  color: #5f5a53;
  margin-top: 10px;
}

.inline-help {
  position: relative;
  display: inline-block;
  color: #2f2b26;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  cursor: help;
  outline: none;
}

.inline-help-bubble {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: min(360px, 86vw);
  display: none;
  z-index: 30;
  background: #fffef9;
  border: 1px solid #d3c6b1;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(31, 28, 24, 0.12);
  color: #3d382f;
  font-size: 12px;
  line-height: 1.35;
  padding: 9px 10px;
}

.inline-help:hover .inline-help-bubble,
.inline-help:focus .inline-help-bubble,
.inline-help:focus-within .inline-help-bubble {
  display: block;
}

.topic-lede {
  max-width: 820px;
  font-size: 18px;
}

.topic-results {
  display: grid;
  gap: 20px;
}

.topic-block {
  background: linear-gradient(180deg, #fdfaf4 0%, #fbf6ee 100%);
  border: 1px solid #ddd3c4;
  border-radius: 12px;
  padding: 14px 14px 10px;
}

.topic-kicker {
  margin: 0 0 2px;
  color: #736d63;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
}

.topic-block h3 {
  margin: 0 0 4px;
  font-size: clamp(20px, 2.8vw, 30px);
  line-height: 1.1;
}

.topic-note {
  margin: 0 0 10px;
  color: #413d36;
  font-size: 15px;
  max-width: 860px;
}

.topic-figure {
  border: 1px solid #d9cfbf;
  border-radius: 10px;
  overflow: hidden;
  background: #fffdf8;
}

.topic-interactive-wrap {
  display: grid;
  gap: 8px;
}

.topic-chart-controls {
  display: grid;
  gap: 6px;
}

.topic-metric-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topic-view-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.topic-legend-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.profile-chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-pill,
.topic-view-pill {
  border: 1px solid #cdbfa8;
  background: #f7f2e7;
  color: #2a2722;
  border-radius: 16px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.topic-pill.is-active,
.topic-view-pill.is-active {
  background: #0f4c5c;
  color: #fff;
  border-color: #0f4c5c;
}

.topic-chart-caption {
  margin: 0;
  color: #4c463d;
  font-size: 13px;
}

.epu-help {
  position: relative;
  display: inline-flex;
}

.epu-help-btn {
  border: 1px solid #c4b59d;
  background: #f8f2e5;
  color: #4a4338;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: help;
  line-height: 1;
}

.epu-help-btn:focus-visible {
  outline: 2px solid #0f4c5c;
  outline-offset: 2px;
}

.epu-help-card {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(420px, 88vw);
  z-index: 30;
  background: #fffef9;
  border: 1px solid #d3c6b1;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(31, 28, 24, 0.12);
  color: #3d382f;
  font-size: 12px;
  line-height: 1.4;
  padding: 10px 11px;
  display: none;
}

.epu-help:hover .epu-help-card,
.epu-help:focus-within .epu-help-card {
  display: block;
}

.topic-figure-interactive {
  position: relative;
}

#topic-time-svg {
  width: 100%;
  height: auto;
  display: block;
  background: #fffdf8;
}

#topic-time-fallback {
  display: none;
}

.topic-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(30, 28, 25, 0.93);
  color: #fff;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.25;
  transform: translate(8px, -8px);
  white-space: nowrap;
  z-index: 20;
}

.topic-insight-rail {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

.topic-callout {
  background: #f3ebdc;
  border: 1px solid #d6cab8;
  border-radius: 10px;
  padding: 9px 10px;
}

.topic-label {
  color: #6f675b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  margin-bottom: 4px;
}

.topic-value {
  font-size: 15px;
  line-height: 1.3;
  color: #22201c;
}

.mp-lookup-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 4px 0 8px;
}

.mp-mode-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 2px 0 6px;
}

.mp-lookup-input {
  flex: 1 1 280px;
  border: 1px solid #cdbfa8;
  background: #fffcf4;
  color: #2a2722;
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

.mp-lookup-input:focus-visible {
  outline: 2px solid #0f4c5c;
  outline-offset: 1px;
}

.mp-lookup-result {
  min-height: 22px;
  color: #4f473d;
  font-size: 13px;
}

.mp-table-wrap {
  overflow-x: auto;
  border: 1px solid #d9cfbf;
  border-radius: 10px;
  background: #fffdf8;
}

.mp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.mp-table thead th {
  text-align: left;
  padding: 8px 10px;
  background: #f4ecde;
  color: #4d453b;
  border-bottom: 1px solid #d9cfbf;
  font-weight: 600;
}

.mp-sort-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.mp-sort-btn.is-active {
  color: #0f4c5c;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mp-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid #eee4d4;
  color: #2f2a24;
}

.mp-table tbody tr:last-child td {
  border-bottom: 0;
}

.mp-table tbody tr.is-hit {
  background: #f1f7f8;
}

.topic-explain {
  margin-top: 6px;
  font-size: 12px;
  color: #5a5348;
  line-height: 1.35;
}

@media (max-width: 640px) {
  .hero {
    padding-top: 36px;
  }

  .dek {
    font-size: 17px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .scrolly-wrap {
    grid-template-columns: 1fr;
  }

  .sticky-figure {
    position: relative;
    top: auto;
  }

  .chapter {
    min-height: 26vh;
  }

  .topic-insight-rail {
    grid-template-columns: 1fr;
  }

  .topic-legend-controls {
    gap: 5px;
  }

  .topic-pill,
  .topic-view-pill {
    font-size: 11px;
    padding: 4px 8px;
  }
}
