:root {
  color-scheme: light;
  --page-bg: #f7f4ee;
  --surface: #fdfcfa;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --series-blue: #2a78d6;
  --series-orange: #eb6834;
  --series-gray: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page-bg: #141311;
    --surface: #1b1a18;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --series-blue: #3987e5;
    --series-orange: #d95926;
    --series-gray: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --success: #0ca30c;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --page-bg: #141311;
  --surface: #1b1a18;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --series-blue: #3987e5;
  --series-orange: #d95926;
  --series-gray: #898781;
  --border: rgba(255, 255, 255, 0.10);
  --success: #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body { font-size: 15px; line-height: 1.5; }

a { color: var(--series-blue); }

.site-header {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 8px;
}
.site-header h1 { font-size: clamp(24px, 4vw, 34px); margin: 0 0 6px; }
.site-header .subtitle { color: var(--text-secondary); margin: 0; font-size: 16px; max-width: 65ch; }

.controls-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--page-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
}
.controls-bar .control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.controls-bar select {
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
.controls-bar .hint { font-size: 11px; color: var(--muted); }
.units-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.units-toggle button {
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}
.units-toggle button[aria-pressed='true'] { background: var(--series-blue); color: #fff; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px 20px;
}
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card .subtitle { margin: 0 0 14px; color: var(--text-secondary); font-size: 13.5px; max-width: 75ch; }
.card .note { color: var(--muted); font-size: 12px; margin-top: 8px; }

.chart-root { width: 100%; }
.chart-root svg { display: block; overflow: visible; }
.chart-scroll { overflow-x: auto; overflow-y: hidden; }

.sub-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 12px; font-size: 13px; }
.sub-controls fieldset { border: none; padding: 0; margin: 0; display: flex; gap: 10px; align-items: center; }
.sub-controls legend { font-size: 12px; color: var(--text-secondary); padding: 0; margin-right: 4px; float: left; }
.sub-controls label { display: inline-flex; align-items: center; gap: 4px; color: var(--text-secondary); cursor: pointer; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.legend-line { width: 16px; height: 2px; display: inline-block; flex: none; }

.tooltip {
  position: fixed;
  z-index: 100;
  background: var(--text-primary);
  color: var(--page-bg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.45;
  pointer-events: none;
  max-width: 260px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
:root:not([data-theme='light']) .tooltip { background: #ffffff; color: #0b0b0b; }
:root[data-theme='dark'] .tooltip { background: #ffffff; color: #0b0b0b; }
.tooltip strong { font-weight: 700; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 10px; }
.tooltip .tt-title { font-weight: 700; margin-bottom: 3px; }

.axis text { fill: var(--muted); font-size: 11px; }
.axis path.domain, .axis line { stroke: var(--baseline); }
.gridline { stroke: var(--gridline); stroke-width: 1px; }

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 16px 0 4px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-tile .label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-tile .value { font-size: 26px; font-weight: 600; font-variant-numeric: proportional-nums; }
.stat-tile .value small { font-size: 14px; color: var(--text-secondary); font-weight: 400; }
.stat-tile .compare { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.stat-tile .compare .num { font-size: 22px; font-weight: 600; }
.stat-tile .compare .arrow { color: var(--muted); font-size: 14px; }
.stat-tile .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat-tile .swatch-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }

#short-answer { max-width: 75ch; }
#short-answer p { margin: 0 0 10px; }

.stale-notice {
  max-width: 75ch;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fbe9c8;
  border: 1px solid #d9a441;
  color: #5c4308;
  font-size: 13px;
  line-height: 1.5;
}

details.card summary { cursor: pointer; font-size: 19px; font-weight: 600; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: '▸ '; color: var(--muted); }
details.card[open] summary::before { content: '▾ '; }
details.card .details-body { margin-top: 12px; }
details.card .details-body h3 { font-size: 15px; margin: 16px 0 6px; }
details.card .details-body p { color: var(--text-secondary); font-size: 13.5px; }

table.data-table { border-collapse: collapse; width: 100%; min-width: 620px; font-size: 13px; }
table.data-table th, table.data-table td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data-table th:first-child, table.data-table td:first-child,
table.data-table th:nth-child(2), table.data-table td:nth-child(2) { text-align: left; }
table.data-table th { color: var(--text-secondary); font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; }
table.data-table th:hover { color: var(--text-primary); }
table.data-table th .sort-arrow { font-size: 10px; color: var(--muted); margin-left: 3px; }
table.data-table tbody tr:hover { background: var(--page-bg); }
table.data-table tbody tr.row-selected td:first-child { box-shadow: inset 3px 0 0 var(--series-orange); padding-left: 7px; }
.table-scroll { overflow-x: auto; }

.stats-table { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 12.5px; margin-top: 10px; }
.stats-table th, .stats-table td { padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table th { color: var(--text-secondary); font-weight: 600; }
.stats-table tr.current-row { background: color-mix(in srgb, var(--series-blue) 12%, transparent); font-weight: 600; }

button.btn {
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--series-blue);
  color: #fff;
  cursor: pointer;
}
button.btn:disabled { opacity: 0.5; cursor: default; }
button.btn.secondary { background: var(--surface); color: var(--text-primary); }

.two-col {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 820px) {
  .two-col { grid-template-columns: 1fr; }
}

.small-multiples { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.small-multiple h3 { font-size: 14px; margin: 0 0 2px; }
.small-multiple .sub { font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }

.calendar-scroll { overflow-x: auto; }

footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  color: var(--muted);
  font-size: 12.5px;
}

.year-picker { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.year-picker select { font: inherit; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text-primary); }

.slider-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--series-blue); }
.slider-row .slider-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 70px; text-align: right; }

.callout {
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-top: 14px;
}
.callout strong { color: var(--text-primary); }

.no-data-note { font-size: 12px; color: var(--muted); font-style: italic; }

/* --- selection UI ("Which years were you there?") --- */
.selection-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}
.selection-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-btn { padding: 6px 12px; font-size: 12.5px; }
#sel-copy-link.copied { background: var(--success); color: #fff; border-color: transparent; }

.year-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.year-chip {
  font: inherit;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: var(--page-bg);
  color: var(--text-primary);
  cursor: pointer;
}
.year-chip:hover:not(:disabled) { border-color: var(--series-blue); }
.year-chip.selected {
  background: var(--series-orange);
  border-color: var(--series-orange);
  color: #fff;
  font-weight: 600;
}
.year-chip.incomplete { border-style: dashed; }
.year-chip.not-held {
  background: repeating-linear-gradient(45deg, var(--gridline), var(--gridline) 3px, transparent 3px, transparent 7px);
  color: var(--muted);
  border-color: var(--border);
  cursor: not-allowed;
}
.selection-count { font-size: 13px; color: var(--text-secondary); margin: 4px 0 0; }

.personal-card {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--page-bg);
  border: 1px solid var(--border);
  max-width: 75ch;
}
.personal-card p { margin: 0 0 8px; font-size: 14px; color: var(--text-primary); }
.personal-card p:last-child { margin-bottom: 0; }
.personal-card h3 { color: var(--text-primary); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 480px) {
  .card { padding: 14px 14px 16px; }
  .controls-bar { gap: 10px; }
}
