/* Pharos UI — calm, theme-aware, on the Pharos brand tokens (see
   /brand/tokens.css, loaded before this file). Local vars alias the semantic
   tokens, whose own media query handles the light/dark flip. Amber is UI
   chrome only; data-viz layers keep the project dataviz standard (validated
   blue sequential ramp; no saturated danger scales). */

:root {
  color-scheme: light;
  --surface-1: var(--pharos-surface);
  --page: var(--pharos-bg);
  --text-primary: var(--pharos-text);
  --text-secondary: var(--pharos-text-2);
  /* Muted caveat text stays >= 4.5:1 (WCAG AA) on both surfaces — the token
     values are tuned for this; don't lighten them locally. */
  --muted: var(--pharos-muted);
  --hairline: var(--pharos-line);
  --border: var(--pharos-border);
  --insufficient: var(--pharos-line);
  /* Amber accent: amber-dark on light surfaces, bright amber on dark —
     both AA against their background (see brand.tokens.json). */
  --accent: var(--pharos-accent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Visible keyboard focus on every interactive control (WCAG 2.4.7): the UI
   previously had no :focus styling at all, so keyboard/switch users had no
   position indicator on the selects, sliders, buttons, and modal controls. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}
/* Honor a reduced-motion preference (WCAG 2.3.3): neutralize CSS transitions
   and animations. The year animation is JS + user-initiated (Play toggles to
   Pause), so it already satisfies pause/stop/hide. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
/* Skip link: jump past the topbar to the map controls. Off-screen till focused. */
.skip-link {
  position: absolute; left: 0.5rem; top: -3rem; z-index: 1000;
  background: var(--surface-1); color: var(--accent);
  padding: 0.5rem 0.9rem; border: 2px solid var(--accent); border-radius: 0 0 6px 6px;
  font-size: 0.9rem; font-weight: 600; text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  font-family: var(--pharos-font);
  background: var(--page);
  color: var(--text-primary);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-1);
}
.topbar h1 { font-size: 1rem; margin: 0; }
.brand {
  display: flex; align-items: center; gap: 0.55rem;
  font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase;
}
.brand-tile { display: block; border-radius: 6px; }
.tagline { margin: 0; color: var(--text-secondary); font-size: 0.85rem; flex: 1; }
.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 0.9rem; text-decoration: underline;
}

.layout { flex: 1; display: flex; min-height: 0; position: relative; }

.controls {
  width: 270px;
  padding: 0.9rem;
  overflow-y: auto;
  border-right: 1px solid var(--hairline);
  background: var(--surface-1);
  font-size: 0.88rem;
}
.controls label { display: block; margin: 0.7rem 0 0.25rem; color: var(--text-secondary); }
.controls select, .controls input[type="range"] { width: 100%; }
.controls input[type="range"], .controls input[type="checkbox"] {
  accent-color: var(--accent);
}
.controls select {
  padding: 0.3rem; background: var(--page); color: var(--text-primary);
  border: 1px solid var(--hairline); border-radius: 4px;
}
#advanced { margin-top: 0.9rem; }
#advanced summary { cursor: pointer; color: var(--text-secondary); }

.fine { font-size: 0.75rem; color: var(--muted); line-height: 1.35; }

.anim-row { display: flex; gap: 0.5rem; margin-top: 0.45rem; align-items: center; }
.anim-row #play-btn {
  flex: 1; padding: 0.3rem 0.6rem; cursor: pointer;
  background: var(--page); color: var(--accent);
  border: 1px solid var(--hairline); border-radius: 4px; font-size: 0.85rem;
}
.anim-row #play-btn[aria-pressed="true"] { border-color: var(--accent); }
.anim-row select { width: auto; }
#hex-controls { margin: 0; }

/* Bivariate 3x3 legend */
.biv-wrap { display: flex; gap: 0.35rem; align-items: flex-end; margin: 0.3rem 0; }
.biv-grid { display: grid; grid-template-columns: repeat(3, 16px); gap: 2px; }
.biv-grid .swatch { width: 16px; height: 16px; border-radius: 2px; border: 1px solid var(--border); }
.biv-ylabel {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: 0.7rem; color: var(--muted);
  max-height: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Proportional-symbol size key + heatmap gradient */
.legend .size-dot {
  flex: none; border-radius: 50%; border: 1px solid var(--border);
  display: inline-block;
}
.legend .gradient { height: 10px; border-radius: 3px; border: 1px solid var(--border); }

/* Embedded per-county mini bar charts */
.chart-marker {
  display: flex; align-items: flex-end; gap: 2px;
  padding: 1px 2px; background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  border: 1px solid var(--border); border-radius: 3px; cursor: default;
}
.chart-marker i { display: block; width: 7px; border-radius: 1px 1px 0 0; }

#map { flex: 1; background: var(--page); }

.legend { margin-top: 1rem; }
.legend h3 { font-size: 0.8rem; margin: 0 0 0.4rem; color: var(--text-secondary); font-weight: 600; }
.legend .row { display: flex; align-items: center; gap: 0.45rem; margin: 0.18rem 0; }
.legend .swatch {
  width: 16px; height: 16px; border-radius: 3px; flex: none;
  border: 1px solid var(--border);
}
.legend .swatch.insufficient {
  background:
    repeating-linear-gradient(45deg, transparent 0 3px, var(--muted) 3px 4px),
    var(--insufficient);
}
.legend .val { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.detail {
  position: absolute; right: 0.8rem; top: 0.8rem;
  width: 320px; max-height: calc(100% - 1.6rem); overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--hairline);
  border-radius: 8px; padding: 0.9rem; font-size: 0.85rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}
.detail h2 { font-size: 1rem; margin: 0 0 0.5rem; padding-right: 1.2rem; }
.detail .shap-bar { display: flex; align-items: center; gap: 0.4rem; margin: 0.15rem 0; }
.detail .shap-bar .bar {
  height: 8px; border-radius: 4px; background: var(--accent); opacity: 0.7;
}
.detail .shap-bar .bar.neg { background: var(--muted); }
.detail .shap-bar .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail .status-note { color: var(--muted); font-style: italic; }

.close-btn {
  position: absolute; right: 0.5rem; top: 0.4rem;
  background: none; border: none; font-size: 1.1rem;
  color: var(--muted); cursor: pointer;
}

dialog#methodology-modal {
  max-width: 46rem; width: 90vw; max-height: 84vh;
  border: 1px solid var(--hairline); border-radius: 10px;
  background: var(--surface-1); color: var(--text-primary);
  padding: 1.4rem;
}
dialog::backdrop { background: rgba(0,0,0,0.45); }
.prose { line-height: 1.5; font-size: 0.92rem; }
.prose h1, .prose h2 { font-size: 1.05rem; }
.prose a { color: var(--accent); }

.crisis-footer {
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--hairline);
  background: var(--surface-1);
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.crisis-footer a { color: var(--accent); font-weight: 600; }

.maplibregl-popup-content {
  background: var(--surface-1); color: var(--text-primary);
  border-radius: 6px; font-size: 0.82rem;
}

.vif-table {
  width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.6rem;
}
.vif-table th, .vif-table td {
  text-align: left; padding: 0.25rem 0.55rem; border-bottom: 1px solid var(--hairline);
}
.vif-table th { color: var(--text-secondary); font-weight: 600; }
/* Darkened from #b4604f / #a08430 to clear WCAG AA (4.5:1) at this 13.6px
   weight — 0.85rem bold is below the large-text threshold, so 3:1 isn't enough. */
.vif-severe td:nth-child(2), .vif-severe td:nth-child(3) { color: #a4402f; font-weight: 600; }
.vif-moderate td:nth-child(2), .vif-moderate td:nth-child(3) { color: #806619; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .vif-severe td:nth-child(2),
  :root:not([data-theme="light"]) .vif-severe td:nth-child(3) { color: #e79484; }
  :root:not([data-theme="light"]) .vif-moderate td:nth-child(2),
  :root:not([data-theme="light"]) .vif-moderate td:nth-child(3) { color: #d8b652; }
}
