/* State Budget Resilience Monitor. Self-contained layout on top of theme.css,
   so the page still works if web fonts fail to load. */
:root {
  --sb-scn: #1F3D73; --sb-pub: #B9C3D0; --sb-neg: #B04B37; --sb-pos: #2F7A62;
  --mx-gst: #1F3D73; --mx-otherGrants: #6F8FC4; --mx-payroll: #2F7A62; --mx-duty: #C08A2E;
  --mx-otherTax: #9DB8AE; --mx-royalties: #8B5A3C; --mx-other: #CBD3DD;
}
[data-theme="dark"] {
  --sb-scn: #A9C1EE; --sb-pub: #4A5870; --sb-neg: #F1A18C; --sb-pos: #7FCBB0;
  --mx-gst: #A9C1EE; --mx-otherGrants: #6E86B3; --mx-payroll: #6FBFA3; --mx-duty: #E0B567;
  --mx-otherTax: #5D7C72; --mx-royalties: #C9926E; --mx-other: #3A4558;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--surface); }
a { color: var(--accent); }
.sb-wrap, .more-projects { width: min(1160px, calc(100% - 48px)); margin-inline: auto; }
.skip-link { position: absolute; left: 1rem; top: -100px; z-index: 1100; padding: .6rem; background: var(--surface); }
.skip-link:focus { top: .5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* Hero */
.sb-hero { padding: 64px 0 30px; }
.eyebrow, .section-number { text-transform: uppercase; font-size: .72rem; font-weight: 600; letter-spacing: .12em; color: var(--muted); }
.eyebrow { display: flex; align-items: center; gap: 10px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sb-pos); }
.sb-hero h1 { font-size: clamp(3.1rem, 7vw, 5.5rem); line-height: .99; margin: 22px 0; letter-spacing: -.045em; }
.hero-deck { font-size: clamp(1rem, 2vw, 1.2rem); line-height: 1.65; color: var(--soft); margin: 0 0 24px; max-width: 70ch; }
.hero-meta { display: flex; gap: 24px; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
.hero-meta span + span { border-left: 1px solid var(--line); padding-left: 24px; }
.sb-wrap h2 { font-family: "Newsreader", Georgia, serif !important; font-weight: 400; font-size: 1.9rem; margin: 8px 0 14px; }

/* How to use */
.how-to { border-block: 1px solid var(--line); padding: 18px 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: center; }
.how-to ol { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; counter-reset: step; }
.how-to li { font-size: .86rem; color: var(--soft); line-height: 1.55; counter-increment: step; padding-left: 30px; position: relative; }
.how-to li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .72rem; font-weight: 600; display: grid; place-items: center; }
.how-to strong { color: var(--ink); font-weight: 600; }
.how-note { margin: 0; font-size: .75rem; color: var(--muted); max-width: 24ch; }

/* Glossary terms and the pop-up */
.term { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: help; text-align: inherit;
  text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.term:hover, .term[aria-expanded="true"] { text-decoration-color: var(--accent); color: var(--accent); }
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.term-plain { text-decoration-color: transparent; }
.term-pop { position: absolute; z-index: 1200; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 14px 34px rgba(20, 35, 58, .18); padding: 14px 16px; font-size: .84rem; line-height: 1.55; }
[data-theme="dark"] .term-pop { box-shadow: 0 14px 34px rgba(0, 0, 0, .5); }
.term-pop strong { display: block; font-size: .8rem; margin-bottom: 4px; color: var(--accent); }

/* Choose */
.pick { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin: 44px 0 22px; }
.pick-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chip { font: inherit; font-size: .9rem; font-weight: 500; min-width: 54px; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.chip:hover { border-color: var(--muted); }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.jur-select { display: none; width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line); padding: 12px 16px; border-radius: 8px; font: inherit; }

/* Baseline */
.baseline { border-top: 1px solid var(--line); padding-top: 26px; }
.baseline-head h3 { font-size: 1.2rem; margin: 0 0 4px; }
.small-note { color: var(--muted); font-size: .8rem; line-height: 1.6; margin: 4px 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; margin: 22px 0 18px; }
.stat { padding-left: 18px; border-left: 1px solid var(--line); }
.stat:first-child { padding-left: 0; border-left: 0; }
.stat > span { display: block; color: var(--muted); font-size: .78rem; }
.stat strong { display: block; font-size: 2rem; font-weight: 500; letter-spacing: -.035em; margin: 5px 0; font-variant-numeric: tabular-nums; }
.stat small { display: block; font-size: .74rem; color: var(--muted); line-height: 1.45; }
.negative { color: var(--sb-neg); }
.j-note { font-size: .8rem; color: var(--soft); border-left: 3px solid var(--accent); padding: 8px 14px; background: var(--track); border-radius: 0 6px 6px 0; line-height: 1.6; }
.mix { margin: 26px 0 40px; }
.mix-head h3 { font-size: .95rem; margin: 0; }
.mix-bar { display: flex; height: 22px; border-radius: 5px; overflow: hidden; margin: 14px 0 12px; background: var(--track); }
.mx { display: block; height: 100%; }
.mx + .mx { box-shadow: inset 2px 0 0 var(--surface); }
.mx-gst { background: var(--mx-gst); } .mx-otherGrants { background: var(--mx-otherGrants); } .mx-payroll { background: var(--mx-payroll); }
.mx-duty { background: var(--mx-duty); } .mx-otherTax { background: var(--mx-otherTax); } .mx-royalties { background: var(--mx-royalties); } .mx-other { background: var(--mx-other); }
.mix-legend { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 22px; }
.mix-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 8px; align-items: baseline; font-size: .8rem; }
.mix-legend .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.mx-val { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Scenario layout */
.scenario-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 40px; align-items: start; }
.scenario-layout > * { min-width: 0; }
.controls { border: 1px solid var(--line); border-radius: 12px; padding: 24px; background: var(--track); position: sticky; top: calc(var(--hdr-h, 64px) + var(--bar-h, 0px) + 12px); max-height: calc(100vh - var(--hdr-h, 64px) - var(--bar-h, 0px) - 24px); overflow-y: auto; overscroll-behavior: contain; transition: top .2s; }
.controls h2 { font-size: 1.55rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { float: none; width: auto; line-height: 1.4; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: 0; margin-bottom: 4px; }
.presets { margin: 18px 0 6px; }
.preset-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.preset { font: inherit; font-size: .78rem; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.preset:hover { border-color: var(--muted); }
.preset.on { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.preset-desc { font-size: .76rem; color: var(--soft); line-height: 1.5; min-height: 2.3em; margin: 10px 0 0; }
.group { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; }
.control { margin-top: 14px; padding: 2px 0; }
.control label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: .85rem; font-weight: 500; }
.val { display: inline-flex; align-items: baseline; gap: 3px; flex-shrink: 0; }
.num { width: 64px; font: inherit; font-size: .84rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; -moz-appearance: textfield; }
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.unit { font-size: .74rem; color: var(--muted); }
.control.down .num { color: var(--sb-neg); border-color: color-mix(in srgb, var(--sb-neg) 45%, var(--line)); }
.control.up .num { color: var(--sb-pos); border-color: color-mix(in srgb, var(--sb-pos) 45%, var(--line)); }
.panel-lead { font-size: .82rem; line-height: 1.55; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 4px 0 8px; }
.scale { position: relative; display: flex; justify-content: space-between; font-size: .64rem; line-height: 1.2; color: var(--muted); margin: 0 0 4px; padding-top: 10px; }
.sc-zero { position: absolute; top: 0; width: 2px; height: 7px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.sc-zt { position: absolute; top: 10px; transform: translateX(-50%); font-weight: 600; color: var(--ink); }
.control input[type="range"] { width: 100%; margin: 10px 0 0; accent-color: var(--accent); cursor: pointer; }
.control p { font-size: .72rem; color: var(--muted); line-height: 1.5; margin: 2px 0 0; }
.advanced { margin-top: 16px; }
.advanced summary { font-size: .8rem; cursor: pointer; color: var(--soft); }
.form-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 20px; }
.quiet-button { background: none; color: var(--accent); border: 0; border-bottom: 1px solid var(--line); padding: 4px 0; font: inherit; font-size: .8rem; cursor: pointer; text-align: left; }
.quiet-button:hover { border-color: var(--accent); }
.share-status { font-size: .75rem; color: var(--sb-pos); min-height: 1.2em; margin: 6px 0 0; }

/* Results */
.result-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.result-heading h2 { font-size: 1.75rem; }
.scenario-tag { white-space: nowrap; font-size: .72rem; font-weight: 600; border: 1px solid var(--line); border-radius: 20px; padding: 4px 11px; color: var(--accent); }
.verdict { font-size: 1.05rem; line-height: 1.6; color: var(--ink); margin: 6px 0 0; max-width: 70ch; }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; border-block: 1px solid var(--line); padding: 20px 0; margin: 20px 0 24px; }
.result-grid span { display: block; color: var(--muted); font-size: .76rem; }
.result-grid strong { display: block; font-size: clamp(1.5rem, 2.6vw, 2.1rem); font-weight: 500; letter-spacing: -.035em; margin: 6px 0; font-variant-numeric: tabular-nums; }
.result-grid small { display: block; font-size: .72rem; color: var(--muted); line-height: 1.45; }
.chart-block { margin: 6px 0 22px; }
.chart-title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.chart-title-row h3 { font-size: .9rem; margin: 0; }
.chart-key { display: flex; gap: 18px; font-size: .74rem; color: var(--muted); }
.chart-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart-key i.line { height: 3px; width: 16px; vertical-align: 2px; }
.k-pub { background: var(--sb-pub); } .k-scn { background: var(--sb-scn); }
.chart { display: block; width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-zero { stroke: var(--muted); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.c-label { fill: var(--sb-scn); font-size: 12px; font-weight: 600; }
.b-pub { fill: var(--sb-pub); } .b-scn { fill: var(--sb-scn); } .b-scn.neg { fill: var(--sb-neg); }
.l-pub { fill: none; stroke: var(--sb-pub); stroke-width: 2.5; stroke-dasharray: 6 5; }
.l-scn { fill: none; stroke: var(--sb-scn); stroke-width: 2.5; }
.p-scn { fill: var(--sb-scn); }
.drivers { margin-top: 10px; }
.drivers h3 { font-size: .9rem; margin: 0; }
.driver { display: grid; grid-template-columns: 140px minmax(0, 1fr) 84px; gap: 12px; align-items: center; font-size: .8rem; margin: 10px 0; }
.driver-track { position: relative; height: 10px; background: var(--track); border-radius: 3px; }
.driver-track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.driver-track i { position: absolute; top: 0; height: 100%; border-radius: 3px; }
.driver-track i.neg, .cmp-track i.neg { background: var(--sb-neg); }
.driver-track i.pos, .cmp-track i.pos { background: var(--sb-pos); }
.driver strong { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.driver.total { border-top: 1px solid var(--line); padding-top: 10px; font-weight: 600; }
.driver.total strong { font-weight: 600; }
.empty-note { font-size: .82rem; color: var(--muted); }
.table-details { border-top: 1px solid var(--line); margin: 22px 0 12px; padding-top: 12px; }
summary { cursor: pointer; color: var(--ink); font-size: .86rem; font-weight: 500; }
.table-scroll { max-width: 100%; overflow-x: auto; margin: 14px 0; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; text-align: left; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: .72rem; color: var(--muted); font-weight: 500; }
td { font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { padding-left: 0; }
caption { text-align: left; padding: 8px 0; color: var(--muted); font-size: .75rem; caption-side: top; }
tr.on th, tr.on td { background: var(--accent-soft); }

/* Compare */
.compare, .method-section, .sources-section { margin-top: 64px; border-top: 1px solid var(--line); padding-top: 32px; }
.section-deck { font-size: .9rem; color: var(--soft); max-width: 88ch; line-height: 1.65; }
.compare-chart { display: grid; gap: 4px; margin: 20px 0 10px; max-width: 760px; }
.cmp { display: grid; grid-template-columns: 56px minmax(0, 1fr) 70px; gap: 12px; align-items: center; font: inherit; font-size: .84rem; color: var(--ink);
  background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; cursor: pointer; text-align: left; }
.cmp:hover { border-color: var(--line); }
.cmp.on { background: var(--accent-soft); }
.cmp-name { font-weight: 600; }
.cmp-track { position: relative; height: 14px; background: var(--track); border-radius: 3px; }
.cmp-track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.cmp-track i { position: absolute; top: 0; height: 100%; border-radius: 3px; }
.cmp-val { text-align: right; font-variant-numeric: tabular-nums; }

/* Method and sources */
.method-section details, .source { border-bottom: 1px solid var(--line); padding: 16px 0; }
.method-section p, .method-section li { font-size: .9rem; color: var(--soft); max-width: 88ch; line-height: 1.65; }
.method-section details p:first-of-type { margin-top: 14px; }
.source summary { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.source summary span { font-size: .78rem; color: var(--muted); font-weight: 400; }
.source p, .source li { font-size: .8rem; color: var(--soft); line-height: 1.6; }
.source ul { padding-left: 18px; margin: 6px 0 0; }
.hash { display: block; color: var(--muted); font-size: .7rem; word-break: break-all; margin-top: 4px; }
.downloads { display: flex; flex-wrap: wrap; gap: 12px 24px; margin: 26px 0; font-size: .8rem; }
.sb-footer { border-top: 1px solid var(--line); padding-block: 24px; font-size: .75rem; margin-top: 50px; color: var(--muted); }
.error { border-left: 3px solid var(--sb-neg); padding: 12px; background: var(--track); }

/* History buttons under sliders and the colour key they share with presets */
.hk { display: inline-block; font-size: .64rem; font-weight: 600; letter-spacing: .02em; padding: 1px 6px; border-radius: 4px; margin-left: 6px; vertical-align: 1px; }
.hk-bad { background: color-mix(in srgb, var(--mx-duty) 22%, transparent); color: var(--ink); }
.hk-worst { background: color-mix(in srgb, var(--sb-neg) 22%, transparent); color: var(--ink); }
.hk-good { background: color-mix(in srgb, var(--sb-pos) 20%, transparent); color: var(--ink); }
.preset .hk { margin-left: 6px; }
.preset.on .hk { background: rgba(255, 255, 255, .22); color: inherit; }
.preset:disabled { opacity: .45; cursor: not-allowed; }
.preset-key { font-size: .7rem; color: var(--muted); margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; }
.preset-key .hk { margin: 0; justify-self: start; }
.hist { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 6px; margin-top: 6px; }
.hist-label { font-size: .68rem; color: var(--muted); width: 100%; }
.hist-btn { font: inherit; font-size: .7rem; font-weight: 500; padding: 3px 8px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; color: var(--ink); font-variant-numeric: tabular-nums; }
.hist-btn.hk-bad { background: color-mix(in srgb, var(--mx-duty) 18%, transparent); }
.hist-btn.hk-worst { background: color-mix(in srgb, var(--sb-neg) 16%, transparent); }
.hist-btn.hk-good { background: color-mix(in srgb, var(--sb-pos) 15%, transparent); }
.hist-btn:hover { border-color: var(--muted); }
.hist-none { font-size: .7rem; color: var(--muted); }

/* Sticky summary bar under the site header */
.sb-bar { position: sticky; top: var(--hdr-h, 64px); z-index: 990; background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); box-shadow: 0 6px 18px rgba(20, 35, 58, .06); }
.sb-bar-in { display: flex; align-items: center; gap: 14px; min-height: 48px; font-size: .82rem; }
.bar-jur { font: inherit; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; max-width: 220px; }
.bar-scn { color: var(--accent); font-weight: 500; white-space: nowrap; }
.bar-out { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-out .bar-lab, .bar-out .bar-chg { color: var(--muted); }
.bar-out .bar-chg, .bar-out strong { white-space: nowrap; }
.bar-link { white-space: nowrap; font-weight: 500; }

/* Tables: header row and first column stay put while scrolling */
.table-scroll { max-height: none; }
.sticky-head thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.table-scroll th[scope="row"], .table-scroll thead th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.table-scroll thead th:first-child { z-index: 2; }
tr.on th[scope="row"] { background: var(--accent-soft); }
.evidence-section { margin-top: 64px; border-top: 1px solid var(--line); padding-top: 32px; }
.sub-h { font-size: 1rem; margin: 34px 0 6px; }
.src-cell { font-size: .72rem; color: var(--muted); min-width: 260px; }
.tool-cell { color: var(--accent); font-weight: 600; }
.evidence-table td, .check-table td { white-space: nowrap; }
.evidence-table td.src-cell { white-space: normal; }

@media (max-width: 980px) {
  .scenario-layout { grid-template-columns: 300px minmax(0, 1fr); gap: 26px; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 22px; }
  .stat:nth-child(3) { padding-left: 0; border-left: 0; }
}
@media (max-width: 760px) {
  .sb-wrap, .more-projects { width: calc(100% - 32px); }
  .sb-hero { padding-top: 40px; }
  .hero-meta { gap: 12px; } .hero-meta span + span { padding-left: 12px; }
  .how-to { grid-template-columns: 1fr; }
  .how-to ol { grid-template-columns: 1fr; gap: 12px; }
  .how-note { max-width: none; }
  .pick { display: block; margin-top: 30px; }
  .pick-controls { align-items: stretch; margin-top: 14px; }
  .chips { justify-content: flex-start; }
  .chip { flex: 1 0 calc(25% - 6px); min-width: 0; padding: 9px 6px; }
  .scenario-layout { grid-template-columns: 1fr; gap: 32px; }
  .controls { position: static; max-height: none; overflow: visible; padding: 20px; }
  .sb-bar-in { gap: 8px; min-height: 44px; font-size: .74rem; flex-wrap: wrap; padding: 6px 0; }
  .bar-jur { max-width: 150px; padding: 4px 6px; }
  .bar-scn { display: none; }
  .bar-out { margin-left: 0; white-space: normal; flex: 1; }
  .bar-out .bar-lab { display: none; }
  .table-scroll th[scope="row"] { min-width: 120px; max-width: 150px; white-space: normal; }
  .result-heading { flex-wrap: wrap; }
  .stat strong { font-size: 1.6rem; }
  .driver { grid-template-columns: 110px minmax(0, 1fr) 70px; gap: 8px; }
  .cmp { grid-template-columns: 44px minmax(0, 1fr) 62px; }
  th, td { min-width: 96px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
