/* SafeCross AI: mobile-first. Bottom tab bar on phones, top bar on wide screens.
   Look: street signage. Warm paper and asphalt ink, one signal-amber accent, Overpass (a highway-sign typeface) with a
   monospace for numbers, and crosswalk stripes as the recurring motif. Risk tier colours are data and never change. */

@font-face {
  font-family: "Overpass"; src: url("/fonts/overpass.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Overpass Mono"; src: url("/fonts/overpass-mono.woff2") format("woff2");
  font-weight: 300 700; font-style: normal; font-display: swap;
}

:root {
  --paper: #f3f0e8; --ink: #17191b; --amber: #f5b301;
  --bg: var(--paper); --surface: #fffdf9; --surface-2: #ebe7dd; --text: var(--ink); --muted: #5f6064;
  --border: #ddd7ca; --border-strong: #bfb7a5;
  --primary: var(--ink); --primary-text: #f7f4ec; --primary-soft: #f8eac0;
  --focus-halo: rgba(245, 179, 1, .45); --marker: rgba(245, 179, 1, .55); --skeleton-hi: #f7f4ec;
  --danger: #c4261d; --ok: #1e7a3c;
  --warn-bg: #fbf0cc; --warn-text: #4f3b00; --warn-rule: #e0a500;
  --info-bg: #e7e9e6; --info-text: #26313b; --info-rule: #6b7c8f;
  --error-bg: #fbe6e3; --error-text: #8a1c14; --error-rule: #c4261d;
  --shadow-sm: 0 1px 2px rgba(46, 36, 12, .06), 0 2px 6px -2px rgba(46, 36, 12, .08);
  --shadow-md: 0 2px 4px rgba(46, 36, 12, .05), 0 12px 28px -10px rgba(46, 36, 12, .22);
  --shadow-lg: 0 4px 10px rgba(23, 25, 27, .08), 0 24px 60px -16px rgba(23, 25, 27, .35);
  --font-sans: "Overpass", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Overpass Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in: cubic-bezier(.55, 0, 1, .45);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
  --radius: 18px; --nav-h: 64px; --topbar-h: 60px;
  color-scheme: light dark;
  interpolate-size: allow-keywords;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --surface: #1a1c1f; --surface-2: #24272b; --text: #ece8de; --muted: #a19e95;
    --border: #2d3034; --border-strong: #464a50;
    --primary: var(--amber); --primary-text: #111214; --primary-soft: #362b0c;
    --focus-halo: rgba(245, 179, 1, .3); --marker: rgba(245, 179, 1, .32); --skeleton-hi: #2e3237;
    --danger: #ff7b6e; --ok: #63c483;
    --warn-bg: #2c2408; --warn-text: #f5dc95; --warn-rule: #c99a10;
    --info-bg: #1c2228; --info-text: #c9d3dd; --info-rule: #7d8fa3;
    --error-bg: #361512; --error-text: #ffb4ab; --error-rule: #e5544a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, .3), 0 14px 30px -12px rgba(0, 0, 0, .7);
    --shadow-lg: 0 4px 10px rgba(0, 0, 0, .35), 0 28px 60px -18px rgba(0, 0, 0, .85);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 var(--font-sans); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
::selection { background: var(--marker); color: inherit; }
a { color: var(--text); text-decoration-color: var(--amber); text-decoration-thickness: 2px; text-underline-offset: 3px; transition: text-decoration-color .2s; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3, h4 { text-wrap: balance; }
h1 { font-size: clamp(2.1rem, 1.3rem + 3.4vw, 3.6rem); font-weight: 800; line-height: .98; letter-spacing: -.03em; margin: .15rem 0 .5rem; }
h2 { font-size: 1.4rem; font-weight: 800; letter-spacing: -.015em; line-height: 1.15; margin: 2.2rem 0 .5rem; }
h3 { font-size: 1.1rem; font-weight: 750; letter-spacing: -.01em; margin: 1.2rem 0 .3rem; }
p { text-wrap: pretty; }
strong { font-weight: 750; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--primary); color: var(--primary-text); padding: .5rem 1rem; z-index: 100; border-radius: 10px; }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 4px; }
/* Headings get focus from script on navigation so screen readers announce them; they aren't controls, so no ring. */
[tabindex="-1"]:focus { outline: none; }
[hidden] { display: none !important; }
.icon { flex: none; display: block; }

/* Small mono labels, used for kickers, labels and section tags. */
.kicker, label, legend, .metric-label, .fact-group h4, .filter-card h2 {
  font-family: var(--font-mono); font-size: .72rem; line-height: 1rem; font-weight: 600;
  letter-spacing: .01em; color: var(--muted);
}

/* ---------- top bar & navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: stretch; gap: 12px;
  min-height: var(--topbar-h); padding: env(safe-area-inset-top) 16px 0;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); border-radius: 10px; }
.brand-mark { display: block; transition: transform .5s var(--ease-spring); }
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.06); }
.bm-bg { fill: var(--text); } .bm-stripes { fill: var(--bg); } .bm-signal { fill: var(--amber); }
.brand-name { font-weight: 800; font-size: 1.12rem; letter-spacing: -.02em; display: flex; align-items: center; gap: 6px; }
.brand-tag {
  font-family: var(--font-mono); font-size: .62rem; font-weight: 700; letter-spacing: .08em;
  padding: 3px 5px 1px; border-radius: 5px; border: 1.5px solid currentColor; line-height: 1;
}
.tabs { display: none; position: relative; gap: 4px; margin-left: 20px; }
.tabs a {
  display: flex; align-items: center; padding: 0 14px; text-decoration: none; color: var(--muted);
  font-weight: 650; transition: color .25s;
}
.tabs a:hover, .tabs a[aria-current="page"] { color: var(--text); }
.tabs .nav-indicator {
  position: absolute; left: 0; bottom: -1px; height: 3px; width: var(--w, 0); border-radius: 3px 3px 0 0;
  background: var(--amber); transform: translateX(var(--x, 0)); opacity: 0;
}
.nav-indicator.is-placed { opacity: 1; transition: transform .5s var(--ease-out), width .5s var(--ease-out), opacity .2s; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
/* While the map pans or zooms, drop the blur (it would be recomputed every frame) for a near-solid bar. */
.map-moving .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; background: color-mix(in srgb, var(--bg) 97%, transparent); }
.map-moving .bottom-nav { -webkit-backdrop-filter: none; backdrop-filter: none; background: color-mix(in srgb, var(--surface) 97%, transparent); }
.bottom-nav a {
  position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: var(--nav-h); text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 650; letter-spacing: .02em;
  transition: color .25s; -webkit-tap-highlight-color: transparent;
}
.bottom-nav a[aria-current="page"] { color: var(--text); }
.bottom-nav a:active .bn-icon { transform: scale(.88); }
.bn-icon { display: grid; place-items: center; height: 30px; transition: transform .3s var(--ease-spring); }
.bottom-nav .nav-indicator {
  position: absolute; z-index: 0; top: 9px; left: 0; width: 60px; height: 30px; border-radius: 999px;
  background: color-mix(in srgb, var(--amber) 30%, transparent); transform: translateX(calc(var(--x, 0px) + var(--w, 60px) / 2 - 30px)); opacity: 0;
}
.bottom-nav .nav-indicator.is-placed { transition: transform .55s var(--ease-spring), opacity .2s; }
main { max-width: 1120px; margin: 0 auto; padding: 24px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); outline: none; }
@media (min-width: 860px) {
  .tabs { display: flex; } .bottom-nav { display: none; }
  main { padding: 40px 28px 64px; }
}
@media (max-width: 520px) { .btn-icon-label { display: none; } .btn-icon { padding: 0 9px; } }

/* ---------- page header & entrance ---------- */
.page-head { margin-bottom: 22px; }
.kicker { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.kicker::before {
  content: ""; width: 26px; height: 10px; flex: none; border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--amber) 0 4px, transparent 4px 7px);
}
.lede { font-size: 1.1rem; color: var(--muted); max-width: 60ch; margin: .4rem 0 0; }
.page > * { animation: rise .6s var(--ease-out) both; }
.page > :nth-child(2) { animation-delay: 60ms; } .page > :nth-child(3) { animation-delay: 120ms; }
.page > :nth-child(4) { animation-delay: 170ms; } .page > :nth-child(n+5) { animation-delay: 210ms; }
.results > * { animation: rise .55s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
.results > .cards, .page > .sheet-host, .results > .sheet-host { animation: none; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes rise-sm { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
@keyframes bar-grow { from { transform: scaleX(0); } to { transform: none; } }
@keyframes marker { to { background-size: 100% 3px; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes march { to { background-position: 14px 0; } }
@keyframes dash-flow { to { background-position: 0 16px; } }

/* ---------- controls ---------- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1.5px solid var(--primary); background: var(--primary); color: var(--primary-text);
  font: 650 1rem/1 var(--font-sans); padding: 2px 20px 0; border-radius: 12px; cursor: pointer; min-height: 48px;
  text-decoration: none; box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 8px 18px -10px rgba(23, 25, 27, .55);
  transition: transform .2s var(--ease-out), box-shadow .25s var(--ease-out), background-color .2s, color .2s, border-color .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 12px 24px -10px rgba(23, 25, 27, .6); }
.btn:active { transform: translateY(0) scale(.97); transition-duration: .08s; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text); box-shadow: none; }
.btn-small { min-height: 38px; padding: 2px 13px 0; font-size: .9rem; border-radius: 10px; gap: 6px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.btn .icon { margin-top: -2px; }
.btn.is-busy { cursor: progress; }
label { display: block; margin-bottom: 6px; }
input[type="text"] {
  width: 100%; font: inherit; font-size: 1rem; padding: 13px 14px 11px; min-height: 50px;
  border: 1.5px solid transparent; border-radius: 12px; background: var(--surface-2); color: var(--text);
  transition: border-color .2s, background-color .2s, box-shadow .3s var(--ease-out);
}
input[type="text"]:hover { border-color: var(--border-strong); }
input[type="text"]:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px var(--focus-halo); }
input::placeholder { color: var(--muted); opacity: .75; }
.field { margin-bottom: 14px; position: relative; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }

/* Trip form: a start ring and a destination diamond joined by a dashed line, like a transit ticket. */
.trip-form { padding: 20px; }
.trip-fields { display: grid; gap: 12px; margin-bottom: 18px; }
.trip-row { display: grid; grid-template-columns: 26px 1fr; gap: 10px; align-items: end; }
.trip-row .field { margin: 0; }
.trip-pin { position: relative; height: 50px; display: grid; place-items: center; }
.trip-pin::after { content: ""; position: relative; z-index: 1; width: 14px; height: 14px; }
.trip-pin-start::after { border-radius: 50%; border: 3px solid var(--text); background: var(--amber); }
.trip-pin-end::after { width: 12px; height: 12px; background: var(--text); transform: rotate(45deg); border-radius: 2px; }
.trip-pin-start::before {
  content: ""; position: absolute; left: 12px; top: 50%; width: 2px; height: calc(68px + 1rem);
  background: repeating-linear-gradient(to bottom, var(--border-strong) 0 5px, transparent 5px 8px);
}
.trip-form.is-busy .trip-pin-start::before {
  background-image: repeating-linear-gradient(to bottom, var(--amber) 0 5px, transparent 5px 8px); background-size: 2px 16px;
  animation: dash-flow .5s linear infinite;
}
.input-action {
  position: absolute; right: 6px; bottom: 6px; width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer;
  transition: background-color .2s, color .2s, transform .2s var(--ease-out);
}
.input-action:hover { background: var(--surface); color: var(--text); }
.input-action:active { transform: scale(.9); }
.input-action.is-locating .icon { animation: spin 1.2s linear infinite; }
.field:has(.input-action) input { padding-right: 52px; }
.form-hint { margin: 14px 0 0; font-size: .85rem; color: var(--muted); }

/* Segmented control with a sliding thumb. */
.segmented {
  position: relative; isolation: isolate; display: grid; grid-template-columns: repeat(3, 1fr);
  width: 100%; max-width: 480px; padding: 4px; border-radius: 14px; background: var(--surface-2);
}
.segmented::before {
  content: ""; position: absolute; z-index: -1; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 3);
  border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
  transition: transform .5s var(--ease-spring);
}
.segmented:has(label:nth-child(2) input:checked)::before { transform: translateX(100%); }
.segmented:has(label:nth-child(3) input:checked)::before { transform: translateX(200%); }
.segmented label { margin: 0; position: relative; font: inherit; letter-spacing: normal; text-transform: none; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 2px 8px 0;
  cursor: pointer; font-weight: 650; font-size: .95rem; color: var(--muted); border-radius: 10px; transition: color .25s;
}
.segmented span .icon { margin-top: -2px; transition: transform .4s var(--ease-spring); }
.segmented input:checked + span { color: var(--text); }
.segmented input:checked + span .icon { transform: scale(1.12); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; min-height: 38px; padding: 2px 14px 0; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--muted); font: 600 .9rem/1 var(--font-sans);
  cursor: pointer; transition: background-color .2s, border-color .2s, color .2s, transform .2s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip:active { transform: scale(.95); transition-duration: .08s; }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--text); }
.chip .dot { transition: opacity .25s, transform .35s var(--ease-spring), filter .25s; }
.chip[aria-pressed="false"] .dot { opacity: .45; filter: saturate(.2); transform: scale(.8); }

/* ---------- banners, cards, badges ---------- */
.banner {
  padding: 12px 16px 11px; border-radius: 12px; margin: 12px 0; display: flex; gap: 12px; align-items: center;
  justify-content: space-between; border-left: 4px solid transparent; font-size: .95rem; line-height: 1.5;
}
.banner-warn { background: var(--warn-bg); color: var(--warn-text); border-left-color: var(--warn-rule); display: block; }
.banner-info { background: var(--info-bg); color: var(--info-text); border-left-color: var(--info-rule); }
.banner-error { background: var(--error-bg); color: var(--error-text); border-left-color: var(--error-rule); display: block; animation: shake .45s var(--ease-out); }
.banner-offline { background: var(--ink); color: var(--paper); margin: 0; border-radius: 0; border: 0; justify-content: center; font-size: .9rem; }
@keyframes shake { 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.filter-card h2 { margin: 0 0 10px; }
.filter-card h2 ~ h2 { margin-top: 18px; }
.cards { display: grid; gap: 14px; grid-template-columns: 1fr; margin: 16px 0 18px; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); } }
.route-card {
  position: relative; overflow: hidden; padding: 22px 18px 16px; cursor: pointer; border-width: 1.5px;
  animation: rise .6s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 80ms + 60ms);
  transition: transform .4s var(--ease-out), box-shadow .4s var(--ease-out), border-color .25s, background-color .25s;
}
.route-card::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: var(--route-color, var(--border-strong));
  transform-origin: left; animation: bar-grow .8s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 80ms + 160ms);
  transition: height .3s var(--ease-out);
}
.route-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.route-card.is-selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-halo), var(--shadow-md); }
.route-card.is-selected::before { height: 7px; }
.route-card h3 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 1.2rem; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 10px; }
.metric-label { margin-bottom: 2px; }
.metric-value { font-family: var(--font-mono); font-size: 1.75rem; font-weight: 600; line-height: 1.15; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.delta { font-family: var(--font-mono); font-size: .78rem; font-weight: 600; color: var(--danger); margin-top: 2px; }
.delta.good { color: var(--ok); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; min-height: 22px; }
.badge {
  font-family: var(--font-mono); font-size: .66rem; font-weight: 700; letter-spacing: .01em;
  padding: 5px 8px 3px; border-radius: 6px; background: var(--text); color: var(--bg); line-height: 1;
  animation: pop .5s var(--ease-spring) both; animation-delay: calc(var(--i, 0) * 80ms + 420ms);
}
.headline { font-size: clamp(1.15rem, 1rem + .8vw, 1.5rem); font-weight: 500; line-height: 1.35; margin: 6px 0 12px; max-width: 52ch; }
.headline strong {
  font-weight: 800; padding-bottom: 3px; background: linear-gradient(var(--amber), var(--amber)) no-repeat 0 100% / 0% 3px;
  animation: marker .9s .45s var(--ease-out) forwards; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}

/* ---------- map & tables ---------- */
.map { height: 58vh; min-height: 340px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); box-shadow: var(--shadow-sm); }
.map-loading {
  display: grid; place-items: center; color: var(--muted); font-family: var(--font-mono); font-size: .75rem; letter-spacing: .01em;
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--skeleton-hi) 50%, var(--surface-2) 70%) 0 0 / 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
.map-error { padding: 16px; }

/* Explore: SafeCross risk | 3D crash history */
.segmented-2 { grid-template-columns: repeat(2, 1fr); }
.segmented-2::before { width: calc((100% - 8px) / 2); }
.view-toggle { margin: 0 0 16px; }
.explore-mode > * + * { margin-top: 12px; }
.map-3d { position: relative; height: 66vh; min-height: 380px; touch-action: none; }
.map-3d .maplibregl-ctrl-group { border-radius: 10px; }
.month-range { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.month-range:not(:empty) { margin-top: 12px; }
.month-range label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.month-range input { min-width: 0; width: 11.5rem; }
.ring-swatch {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid; margin-right: 6px;
  vertical-align: -2px; background: rgba(255, 255, 255, .25);
}
.ramp-legend { display: inline-flex; align-items: center; gap: 8px; }
.ramp { display: inline-block; width: 110px; height: 10px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.top-cells { margin: 0; padding-left: 1.3em; }
.top-cells li { padding: 3px 0; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; font-size: .82rem; color: var(--muted); margin: 10px 2px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.wrap { white-space: normal; }

details { margin: 22px 0 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
summary {
  cursor: pointer; font-weight: 700; padding: 15px 18px 13px; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  transition: background-color .2s;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: ""; width: 9px; height: 9px; flex: none; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-3px) rotate(45deg); transition: transform .35s var(--ease-out);
}
details[open] summary::after { transform: translateY(2px) rotate(-135deg); }
summary:hover { background: var(--surface-2); }
details > :not(summary) { margin-left: 18px; margin-right: 18px; }
details ul { padding-left: 1.1rem; }
details li { margin: 6px 0; }
details::details-content { block-size: 0; overflow: hidden; transition: block-size .4s var(--ease-out), content-visibility .4s allow-discrete; }
details[open]::details-content { block-size: auto; }

/* The loading indicator is a crosswalk: stripes marching across. */
.spinner {
  display: inline-block; width: 30px; height: 10px; border-radius: 2px; vertical-align: 0; margin-right: 6px;
  background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px);
  -webkit-mask: linear-gradient(90deg, transparent, #000 25%, #000 75%, transparent); mask: linear-gradient(90deg, transparent, #000 25%, #000 75%, transparent);
  animation: march .45s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-line { display: flex; align-items: center; min-height: 1.5em; margin: 12px 2px 0; font-size: .92rem; }
.status-line:empty { margin: 0; min-height: 0; }

/* Skeletons while results or details load. */
.skeleton { border-radius: 8px; background: linear-gradient(100deg, var(--surface-2) 30%, var(--skeleton-hi) 50%, var(--surface-2) 70%) 0 0 / 200% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton-line { height: 12px; margin: 10px 0; }
.skeleton-title { height: 22px; width: 60%; margin: 4px 0 14px; }
.skeleton-card { min-height: 190px; }
.skeleton-card .skeleton-num { height: 30px; width: 70%; margin-top: 8px; }

/* ---------- toast, overlay (onboarding), sheet ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); z-index: 40;
  display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--text); color: var(--bg);
  padding: 10px 10px 10px 18px; border-radius: 14px; max-width: 520px; margin: 0 auto; box-shadow: var(--shadow-lg);
  animation: toast-in .5s var(--ease-spring) both;
}
.toast .btn { background: var(--amber); border-color: var(--amber); color: var(--ink); box-shadow: none; }
.toast.is-leaving { animation: toast-out .25s var(--ease-in) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(24px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(16px) scale(.98); } }
@media (min-width: 860px) { .toast { bottom: 20px; } }

.overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(17, 18, 20, .5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fade-in .3s ease-out both;
}
.dialog {
  position: relative; background: var(--surface); width: 100%; max-width: 580px; max-height: 92vh; overflow: auto;
  padding: 22px 22px calc(22px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  animation: dialog-in .55s var(--ease-out) both;
}
.overlay.is-leaving { animation: fade-out .26s ease-in both; }
.overlay.is-leaving .dialog { animation: dialog-out .26s var(--ease-in) both; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(48px); } to { opacity: 1; transform: none; } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(32px); } }
@media (min-width: 700px) {
  .overlay { align-items: center; }
  .dialog { border-radius: 24px; padding: 28px; }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(20px) scale(.97); } to { opacity: 1; transform: none; } }
  @keyframes dialog-out { to { opacity: 0; transform: translateY(10px) scale(.98); } }
}
.dialog h2 { margin-top: .4rem; font-size: 1.6rem; line-height: 1.1; }
.dialog ul, .dialog ol { padding-left: 1.2rem; }
.dialog li { margin: 5px 0; }
.tour-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tour-meta .kicker { margin: 0; }
.progress { display: grid; grid-template-columns: repeat(var(--steps, 4), 1fr); gap: 5px; width: 120px; }
.progress > span { position: relative; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.progress > span::after {
  content: ""; position: absolute; inset: 0; background: var(--amber); transform: scaleX(0); transform-origin: left;
  transition: transform .5s var(--ease-out);
}
.progress > span.is-done::after { transform: none; }
.tour-step { animation: step-next .45s var(--ease-out) both; }
.tour-step[data-dir="back"] { animation-name: step-back; }
@keyframes step-next { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes step-back { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }

.sheet {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 18px 18px 20px;
  max-height: 62vh; overflow: auto; overscroll-behavior: contain; box-shadow: var(--shadow-lg);
  animation: sheet-in .5s var(--ease-out) both;
}
.sheet.is-leaving { animation: sheet-out .26s var(--ease-in) both; }
.sheet > * { animation: fade-in .3s ease-out both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes sheet-out { to { opacity: 0; transform: translateY(28px); } }
@media (min-width: 860px) {
  .sheet { left: auto; right: 20px; bottom: 20px; width: 400px; max-height: min(78vh, 720px); }
  @keyframes sheet-in { from { opacity: 0; transform: translateX(32px); } to { opacity: 1; transform: none; } }
  @keyframes sheet-out { to { opacity: 0; transform: translateX(24px); } }
}
.sheet h3 { margin-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 8px 0; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.noscript { padding: 16px; }

/* ---------- route score, stop list, details panel ---------- */
.score-bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.score-bar > span {
  display: block; height: 100%; border-radius: 999px; transform-origin: left;
  animation: bar-grow 1s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 80ms + 260ms);
}
.chip .dot { margin-right: 6px; }
.tier-pill { display: inline-flex; align-items: center; font-size: .78rem; font-weight: 700; }
.tier-pill .dot { margin-right: 5px; }
.street-title { margin: 0; line-height: 1.2; }
.street-main { display: block; font-weight: 750; }
.street-cross { display: block; font-weight: 500; color: var(--muted); }
.top-card { margin-top: 18px; }
.top-card h3 { font-size: 1.15rem; }
.top3 { margin: 0; padding: 0; list-style: none; counter-reset: top; display: grid; gap: 4px; }
.top3 li { counter-increment: top; display: grid; grid-template-columns: 2.2rem 1fr; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--border); }
.top3 li::before { content: counter(top, decimal-leading-zero); font-family: var(--font-mono); font-weight: 700; font-size: .9rem; color: var(--muted); }
.top3 li > .muted { grid-column: 2; font-size: .88rem; }
.top3 .street-main, .top3 .street-cross { display: inline; }
.link-button {
  background: none; border: 0; padding: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--amber); text-decoration-thickness: 2px; text-underline-offset: 3px;
  transition: text-decoration-color .2s;
}
.link-button:hover { text-decoration-color: currentColor; }
.list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0 10px; }
.list-head > .muted { font-family: var(--font-mono); font-size: .78rem; letter-spacing: .01em; }
.stop-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.stop-list.is-entering > li { animation: rise-sm .45s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 24ms); }
.stop {
  display: flex; align-items: stretch; gap: 12px; width: 100%; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; padding: 0; cursor: pointer; overflow: hidden; min-height: 58px;
  transition: transform .25s var(--ease-out), border-color .2s, box-shadow .3s var(--ease-out), background-color .2s;
}
.stop:hover { border-color: var(--border-strong); transform: translateX(3px); }
.stop:active { transform: scale(.99); }
.stop.selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface)); box-shadow: 0 0 0 3px var(--focus-halo); }
.stop:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stop-bar { width: 6px; flex: none; transition: width .3s var(--ease-out); }
.stop:hover .stop-bar, .stop.selected .stop-bar { width: 9px; }
.stop-main { flex: 1; padding: 10px 0 8px; min-width: 0; }
.stop-chips { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px; }
.mini-chip { font-size: .78rem; color: var(--muted); }
.mini-chip.warn { color: var(--warn-text); background: var(--warn-bg); border-radius: 6px; padding: 1px 7px 0; }
.stop-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; padding: 8px 14px 8px 0; flex: none; }
.stop-share { font-family: var(--font-mono); font-weight: 600; font-size: 1.1rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stop-side .small { font-family: var(--font-mono); font-size: .74rem; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-head .street-title { font-size: 1.25rem; }
.sheet-close { flex: none; }
.detail-risk { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 10px 0 2px; }
.detail-index { margin: 4px 0 10px; font-weight: 650; }
.fact-group { margin-top: 16px; }
.fact-group h4 { margin: 0 0 6px; }
.facts { margin: 0; display: grid; gap: 0; }
.fact { display: grid; grid-template-columns: minmax(0, 11rem) 1fr; gap: 2px 12px; padding: 7px 0 6px; border-bottom: 1px solid var(--border); font-size: .92rem; }
.fact dt { color: var(--muted); }
.fact dd { margin: 0; display: flex; align-items: baseline; gap: 7px; }
.tone-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--border-strong); transform: translateY(-1px); }
.tone-good .tone-dot { background: var(--ok); }
.tone-warn .tone-dot { background: #e8710a; }
.plain { margin: 4px 0; padding-left: 1.1rem; }
.plain li { margin: 3px 0; }
@media (max-width: 420px) { .fact { grid-template-columns: 1fr; } }

/* ---------- About page ---------- */
.prose { counter-reset: section; }
.prose > p, .prose > ul, .prose > .banner { max-width: 70ch; }
.prose > h2 { counter-increment: section; padding-top: 22px; border-top: 1px solid var(--border); margin-top: 2.4rem; }
.prose > h2::before {
  content: counter(section, decimal-leading-zero); display: block; margin-bottom: 6px;
  font-family: var(--font-mono); font-size: .75rem; font-weight: 600; letter-spacing: .12em; color: var(--muted);
}
.prose li { margin: 6px 0; }

/* ---------- reduced motion: everything lands in its final state at once ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* ---------- home ---------- */
.home-hero { display: grid; gap: 28px; align-items: center; padding: 10px 0 8px; }
.home-title { font-size: clamp(2.4rem, 1.4rem + 4.2vw, 4.4rem); max-width: 14ch; }
.home-title em {
  font-style: normal; padding-bottom: .04em;
  background: linear-gradient(var(--amber), var(--amber)) no-repeat 0 100% / 0% .12em;
  animation: marker-thick .9s .5s var(--ease-out) forwards;
}
@keyframes marker-thick { to { background-size: 100% .12em; } }
.home-hero .lede { font-size: 1.2rem; }
.home-hero .btn-row { margin-top: 22px; }

/* A street sign: dark plate, inset white rule, crosswalk stripes, amber numbers. */
.home-sign {
  position: relative; display: grid; gap: 14px; padding: 26px 26px 22px; border-radius: 20px;
  background: #17191b; color: #f3f0e8; border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  outline: 2px solid rgba(243, 240, 232, .8); outline-offset: -10px;
  transform: rotate(-1.5deg); transition: transform .5s var(--ease-out);
}
.home-sign:hover { transform: rotate(0) translateY(-2px); }
.sign-stripes { display: flex; gap: 8px; height: 14px; margin-bottom: 4px; }
.sign-stripes span { flex: 1; border-radius: 2px; background: #f3f0e8; }
.sign-row { display: grid; gap: 2px; }
.sign-number { font-family: var(--font-mono); font-weight: 700; font-size: clamp(2rem, 1.5rem + 2vw, 2.8rem); line-height: 1; color: var(--amber); font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.sign-label { font-weight: 650; font-size: 1rem; }
.sign-foot { font-family: var(--font-mono); font-size: .75rem; color: rgba(243, 240, 232, .65); border-top: 1px solid rgba(243, 240, 232, .2); padding-top: 12px; }

.home-section { margin-top: 64px; }
.home-section > h2 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); margin: 0 0 22px; max-width: 24ch; }

/* The story: a full-width dark plate like the hero sign, with a crosswalk across the top. */
.story-link {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 18px; padding: 4px 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-weight: 700; color: var(--text); border-bottom: 2px solid var(--amber);
}
.story-link svg { transform: rotate(90deg); transition: transform .3s var(--ease-out); }
.story-link:hover svg { transform: rotate(90deg) translateX(3px); }
.home-story {
  margin-top: 56px; padding: 30px 22px 34px; border-radius: 24px; background: #17191b; color: #f3f0e8;
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
}
.story-stripes { display: flex; gap: 10px; height: 12px; margin-bottom: 26px; }
.story-stripes span { flex: 1; border-radius: 2px; background: rgba(243, 240, 232, .85); }
.story-kicker { color: var(--amber); }
.home-story h2 { font-size: clamp(2rem, 1.3rem + 3vw, 3.4rem); line-height: 1.05; margin: 0 0 28px; max-width: 18ch; color: #f3f0e8; }
.home-story h2:focus { outline: none; }
.story-text { border-left: 4px solid var(--amber); padding-left: 20px; font-size: 1.15rem; line-height: 1.7; color: rgba(243, 240, 232, .88); }
.story-text p { margin: 0 0 1.1em; max-width: 60ch; } .story-text p:last-child { margin-bottom: 0; }
.story-text .story-first { font-size: 1.3rem; line-height: 1.55; color: #f3f0e8; font-weight: 600; }
.story-text strong { color: var(--amber); }

.feature-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.feature {
  padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  transition: transform .35s var(--ease-out), box-shadow .35s var(--ease-out), border-color .35s;
}
.feature:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.feature-top { display: flex; align-items: center; justify-content: space-between; }
.feature-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--amber); color: #17191b; }
.feature-number { font-family: var(--font-mono); font-weight: 700; color: var(--muted); }
.feature h3 { font-size: 1.2rem; margin: 18px 0 6px; }
.feature p { margin: 0; color: var(--muted); line-height: 1.55; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; counter-reset: step; }
.steps li {
  counter-increment: step; position: relative; display: grid; gap: 4px; padding: 18px 18px 18px 74px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
}
.steps li::before {
  content: counter(step); position: absolute; left: 18px; top: 16px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; padding-top: 2px; background: var(--text); color: var(--bg);
  font-family: var(--font-mono); font-weight: 700;
}
.steps strong { font-size: 1.05rem; }
.steps span { color: var(--muted); }

.home-cta {
  margin: 64px 0 12px; padding: 40px 28px; border-radius: 24px; text-align: center; background: #17191b; color: #f3f0e8;
  background-image: repeating-linear-gradient(90deg, rgba(243, 240, 232, .05) 0 26px, transparent 26px 52px);
  border: 1px solid var(--border-strong);
}
.home-cta h2 { margin: 0 0 6px; font-size: clamp(1.7rem, 1.2rem + 2vw, 2.5rem); }
.home-cta p { margin: 0 0 22px; color: rgba(243, 240, 232, .7); }
.btn-amber { background: var(--amber); color: #17191b; border-color: var(--amber); }
.btn-amber:hover { background: #ffc21f; }

@media (min-width: 860px) {
  .home-hero { grid-template-columns: 1.5fr 1fr; gap: 48px; padding-top: 24px; }
  .home-story { padding: 40px 48px 48px; }
  .steps { grid-template-columns: repeat(4, 1fr); }
  .steps li { padding: 70px 18px 20px; }
  .steps li::before { top: 18px; }
  /* Crosswalk stripes joining the step numbers. */
  .steps li:not(:last-child)::after {
    content: ""; position: absolute; top: 37px; left: 66px; right: -8px; height: 2px;
    background: repeating-linear-gradient(90deg, var(--border-strong) 0 6px, transparent 6px 10px);
  }
}

/* Sections rise in as they scroll into view, where the browser supports scroll-driven animations. */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .home > .home-section, .home > .home-story, .home > .home-cta { animation: rise linear both; animation-timeline: view(); animation-range: entry 0% entry 35%; animation-delay: 0s; }
  }
}
.ring-hint:not(:empty) { margin: 8px 0 0; }
