/*
  Tokens follow the reference data-viz palette (validated with the palette checker):
  chrome/ink, two series (blue, orange) for counts, seven categorical day colors
  (passes the colorblind checks; contrast relief = legends, tooltips and the table),
  red for the mainshock, gray for the week before, status colors for the live pill. Intensity uses the USGS
  ShakeMap scale (set in js/intensity.js). Dark mode has its own validated steps.
*/
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --link: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  /* one color per day (reference categorical slots, validated), mainshock, week before */
  --day-1: #2a78d6;
  --day-2: #eb6834;
  --day-3: #1baf7a;
  --day-4: #eda100;
  --day-5: #e87ba4;
  --day-6: #008300;
  --day-7: #6250d6;
  --main: #d03b3b;
  --pre: #52514e;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  --tiles-filter: none;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --link: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --day-1: #3987e5;
    --day-2: #d95926;
    --day-3: #199e70;
    --day-4: #c98500;
    --day-5: #d55181;
    --day-6: #008300;
    --day-7: #9085e9;
    --main: #e66767;
    --pre: #c3c2b7;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    --tiles-filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }
.page { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
h1 { font-size: clamp(24px, 4vw, 32px); line-height: 1.15; font-weight: 650; margin: 6px 0 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
h3 { font-size: 14px; font-weight: 600; margin: 8px 0 4px; }
.take { color: var(--ink-2); max-width: 75ch; margin: 8px 0 0; }
.muted { color: var(--ink-2); }
.note { color: var(--ink-2); font-size: 13px; margin: 4px 0 12px; max-width: 85ch; }

.status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.status[data-kind=ok] .dot { background: var(--good); animation: live 2s ease-in-out infinite; }
.status[data-kind=bad] .dot { background: var(--critical); }
.status .synced { color: var(--ink-2); }
@keyframes live { 50% { opacity: 0.35; } }
.headrow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.lang .btn { padding: 4px 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; }

.toast { position: sticky; top: 8px; z-index: 1000; align-self: center; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: 14px; max-width: 100%; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 2px; }
.lbl { font-size: 12px; color: var(--ink-2); }
.num { font-size: 30px; line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; }
.sub { font-size: 12px; color: var(--ink-2); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); gap: 16px; }

.mapbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.mapbar input[type=range] { flex: 1 1 160px; min-width: 120px; accent-color: var(--series-1); }
.maptime { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 16rem; }
.btn { font: inherit; font-size: 13px; padding: 5px 10px; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--page); }
.btn[aria-pressed=true] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.seg { display: inline-flex; }
.seg .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.seg .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.seg .btn + .btn { margin-left: -1px; }
.seg .btn:not(:first-child):not(:last-child) { border-radius: 0; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; font-size: 13px; }
.fgroup { display: inline-flex; align-items: center; gap: 8px; }
.flabel { color: var(--ink-2); font-size: 12px; }
.fnote { flex-basis: 100%; margin: 0; font-size: 13px; }
.fnote:has(span:empty + span:empty + span:empty) { display: none; }
.map { height: clamp(360px, 62vh, 620px); border-radius: 8px; border: 1px solid var(--border); background: var(--page); }
.leaflet-container { font: inherit; background: var(--page); }
.map .leaflet-tile-pane { filter: var(--tiles-filter); }
.place span { font-size: 12px; font-weight: 600; color: var(--ink); white-space: nowrap; text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface), 0 0 3px var(--surface); position: relative; left: 4px; top: -8px; }
.place::before { content: ""; position: absolute; width: 5px; height: 5px; left: -2px; top: -2px; background: var(--ink-2); border-radius: 1px; }
.refpin span { display: block; color: var(--link); font-size: 16px; line-height: 16px; text-align: center; text-shadow: 0 0 3px var(--surface); }
.leaflet-tooltip.main-label { background: none; border: 0; box-shadow: none; padding: 0; font-weight: 700; color: var(--ink); text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface); }
.leaflet-tooltip.main-label::before { display: none; }
.leaflet-tooltip, .leaflet-popup-content { font-size: 12px; line-height: 1.45; }
.qtip .tip-h { color: #52514e; }
.qtip .muted { font-size: 11px; }
.qtip a { display: inline-block; margin-top: 4px; }
path.pulse { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { from { stroke-width: 2; stroke-opacity: 1; } to { stroke-width: 18; stroke-opacity: 0; } }
@media (prefers-reduced-motion: reduce) { path.pulse, .status[data-kind=ok] .dot { animation: none; } }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-top: 10px; align-items: center; }
.legend.top { margin: 0 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-title { font-weight: 600; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); vertical-align: -1px; }
.legend .sw { margin-right: 0; border-radius: 2px; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }

.chart { position: relative; width: 100%; min-height: 240px; }
.chart svg { display: block; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart text.strong, .chart text.label.strong { fill: var(--ink); font-weight: 600; }
.chart text.label { fill: var(--ink-2); }
.chart .grid { stroke: var(--grid); }
.chart .axis { stroke: var(--axis); }
.chart .ref, .chart .model { stroke: var(--ink-2); stroke-dasharray: 5 4; fill: none; stroke-width: 1.5; }
.chart .crosshair { stroke: var(--axis); }
.chart .bar.s1 { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.chart .open { opacity: 0.55; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }
.prebar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 13px; }
.switch { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--axis); border-radius: 999px; background: var(--surface); cursor: pointer; }
.switch input { accent-color: var(--series-1); width: 16px; height: 16px; margin: 0; }
.chart .stem { stroke-opacity: 0.35; stroke-width: 1; }
.chart .dot.day { fill-opacity: 0.8; stroke: var(--surface); stroke-width: 1; }
.chart .dot.s1 { fill: var(--series-1); fill-opacity: 0.55; stroke: var(--surface); stroke-width: 1; }
.chart .dot.main { fill: var(--main); stroke: var(--surface); stroke-width: 2; }
.chart .dot.mmi { stroke: rgba(0, 0, 0, 0.45); stroke-width: 1; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.chart .hover-ring, .chart .sel-ring { fill: none; stroke: var(--ink); stroke-width: 2; }
.skeleton { background: linear-gradient(90deg, var(--grid), var(--border), var(--grid)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.tip { position: absolute; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 10px; font-size: 12px; max-width: 19rem; opacity: 0; z-index: 5; }
.tip .tip-h { color: var(--ink-2); }
.tip .tip-hint { color: var(--link); margin-top: 2px; }
.tip.pinned { pointer-events: auto; }
.tip a { display: inline-block; margin-top: 4px; padding: 4px 0; font-weight: 600; }

.refhead, .tablehead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.tablehead h2 { margin-right: auto; }
.refsel { font-size: 13px; color: var(--ink-2); }
.refsel select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 4px 8px; margin-left: 4px; }
.refrow { display: flex; gap: 14px; align-items: center; margin: 4px 0 12px; font-size: 14px; }
.badgebox { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.badge { flex: none; width: 52px; height: 52px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 20px; color: #0b0b0b; background: var(--grid); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.badgecap { font-size: 11px; color: var(--ink-2); }

table.fc { border-collapse: collapse; font-size: 14px; margin-bottom: 8px; }
table.fc th, table.fc td { padding: 6px 14px 6px 0; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; font-weight: 400; }
table.fc thead th { color: var(--ink-2); font-size: 12px; }
table.fc th[scope=row] { font-weight: 600; }
table.fc td b { font-size: 17px; }
table.fc td .muted { font-size: 12px; }
#forecast p { font-size: 13px; margin: 6px 0; max-width: 85ch; }

.search { width: 100%; max-width: 420px; font: inherit; padding: 7px 10px; margin: 10px 0; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); color: var(--ink); }
.tablebox { max-height: 460px; overflow: auto; border-top: 1px solid var(--grid); }
#events { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
#events th { position: sticky; top: 0; background: var(--surface); text-align: left; border-bottom: 1px solid var(--axis); padding: 0; z-index: 1; }
#events th button, #events th .th { all: unset; cursor: pointer; display: block; padding: 7px 8px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
#events th .th { cursor: default; }
#events th[aria-sort=ascending] button::after { content: " ↑"; }
#events th[aria-sort=descending] button::after { content: " ↓"; }
#events td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.n { text-align: right; }
#events th.n button { text-align: right; width: 100%; box-sizing: border-box; }
#events tr.main td { font-weight: 700; }
@media (max-width: 640px) { .hide-s { display: none; } .maptime { min-width: 0; } }

.foot { font-size: 12px; color: var(--ink-2); max-width: 90ch; }
.foot p { margin: 0 0 8px; }
body.empty .page > section { display: none; }
