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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #1a1a1a;
  background: #fff;
}

a { color: #b5003e; }
a:hover { text-decoration: underline; }

/* ── Nav ────────────────────────────────────────────────────────── */
.story-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.5rem;
  background: #1a1a1a;
  color: #fff;
}

.nav-back {
  color: #ccc;
  text-decoration: none;
  font-size: 0.875rem;
  white-space: nowrap;
}
.nav-back:hover { color: #fff; }

.nav-title {
  flex: 1;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #ddd;
}

.btn-export-story {
  padding: 0.35rem 0.9rem;
  border: 1px solid #555;
  border-radius: 4px;
  background: transparent;
  color: #ccc;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-export-story:hover { background: #333; color: #fff; }
.btn-export-story:disabled { opacity: 0.45; cursor: default; }

/* ── Hero ───────────────────────────────────────────────────────── */
.story-hero {
  background: #b5003e;
  color: #fff;
  padding: 4rem 1.5rem 3.5rem;
  text-align: center;
}

.hero-inner { max-width: 700px; margin: 0 auto; }

.hero-eyebrow {
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 1.25rem;
}

.hero-headline {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 1.5rem;
}

.hero-pct {
  display: block;
  font-size: clamp(4rem, 12vw, 7rem);
  font-weight: 900;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.hero-pct-label {
  display: block;
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  font-weight: 400;
  opacity: 0.9;
}

.hero-sub {
  font-size: 1rem;
  opacity: 0.85;
  max-width: 580px;
  margin: 0 auto;
}
.hero-sub strong { font-weight: 700; }

/* ── Section layout ─────────────────────────────────────────────── */
.story-section {
  padding: 3.5rem 1.5rem;
  background: #fff;
}
.story-section.section-alt { background: #f5f5f5; }

.section-inner {
  max-width: 820px;
  margin: 0 auto;
}

.section-header { margin-bottom: 1.25rem; }

.section-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #b5003e;
  margin-bottom: 0.35rem;
}

.section-header h2 {
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 800;
  color: #111;
  line-height: 1.2;
}

.section-lead {
  font-size: 1.05rem;
  color: #333;
  margin-bottom: 2rem;
  max-width: 740px;
  line-height: 1.7;
}

/* ── Stat cards ─────────────────────────────────────────────────── */
.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  flex: 1 1 155px;
  padding: 1.25rem 1rem;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  text-align: center;
  min-width: 125px;
}

.section-alt .stat-card { background: #fff; }

.stat-val {
  font-size: 2.1rem;
  font-weight: 800;
  color: #b5003e;
  line-height: 1.1;
  margin-bottom: 0.3rem;
}
.stat-val.neutral { color: #333; }
.stat-val.pos { color: #1a6e3a; }
.stat-val.neg { color: #b5003e; }

.stat-lbl {
  font-size: 0.75rem;
  font-weight: 700;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.35;
}

.stat-sub {
  font-size: 0.73rem;
  color: #999;
  margin-top: 0.3rem;
}

/* ── Finding box ────────────────────────────────────────────────── */
.finding-box {
  padding: 1.25rem 1.5rem;
  border-left: 4px solid #b5003e;
  background: #fff8f9;
  border-radius: 0 6px 6px 0;
  margin-top: 1.75rem;
  font-size: 0.975rem;
  line-height: 1.7;
  color: #222;
}
.finding-box strong { color: #b5003e; }
.finding-box p + p { margin-top: 0.75rem; }

/* ── Charts ─────────────────────────────────────────────────────── */
.chart-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #444;
  margin: 1.75rem 0 0.75rem;
}

.chart-wrap {
  position: relative;
  width: 100%;
  max-width: 740px;
  height: 300px;
  margin-bottom: 0.5rem;
}
.chart-wrap--horiz { height: 230px; }
#chart-regions-wrap { height: 310px; }

.chart-note {
  font-size: 0.78rem;
  color: #999;
  margin-bottom: 1.5rem;
}

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0;
}

.story-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.story-table th {
  text-align: right;
  padding: 0.55rem 0.75rem;
  background: #ebebeb;
  color: #444;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 2px solid #d0d0d0;
}
.story-table th:first-child { text-align: left; }

.story-table td {
  text-align: right;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #eee;
  color: #333;
  white-space: nowrap;
}
.story-table td:first-child { text-align: left; font-weight: 600; white-space: normal; }
.story-table tr:hover td { background: #fafafa; }
.story-table tr.highlight td { background: #fff7ee; }
.section-alt .story-table tr:hover td { background: #f0f0f0; }

.gap-pos { color: #1a6e3a; font-weight: 700; }
.gap-neg { color: #b5003e; font-weight: 700; }
.gap-neutral { color: #666; }
.small-sample { font-size: 0.72em; color: #bbb; margin-left: 0.2em; }

/* ── Election-type cards ────────────────────────────────────────── */
.etype-cards {
  display: flex;
  gap: 1.5rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.etype-card {
  flex: 1 1 260px;
  padding: 1.5rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
}

.etype-card h3 {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #b5003e;
  color: #222;
}

.etype-stat-list { list-style: none; font-size: 0.875rem; }
.etype-stat-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.3rem 0;
  border-bottom: 1px solid #f2f2f2;
}
.etype-stat-list li:last-child { border-bottom: none; }
.etype-stat-key { color: #666; }
.etype-stat-val { font-weight: 600; }
.etype-stat-val.gap-pos { color: #1a6e3a; }
.etype-stat-val.gap-neg { color: #b5003e; }

/* ── Correlation cards ──────────────────────────────────────────── */
.corr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.corr-card {
  padding: 1rem 1.25rem;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
}

.corr-vars {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #999;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.corr-r {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 0.35rem;
}
.corr-r.pos { color: #1a6e3a; }
.corr-r.neg { color: #b5003e; }
.corr-r.neut { color: #888; }

.corr-n {
  font-size: 0.73rem;
  color: #bbb;
  margin-bottom: 0.45rem;
}

.corr-interp {
  font-size: 0.8rem;
  color: #444;
  line-height: 1.45;
}

/* ── Region filter ──────────────────────────────────────────────── */
.region-filter-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.filter-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #555;
}

#region-select {
  padding: 0.35rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.875rem;
  background: #fff;
  cursor: pointer;
}

/* ── Footer ─────────────────────────────────────────────────────── */
.story-footer {
  background: #1a1a1a;
  color: #999;
  padding: 2.5rem 1.5rem;
}

.footer-inner {
  max-width: 820px;
  margin: 0 auto;
  font-size: 0.8rem;
  line-height: 1.7;
}
.footer-inner p + p { margin-top: 0.75rem; }
.footer-inner a { color: #bbb; }
.footer-inner a:hover { color: #fff; }
.footer-inner .footer-stat-note { font-style: italic; color: #777; }

/* ── Methodology details (footer) ──────────────────────────────── */
.footer-meth {
  margin-top: 1.5rem;
  border-top: 1px solid #333;
  padding-top: 1rem;
}
.footer-meth > summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  color: #bbb;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.25rem 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}
.footer-meth > summary::-webkit-details-marker { display: none; }
.footer-meth > summary::before { content: '▶'; font-size: 0.6rem; transition: transform 0.15s; }
.footer-meth[open] > summary::before { transform: rotate(90deg); }
.footer-meth > summary:hover { color: #fff; }

.meth-body { padding-top: 1rem; }
.meth-body h4 {
  font-size: 0.72rem;
  font-weight: 700;
  color: #ddd;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 1.25rem 0 0.4rem;
}
.meth-body h4:first-child { margin-top: 0; }
.meth-body p { font-size: 0.78rem; color: #aaa; margin: 0.25rem 0; line-height: 1.55; }
.meth-body ul, .meth-body ol {
  padding-left: 1.4rem;
  margin: 0.35rem 0;
  font-size: 0.78rem;
  color: #aaa;
  line-height: 1.55;
}
.meth-body li { margin-bottom: 0.25rem; }
.meth-body a { color: #e07070; }
.meth-body code {
  background: #2c2c2c;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.75rem;
  color: #e0c080;
}
.meth-source-list { list-style: none; padding-left: 0; }
.meth-source-list li { border-bottom: 1px solid #2c2c2c; padding: 0.35rem 0; }
.meth-source-list li:last-child { border-bottom: none; }
.meth-source-list strong { color: #ccc; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .story-section { padding: 2.5rem 1rem; }
  .story-hero { padding: 3rem 1rem 2.5rem; }
  .stat-val { font-size: 1.7rem; }
  .etype-cards { flex-direction: column; }
  .nav-title { display: none; }
  .chart-wrap { height: 260px; }
  .chart-wrap--horiz { height: 220px; }
}
