/* Vibe Check · NZ
   Diverging palette: teal = toward −10, amber = toward +10, neutral grey at 0.
   Colour shows direction only. Validated (OKLab ΔE, CVD, 3:1 marks) against the
   card surface in each theme; text steps are ≥ 4.5:1. */

:root {
  color-scheme: light;
  --bg: #f3f2ec;
  --surface: #fbfaf7;
  --surface-2: #f1f0ea;
  --ink: #161614;
  --ink-2: #4d4c47;
  --muted: #6b6a66;
  --hair: #e4e2da;
  --axis: #c9c7be;
  --zero: #8f8d85;
  --ring: rgba(22, 22, 20, 0.08);
  --focus: #2f5fd0;

  --neg: #008c7e;       /* marks, toward −10 */
  --pos: #b86e00;       /* marks, toward +10 */
  --neg-ink: #00716b;   /* text */
  --pos-ink: #9a5a00;
  --neg-tint: rgba(0, 140, 126, 0.15);
  --pos-tint: rgba(184, 110, 0, 0.15);
  --neutral-mark: #8a8880;

  --shadow: 0 1px 2px rgba(22, 22, 20, 0.04), 0 8px 24px -12px rgba(22, 22, 20, 0.12);
  --radius: 14px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --dur: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #161614;
    --surface-2: #1d1d1b;
    --ink: #f3f2ee;
    --ink-2: #c9c7bf;
    --muted: #9d9b94;
    --hair: #2a2a27;
    --axis: #3d3c38;
    --zero: #6f6d66;
    --ring: rgba(255, 255, 255, 0.08);
    --focus: #8fb0ff;
    --neg: #1fa39a;
    --pos: #c47f14;
    --neg-ink: #5fcfc6;
    --pos-ink: #f2b04f;
    --neg-tint: rgba(31, 163, 154, 0.2);
    --pos-tint: rgba(196, 127, 20, 0.2);
    --neutral-mark: #8a8880;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e;
  --surface: #161614;
  --surface-2: #1d1d1b;
  --ink: #f3f2ee;
  --ink-2: #c9c7bf;
  --muted: #9d9b94;
  --hair: #2a2a27;
  --axis: #3d3c38;
  --zero: #6f6d66;
  --ring: rgba(255, 255, 255, 0.08);
  --focus: #8fb0ff;
  --neg: #1fa39a;
  --pos: #c47f14;
  --neg-ink: #5fcfc6;
  --pos-ink: #f2b04f;
  --neg-tint: rgba(31, 163, 154, 0.2);
  --pos-tint: rgba(196, 127, 20, 0.2);
  --neutral-mark: #8a8880;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.6);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.num, .score, .delta, .axis-label, .tt-score, time { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 16px; top: -48px; z-index: 10;
  background: var(--ink); color: var(--surface); padding: 8px 12px; border-radius: 8px;
  text-decoration: none; transition: top var(--dur);
}
.skip:focus { top: 12px; }

.page { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .page { padding: 0 32px; } }

/* ---------- Masthead ---------- */
.masthead { padding: 28px 0 28px; border-bottom: 1px solid var(--hair); margin-bottom: 28px; }
@media (min-width: 768px) { .masthead { padding: 48px 0 36px; margin-bottom: 36px; } }
.masthead-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { margin: 0; font-weight: 700; letter-spacing: -0.01em; font-size: 15px; }
.brand span { color: var(--muted); padding: 0 2px; }
.dateline { margin: 20px 0 8px; color: var(--ink-2); font-size: 14px; font-weight: 500; }
.headline {
  margin: 0; max-width: 34ch;
  font: 400 clamp(26px, 4.6vw, 42px)/1.15 var(--serif);
  letter-spacing: -0.012em; text-wrap: balance;
}
.lead-credit { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.lead-credit a { color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px; }
.lead-credit a:hover { text-decoration-color: currentColor; }
.meta { margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; }
.meta-topics { font-weight: 600; font-size: 15px; }
.meta-updated { color: var(--muted); font-size: 13px; }
.meta-stale { color: var(--muted); font-size: 13px; }

.theme-toggle, .icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--hair); background: var(--surface); border-radius: 999px; cursor: pointer;
  transition: background var(--dur), border-color var(--dur);
}
.theme-toggle:hover, .icon-btn:hover { border-color: var(--axis); }
.theme-toggle svg, .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: block; }
}

/* ---------- Grid & cards ---------- */
/* Every row gets the same height (the tallest card's), so all cards match.
   "Why" and info panels float, so opening them never changes a card's size. */
.grid { display: grid; gap: 16px; grid-template-columns: 1fr; grid-auto-rows: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; } }

.card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--ring);
  padding: 18px 20px;
  transition: box-shadow var(--dur);
}
.card:hover { box-shadow: 0 0 0 1px var(--axis); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-title { margin: 0; font-size: inherit; min-width: 0; display: flex; align-items: center; gap: 6px; }
.card-open {
  all: unset; cursor: pointer; display: inline-block;
  font-weight: 600; font-size: 15px; letter-spacing: -0.01em; line-height: 1.3;
}
/* The whole card opens the detail view (click handler in app.js). */
.card { cursor: pointer; }
.card.skeleton { cursor: default; }
.card-open:focus-visible { outline: none; }
.card:has(.card-open:focus-visible) { box-shadow: 0 0 0 2px var(--focus); }
.card-meta { display: inline-flex; align-items: baseline; gap: 10px; flex: none; font-size: 12px; color: var(--muted); }

.card-readout { display: flex; align-items: baseline; gap: 12px; margin: 16px 0 12px; min-height: 42px; }
.score { font-weight: 600; font-size: 44px; line-height: 1; letter-spacing: -0.04em; }
.score.pos { color: var(--pos-ink); }
.score.neg { color: var(--neg-ink); }
.score.zero { color: var(--muted); }
.score.none { color: var(--axis); font-weight: 400; }
.readout-note { font-size: 13px; color: var(--muted); display: inline-flex; align-items: baseline; gap: 5px; }
.readout-note.strong { color: var(--ink); font-weight: 600; font-size: 14px; }
/* Info button + popover */
.info-btn {
  all: unset; position: relative; z-index: 2; cursor: pointer; flex: none;
  display: inline-grid; place-items: center; width: 22px; height: 22px; margin: -3px 0; border-radius: 50%;
  color: var(--muted); transition: color var(--dur), background var(--dur);
}
.info-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.info-btn:hover, .info-btn[aria-expanded="true"] { color: var(--ink); background: var(--surface-2); }
.info-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.card-head { position: relative; }
.info-pop {
  display: none; position: absolute; z-index: 6; top: calc(100% + 8px); left: -8px; width: min(320px, calc(100vw - 48px));
  padding: 12px 14px; border-radius: 10px; background: var(--surface); color: var(--ink);
  box-shadow: 0 0 0 1px var(--ring), 0 14px 36px -12px rgba(0, 0, 0, 0.45);
  font-size: 13px; line-height: 1.45; text-transform: none; letter-spacing: 0; font-weight: 400;
}
.info-pop.open { display: block; }
@media (hover: hover) { .card-title:has(.info-btn:hover) ~ .info-pop { display: block; } }
.info-q { margin: 0 0 8px; }
.info-poles { display: grid; grid-template-columns: 30px 1fr; gap: 3px 8px; margin: 0 0 8px; font-size: 12px; color: var(--ink-2); }
.info-poles dt { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }
.info-poles dd { margin: 0; }
.info-foot { margin: 0; font-size: 12px; color: var(--muted); }

.card-foot { margin-top: auto; padding-top: 14px; min-height: 36px; display: flex; align-items: flex-end; }
.card-foot:empty { padding-top: 0; }

.delta { font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.delta .tri { font-size: 9px; margin-right: 3px; position: relative; top: -1px; }
.delta-new { font-weight: 500; color: var(--muted); }
.conf { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.conf .dots, .pill .dots { display: inline-flex; gap: 2px; }
.conf .dots i, .pill .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--axis); }
.conf .dots i.on, .pill .dots i.on { background: var(--ink-2); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 500; line-height: 1; padding: 5px 9px;
  border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--hair); white-space: nowrap;
}

/* Gauge: [pole] ——|——● [pole] */
.gauge {
  display: grid; grid-template-columns: auto minmax(56px, 1fr) auto; align-items: center; gap: 8px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
}
/* Multi-word pole names wrap before the track gets squeezed below 56px. */
.gauge .pole { line-height: 1.15; }
.gauge .pole:last-child { text-align: right; }
.gauge-track { position: relative; height: 12px; }
.gauge-track::before { /* rail */
  content: ""; position: absolute; left: 0; right: 0; top: 5px; height: 2px;
  border-radius: 2px; background: var(--hair);
}
.gauge.dotted .gauge-track::before { background: none; border-top: 2px dotted var(--axis); height: 0; }
.gauge-center { position: absolute; left: 50%; top: 2px; width: 1.5px; height: 8px; margin-left: -0.75px; background: var(--zero); border-radius: 1px; }
.gauge-fill { position: absolute; top: 5px; height: 2px; border-radius: 2px; }
.gauge-fill.pos { background: var(--pos); }
.gauge-fill.neg { background: var(--neg); }
.gauge-marker {
  position: absolute; top: 1px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%;
  background: var(--neutral-mark); box-shadow: 0 0 0 2px var(--surface);
}
.gauge-marker.pos { background: var(--pos); }
.gauge-marker.neg { background: var(--neg); }
.gauge-marker.ghost { background: var(--surface); box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 1.5px var(--muted); }
.gauge-note { margin: 0; font-size: 12px; color: var(--muted); }
.gauge-note button {
  all: unset; position: relative; z-index: 1;
  cursor: pointer; text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px;
}
.gauge-note button:hover { color: var(--ink); }
.gauge-note button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* Sparkline */
.spark { display: block; width: 100%; height: auto; margin-top: 14px; overflow: visible; }

.line-pos { stroke: var(--pos); }
.line-neg { stroke: var(--neg); }
.area-pos { fill: var(--pos-tint); }
.area-neg { fill: var(--neg-tint); }
.zero-line { stroke: var(--zero); }
.grid-line { stroke: var(--hair); }
.dot-fill-pos { fill: var(--pos); } .dot-fill-neg { fill: var(--neg); } .dot-fill-zero { fill: var(--neutral-mark); }
.dot-hollow { fill: var(--surface); stroke-width: 1.5; }
.dot-hollow.pos { stroke: var(--pos); } .dot-hollow.neg { stroke: var(--neg); } .dot-hollow.zero { stroke: var(--neutral-mark); }

/* Card footer: source count (details are in the drawer) */
.source-count { font-size: 12px; font-weight: 500; color: var(--muted); }
.card:hover .source-count { color: var(--ink-2); }

.reason { margin: 8px 0 10px; font-size: 14px; line-height: 1.5; color: var(--ink); }
.sources { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sources li { font-size: 13px; line-height: 1.4; }
.sources a { font-weight: 500; text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px; }
.sources a:hover { text-decoration-color: currentColor; }
.src-meta { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }

/* ---------- Skeletons ---------- */
.sk {
  display: block; height: 12px; border-radius: 6px; background: var(--hair);
  animation: pulse 1.4s ease-in-out infinite;
}
.sk-line { display: inline-block; height: 12px; }
.sk-head { height: 30px; width: 90%; margin: 8px 0; }
.card.skeleton { min-height: 190px; gap: 12px; }
.card.skeleton .sk:nth-child(1) { width: 45%; height: 16px; }
.card.skeleton .sk:nth-child(2) { width: 85%; }
.card.skeleton .sk:nth-child(3) { width: 30%; height: 48px; margin-top: 12px; }
.card.skeleton .sk:nth-child(4) { width: 100%; height: 4px; margin-top: 12px; }
.card.skeleton .sk:nth-child(5) { width: 100%; height: 40px; margin-top: 8px; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 72px 16px 88px; border-radius: var(--radius);
  background: var(--surface); box-shadow: 0 0 0 1px var(--ring);
}
.empty svg { width: 120px; height: 40px; margin-bottom: 16px; }
.empty h2 { margin: 0 0 8px; font: 400 28px/1.2 var(--serif); }
.empty p { margin: 0 auto; max-width: 42ch; color: var(--ink-2); }

/* ---------- Footer ---------- */
.footer { margin: 48px 0 40px; padding-top: 20px; border-top: 1px solid var(--hair); color: var(--muted); font-size: 13px; max-width: 72ch; }
.footer p { margin: 0 0 8px; }
.footer strong { color: var(--ink-2); font-weight: 600; }

/* ---------- Detail panel ---------- */
.detail {
  padding: 0; border: 0; color: var(--ink); background: var(--surface);
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0;
}
@media (min-width: 900px) {
  .detail {
    width: min(760px, 62vw); height: 100dvh; margin: 0 0 0 auto;
    box-shadow: -1px 0 0 var(--ring), -24px 0 60px -30px rgba(0, 0, 0, 0.35);
  }
}
.detail::backdrop { background: rgba(10, 10, 9, 0.38); }
.detail[open] { animation: slide-in var(--dur) ease-out; }
@media (max-width: 899px) { .detail[open] { animation-name: sheet-in; } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
.detail-inner { padding: 20px 16px 40px; }
@media (min-width: 900px) { .detail-inner { padding: 28px 32px 48px; } }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.detail-title { margin: 0; font: 400 28px/1.15 var(--serif); letter-spacing: -0.01em; }
.detail-q { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.detail-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; margin: 4px 0 20px; }
.detail-summary .score { font-size: 40px; }
.detail-summary .summary-text { color: var(--ink-2); font-size: 14px; }
.detail-why { margin: -8px 0 24px; max-width: 60ch; }
.detail-why .reason { margin: 0 0 10px; }

.chart-wrap { position: relative; margin: 0 -4px; touch-action: pan-y; }
.chart { display: block; width: 100%; overflow: visible; }
.chart:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 8px; }
.axis-label { fill: var(--muted); font-size: 11px; }
.pole-label { fill: var(--ink-2); font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.ma-line { stroke: var(--ink-2); stroke-opacity: 0.55; stroke-width: 1.25; fill: none; stroke-dasharray: 3 3; }
.nosig-tick { stroke: var(--muted); stroke-width: 1.5; }
.miss-mark { fill: none; stroke: var(--muted); stroke-width: 1; }
.hatch-line { stroke: var(--muted); stroke-width: 1.2; }
.crosshair { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 2 3; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 18px; height: 10px; overflow: visible; }

.tooltip {
  position: absolute; z-index: 2; width: min(300px, calc(100% - 16px));
  background: var(--surface); color: var(--ink); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 0 0 1px var(--ring), 0 12px 32px -12px rgba(0, 0, 0, 0.35);
  font-size: 13px; line-height: 1.45; pointer-events: auto;
}
.tooltip[hidden] { display: none; }
.tt-date { color: var(--muted); font-size: 12px; }
.tt-score { font-weight: 600; font-size: 18px; margin-right: 6px; }
.tt-reason { margin: 4px 0 6px; }
.tooltip .sources li { font-size: 12px; }

.log { margin-top: 32px; }
.log h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.log ol { list-style: none; margin: 0; padding: 0; }
.log ol > li { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 14px 0; border-top: 1px solid var(--hair); scroll-margin-top: 16px; }
.log ol > li.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--surface-2); } }
.log-score { font-weight: 600; font-size: 20px; line-height: 1.2; }
.log-score.pos { color: var(--pos-ink); } .log-score.neg { color: var(--neg-ink); } .log-score.zero, .log-score.none { color: var(--muted); }
.log-date { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.log .reason { margin: 0 0 6px; }
.log .pill { margin-left: 6px; vertical-align: 1px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
@media (forced-colors: active) {
  .gauge-fill, .gauge-marker { forced-color-adjust: none; }
}

.muted-note { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
