:root {
  --bg: #f7f7f5; --surface: #ffffff; --surface-2: #f0f0ed; --text: #1c1d1f; --muted: #5d6068;
  --border: #dcdcd6; --accent: #1f4e79; --accent-soft: #e3ecf5; --focus: #2b6cb0;
  --b-match-bg: #e2f2e6; --b-match-fg: #1d5e2f; --b-differs-bg: #fbeed3; --b-differs-fg: #7a4c00;
  --b-subset-bg: #e1ecf8; --b-subset-fg: #1f4e79; --b-ns-bg: #ebebea; --b-ns-fg: #4a4c52;
  --b-muted-fg: #5d6068; --g-a-bg: #2f6b3d; --g-b-bg: #9a6100; --g-c-fg: #5d6068;
  --f-high: #a3361f; --f-med: #7a5a00; --f-low: #5d6068;
  --control-border: #858890;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517; --surface: #1c1d20; --surface-2: #24262a; --text: #e8e8e6; --muted: #a2a5ad;
    --border: #34363b; --accent: #8fb8e3; --accent-soft: #1e2b3a; --focus: #8fb8e3;
    --b-match-bg: #183322; --b-match-fg: #9bd8ab; --b-differs-bg: #3a2c10; --b-differs-fg: #f0c674;
    --b-subset-bg: #1a2b3f; --b-subset-fg: #9cc3ec; --b-ns-bg: #2a2c30; --b-ns-fg: #c2c4ca;
    --b-muted-fg: #a2a5ad; --g-a-bg: #357a48; --g-b-bg: #8f6200; --g-c-fg: #a2a5ad;
    --f-high: #f08c74; --f-med: #e2c46a; --f-low: #a2a5ad; --control-border: #767980; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141517; --surface: #1c1d20; --surface-2: #24262a; --text: #e8e8e6; --muted: #a2a5ad;
  --border: #34363b; --accent: #8fb8e3; --accent-soft: #1e2b3a; --focus: #8fb8e3;
  --b-match-bg: #183322; --b-match-fg: #9bd8ab; --b-differs-bg: #3a2c10; --b-differs-fg: #f0c674;
  --b-subset-bg: #1a2b3f; --b-subset-fg: #9cc3ec; --b-ns-bg: #2a2c30; --b-ns-fg: #c2c4ca;
  --b-muted-fg: #a2a5ad; --g-a-bg: #357a48; --g-b-bg: #8f6200; --g-c-fg: #a2a5ad;
  --f-high: #f08c74; --f-med: #e2c46a; --f-low: #a2a5ad; --control-border: #767980; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, .brand:focus, input:focus-visible, select:focus-visible, summary:focus-visible, tr:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 50; background: var(--surface); color: var(--accent); border: 2px solid var(--focus); border-radius: 6px; padding: 6px 12px; }
.skip-link:focus { top: 8px; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding-top: 12px; padding-bottom: 12px; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.nav a { color: var(--muted); text-decoration: none; font-size: 14px; padding: 4px 0; }
.nav a[aria-current="page"] { color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.header-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.dataset-meta { font-size: 12px; color: var(--muted); }
.theme-toggle { gap: 6px; min-height: 32px; padding: 4px 10px; font-size: 13px; }
.theme-toggle[data-current="dark"] .i-moon, .theme-toggle[data-current="light"] .i-sun { display: none; }
main { padding: 20px 0 48px; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 18px 0 6px; }
.lede { color: var(--muted); margin: 0 0 16px; max-width: 75ch; }
.site-footer { border-top: 1px solid var(--border); padding: 12px 0 72px; color: var(--muted); font-size: 13px; }
.site-footer p { margin: 8px 0; max-width: 110ch; }
.about-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* back to top */
.to-top { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; min-height: 40px;
  background: var(--surface); color: var(--text); border: 1px solid var(--control-border); border-radius: 999px; box-shadow: 0 4px 14px rgba(0,0,0,.18); text-decoration: none; font-size: 14px; }
.to-top:hover { background: var(--surface-2); }
.to-top:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .to-top { animation: to-top-in .15s ease-out; }
  @keyframes to-top-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0 0; overflow-x: auto; }
.tab { appearance: none; border: 0; background: none; padding: 10px 12px; font: inherit; font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tab .count { color: var(--muted); font-weight: 400; margin-left: 4px; }
.section-desc { color: var(--muted); font-size: 14px; margin: 10px 0 0; max-width: 80ch; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 16px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.card .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .v { font-size: 22px; font-weight: 650; margin-top: 2px; }
.card .d { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* filters */
.filters { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--border); }
.btn.filters-toggle { display: none; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-row input[type="search"], .filter-row select, .ms > summary {
  font: inherit; font-size: 14px; background: var(--surface); color: var(--text); border: 1px solid var(--control-border); border-radius: 6px; padding: 6px 10px; min-height: 34px; }
.filter-row input[type="search"] { min-width: 220px; flex: 1 1 220px; max-width: 320px; }
.ms { position: relative; }
.ms > summary { list-style: none; cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 6px; }
.ms > summary::-webkit-details-marker { display: none; }
.ms > summary::after { content: "▾"; font-size: 11px; color: var(--muted); }
.ms[data-active="true"] > summary { border-color: var(--accent); background: var(--accent-soft); }
.ms .panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 10; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 8px; min-width: 220px; max-height: 320px; overflow: auto; }
.ms .panel label { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 4px; font-size: 14px; cursor: pointer; }
.ms .panel label:hover { background: var(--surface-2); }
.ms .panel .n { margin-left: auto; color: var(--muted); font-size: 12px; }
.btn { font: inherit; font-size: 14px; border: 1px solid var(--control-border); background: var(--surface); color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; min-height: 34px; text-decoration: none; display: inline-flex; align-items: center; }
.btn:hover { background: var(--surface-2); }
.result-line { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin: 12px 0 8px; font-size: 14px; color: var(--muted); }

/* badges */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; line-height: 1.5; }
button.badge { cursor: pointer; font-family: inherit; }
.badge.s-match { background: var(--b-match-bg); color: var(--b-match-fg); }
.badge.s-differs { background: var(--b-differs-bg); color: var(--b-differs-fg); }
.badge.s-subset { background: var(--b-subset-bg); color: var(--b-subset-fg); }
.badge.s-not_spending { background: var(--b-ns-bg); color: var(--b-ns-fg); }
.badge.s-muted { background: transparent; color: var(--b-muted-fg); border-color: var(--border); }
.grade { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 6px; font-weight: 700; font-size: 13px; border: 1px solid transparent; cursor: pointer; font-family: inherit; }
.grade.g-A { background: var(--g-a-bg); color: #fff; }
.grade.g-B { background: var(--g-b-bg); color: #fff; }
.grade.g-C { background: transparent; color: var(--g-c-fg); border-color: var(--border); }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; margin: 1px 6px 1px 0; }
.flag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.flag.p-high { color: var(--f-high); font-weight: 600; }
.flag.p-medium { color: var(--f-med); }
.flag.p-low { color: var(--f-low); }
.tag { display: inline-block; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: 1px; }

/* table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
th.r, td.r { text-align: right; }
th button.sort { all: unset; cursor: pointer; }
th button.sort:focus-visible { outline: 2px solid var(--focus); }
th[aria-sort="ascending"] button.sort::after { content: " ▲"; }
th[aria-sort="descending"] button.sort::after { content: " ▼"; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.name a { color: var(--text); font-weight: 600; text-decoration: none; }
td.name a:hover { text-decoration: underline; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* detail */
.crumbs { font-size: 14px; margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.detail-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 4px; }
.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 16px 0; }
.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.kv > div { padding: 8px 12px; border-bottom: 1px solid var(--border); min-width: 0; overflow-wrap: anywhere; }
.kv > .k { color: var(--muted); font-size: 13px; background: var(--surface-2); }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.note { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.note.warn { border-left-color: var(--f-high); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.history .h { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.prose { max-width: 78ch; }
.prose p, .prose li { margin: 6px 0; }
code { font-size: 13px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
.hash { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }

/* political timeline */
.tl-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px; margin: 16px 0; }
.tl-cell { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; text-decoration: none; color: var(--text); }
.tl-cell:hover { background: var(--surface-2); }
.tl-c { font-weight: 650; }
.tl-y, .tl-n { font-size: 12px; color: var(--muted); }
.tl-period { margin-bottom: 8px; scroll-margin-top: 12px; }
.tl-period h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.tl-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.tl-filters { margin: 4px 0 8px; }
.tl-filters label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.tl-gaps { margin: 6px 0 0; padding-left: 20px; }
.tl-gaps li { margin: 4px 0; }
#figures, #no-period { scroll-margin-top: 12px; }

/* opportunity cost */
.oc-bases td:first-child { min-width: 260px; max-width: 420px; }
.oc-id { font-weight: 700; color: var(--text); margin-left: 0; }

/* mobile: stacked cards */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .header-end { margin-left: 0; width: 100%; justify-content: space-between; }
  .to-top span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .to-top { padding: 0; width: 44px; height: 44px; justify-content: center; }
  .filters { position: static; }
  .btn.filters-toggle { display: inline-flex; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 10px; }
  .card .v { font-size: 19px; }
  h1 { font-size: 21px; }
  .filters .filter-row { display: none; margin-top: 8px; }
  .filters.open .filter-row { display: flex; }
  .filter-row input[type="search"] { max-width: none; flex-basis: 100%; }
  .ms .panel { position: static; box-shadow: none; margin-top: 4px; }
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr.row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 10px 12px; }
  table.list td { border: 0; padding: 3px 0; display: flex; gap: 12px; justify-content: space-between; text-align: right; }
  table.list td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  table.list td.name { display: block; text-align: left; font-size: 16px; padding-bottom: 6px; }
  table.list td.name::before { content: none; }
  table.list td .cv { min-width: 0; }
  table.list td.id { display: none; }
  table.list td:empty, table.list td:has(> .cv:empty) { display: none; }
  .kv { grid-template-columns: 1fr; }
  .kv > .k { border-bottom: 0; padding-bottom: 0; background: none; }
  .simple-table thead { display: none; }
  .simple-table, .simple-table tbody, .simple-table tr, .simple-table td { display: block; width: 100%; }
  .simple-table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .simple-table td { border: 0; padding: 2px 10px; }
  .simple-table td::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
  .tl-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tl-filters label { flex: 1 1 100%; justify-content: space-between; }
  .tl-filters select { flex: 1; }
  .oc-bases td:first-child { min-width: 0; max-width: none; }
  .simple-table td.r { text-align: left; }
}
