/* WattsOpen — shared styling.
   High-end data publication: confident serifs, monospace numerals,
   warm parchment ground, crisp surfaces. */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..900;1,9..144,300..900&display=swap');

:root {
  --bg: #f3efe5;
  --bg-card: #fcfaf5;
  --ink: #1a1d22;
  --ink-soft: #3c4149;
  --ink-mute: #6a6f78;
  --rule: #d5cfc0;
  --accent: #bf4712;
  --accent-soft: #f0c19a;
  --accent-hover: #d4561f;
  --positive: #1a7044;
  --negative: #8c1818;
  --map-base: #e8dbb0;
  --radius: 5px;
  --shadow-sm: 0 1px 2px rgba(20,16,8,0.05);
  --shadow: 0 1px 2px rgba(20,16,8,0.04), 0 6px 20px rgba(20,16,8,0.06);
  --shadow-lg: 0 2px 4px rgba(20,16,8,0.05), 0 16px 40px rgba(20,16,8,0.09);
  --transition: 160ms ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--ink);
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  transition: border-color var(--transition), color var(--transition);
}
a:hover { border-bottom-color: var(--accent); color: var(--accent-hover); }

code, .num, .mono {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.95em;
}

h1, h2, h3 {
  font-family: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 0.45em;
  color: var(--ink);
}
h1 {
  font-family: "Fraunces", "Source Serif 4", Georgia, serif;
  font-size: 2.8rem;
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.025em;
  font-optical-sizing: auto;
}
h2 { font-size: 1.55rem; line-height: 1.2; margin-top: 1.6em; }
h3 { font-size: 1.1rem; }

/* Chapter kicker — sits above the page <h1> on each chapter page. */
.kicker {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--accent);
  margin: 0 0 8px;
  font-weight: 600;
  opacity: 0.85;
}

/* Component sub-score bars on the co-location detail card. */
.subscore {
  display: grid;
  grid-template-columns: 1.3fr 60px;
  gap: 6px 10px;
  align-items: center;
  margin: 4px 0;
  font-size: 0.85rem;
}
.subscore .bar {
  position: relative;
  height: 6px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.subscore .bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent);
  display: block;
}
.subscore .lab { color: var(--ink-soft); font-size: 0.8rem; }
.subscore .lab .w { color: var(--ink-mute); font-size: 0.7rem; margin-left: 4px; }
.subscore .val { font-family: "JetBrains Mono", monospace; font-size: 0.85rem; text-align: right; }

/* "Ready now" toggle button on the atlas. */
button.preset {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 12px;
  background: var(--bg-card);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform 80ms ease;
}
button.preset:hover { color: var(--ink); border-color: var(--ink-mute); }
button.preset:active { transform: scale(0.97); }
button.preset.on {
  background: var(--ink);
  color: var(--bg-card);
  border-color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
button.preset.on:hover { background: var(--accent); border-color: var(--accent); }

/* Limitations expander, used inside chapter notes. */
details.limits { margin-top: 14px; }
details.limits > summary {
  cursor: pointer;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--ink-soft);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
details.limits > summary::before {
  content: "›";
  display: inline-block;
  transition: transform 180ms ease;
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
}
details.limits[open] > summary::before { transform: rotate(90deg); }
details.limits[open] > summary { color: var(--ink); }
details.limits ul {
  margin: 10px 0 0 22px;
  padding: 0;
  list-style: disc;
  font-size: 0.88rem;
  color: var(--ink-soft);
}
details.limits li { margin: 4px 0; }

/* ── Layout primitives ────────────────────────────────────────────────── */

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 36px 32px 80px;
}

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 14px;
}
.site-header .brand {
  font-family: "Fraunces", "Source Serif 4", Georgia, serif;
  font-size: 1.22rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  border-bottom: none;
}
.site-header .brand .pip {
  color: var(--accent);
  margin-right: 0.35em;
  font-size: 0.8em;
}
.context-banner {
  flex-basis: 100%;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.88rem;
  font-style: italic;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--accent-soft) 25%, var(--bg-card));
  border-left: 3px solid var(--accent);
  padding: 8px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-top: 4px;
}
.context-banner a {
  font-style: normal;
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  margin-left: 6px;
  white-space: nowrap;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  font-size: 0.88rem;
}
.site-nav a {
  color: var(--ink-mute);
  border-bottom: 1.5px solid transparent;
  padding-bottom: 2px;
  transition: color var(--transition), border-color var(--transition);
}
.site-nav a.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.site-nav a:hover {
  color: var(--ink);
  border-bottom-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.site-footer {
  margin-top: 72px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-size: 0.84rem;
  color: var(--ink-mute);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  letter-spacing: 0.005em;
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 40px;
  align-items: end;
  margin-bottom: 40px;
}
@media (max-width: 780px) {
  .hero { grid-template-columns: 1fr; gap: 20px; }
}
.hero .lead {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
.hero .lead em { color: var(--accent); font-style: normal; }

/* ── Stat blocks ──────────────────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 18px 0 8px;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .v {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.1;
}
.stat .v small { font-size: 0.65em; color: var(--ink-mute); font-weight: 400; margin-left: 4px; }
.stat .k { font-size: 0.78rem; color: var(--ink-mute); margin-top: 8px; text-transform: uppercase; letter-spacing: 0.07em; line-height: 1.35; }

/* ── Story cards on the index page ────────────────────────────────────── */

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 32px;
}
.story {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 24px 26px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.story:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--accent) 25%, var(--rule));
}
.story .tag {
  font-size: 0.7rem;
  color: var(--ink-mute);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.story h3 a {
  color: var(--ink);
  border-bottom-color: transparent;
  transition: color var(--transition), border-color var(--transition);
}
.story h3 a:hover { border-bottom-color: var(--accent); color: var(--accent); }
.story p { margin: 0; color: var(--ink-soft); font-size: 0.94rem; line-height: 1.55; }
.story .why { font-family: "Source Serif 4", Georgia, serif; font-style: italic; color: var(--ink-mute); font-size: 0.9rem; line-height: 1.5; }

/* ── Map + chart frame ────────────────────────────────────────────────── */

.frame {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px 20px;
  margin-top: 18px;
  box-shadow: var(--shadow-sm);
}
.frame .caption {
  font-size: 0.85rem;
  color: var(--ink-mute);
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  margin: 18px 0 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.controls label { font-size: 0.84rem; color: var(--ink-mute); letter-spacing: 0.01em; }
.controls select,
.controls input[type="range"],
.controls input[type="number"] {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 5px 10px;
  font-size: 0.9rem;
  transition: border-color var(--transition);
}
.controls select:focus,
.controls input:focus {
  outline: none;
  border-color: var(--accent);
}
.controls input[type="range"] { accent-color: var(--accent); padding: 0; min-width: 200px; flex: 1 1 200px; }
.controls button {
  font: inherit;
  background: var(--ink);
  color: var(--bg-card);
  border: none;
  border-radius: 3px;
  padding: 6px 14px;
  cursor: pointer;
  letter-spacing: 0.04em;
  font-size: 0.85rem;
  transition: background var(--transition), transform 80ms ease;
}
.controls button.secondary {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
}
.controls button:hover { background: var(--accent); }
.controls button.secondary:hover { background: transparent; border-color: var(--accent); color: var(--accent); }
.controls button:active { transform: scale(0.97); }

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 8px;
  flex-wrap: wrap;
}
.legend .swatch {
  display: inline-block;
  width: 18px;
  height: 12px;
  border: 1px solid var(--rule);
}
.legend .ramp {
  height: 10px;
  width: 200px;
  border: 1px solid var(--rule);
}
/* "no data" swatch on shared legends — matches the SVG <pattern> defined by
   ensureNaPattern(). The two backgrounds are layered to mimic the hatch. */
.legend-na .na-swatch,
.legend .legend-na .na-swatch {
  display: inline-block;
  width: 16px;
  height: 10px;
  border: 1px solid var(--rule);
  background-color: #ebe5d4;
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0 2.4px,
    #c0b896 2.4px 3.6px
  );
}
.legend .legend-na {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 14px;
  color: var(--ink-mute);
}

/* Map toolbar — sits between the legend row and the SVG. Holds the county
   search input and the "Reset view" zoom button. */
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 6px;
  font-size: 0.82rem;
  flex-wrap: wrap;
}
.map-toolbar .county-search {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 0.84rem;
  min-width: 200px;
  flex: 1 1 200px;
  max-width: 320px;
}
.map-toolbar .county-search.search-nomatch {
  border-color: var(--negative);
  background: color-mix(in srgb, var(--negative) 8%, var(--bg));
}
.map-toolbar .map-btn {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.82rem;
}
.map-toolbar .map-btn:hover { color: var(--ink); border-color: var(--ink-mute); }
.map-toolbar .map-aside {
  margin-left: auto;
  color: var(--ink-mute);
  font-size: 0.78rem;
}

/* Off-map plant counter (AK/HI etc.) — sits in the legend row so the reader
   sees which plants the projection drops. */
.offmap-note {
  margin-left: auto;
  color: var(--ink-mute);
  font-size: 0.78rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* ── Bivariate legend (rendered as a single inline SVG by renderBivariateLegend)
   — keep these few rules so the legend sits inline with the NA swatch. */
svg.bivariate-legend { display: inline-block; vertical-align: middle; }
svg.bivariate-legend rect { shape-rendering: crispEdges; }

/* ── Map (SVG) ────────────────────────────────────────────────────────── */

.map { width: 100%; height: auto; display: block; }
.map .county {
  fill: var(--map-base);
  stroke: rgba(40, 36, 28, 0.18);
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.map .county:hover { stroke: var(--ink); stroke-width: 1.2; }
/* Keyboard focus ring for any tabbable map feature (county path, plant
   circle, etc.) so keyboard users can see what's selected. */
.map [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  stroke: var(--ink);
  stroke-width: 1.5;
}
/* Highlight applied by the county search helper on the matched county. */
.map .county--found {
  stroke: var(--accent) !important;
  stroke-width: 2.2 !important;
  stroke-opacity: 1 !important;
}
.map .state-border {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.5;
  stroke-opacity: 0.45;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.map .nation {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  background: var(--ink);
  color: var(--bg-card);
  padding: 9px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  line-height: 1.4;
  max-width: 280px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2), 0 12px 28px rgba(0,0,0,0.15);
  opacity: 0;
  transition: opacity 80ms ease;
  backdrop-filter: blur(2px);
}
.tooltip.show { opacity: 1; }
.tooltip .name { font-weight: 600; letter-spacing: -0.01em; }
.tooltip .num { color: var(--accent-soft); }

/* ── Side panels (leaderboards, plant lists) ──────────────────────────── */

.split {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 22px;
  margin-top: 18px;
}
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.panel h3 { margin-top: 0; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.table th, .table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
.table th {
  color: var(--ink-mute);
  font-weight: 500;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom-width: 2px;
}
.table td.num { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; text-align: right; }
.table tr.row-clickable { cursor: pointer; transition: background var(--transition); }
.table tr.row-clickable:hover td { background: rgba(198, 74, 22, 0.06); }
.table tbody tr:last-child td { border-bottom: none; }
.table .pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.74rem;
  background: var(--accent-soft);
  color: #6e2f10;
}

/* ── Stacked bars (queue funnel) ──────────────────────────────────────── */

.stack-row {
  display: grid;
  grid-template-columns: 90px 1fr 90px;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.88rem;
}
.stack-row .label { color: var(--ink-soft); }
.stack-row .bar {
  display: flex;
  width: 100%;
  height: 16px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.stack-row .bar span {
  display: block;
  height: 100%;
}
.stack-row .total { text-align: right; color: var(--ink-mute); font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

.legend-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--ink-mute);
}
.legend-row .sw { display: inline-block; width: 14px; height: 8px; margin-right: 4px; vertical-align: middle; border-radius: 1px; }

/* ── Note callouts ────────────────────────────────────────────────────── */

.note {
  margin: 22px 0;
  padding: 16px 20px;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-style: italic;
  color: var(--ink-soft);
  line-height: 1.55;
  box-shadow: var(--shadow-sm);
}
.note strong { font-style: normal; color: var(--ink); }

/* ── Takeaway pull-quote (the screenshot-able sentence above each chart) ── */

.takeaway {
  margin: 4px 0 24px;
  padding: 20px 24px;
  background: linear-gradient(170deg, var(--bg-card) 0%, color-mix(in srgb, var(--accent-soft) 30%, var(--bg-card)) 100%);
  border: 1px solid color-mix(in srgb, var(--accent-soft) 60%, var(--rule));
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.12rem;
  line-height: 1.5;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.takeaway strong, .takeaway .big {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}
.takeaway .label {
  display: block;
  font-family: "Inter", sans-serif;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-mute);
  font-style: normal;
  margin-bottom: 10px;
}

/* ── Next-story bridge (chapter-to-chapter navigation) ──────────────────── */

.next-story {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  margin: 56px 0 0;
  padding: 26px 30px;
  background: var(--ink);
  color: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.next-story .kicker {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: color-mix(in srgb, var(--bg-card) 50%, transparent);
  margin-bottom: 8px;
}
.next-story .bridge {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.08rem;
  line-height: 1.45;
  color: color-mix(in srgb, var(--bg-card) 90%, transparent);
}
.next-story .bridge em { color: var(--accent-soft); font-style: italic; }
.next-story a.go {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--bg-card);
  border: 1px solid color-mix(in srgb, var(--bg-card) 25%, transparent);
  border-radius: 3px;
  padding: 12px 22px;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), transform 80ms ease;
}
.next-story a.go:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-card);
  transform: translateX(2px);
}
@media (max-width: 640px) {
  .next-story { grid-template-columns: 1fr; }
}

/* ── Co-location atlas: filters / actions stacked controls ─────────────── */

/* `.controls` is the boxed filter row used across chapters. On the atlas we
   stack a second, lighter "actions" row directly under it so filters (what am
   I looking at) and actions (verbs) are visually separated. */
.controls.controls--actions {
  margin-top: -10px;
  padding-top: 8px;
  padding-bottom: 8px;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: 0.86rem;
}

/* ── Co-location atlas: map + list / detail split ──────────────────────── */

.atlas-split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 6px;
  align-items: stretch;
  position: relative;
}
@media (max-width: 900px) {
  .atlas-split { grid-template-columns: 1fr; }
}
.atlas-split > .map-frame { margin-top: 0; }
/* Detail pane shares the same grid slot as the list pane (column 2). When
   list is hidden + detail is visible, detail occupies column 2 alone. */
.atlas-split > .detail-pane { grid-column: 2; grid-row: 1; }
.atlas-split > .list-pane   { grid-column: 2; grid-row: 1; }
@media (max-width: 900px) {
  .atlas-split > .detail-pane,
  .atlas-split > .list-pane { grid-column: 1; grid-row: auto; }
}

.list-pane,
.detail-pane {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 720px;
  box-shadow: var(--shadow-sm);
}
/* Native [hidden] is `display: none` but our explicit `display: flex` above
   overrides it — restore the intent so toggling visibility from JS works. */
.list-pane[hidden],
.detail-pane[hidden] { display: none; }
@media (max-width: 900px) {
  .list-pane, .detail-pane { max-height: 70vh; }
}

.list-pane__header,
.detail-pane__header {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.list-pane__header h3,
.detail-pane__header h3 { margin: 0; }
.list-pane__header h3 { font-size: 1.05rem; }
.detail-pane__header h3 { font-size: 1.05rem; flex: 1 1 auto; min-width: 0; }

.list-sort {
  margin-left: auto;
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-mute);
}
.list-sort label { font-size: 0.78rem; color: var(--ink-mute); }
.list-sort select {
  font: inherit;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 0.82rem;
}
.sort-dir-btn {
  font: inherit;
  background: var(--bg);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 0.82rem;
  min-width: 26px;
}
.sort-dir-btn:hover { color: var(--ink); border-color: var(--ink-mute); }

.list-pane__cards {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.list-pane__cards .empty {
  font-size: 0.86rem;
  color: var(--ink-mute);
  padding: 24px 8px;
  text-align: center;
}

.plant-card {
  display: grid;
  grid-template-columns: auto auto 1fr;
  column-gap: 10px;
  row-gap: 4px;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 3px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  align-items: center;
}
.plant-card:hover {
  background: rgba(198, 74, 22, 0.04);
  border-color: var(--ink-mute);
  box-shadow: var(--shadow-sm);
}
.plant-card.selected {
  border-left-color: var(--accent);
  background: rgba(198, 74, 22, 0.08);
}
.plant-card .star-cell { grid-column: 1; }
.plant-card .score-cell { grid-column: 2; }
.plant-card .main-cell { grid-column: 3; min-width: 0; }
.plant-card .name {
  font-weight: 600;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.plant-card .sub-line {
  font-size: 0.76rem;
  color: var(--ink-mute);
  line-height: 1.3;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plant-card .sub-line .v {
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-variant-numeric: tabular-nums;
}
.plant-card .metrics-line {
  grid-column: 1 / -1;
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 0.74rem;
  color: var(--ink-mute);
  padding-top: 5px;
  margin-top: 2px;
  border-top: 1px dashed var(--rule);
}
.plant-card .metrics-line .m { color: var(--ink-mute); }
.plant-card .metrics-line .m strong {
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.detail-pane__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.back-btn {
  font: inherit;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  white-space: nowrap;
}
.back-btn:hover { color: var(--ink); border-color: var(--ink-mute); background: var(--bg); }

/* ── Co-location atlas: score chip, kv list, readiness banner, sort arrows ── */

.score-chip {
  display: inline-block;
  min-width: 36px;
  text-align: center;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
}

.row-selected td { background: rgba(198, 74, 22, 0.10) !important; }
.row-selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

#plant-table th.sortable { user-select: none; }
#plant-table th.sortable:hover { color: var(--ink); }
#plant-table th.sort-asc::after  { content: " ▲"; font-size: 0.65em; color: var(--accent); }
#plant-table th.sort-desc::after { content: " ▼"; font-size: 0.65em; color: var(--accent); }

.readiness-big {
  margin: 0 0 18px;
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
  color: var(--ink);
}
.readiness-big .big-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  opacity: 0.7;
}
.readiness-big .big-value {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1.05;
  margin-top: 4px;
}
.readiness-big .big-value small {
  font-size: 0.5em;
  opacity: 0.55;
  font-weight: 500;
  margin-left: 4px;
}

.kvh {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.92rem;
  font-weight: 600;
  margin: 14px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
}
dl.kv {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 14px;
  row-gap: 4px;
  margin: 0;
  font-size: 0.88rem;
}
dl.kv dt { color: var(--ink-mute); }
dl.kv dd { margin: 0; color: var(--ink); text-align: right; }
dl.kv dd.num { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }

.map .plant { transition: r 100ms ease, fill-opacity 100ms ease; }
.map .plant:hover { fill-opacity: 1; stroke: var(--ink); stroke-width: 1.4; }

/* ── Header data-as-of badge ────────────────────────────────────────────── */

.site-header .as-of {
  font-size: 0.78rem;
  color: var(--ink-mute);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  padding: 3px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg-card);
}
.site-header .as-of .dot {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--positive);
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
}

/* ── Pill toggles (mode switchers used across chapters) ──────────────────── */

.pill-toggle {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--bg);
  padding: 2px;
  gap: 2px;
}
.pill-toggle button {
  font: inherit;
  background: transparent !important;
  color: var(--ink-soft) !important;
  border: none !important;
  border-radius: 999px !important;
  padding: 4px 14px !important;
  cursor: pointer;
  font-size: 0.82rem !important;
  font-weight: 500;
  letter-spacing: 0;
  transition: background var(--transition), color var(--transition);
}
.pill-toggle button:hover { color: var(--ink) !important; background: rgba(0,0,0,0.04) !important; }
.pill-toggle button.on {
  background: var(--ink) !important;
  color: var(--bg-card) !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15) !important;
}
.pill-toggle button.on:hover { background: var(--accent) !important; }

label.ba-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.84rem;
  color: var(--ink-soft);
  cursor: pointer;
}
label.ba-toggle input[type="checkbox"] { accent-color: var(--accent); }

/* ── Pinned-county legend chips (Time Machine) ─────────────────────────── */

.pin-legend {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 8px 0 10px;
  min-height: 24px;
}
.pin-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--c, var(--accent));
  border-radius: 3px;
  padding: 3px 8px 3px 6px;
  font-size: 0.82rem;
  color: var(--ink);
  cursor: pointer;
  letter-spacing: 0;
}
.pin-chip .dot {
  display: inline-block; width: 8px; height: 8px;
  background: var(--c, var(--accent));
  border-radius: 50%;
}
.pin-chip .x {
  margin-left: 4px;
  color: var(--ink-mute);
  font-size: 0.9em;
}
.pin-chip:hover { border-color: var(--ink-mute); }
.pin-chip:hover .x { color: var(--accent); }

/* ── Sparkline grid (Time Machine) ──────────────────────────────────────── */

.sparkgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.spark-cell {
  font: inherit;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 8px 10px 5px;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.spark-cell:hover { border-color: var(--ink-mute); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.spark-cell.pinned {
  border-color: var(--c, var(--accent));
  box-shadow: inset 0 0 0 1px var(--c, var(--accent));
}
.spark-title {
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.spark-cell svg { display: block; width: 100%; height: 56px; }
.spark-foot {
  display: flex; justify-content: space-between;
  font-size: 0.72rem;
  color: var(--ink-mute);
  margin-top: 2px;
}
.spark-foot .num { color: var(--ink); font-family: "JetBrains Mono", monospace; }
.spark-foot .delta.pos { color: var(--accent); }
.spark-foot .delta.neg { color: var(--positive); }

/* ── Radar / parallel-coords for plant shortlist (Co-location Atlas) ─── */

.shortlist-panel {
  margin-top: 18px;
  padding: 18px 20px;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.shortlist-panel header {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 10px;
}
.shortlist-panel h3 { margin: 0; }
.shortlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.shortlist-card {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--c, var(--accent));
  border-radius: 3px;
  padding: 8px 10px;
  position: relative;
  font-size: 0.84rem;
}
.shortlist-card .name {
  font-weight: 600;
  font-family: "Source Serif 4", serif;
  margin-bottom: 2px;
  padding-right: 16px;
}
.shortlist-card .sub {
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-bottom: 8px;
}
.shortlist-card .close {
  position: absolute; top: 4px; right: 6px;
  background: none; border: none; color: var(--ink-mute);
  cursor: pointer; font-size: 1rem; line-height: 1;
}
.shortlist-card .close:hover { color: var(--accent); }
.shortlist-card .sl-bars { margin: 6px 0 4px; }
.sl-bar-row {
  display: grid;
  grid-template-columns: 82px 1fr 26px;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 0.78rem;
}
.sl-bar-label { color: var(--ink-soft); white-space: nowrap; }
.sl-bar-track {
  height: 8px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.sl-bar-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  opacity: 0.75;
}
.sl-bar-val {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  color: var(--ink);
  text-align: right;
}
.shortlist-card .score-line {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 2px;
}

button.star {
  background: none;
  border: none;
  color: var(--ink-mute);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
  line-height: 1;
}
button.star:hover { color: var(--accent); }
button.star.on { color: var(--accent); }

/* ── BA region overlay layer styling (Time Machine, Retirement Cliff) ──── */

.ba-overlay-layer .ba-region { mix-blend-mode: multiply; }
.ba-region {
  /* fill is set per element; transparent on counties without BA */
}

/* ── Small-multiples grid (Retirement Cliff mini-maps) ─────────────────── */

.minimaps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}
@media (max-width: 720px) { .minimaps { grid-template-columns: repeat(2, 1fr); } }
.minimap {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 4px 6px 2px;
  cursor: pointer;
  transition: border-color 120ms ease;
}
.minimap:hover { border-color: var(--ink-mute); }
.minimap.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.minimap .yr {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.minimap .tot {
  float: right;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--ink-mute);
}
.minimap svg { display: block; width: 100%; height: auto; }

/* ── Seasonal selector tabs (Generation Clock) ─────────────────────────── */

.season-tabs {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
  margin-right: 12px;
}
.season-tabs button {
  font: inherit;
  background: var(--bg) !important;
  color: var(--ink-soft) !important;
  border: none !important;
  border-right: 1px solid var(--rule) !important;
  border-radius: 0 !important;
  padding: 6px 14px !important;
  cursor: pointer;
  font-size: 0.82rem !important;
}
.season-tabs button:last-child { border-right: none !important; }
.season-tabs button:hover { background: var(--bg-card) !important; color: var(--ink) !important; }
.season-tabs button.on {
  background: var(--ink) !important;
  color: var(--bg-card) !important;
}

/* ── Screening page (county scatter) ───────────────────────────────────── */

.screen-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  margin-top: 18px;
}
@media (max-width: 900px) { .screen-grid { grid-template-columns: 1fr; } }

#scatter-svg { width: 100%; height: auto; display: block; }

.axis-pickers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 16px;
  margin-bottom: 10px;
}
.axis-pickers label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-mute); display: block; margin-bottom: 2px; }
.axis-pickers select { width: 100%; }

.pareto-list .pl-row {
  display: grid;
  grid-template-columns: 1fr 60px 60px;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.86rem;
  cursor: pointer;
}
.pareto-list .pl-row:hover { background: rgba(198, 74, 22, 0.06); }
.pareto-list .pl-row .num { font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; text-align: right; }

/* ── Marginal-fuel note (Generation Clock methodology callout) ─────────── */

.method-note {
  margin: 18px 0 6px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink-mute);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* ── Small responsive helpers ─────────────────────────────────────────── */

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.muted { color: var(--ink-mute); }
.pill-status {
  font-size: 0.74rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}

/* ── Lead paragraph refinement ────────────────────────────────────────── */

.lead {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

/* ── Custom scrollbar for list panes ──────────────────────────────────── */

.list-pane__cards,
.detail-pane__body {
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.list-pane__cards::-webkit-scrollbar,
.detail-pane__body::-webkit-scrollbar {
  width: 5px;
}
.list-pane__cards::-webkit-scrollbar-track,
.detail-pane__body::-webkit-scrollbar-track {
  background: transparent;
}
.list-pane__cards::-webkit-scrollbar-thumb,
.detail-pane__body::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 4px;
}
.list-pane__cards::-webkit-scrollbar-thumb:hover,
.detail-pane__body::-webkit-scrollbar-thumb:hover {
  background: var(--ink-mute);
}

/* ── Subtle page-load animation ───────────────────────────────────────── */

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero,
.takeaway,
.story-grid {
  animation: fadeInUp 0.5s ease both;
}
.hero { animation-delay: 0.05s; }
.takeaway { animation-delay: 0.15s; }
.story-grid { animation-delay: 0.2s; }

/* ── Focus styles ─────────────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Smooth transitions for interactive map features ──────────────────── */

.map .county {
  transition: fill 200ms ease;
}

/* ── Print tweaks ─────────────────────────────────────────────────────── */

@media print {
  .site-header, .site-footer, .controls, .next-story, .map-toolbar { display: none !important; }
  .shell { max-width: 100%; padding: 0; }
  .note, .takeaway { break-inside: avoid; }
  * { box-shadow: none !important; }
}
