/* Regional Fail - dark theme. Status colors are the validated fixed status palette; text never wears them. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --ring: rgba(255, 255, 255, 0.10);
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #3987e5;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font-family: var(--font); }
a { color: var(--ink); }
button { font: inherit; }

/* ---------- header ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 28px; padding: 14px 20px; border-bottom: 1px solid var(--grid); }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.brand h1::before { content: "👻 "; }
.tagline { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.traffic { display: flex; flex-direction: column; padding: 8px 14px; background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; min-width: 260px; }
.traffic-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.traffic-level { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.traffic-level::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--lvl, var(--muted)); }
.traffic-detail { font-size: 13px; color: var(--ink-2); }
.nav { margin-left: auto; display: flex; gap: 6px; font-size: 14px; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 7px 12px; border-radius: 999px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface-3); color: var(--ink); font-weight: 600; }

/* ---------- shared controls ---------- */
.seg { background: var(--surface); color: var(--ink-2); border: 1px solid var(--ring); border-radius: 999px; padding: 6px 14px; font-size: 14px; cursor: pointer; transition: background .15s, transform .1s; }
.seg:hover { background: var(--surface-2); color: var(--ink); }
.seg:active { transform: scale(0.97); }
.seg[aria-pressed="true"] { color: var(--ink); background: var(--surface-3); border-color: var(--ink-2); font-weight: 600; }

.grade-badge { display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 9px; background: var(--g); color: var(--gi); font-weight: 800; font-size: 18px; transform: rotate(-4deg); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
.grade-badge.sm { width: 22px; height: 22px; font-size: 12px; border-radius: 6px; transform: none; box-shadow: none; }
.grade-badge.lg { width: 52px; height: 52px; font-size: 28px; border-radius: 12px; }
.grade-badge.none { background: var(--surface-3); color: var(--muted); transform: none; box-shadow: none; }

/* ---------- line picker ---------- */
.linebar { display: flex; align-items: center; gap: 10px; padding: 12px 20px 0; }
.linebar-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: thin; }
.chip { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; background: var(--surface); color: var(--ink-2); border: 1px solid var(--ring); border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 14px; cursor: pointer; transition: background .15s, transform .1s; }
.chip:first-child { padding-right: 12px; }
.chip:hover { background: var(--surface-2); color: var(--ink); transform: translateY(-1px); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); font-weight: 600; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 10px 20px 14px; }
@media (max-width: 700px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.tile-value { font-size: 28px; font-weight: 700; }
.tile-label { font-size: 13px; color: var(--ink-2); }

/* ---------- map page layout ---------- */
.layout { display: grid; grid-template-columns: 1fr 340px; gap: 12px; padding: 0 20px 14px; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }
.map-wrap { position: relative; height: 72vh; min-height: 460px; border-radius: 10px; overflow: hidden; border: 1px solid var(--ring); background: var(--surface); }
#map { position: absolute; inset: 0; }

.dir-toggle { position: absolute; top: 10px; left: 10px; display: flex; gap: 4px; padding: 4px; background: rgba(26, 26, 25, 0.92); border: 1px solid var(--ring); border-radius: 999px; }
.dir-toggle .seg { border: none; padding: 5px 12px; font-size: 13px; }

.legend { position: absolute; left: 10px; bottom: 58px; background: rgba(26, 26, 25, 0.92); border: 1px solid var(--ring); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.legend-row { display: flex; align-items: center; gap: 6px; }
.dot { width: var(--s, 10px); height: var(--s, 10px); flex: none; margin: 0 calc((16px - var(--s, 10px)) / 2); border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--surface); }
.ghost-key { width: 16px; text-align: center; font-size: 12px; }

.timebar { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; align-items: center; gap: 10px; background: rgba(26, 26, 25, 0.92); border: 1px solid var(--ring); border-radius: 999px; padding: 5px 8px; }
.timebar input { flex: 1; accent-color: var(--ink-2); }
.timebar button { background: var(--surface-2); color: var(--ink); border: 1px solid var(--ring); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.live-btn[aria-pressed="true"] { border-color: var(--critical); }
.time-label { font-size: 13px; color: var(--ink-2); min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }

.tooltip { position: absolute; z-index: 5; pointer-events: none; background: var(--surface-2); border: 1px solid var(--ring); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--ink-2); max-width: 320px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5); }
.tooltip .tt-head { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.tooltip .tt-key { width: 14px; height: 3px; border-radius: 2px; background: var(--c); }
.tooltip .tt-big { color: var(--ink); font-weight: 700; }
.tooltip .tt-row { margin-top: 2px; }
.tooltip .tt-alert { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--grid); font-size: 12px; }

/* The root is positioned by MapLibre; never override its position. */
.ghost-marker { cursor: default; }
.ghost-marker .ghost-inner { display: block; position: relative; font-size: 18px; line-height: 1; filter: drop-shadow(0 0 2px #000); animation: float 2.4s ease-in-out infinite; }
.ghost-marker .count { position: absolute; top: -6px; right: -10px; background: var(--critical); color: #fff; font-size: 10px; font-weight: 700; border-radius: 8px; padding: 1px 4px; }
@keyframes float { 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .ghost-marker .ghost-inner { animation: none; } }

/* ---------- side panel ---------- */
.side { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 14px; overflow: auto; max-height: 72vh; display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 900px) { .side { max-height: none; } }
.side h2 { font-size: 15px; margin: 2px 0 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.side-head h2 { font-size: 22px; margin: 0; }
.side-quip { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; font-style: italic; }
.side-note { margin: 0; font-size: 12px; color: var(--muted); }
.side-note a { color: var(--ink-2); }
.asof { font-size: 12px; color: var(--muted); margin: 0; }

.dir-block { background: var(--surface-2); border-radius: 10px; padding: 12px; border-left: 4px solid var(--edge); }
.dir-block.in { --edge: var(--accent); }
.dir-block.out { --edge: #9085e9; }
.dir-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dir-title { display: flex; align-items: center; gap: 10px; background: none; border: none; color: var(--ink); cursor: pointer; padding: 0; text-align: left; }
.dir-title strong { display: block; font-size: 16px; }
.dir-title small { display: block; color: var(--muted); font-size: 12px; }
.dir-title:hover strong { text-decoration: underline; }
.dir-icon { font-size: 22px; }
.dir-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.dir-stats div { background: var(--surface); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; }
.dir-stats b { font-size: 18px; }
.dir-stats span { font-size: 11px; color: var(--muted); }
.dir-sub { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

.mini-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.mini-list li { display: flex; gap: 6px; align-items: baseline; padding: 6px 8px; background: var(--surface); border-radius: 8px; color: var(--ink-2); }
.side > .mini-list li { background: var(--surface-2); }
.mini-list li strong { color: var(--ink); }
.mini-list li.clickable { cursor: pointer; }
.mini-list li.clickable:hover { outline: 1px solid var(--ink-2); }
.mini-list .badge { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.mini-list .empty { background: none !important; padding: 0; color: var(--muted); }
.mini-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); align-self: center; flex: none; }

/* ---------- report cards page ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 14px 20px 0; }
.segs { display: flex; gap: 4px; }
.filter-note { font-size: 13px; color: var(--muted); }

.awards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; padding: 14px 20px; }
.award { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 16px 18px; transition: transform .15s; }
.award[href]:hover { transform: translateY(-2px); }
.award.worst { border-top: 4px solid var(--critical); }
.award.best { border-top: 4px solid var(--good); }
.award-kicker { font-size: 13px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
.award-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.award-name { font-size: 28px; font-weight: 800; }
.award-detail { font-size: 14px; color: var(--ink-2); margin: 10px 0 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; padding: 0 20px 20px; }
.line-card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; scroll-margin: 20px; }
.line-card.unranked { opacity: 0.85; }
.line-card.focus { outline: 2px solid var(--ink-2); }
.lc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.lc-head h2 { margin: 2px 0 0; font-size: 20px; }
.lc-rank { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.lc-rank.muted { color: var(--muted); font-weight: 400; }
.lc-quip { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); font-style: italic; }
.lc-score { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.lc-score span { display: block; height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }
.halves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.half { display: block; text-decoration: none; background: var(--surface-2); border-radius: 10px; padding: 10px; border-top: 3px solid var(--edge); transition: background .15s; }
.half:hover { background: var(--surface-3); }
.half.in { --edge: var(--accent); }
.half.out { --edge: #9085e9; }
.half-head { display: flex; justify-content: space-between; align-items: center; }
.half-title { font-weight: 700; font-size: 14px; }
.half-sub { font-size: 11px; color: var(--muted); }
.half-big { font-size: 26px; font-weight: 800; margin-top: 6px; }
.half-big small { font-size: 12px; font-weight: 400; color: var(--muted); }
.half-row { display: flex; flex-direction: column; font-size: 12px; color: var(--ink-2); gap: 2px; margin-top: 4px; }
.lc-link { font-size: 13px; color: var(--ink-2); text-decoration: none; align-self: flex-end; }
.lc-link:hover { color: var(--ink); text-decoration: underline; }

/* ---------- footer ---------- */
.about { padding: 10px 20px 40px; color: var(--ink-2); font-size: 14px; max-width: 900px; }
.about h2 { color: var(--ink); font-size: 18px; }
.about li { margin: 4px 0; }
.fine-print { font-size: 12px; color: var(--muted); }
.maplibregl-ctrl-attrib { font-size: 10px; }
@media (max-width: 520px) {
  .dir-toggle .seg { padding: 4px 8px; font-size: 12px; }
  .nav { margin-left: 0; }
  .legend { display: none; }
}

/* ---------- freshness ---------- */
.traffic-age { font-size: 12px; color: var(--muted); }
.traffic-age.stale-text { color: var(--warning); }
.stale { margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px; background: rgba(250, 178, 25, 0.12); border: 1px solid var(--warning); color: var(--ink); font-size: 14px; }
.stale::before { content: "⚠️ "; }


/* ---------- "What is this?" note ---------- */
.intro { position: relative; margin: 14px 20px 0; padding: 14px 44px 12px 16px; background: var(--surface); border: 1px solid var(--ring); border-left: 4px solid var(--accent); border-radius: 10px; color: var(--ink-2); font-size: 14px; line-height: 1.5; max-width: 980px; }
.intro[hidden] { display: none; }
.intro p { margin: 0 0 8px; }
.intro strong { color: var(--ink); }
.intro .intro-fine { margin: 0; font-size: 12px; color: var(--muted); }
.intro-close { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--ring); background: var(--surface-2); color: var(--ink-2); cursor: pointer; font-size: 14px; line-height: 1; }
.intro-close:hover { color: var(--ink); background: var(--surface-3); }
