/* ============================================================
   Coastal Traffic Authority · Strait Observatory
   One neutral palette, one accent (deep-sea teal), tabular
   numerals, flat panels (no card borders), no gratuitous motion.
   ============================================================ */

:root {
  --paper: #f5f4f0;
  --panel: #fbfaf7;
  --ink: #23262b;
  --ink-soft: #4a5058;
  --muted: #71777f;
  --faint: #9aa0a7;
  --line: #e0ddd4;
  --line-strong: #cfccc2;
  --accent: #0e6b5c;
  --accent-deep: #0a4f44;
  --accent-soft: #dcebe7;
  --accent-faint: #edf4f2;
  --bad: #b3372b;
  --ok: #1c6b47;
  --focus: #0e6b5c;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.95em;
  letter-spacing: -0.01em;
}

/* ---------- focus ring (deliberately not the UA default) ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
  box-shadow: 0 0 0 4px var(--accent-faint);
}
.chip:has(input:focus-visible),
.switch:has(input:focus-visible),
select:focus-visible ~ .focusring { outline: none; }
label.chip:has(input:focus-visible) span,
label.switch:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

/* ---------- header ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 28px;
  padding: 26px 28px 14px;
  border-bottom: 2px solid var(--ink);
}
.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.brand h1 .thin { font-weight: 400; color: var(--muted); }
.lede { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; max-width: 62ch; }

.topbar { display: flex; align-items: center; gap: 18px; }
.count { text-align: right; }
.count-num { font-size: 27px; font-weight: 600; letter-spacing: -0.02em; }
.count-sub { display: block; color: var(--muted); font-size: 11.5px; margin-top: -2px; }

.topbtns { display: flex; gap: 8px; }
.btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  padding: 7px 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-deep); }
.pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 11px;
}
.pill.pill-bad { background: #f3dedb; color: var(--bad); }

/* ---------- filter bar ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 30px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
}
.fgroup { border: 0; margin: 0; padding: 0; }
.fgroup legend {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 5px;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.chip input {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}
.chip span {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 3.5px 11px;
  font-size: 12.5px;
  background: var(--panel);
  color: var(--ink-soft);
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover span { border-color: var(--ink-soft); }
.chip input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
  font-weight: 600;
}

.months { display: flex; align-items: center; gap: 7px; }
.mlab { font-size: 12px; color: var(--muted); }
.mlab select {
  font: inherit;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  margin-left: 4px;
  padding: 4px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--panel);
  color: var(--ink);
}
.msep { color: var(--faint); font-size: 12px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}
.switch .knob {
  width: 30px; height: 17px;
  border-radius: 10px;
  background: var(--line-strong);
  position: relative;
  transition: background-color 0.15s;
  flex: none;
}
.switch .knob::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.15s;
}
.switch input:checked ~ .knob { background: var(--accent); }
.switch input:checked ~ .knob::after { transform: translateX(13px); }
.swlab { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- main grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 24px 22px;
  padding: 22px 28px 8px;
  max-width: 1420px;
  margin: 0 auto;
}
#p-area    { grid-column: span 8; }
#p-rank    { grid-column: span 4; }
#p-scatter { grid-column: span 8; }
#p-hist    { grid-column: span 4; }
#p-heat    { grid-column: span 7; }
#p-cursor  { grid-column: span 5; }

@media (max-width: 1279px) {
  #p-area    { grid-column: span 7; }
  #p-rank    { grid-column: span 5; }
  #p-scatter { grid-column: span 7; }
  #p-hist    { grid-column: span 5; }
  #p-heat    { grid-column: span 7; }
  #p-cursor  { grid-column: span 5; }
}
@media (max-width: 860px) {
  .grid { gap: 18px 14px; padding: 16px 14px 6px; }
  .grid > * { grid-column: span 12 !important; }
  .top { padding: 18px 14px 12px; }
  .filters { padding: 10px 14px; }
}

/* ---------- panels ---------- */
.panel { min-width: 0; }
.phead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.phead h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.pmeta {
  margin: 0;
  width: 100%;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 7px;
  margin-bottom: 8px;
}
.pmeta .fx-on { color: var(--accent-deep); font-weight: 600; }
.pmeta .own { color: var(--faint); font-style: italic; }
.pmeta .tblbtn {
  font: inherit;
  font-size: 11px;
  border: 0;
  background: none;
  color: var(--accent-deep);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.pmeta .tblbtn[aria-expanded="true"] { font-weight: 700; }

.chart { position: relative; }
.chart svg, .chart canvas { display: block; width: 100%; }
#cvScatter { cursor: crosshair; touch-action: none; }

.tblwrap {
  margin-top: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 12px;
  overflow-x: auto;
}
table { border-collapse: collapse; width: 100%; }
.tblcap {
  caption-side: top;
  text-align: left;
  font-size: 11.5px;
  color: var(--muted);
  padding-bottom: 6px;
}
th, td {
  text-align: right;
  padding: 3.5px 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tr.row-hi td { background: var(--accent-faint); }

.srlive {
  /* screen-reader-only live summary */
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

/* ---------- SVG chart internals ---------- */
svg text { font-family: var(--mono); font-variant-numeric: tabular-nums; fill: var(--muted); }
.axis-label { font-size: 10.5px; }
.gridline { stroke: var(--line); stroke-width: 1; }
.axline { stroke: var(--line-strong); stroke-width: 1; }
.anno { font-size: 10.5px; fill: var(--faint); }

.area-band { stroke: var(--paper); stroke-width: 1; }
.area-band.dim { opacity: 0.22; }
.total-line { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.cursor-line { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; }
.cursor-hilite { fill: var(--accent); opacity: 0.14; }
.heat-cell { shape-rendering: crispEdges; }
.heat-spark { fill: none; stroke: var(--ink); stroke-width: 1.1; opacity: 0.75; }
.heat-cursor { fill: none; stroke: var(--accent); stroke-width: 2; }
.rank-bar { fill: var(--accent); opacity: 0.75; }
.rank-bar.other { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; }
.rank-tie { font-size: 9px; fill: var(--faint); }
.hist-bar { fill: var(--accent); opacity: 0.7; }
.hist-cursor { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.rank-label { font-size: 11px; fill: var(--ink-soft); font-family: var(--sans); }
.heat-lab { font-size: 10.5px; }

/* ---- legend under the area chart ---- */
.arealegend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 7px; }
.lg-item {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 11.5px; color: var(--muted);
  background: none; border: 0; padding: 2px 4px; cursor: pointer; border-radius: 3px;
}
.lg-item .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.lg-item.active { color: var(--accent-deep); font-weight: 600; }
.lg-item.dimmed { opacity: 0.4; }

/* ---------- cursor / inspector panel ---------- */
.cursorbox { min-height: 132px; }
.cursor-hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; }
.crtbl { width: 100%; border-collapse: collapse; }
.crtbl th {
  text-align: left;
  font-size: 10.5px;
  color: var(--muted);
  padding: 4px 8px 4px 0;
  width: 118px;
  vertical-align: top;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 0;
}
.crtbl td {
  text-align: left;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.crtbl .anomal { color: var(--bad); font-weight: 700; }
.crtbl .plain { color: var(--ink-soft); }

/* ---------- footer ---------- */
.foot {
  padding: 18px 28px 26px;
  max-width: 1420px;
  margin: 0 auto;
}
.perf {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  border-top: 2px solid var(--ink);
  padding-top: 14px;
}
.perf-t h2 { margin: 0; font-size: 13px; font-weight: 700; }
.perf-sub { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
#frameGraph { width: 264px; height: 44px; background: var(--panel); border: 1px solid var(--line); }
.perfstat { font-size: 11px; color: var(--muted); margin: 0; }
.foot-note {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  max-width: 100ch;
}
.foot-note code { font-family: var(--mono); font-size: 10.5px; }
.foot-note a { color: var(--accent-deep); }

/* ---------- self-test overlay ---------- */
#selftest {
  position: fixed;
  top: 14px;
  right: 14px;
  width: min(600px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line-strong);
  box-shadow: 0 10px 34px rgba(20, 24, 28, 0.18);
  z-index: 60;
}
#selftest[hidden] { display: none; }
.sthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 2px solid var(--ink);
  position: sticky;
  top: 0;
  background: #fff;
}
.sthead h2 { margin: 0; font-size: 13.5px; font-weight: 700; }
.stclose {
  font: inherit;
  font-size: 16px;
  line-height: 1;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  border-radius: 3px;
  width: 26px; height: 26px;
  cursor: pointer;
}
.stclose:hover { border-color: var(--ink-soft); }
.stnote { margin: 10px 14px 4px; font-size: 11px; color: var(--muted); }
.stbody { padding: 6px 14px 14px; }
.strow {
  display: grid;
  grid-template-columns: minmax(150px, 2.2fr) auto auto auto auto minmax(44px, auto);
  gap: 10px;
  align-items: baseline;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  font-size: 11.5px;
}
.strow:last-child { border-bottom: 0; }
.stname { font-weight: 600; }
.stname small { display: block; font-weight: 400; color: var(--faint); font-size: 10px; }
.stval { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 11px; }
.stval.bad { color: var(--bad); font-weight: 700; }
.stchip {
  justify-self: end;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 8px;
  background: #e2efe9;
  color: var(--ok);
}
.stchip.fail { background: #f3dedb; color: var(--bad); }
.stsect {
  margin: 10px 0 2px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed;
  z-index: 80;
  max-width: 262px;
  background: var(--ink);
  color: #f2f1ed;
  font-size: 11.5px;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 3px;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
#tooltip .tt-h { font-weight: 700; margin-bottom: 3px; }
#tooltip .num { font-size: 10.5px; }
#tooltip .tt-anom { color: #ffb4a8; font-weight: 700; }

/* ---------- noscript ---------- */
.noscript {
  position: fixed;
  inset: auto 10px 10px;
  background: #fff8e6;
  border: 1px solid #d9c37a;
  padding: 12px 16px;
  font-size: 13px;
  z-index: 90;
  border-radius: 3px;
}

/* ---------- axis captions for canvas chart ---------- */
.axiscap {
  position: absolute;
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.axiscap-x { bottom: 2px; right: 4px; }
.axiscap-y {
  top: 50%;
  left: -4px;
  transform: rotate(180deg);
  writing-mode: vertical-rl;
  left: -14px;
}

/* ---------- motion (only when the user allows it) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .btn, .chip span, .switch .knob, .switch .knob::after { transition-duration: 0.15s; }
  .area-band, .rank-bar, .hist-bar { transition: opacity 0.18s; }
}
@media (prefers-reduced-motion: reduce) {
  .area-band.dim { opacity: 0.22; } /* final state, no animation */
  * { transition: none !important; animation: none !important; }
}

/* narrow: self-test goes in-flow-ish at bottom */
@media (max-width: 860px) {
  #selftest { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-height: 60vh; }
}
