/* ============================================================
   Movement Observatory — Coastal Traffic Authority
   Warm paper neutrals, one deep-teal accent, tabular numerals.
   ============================================================ */

:root {
  --bg: #f5f3ee;
  --surface: #fdfcf9;
  --surface-2: #faf8f3;
  --hairline: #e3dfd5;
  --hairline-strong: #d5d0c4;
  --ink: #22252a;
  --ink-soft: #3c4046;
  --muted: #6e6a5f;
  --muted-2: #8a8578;
  --accent: #0f6f6a;
  --accent-deep: #0a544f;
  --accent-pale: #dcece8;
  --dim: #b9b6ac;
  --dim-fill: #cdc9bd;
  --error: #a63a2e;
  --good: #146b46;
  --radius: 8px;
  --maxw: 1280px;
  --grid-gap: clamp(14px, 2vw, 24px);
  --mono: "SFMono-Regular", "Cascadia Mono", "IBM Plex Mono", Consolas, monospace;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Georgia", "Times New Roman", serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- masthead ---------- */
.masthead {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(20px, 3.4vw, 36px) clamp(16px, 3vw, 32px) clamp(14px, 2vw, 20px);
}

.masthead-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--hairline-strong);
  padding-bottom: 14px;
  flex-wrap: wrap;
}

.kicker {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  max-width: 62ch;
}

.count-block {
  text-align: right;
  flex-shrink: 0;
}
.live-count-label {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.live-count {
  margin: 2px 0 2px;
  font-size: clamp(28px, 3.4vw, 40px);
  font-weight: 650;
  line-height: 1;
  color: var(--accent-deep);
  letter-spacing: -0.02em;
}
.live-sub {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- filters ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  align-items: flex-start;
  padding: 16px 0 4px;
  border-bottom: 1px solid var(--hairline);
}

.fgroup {
  margin: 0;
  border: 0;
  padding: 0;
  min-width: 0;
}
.fgroup legend,
.fgroup > label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  appearance: none;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.chip:hover { background: var(--surface-2); border-color: #c9c3b4; }
.chip[aria-pressed="true"],
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #f3faf7;
}
.chip.small { padding: 4px 10px; font-size: 11.5px; }
.chip:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible,
.chart:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
.chip.toggle[aria-pressed="true"] { background: var(--error); border-color: var(--error); color: #fff; }

.month-range { display: flex; align-items: center; gap: 8px; }
.month-range .dash { color: var(--muted-2); }
select {
  appearance: none;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  border-radius: 6px;
  padding: 5px 26px 5px 10px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236e6a5f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

/* ---------- status group (frame time) ---------- */
.status-group {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}
.frame-time-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}
.frame-stats {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#frame-graph {
  display: block;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--surface);
  width: 220px;
  height: 42px;
}

/* ---------- main grid ---------- */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 32px) clamp(24px, 3vw, 40px);
}

.panel {
  position: relative;
  padding: 0 clamp(2px, 1vw, 12px) 18px;
  margin-top: clamp(22px, 3vw, 32px);
}

/* The grid: stacked area full-width; bars, scatter, heatmap, histogram in a 12-col grid */
.panel-area { grid-column: 1 / -1; }
.panel-bars { grid-column: span 5; }
.panel-scatter { grid-column: 1 / -1; }
.panel-heatmap { grid-column: span 5; }
.panel-histogram { grid-column: 1 / -1; }
@media (min-width: 1280px) { .panel-histogram { grid-column: span 7; } }

@media (min-width: 1280px) {
  main { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 0 18px; align-items: start; }
  .panel { margin-top: 0; margin-bottom: 18px; }
  .self-test { grid-column: 1 / -1; }
  .panel-area { grid-column: 1 / -1; }
  .panel-bars { grid-column: span 5; }
  .panel-scatter { grid-column: span 7; }
  .panel-heatmap { grid-column: span 5; }
  .panel-histogram { grid-column: span 7; }
}
@media (min-width: 1024px) and (max-width: 1279px) {
  main { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 0 16px; align-items: start; }
  .panel { margin-top: 0; margin-bottom: 18px; }
  .self-test { grid-column: 1 / -1; }
  .panel-area { grid-column: 1 / -1; }
  .panel-bars { grid-column: span 5; }
  .panel-scatter { grid-column: span 7; }
  .panel-heatmap { grid-column: span 5; }
  .panel-histogram { grid-column: span 7; }
}
@media (max-width: 1023px) {
  main { display: block; }
  .panel { margin-top: 14px; }
  .panel-bars, .panel-heatmap, .panel-histogram { margin-top: 14px; }
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 9px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--hairline-strong);
}
.panel-head-text { min-width: 0; }

h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 3px;
  color: var(--ink);
}
.panel-touch {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.panel-touch .touch-active { color: var(--accent-deep); font-weight: 600; }
.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid var(--hairline);
  background: var(--surface-2);
}
.badge--pass {
  color: var(--good);
  border-color: #b7d6c4;
  background: #edf5ef;
}
.badge--fail {
  color: var(--error);
  border-color: #e0b3a7;
  background: #faf0ec;
}

.panel-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-2);
  border: 1px solid var(--hairline);
  padding: 3px 9px;
  border-radius: 999px;
}

.chart { position: relative; margin: 0; cursor: crosshair; }
svg.chart-svg, .chart svg { display: block; width: 100%; height: auto; }
canvas#canvas-scatter { display: block; width: 100%; height: auto; touch-action: none; }

.chart-note {
  margin: 10px 0 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.chart-note em { color: var(--accent-deep); font-style: normal; font-weight: 650; }

.table-alt summary {
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-deep);
  padding: 6px 0 0;
}
.table-wrap { overflow-x: auto; max-height: 340px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; margin: 8px 0 4px; }
th, td {
  text-align: right;
  padding: 3px 8px 3px 0;
  border-bottom: 1px solid #eeece5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
caption { font-size: 11.5px; color: var(--muted); text-align: left; margin-bottom: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- self-test ---------- */
.self-test {
  overflow: hidden;
}
.self-test-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.self-test-summary { margin: 0 0 10px; color: var(--ink-soft); font-size: 13px; }
.self-test-list {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: 1fr; gap: 3px;
}
.self-test-list li {
  display: grid;
  grid-template-columns: 96px 1fr 64px;
  gap: 8px;
  align-items: baseline;
  font-size: 11.5px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  min-width: 0;
}
.self-test-list li > * { min-width: 0; overflow-wrap: anywhere; }
.self-test-list li .st-name { font-weight: 650; color: var(--muted); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; }
.self-test-list li .st-detail { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.self-test-list li .st-verdict { text-align: right; font-weight: 700; letter-spacing: 0.08em; font-size: 11px; }
.self-test-list li.pass .st-verdict { color: var(--good); }
.self-test-list li.fail .st-verdict { color: var(--error); }
.self-test-list li.fail { border-color: #d9b6ad; background: #fbf3f0; }
@media (min-width: 1024px) {
  .self-test-list { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1280px) {
  .self-test-list { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
}

.reference-block {
  font-family: var(--mono);
  font-size: 11.5px;
  background: #f2efe6;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0 0;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------- tooltip ---------- */
.tooltip {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  background: #1f2329;
  color: #f4f2ec;
  border-radius: 8px;
  padding: 9px 11px 10px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 10px 24px rgba(28, 30, 34, 0.28);
  max-width: 250px;
  min-width: 150px;
  transform: translate(-50%, calc(-100% - 12px));
}
.tooltip .tt-kicker {
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: #a9e3d8; margin-bottom: 4px;
}
.tooltip .tt-main { font-size: 13px; font-weight: 650; color: #fff; }
.tooltip .tt-row { color: #d8d4c9; font-variant-numeric: tabular-nums; }
.tooltip .tt-row b { color: #fff; font-weight: 650; }

/* ---------- heatmap ---------- */
.hbar-stack { display: block; }

/* ---------- method footer ---------- */
.method {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 30px clamp(16px, 3vw, 32px) 46px;
  border-top: 1px solid var(--hairline-strong);
}
.method h2 { font-family: var(--serif); font-size: 24px; margin-bottom: 14px; }
.method-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 22px 32px;
}
.method-grid h3 {
  margin: 0 0 6px; font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-deep);
}
.method-grid p { margin: 0; font-size: 13.5px; color: var(--ink-soft); line-height: 1.6; }
.method-foot { margin-top: 22px; color: var(--muted); font-size: 12.5px; }
.method-foot code { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--hairline); border-radius: 4px; padding: 1px 5px; font-size: 11.5px; }

@media (max-width: 720px) {
  .method-grid { grid-template-columns: 1fr; }
}

/* ---------- animations ---------- */
@media (prefers-reduced-motion: no-preference) {
  .chip { transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1023px) {
  .count-block { text-align: left; }
  .status-group { margin-left: 0; align-items: flex-start; }
  .filters { gap: 12px; }
}
@media (max-width: 700px) {
  body { font-size: 14px; }
  .panel { padding: 12px; }
  .panel-head { flex-direction: column; gap: 10px; }
  .panel-badge { order: 2; }
  .masthead { padding-top: 18px; }
  h1 { font-size: 27px; }
  .self-test-list li { grid-template-columns: 1fr; gap: 3px; }
  .self-test-list li .st-verdict { text-align: left; }
}

/* ---------- per-panel filter lines / pin pill / dimming ---------- */
.panel-filters {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted-2);
  line-height: 1.5;
}
.panel.is-dimmed .chart,
.panel.is-dimmed .table-alt,
.panel.is-dimmed .chart-note {
  opacity: 0.45;
  filter: saturate(0.6);
}
.panel.is-dimmed .panel-filters {
  color: var(--muted);
  opacity: 0.75;
}
.panel { transition: opacity 0.18s ease; }
.panel.is-dimmed .chart,
.panel.is-dimmed .table-alt { transition: opacity 0.18s ease, filter 0.18s ease; }
.panel.is-pinned {
  box-shadow: inset 3px 0 0 var(--accent);
}
.panel.is-pinned .panel-badge {
  background: var(--accent);
  color: #fdfcf9;
  border-color: var(--accent-deep);
}
.pin-pill {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent-pale);
  color: var(--accent-deep);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pin-pill:hover { background: #fff; }
.pin-pill:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .panel,
  .panel.is-dimmed .chart,
  .panel.is-dimmed .table-alt,
  .panel-filters { transition: none !important; }
}

/* SVG chart text (skeleton-drawn) */
.tick-label { fill: #8a8578; font-size: 10.5px; font-family: var(--mono); letter-spacing: 0.02em; }
.heat-count { font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.bar-label { fill: #2c2f34; font-size: 12.5px; font-weight: 550; }
.bar-label.is-cursor { fill: var(--accent-deep); }
.bar-value { font-family: var(--mono); font-size: 11px; font-weight: 600; }
.bar-rank { fill: var(--muted-2); font-family: var(--mono); font-size: 10.5px; }

/* no-JS fallback */
.panel-fallback,
#noscript-fallback table.table-fallback {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
#noscript-fallback table.table-fallback th,
#noscript-fallback table.table-fallback td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--hairline);
}
#noscript-fallback table.table-fallback thead th {
  background: var(--surface-2);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline-strong);
}
#noscript-fallback table.table-fallback tbody th { font-weight: 550; color: var(--ink); }
#noscript-fallback table.table-fallback tbody td { color: var(--muted); font-family: var(--mono); }
