/* ==========================================================================
   Grid & Degrees — design system
   Palette is the validated dataviz reference instance. Colours live here only;
   charts.js reads them back off the DOM by role, so light/dark swap in one place.
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- surfaces & ink ---------------------------------------------------- */
  --surface-1:      #fcfcfb;   /* card / chart surface */
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --wash:           rgba(11, 11, 11, 0.035);

  /* --- categorical series (fixed order, never cycled) -------------------- */
  --series-1: #2a78d6;  /* blue    */
  --series-2: #eb6834;  /* orange  */
  --series-3: #1baf7a;  /* aqua    */
  --series-4: #eda100;  /* yellow  */
  --series-5: #e87ba4;  /* magenta */
  --series-6: #008300;  /* green   */
  --series-7: #4a3aa7;  /* violet  */
  --series-8: #e34948;  /* red     */

  /* --- sequential (blue, light -> dark) ---------------------------------- */
  --seq-100: #cde2fb;
  --seq-200: #9ec5f4;
  --seq-300: #6da7ec;
  --seq-400: #3987e5;
  --seq-500: #256abf;
  --seq-600: #184f95;
  --seq-700: #0d366b;

  /* --- diverging: blue <-> red, neutral gray midpoint -------------------- */
  --div-neg-3: #184f95;
  --div-neg-2: #2a78d6;
  --div-neg-1: #9ec5f4;
  --div-mid:   #f0efec;
  --div-pos-1: #f3b3b3;
  --div-pos-2: #d03b3b;
  --div-pos-3: #8f1f1f;

  /* --- status (reserved — never a series colour) ------------------------- */
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --success-text:    #006300;

  /* --- de-emphasis ------------------------------------------------------- */
  --dim: #b9b7b0;

  --radius: 10px;
  --radius-sm: 6px;
  --maxw: 1160px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --wash:           rgba(255, 255, 255, 0.05);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --div-neg-3: #9ec5f4;
    --div-neg-2: #3987e5;
    --div-neg-1: #1c5cab;
    --div-mid:   #383835;
    --div-pos-1: #8f1f1f;
    --div-pos-2: #d03b3b;
    --div-pos-3: #f36b6b;

    --success-text: #0ca30c;
    --dim: #55544f;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --wash:           rgba(255, 255, 255, 0.05);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --div-neg-3: #9ec5f4;
  --div-neg-2: #3987e5;
  --div-neg-1: #1c5cab;
  --div-mid:   #383835;
  --div-pos-1: #8f1f1f;
  --div-pos-2: #d03b3b;
  --div-pos-3: #f36b6b;

  --success-text: #0ca30c;
  --dim: #55544f;
}

/* ==========================================================================
   base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.75rem, 1.3rem + 1.8vw, 2.5rem); }
h2 { font-size: clamp(1.25rem, 1.1rem + 0.7vw, 1.55rem); }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 1rem; }
a  { color: var(--series-1); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--text-primary); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* ==========================================================================
   header / nav
   ========================================================================== */

.site-head {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-head__bar {
  max-width: var(--maxw); margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); flex: none; }
.brand__mark { width: 26px; height: 26px; flex: none; }
.brand__name { font-weight: 650; letter-spacing: -0.02em; font-size: 1.0rem; white-space: nowrap; }
.brand__name em { font-style: normal; color: var(--text-muted); font-weight: 400; }

.nav { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; }
.nav a {
  font-size: 0.875rem; color: var(--text-secondary); text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-sm); white-space: nowrap;
}
.nav a:hover { background: var(--wash); color: var(--text-primary); }
.nav a[aria-current="page"] { color: var(--text-primary); font-weight: 600; background: var(--wash); }

.icon-btn {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { color: var(--text-primary); }
.icon-btn svg { width: 17px; height: 17px; }

/* ==========================================================================
   page furniture
   ========================================================================== */

main { padding: 40px 0 72px; }

.page-head { max-width: 720px; margin-bottom: 32px; }
.page-head .eyebrow {
  font-size: 0.75rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 10px;
}
.page-head p { color: var(--text-secondary); font-size: 1.05rem; margin-top: 12px; margin-bottom: 0; }

section { margin-bottom: 44px; }
.section-head { margin-bottom: 16px; }
.section-head p { color: var(--text-secondary); margin: 6px 0 0; max-width: 68ch; font-size: 0.95rem; }

/* --- hero figure (exactly one per view) --------------------------------- */
.hero {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; margin-bottom: 20px;
  display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 32px; align-items: center;
}
.hero__label { font-size: 0.875rem; color: var(--text-secondary); }
.hero__value { font-size: clamp(3rem, 2rem + 4vw, 4.5rem); font-weight: 650; letter-spacing: -0.035em; line-height: 1; margin: 8px 0; }
.hero__value span { font-size: 0.4em; font-weight: 500; color: var(--text-secondary); letter-spacing: -0.01em; }
.hero__note { font-size: 0.875rem; color: var(--text-secondary); margin: 0; }
.hero__aside { min-width: 0; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; gap: 20px; padding: 22px; } }

/* --- stat tiles / KPI row -----------------------------------------------
   min() on the track minimum is load-bearing: a bare minmax(210px, 1fr)
   cannot collapse below 210px and forces the whole page to scroll sideways
   on a narrow phone. */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.tile__label { font-size: 0.8125rem; color: var(--text-secondary); }
.tile__value { font-size: 1.875rem; font-weight: 650; letter-spacing: -0.025em; line-height: 1.05; }
.tile__value small { font-size: 0.5em; font-weight: 500; color: var(--text-secondary); letter-spacing: 0; }
/* block, not flex — flex made each phrase its own item and broke lines mid-sentence */
.tile__delta { font-size: 0.8125rem; color: var(--text-secondary); text-wrap: pretty; }
.tile__delta b { font-weight: 600; white-space: nowrap; }
.tile__delta.is-good b { color: var(--success-text); }
.tile__delta.is-bad  b { color: var(--status-critical); }
.tile__foot { font-size: 0.75rem; color: var(--text-muted); margin-top: auto; padding-top: 6px; }
.tile__spark { height: 30px; margin-top: 2px; }

/* ==========================================================================
   chart card
   ========================================================================== */

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; min-width: 0;
}
.card + .card { margin-top: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

.card__head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 4px; }
.card__title { font-size: 1rem; font-weight: 600; margin: 0; }
.card__sub { font-size: 0.8125rem; color: var(--text-secondary); margin: 4px 0 0; max-width: 72ch; }
.card__tools { margin-left: auto; flex: none; display: flex; gap: 2px; padding: 2px;
  background: var(--wash); border-radius: var(--radius-sm); }
.card__tools button {
  font: inherit; font-size: 0.75rem; font-weight: 550; padding: 4px 9px; border: 0; cursor: pointer;
  background: transparent; color: var(--text-secondary); border-radius: 4px;
}
.card__tools button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

.card__plot { margin-top: 14px; min-width: 0; }
.card__plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.card__foot { font-size: 0.75rem; color: var(--text-muted); margin-top: 12px; }
.card__foot a { color: var(--text-muted); }

/* --- legend (always present for >= 2 series) ---------------------------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; }
.legend__item { display: inline-flex; align-items: center; gap: 7px; font-size: 0.8125rem; color: var(--text-secondary); }
.legend__key { flex: none; border-radius: 2px; }
.legend__key--rect { width: 11px; height: 11px; }
.legend__key--line { width: 14px; height: 3px; border-radius: 2px; }

/* --- scale legend (sequential / diverging) ------------------------------ */
.scale-legend { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 0.75rem; color: var(--text-muted); }
.scale-legend__ramp { display: flex; height: 10px; border-radius: 2px; overflow: hidden; flex: none; }
.scale-legend__ramp i { width: 20px; height: 100%; }

/* ==========================================================================
   tables (chart table-view twin + standalone data tables)
   ========================================================================== */

.table-scroll { overflow-x: auto; margin-top: 14px; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
table.data caption { text-align: left; font-size: 0.8125rem; color: var(--text-muted); padding-bottom: 8px; }
table.data th, table.data td { text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--gridline); vertical-align: top; }
table.data thead th {
  font-weight: 600; color: var(--text-secondary); font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.04em; border-bottom-color: var(--axis); white-space: nowrap;
}
table.data td.num, table.data th.num { text-align: right; padding-right: 16px; }
table.data tbody tr:hover { background: var(--wash); }
table.data .cat { font-variant-numeric: normal; }
table.data td small { display: block; color: var(--text-muted); font-size: 0.9em; font-variant-numeric: normal; }

.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 7px; vertical-align: baseline; }

/* --- pills / flags ------------------------------------------------------ */
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 0.6875rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-secondary); white-space: nowrap; font-variant-numeric: normal;
}
.pill svg { width: 11px; height: 11px; flex: none; }
.pill--good     { color: var(--success-text);     border-color: color-mix(in srgb, var(--status-good) 40%, transparent); }
.pill--warning  { color: var(--text-primary);     border-color: color-mix(in srgb, var(--status-warning) 55%, transparent); background: color-mix(in srgb, var(--status-warning) 12%, transparent); }
.pill--serious  { color: var(--text-primary);     border-color: color-mix(in srgb, var(--status-serious) 55%, transparent); background: color-mix(in srgb, var(--status-serious) 12%, transparent); }
.pill--critical { color: var(--status-critical);  border-color: color-mix(in srgb, var(--status-critical) 45%, transparent); }

/* estimate marker — medium-confidence figures */
.est { color: var(--text-muted); cursor: help; font-weight: 500; border-bottom: 1px dotted var(--text-muted); }

/* ==========================================================================
   tooltip
   ========================================================================== */

.gd-tip {
  position: fixed; z-index: 90; pointer-events: none; opacity: 0;
  transition: opacity 90ms linear;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px rgba(0,0,0,0.14), 0 1px 3px rgba(0,0,0,0.08);
  padding: 9px 11px; font-size: 0.8125rem; max-width: 280px;
}
.gd-tip[data-show="1"] { opacity: 1; }
.gd-tip__head { font-weight: 600; margin-bottom: 6px; font-size: 0.75rem; color: var(--text-secondary); }
.gd-tip__row { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.gd-tip__row + .gd-tip__row { margin-top: 3px; }
.gd-tip__key { width: 12px; height: 3px; border-radius: 2px; flex: none; align-self: center; }
.gd-tip__val { font-weight: 650; font-variant-numeric: tabular-nums; }
.gd-tip__name { color: var(--text-secondary); font-size: 0.78rem; }
.gd-tip__note { color: var(--text-muted); font-size: 0.72rem; margin-top: 5px; white-space: normal; }

/* ==========================================================================
   prose blocks / callouts
   ========================================================================== */

.note {
  border: 1px solid var(--border); border-left: 3px solid var(--series-1);
  background: var(--surface-1); border-radius: var(--radius-sm);
  padding: 14px 16px; font-size: 0.875rem; color: var(--text-secondary);
}
.note strong { color: var(--text-primary); }
.note p:last-child { margin-bottom: 0; }
.note--caution { border-left-color: var(--status-warning); }

.prose { max-width: 72ch; }
.prose h3 { margin: 28px 0 8px; }
.prose ul { margin: 0 0 1rem; padding-left: 20px; color: var(--text-secondary); }
.prose li { margin-bottom: 6px; }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em;
  background: var(--wash); padding: 1px 5px; border-radius: 4px;
}

/* ==========================================================================
   support / donation page
   ========================================================================== */

.tiers { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 235px), 1fr)); }
.tier {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column;
}
.tier--featured { border-color: color-mix(in srgb, var(--series-1) 45%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--series-1) 22%, transparent); }
.tier__badge { font-size: 0.6875rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--series-1); margin-bottom: 8px; }
.tier__name { font-size: 1.05rem; font-weight: 600; }
.tier__price { font-size: 2rem; font-weight: 650; letter-spacing: -0.025em; margin: 10px 0 2px; }
.tier__price small { font-size: 0.4em; font-weight: 500; color: var(--text-secondary); letter-spacing: 0; }
.tier__blurb { font-size: 0.875rem; color: var(--text-secondary); margin: 6px 0 16px; }
.tier__list { list-style: none; margin: 0 0 20px; padding: 0; font-size: 0.875rem; color: var(--text-secondary); }
.tier__list li { display: flex; gap: 9px; margin-bottom: 8px; }
.tier__list svg { width: 15px; height: 15px; flex: none; margin-top: 3px; color: var(--status-good); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 0.9375rem; font-weight: 600; padding: 10px 18px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); cursor: pointer; text-decoration: none;
  margin-top: auto; width: 100%;
}
.btn:hover { background: var(--wash); color: var(--text-primary); }
.btn--primary { background: var(--series-1); border-color: transparent; color: #fff; }
.btn--primary:hover { background: color-mix(in srgb, var(--series-1) 85%, #000); color: #fff; }
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn--inline { width: auto; margin-top: 0; }

/* ==========================================================================
   footer
   ========================================================================== */

.site-foot {
  border-top: 1px solid var(--border); padding: 32px 0 48px;
  font-size: 0.8125rem; color: var(--text-muted);
}
.site-foot__grid { display: flex; flex-wrap: wrap; gap: 24px 48px; justify-content: space-between; }
.site-foot a { color: var(--text-secondary); text-decoration: none; }
.site-foot a:hover { color: var(--text-primary); text-decoration: underline; }
.site-foot ul { list-style: none; margin: 8px 0 0; padding: 0; }
.site-foot li { margin-bottom: 5px; }
.site-foot h4 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }

/* ==========================================================================
   a11y / motion / print
   ========================================================================== */

:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 3px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--surface-1);
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  transition: top 120ms ease;
}
.skip-link:focus { top: 12px; }

/* ==========================================================================
   narrow screens
   ========================================================================== */

@media (max-width: 760px) {
  /* the nav becomes a single scrolling row under the brand, rather than
     wrapping to three rows and pushing the theme toggle off-screen */
  .site-head__bar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 20px; }
  .brand { margin-right: auto; }
  .nav {
    order: 3; width: 100%; margin-left: 0; flex-wrap: nowrap;
    /* min-width:0 lets the row scroll instead of forcing the page wider —
       a flex item defaults to min-width:auto, i.e. its min-content width */
    min-width: 0;
    overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
    padding-bottom: 2px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 6px 8px; }
  main { padding: 28px 0 56px; }
  section { margin-bottom: 34px; }
  .card { padding: 16px; }
  .card__head { flex-wrap: wrap; gap: 10px; }
  .card__tools { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ==========================================================================
   Live GB grid widget
   ========================================================================== */

.live__body { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
  gap: 28px; align-items: start; margin-top: 14px; }
@media (max-width: 640px) { .live__body { grid-template-columns: 1fr; gap: 20px; } }

.live__value { display: flex; align-items: baseline; gap: 2px; }
.live__num { font-size: 2.75rem; font-weight: 650; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; line-height: 1; }
.live__unit { font-size: 0.875rem; color: var(--text-secondary); }
.live__index { margin-top: 10px; }
.live__lc { font-size: 0.8125rem; color: var(--text-secondary); margin: 10px 0 0;
  text-wrap: pretty; }
.live__lc b { color: var(--text-primary); font-weight: 600; }

.live__mix { display: flex; flex-direction: column; gap: 5px; }
.live__row { display: grid; grid-template-columns: 66px minmax(0, 1fr) 44px;
  align-items: center; gap: 10px; font-size: 0.75rem; min-height: 20px; }
.live__fuel { color: var(--text-secondary); }
.live__track { background: var(--surface-1); border-radius: 3px; height: 10px;
  overflow: hidden; }
.live__bar { display: block; height: 100%; border-radius: 3px;
  background: var(--text-muted); }
.live__bar.is-low { background: var(--series-1); }
.live__pct { text-align: right; font-variant-numeric: tabular-nums;
  color: var(--text-secondary); }

/* ==========================================================================
   News list
   ========================================================================== */

.news { list-style: none; margin: 14px 0 0; padding: 0;
  display: flex; flex-direction: column; }
.news__item { padding: 12px 0; border-top: 1px solid var(--border); }
.news__item:first-child { border-top: 0; padding-top: 4px; }
.news--compact .news__item { padding: 9px 0; }

.news__link { font-size: 0.9375rem; font-weight: 550; line-height: 1.4;
  color: var(--text-primary); text-decoration: none; text-wrap: pretty;
  display: inline-block; }
.news__link:hover { text-decoration: underline; text-underline-offset: 2px; }

.news__meta { font-size: 0.75rem; color: var(--text-muted); margin: 4px 0 0; }
.news__source { font-weight: 550; color: var(--text-secondary); }
.news__sum { font-size: 0.8125rem; color: var(--text-secondary); margin: 6px 0 0;
  max-width: 72ch; text-wrap: pretty; }

.news-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px; align-items: start; }

/* footer about column — was inline styles set from site.js */
.site-foot__about { max-width: 30ch; }
.site-foot__about p { margin: 8px 0 0; }

@media print {
  .site-head, .card__tools, .site-foot, .skip-link { display: none !important; }
  body { background: #fff; }
  .card, .tile, .hero { break-inside: avoid; border-color: #999; }
}
