:root {
  --bg: #f5f4f0; --surface: #ffffff; --surface-2: #f0eee8; --line: #e2dfd7; --ink: #151513; --muted: #5d5b55; --faint: #8c8a83;
  --accent: #2a78d6; --accent-ink: #ffffff; --good: #0c8a0c; --warn: #b26b00; --bad: #c23434;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111213; --surface: #1a1b1d; --surface-2: #232427; --line: #2e3033; --ink: #f0efec; --muted: #b3b1aa; --faint: #85837d;
    --accent: #4b93ea; --good: #3cc13c; --warn: #f0a63a; --bad: #ef6b6b; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111213; --surface: #1a1b1d; --surface-2: #232427; --line: #2e3033; --ink: #f0efec; --muted: #b3b1aa; --faint: #85837d;
  --accent: #4b93ea; --good: #3cc13c; --warn: #f0a63a; --bad: #ef6b6b; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100%; }
:root { --topbar-h: 57px; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; font-weight: 700; }
h3:first-child { margin-top: 4px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.freshness { font-size: 12px; color: var(--muted); }
.freshness::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 6px; vertical-align: 1px; }

.workspace { display: grid; grid-template-columns: 360px minmax(0, 1fr) 330px; gap: 0; height: calc(100vh - var(--topbar-h)); }
.panel { background: var(--surface); overflow-y: auto; min-height: 0; }
.controls { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.insight { border-left: 1px solid var(--line); padding: 16px; }
.steps { display: flex; position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 2; }
.steps button { flex: 1; border: 0; background: none; padding: 12px 2px; font-size: 12.5px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.steps button.active { color: var(--ink); border-bottom-color: var(--accent); }
.step-body { padding: 14px 16px 40px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px 16px; gap: 10px; }
.platforms { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.canvas-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#canvas { max-width: 100%; max-height: 100%; box-shadow: var(--shadow); border-radius: 6px; background: #fff; }
.transport { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 6px; max-width: 760px; width: 100%; margin: 0 auto; }
.transport input[type=range] { flex: 1; }
.play { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 14px; flex: none; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 70px; text-align: right; }

.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.chip:hover { border-color: var(--faint); }
.chip.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip small { opacity: .7; margin-left: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 8px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.ds-group { margin-bottom: 14px; }
.ds { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px; }
.ds:hover { border-color: var(--faint); }
.ds.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ds b { display: block; font-size: 13.5px; font-weight: 600; }
.ds span:not(.badge) { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.live { background: rgba(12,163,12,.14); color: var(--good); }

.lens { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.lens p { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chart-opt { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 10px; text-align: left; }
.chart-opt svg { width: 22px; height: 22px; stroke: var(--ink); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chart-opt b { display: block; font-size: 13px; margin-top: 4px; }
.chart-opt span { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.chart-opt.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.field { margin-bottom: 12px; }
.field > label, .field > .lbl { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.field > label output, .field .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=search], select, textarea { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 34px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--surface); }
.chk { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.chk.small { font-size: 12px; color: var(--muted); margin: 0; white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 12px; font-weight: 600; font-size: 13px; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.ghost { border: 1px solid var(--line); background: none; border-radius: 8px; width: 32px; height: 32px; }
.muted { color: var(--muted); font-size: 12.5px; }
.err { color: var(--bad); font-size: 12.5px; }

.theme-opt { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; overflow: hidden; background: none; text-align: left; }
.theme-opt .sw { height: 34px; display: flex; align-items: flex-end; gap: 3px; padding: 6px 8px; }
.theme-opt .sw i { width: 8px; border-radius: 2px 2px 0 0; }
.theme-opt b { display: block; font-size: 12px; padding: 5px 8px; }
.theme-opt.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pal { display: flex; align-items: center; gap: 10px; width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; margin-bottom: 5px; text-align: left; }
.pal.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pal .strip { display: flex; height: 14px; border-radius: 4px; overflow: hidden; flex: none; width: 110px; }
.pal .strip i { flex: 1; }
.pal b { font-size: 12.5px; font-weight: 600; flex: 1; }
.pal em { font-style: normal; font-size: 11px; color: var(--good); }
.pal em.warn { color: var(--warn); }

.results { margin-top: 10px; }
.result { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.result b { font-size: 13px; display: block; }
.result .meta { font-size: 11.5px; color: var(--muted); margin: 3px 0 6px; }
.result p { font-size: 12px; color: var(--muted); margin: 0 0 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mapper { background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin-top: 10px; }
.mapper table { width: 100%; font-size: 11.5px; border-collapse: collapse; margin-top: 8px; }
.mapper td, .mapper th { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }

.insight h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.headline { font-family: "Source Serif 4", Georgia, serif; font-size: 19px; line-height: 1.35; font-weight: 600; margin: 0 0 12px; }
.facts { list-style: none; padding: 0; margin: 0 0 14px; }
.facts li { padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.howto { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; font-size: 12.5px; margin-bottom: 18px; }
.howto b { display: block; margin-bottom: 4px; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { display: grid; grid-template-columns: 20px 1fr; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.checks li b { display: block; font-size: 13px; }
.checks li p { margin: 2px 0 0; color: var(--muted); }
.checks .ic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; margin-top: 1px; }
.ic.pass { background: var(--good); } .ic.warn { background: var(--warn); } .ic.info { background: var(--faint); }
.checks button { margin-top: 6px; }
.trust-score { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; font-size: 12.5px; color: var(--muted); }
.trust-score b { font-size: 22px; color: var(--ink); }
.data-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.data-table td, .data-table th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.data-table td:last-child, .data-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; padding: 8px 0; }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 13px; transition: transform .25s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }

/* Layout adapts to the space it gets, not to named devices: wide foldable or tablet
   screens get side-by-side panels; phones get a stacked flow with the preview on top. */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 340px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: auto; min-height: calc(100vh - var(--topbar-h)); }
  .controls { grid-row: 1 / 3; max-height: calc(100vh - var(--topbar-h)); position: sticky; top: var(--topbar-h); }
  .stage { height: calc(100vh - var(--topbar-h) - 40px); min-height: 520px; }
  .insight { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .workspace { display: flex; flex-direction: column; }
  .stage { order: 1; height: auto; min-height: 0; padding: 10px 16px; position: sticky; top: var(--topbar-h); z-index: 3; background: var(--bg); }
  .canvas-wrap { height: 42vh; flex: none; }
  .controls { order: 2; max-height: none; position: static; border-right: 0; }
  .insight { order: 3; }
  .platforms { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; padding-bottom: 2px; }
  .platforms .chip { flex: none; }
  .brand span { display: none; }
  .freshness { display: none; }
}

/* ---------- sources & states ---------- */
.state-pick { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 6px; }
.state-pick label { font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.state-pick select { flex: 1; min-width: 0; }
.state-note { margin: 0 0 10px; }
.topic-chips, .scope-chips { margin: 0 0 12px; }
.tier-desc { margin: -4px 0 8px; }
.badge.tier-federal { background: rgba(42,120,214,.14); color: var(--accent); }
.badge.tier-state { background: rgba(27,175,122,.15); color: var(--good); }
.badge.tier-local { background: rgba(27,175,122,.10); color: var(--good); }
.badge.tier-academic { background: rgba(98,80,214,.14); color: #6250d6; }
.badge.tier-nonprofit { background: rgba(98,80,214,.10); color: #6250d6; }
.badge.tier-industry { background: rgba(235,104,52,.15); color: var(--warn); }
.badge.tier-international { background: var(--surface-2); color: var(--muted); }
:root[data-theme="dark"] .badge.tier-academic, :root[data-theme="dark"] .badge.tier-nonprofit { color: #9085e9; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.tier-academic, :root:not([data-theme="light"]) .badge.tier-nonprofit { color: #9085e9; } }
.ds .local { display: inline-block; margin-top: 4px; font-size: 11.5px; font-weight: 600; color: var(--good); }
.portal-list { display: grid; gap: 6px; margin-bottom: 8px; }
.portal { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-decoration: none; color: inherit; }
.portal:hover { border-color: var(--faint); }
.portal b { display: block; font-size: 13px; }
.portal span { font-size: 11.5px; color: var(--muted); }
.src { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 6px; overflow: hidden; }
.src.open { border-color: var(--faint); }
.src-head { display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: var(--surface); padding: 10px 12px; text-align: left; }
.src-head b { flex: 1; font-size: 13px; }
.src-head span:last-child { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.src-body { padding: 0 12px 12px; font-size: 12.5px; }
.src-body p { margin: 0 0 8px; }
.src-body .disclose { background: rgba(235,104,52,.10); border-radius: 6px; padding: 8px 10px; }
.state-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; margin-bottom: 6px; }
.state-cell { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 5px 2px; text-align: center; }
.state-cell b { display: block; font-size: 12.5px; }
.state-cell span { display: block; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.state-cell.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; font-size: inherit; }
.result .meta .badge { margin-left: 0; margin-right: 4px; }

/* ---------- overlay / compare ---------- */
.cmp-box { background: var(--surface-2); border-radius: var(--radius); padding: 10px; margin-bottom: 6px; }
.cmp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.cmp-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; font-weight: 600; }
.cmp-chip.main { padding-right: 10px; border-color: var(--accent); }
.cmp-chip button { border: 0; background: var(--surface-2); border-radius: 50%; width: 20px; height: 20px; font-size: 11px; line-height: 1; }
.cmp-list { max-height: 360px; overflow-y: auto; }
.cmp { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; margin-bottom: 5px; }
.cmp b { display: block; font-size: 12.5px; }
.cmp span { display: block; font-size: 11.5px; color: var(--muted); }
.cmp.ok:hover { border-color: var(--accent); }
.cmp.no { opacity: .75; background: none; }
.howto.fit { border-left: 3px solid var(--accent); }

.local-state { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 5px; }
.local-state summary { font-size: 13px; }
.local-state .portal-list { margin-top: 8px; }

/* ---------- claim check ---------- */
.ic.block { background: var(--bad); }
.trust-score .bad { color: var(--bad); }
.integrity { border: 1px solid var(--bad); background: rgba(194,52,52,.07); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px; }
.integrity > b { display: block; color: var(--bad); margin-bottom: 6px; font-size: 13px; }
.integrity p { margin: 6px 0; }
.integrity .btn { margin-bottom: 4px; }
.cap-tabs { margin-bottom: 6px; }

/* ---------- presentation exports ---------- */
.export-grid { display: grid; gap: 6px; }
.export-grid .btn { text-align: left; display: block; width: 100%; }
.export-grid .btn small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------- embed mode (?embed=1): chart only, with live-data provenance ---------- */
body.embed { background: var(--bg); }
body.embed .topbar, body.embed .controls, body.embed .insight, body.embed #platforms, body.embed .transport .chk, body.embed .toast { display: none; }
body.embed .workspace { display: block; height: 100vh; min-height: 0; }
body.embed .stage { height: 100vh; min-height: 0; padding: 0; gap: 6px; position: static; }
body.embed .canvas-wrap { flex: 1; height: auto; }
body.embed #canvas { box-shadow: none; border-radius: 0; }
body.embed .transport { padding: 2px 10px 2px 2px; border: 0; background: none; }
.embed-bar { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; font-size: 11.5px; color: var(--muted); padding: 0 8px 6px; }
.embed-bar a { color: var(--accent); text-decoration: none; font-weight: 600; }
.embed-warn { flex-basis: 100%; color: var(--bad); font-weight: 600; }

/* ---------- popular questions & ready-made search ---------- */
.pop-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.pop { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.pop:hover { border-color: var(--accent); }
.pop.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.pop b { font-size: 14px; line-height: 1.3; }
.pop-val { font-size: 13px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.pop-src { font-size: 11.5px; color: var(--muted); }
.search-filters { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.search-filters .chips { margin: 0; }
.search-filters select { flex: 1; min-width: 0; }
.local-count { margin: 4px 0 6px; }
@media (min-width: 761px) and (max-width: 1180px) { .pop-grid { grid-template-columns: 1fr; } }
