/* Own the Neighborhood web (CN-8, lld.md §7). One token set, light on :root, dark from the system setting until the
   reader picks one (data-theme on <html>). Every colour below, map overlays and SVG diagrams included, is a token.
   System fonts only. Visual pattern after the qrypt-quickstart site and its design page. */
:root {
  --bg: #fbfaf8; --surface: #ffffff; --ink: #0c0c0d; --muted: #5f5f66; --faint: #8b8b92; --line: #e6e2dc;
  --soft: #f4f2ee; --wire: #8f8880; --glow: #b9a6ff; --accent: #2f55c9; --on-ink: #ffffff;
  --ok: #1d7843; --ok-bg: #e8f5ec; --warn: #9a4a0b; --warn-bg: #fdf1e6; --bad: #b2362a; --bad-bg: #fbeceb;
  --nav: rgba(251, 250, 248, 0.9); --landlord: #8b8b92; --route: #2f55c9;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e10; --surface: #17171a; --ink: #f3f3f4; --muted: #a3a3ab; --faint: #75757e; --line: #2a2a2f;
    --soft: #1f1f23; --wire: #6f6f78; --glow: #6f5fe0; --accent: #93b2ff; --on-ink: #0e0e10;
    --ok: #4cc27e; --ok-bg: #12291b; --warn: #f0a35e; --warn-bg: #2d1f12; --bad: #f07466; --bad-bg: #2e1715;
    --nav: rgba(14, 14, 16, 0.9); --landlord: #75757e; --route: #93b2ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e10; --surface: #17171a; --ink: #f3f3f4; --muted: #a3a3ab; --faint: #75757e; --line: #2a2a2f;
  --soft: #1f1f23; --wire: #6f6f78; --glow: #6f5fe0; --accent: #93b2ff; --on-ink: #0e0e10;
  --ok: #4cc27e; --ok-bg: #12291b; --warn: #f0a35e; --warn-bg: #2d1f12; --bad: #f07466; --bad-bg: #2e1715;
  --nav: rgba(14, 14, 16, 0.9); --landlord: #75757e; --route: #93b2ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--ink); overflow-wrap: break-word;
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
code, .mono { font: 0.88em/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
code { background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
.skip { position: absolute; left: -9999px; z-index: 10; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); color: var(--ink); padding: 6px 12px; border-radius: 8px; }
.wrap { max-width: 1080px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top nav: sticky, translucent, pill links, round theme toggle ---------- */
header.top {
  position: sticky; top: 0; z-index: 20; background: var(--nav); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.bar-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand i { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, var(--accent), var(--glow)); }
.top nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.top nav a, .views a {
  white-space: nowrap; text-decoration: none; color: var(--muted); font-size: 14px; padding: 6px 12px; border-radius: 999px;
}
.top nav a:hover, .views a:hover, .top nav a[aria-current] { color: var(--ink); background: var(--soft); }
.top nav a[aria-current] { font-weight: 600; }
.theme-toggle {
  flex: none; width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; font-size: 16px; line-height: 1; padding: 0;
}
.theme-toggle:hover { border-color: var(--ink); }
@media (max-width: 640px) {
  .top nav { order: 3; flex: 1 0 100%; margin-left: -12px; }
  .theme-toggle { margin-left: auto; }
}

/* ---------- hero, stats, sections, cards ---------- */
.hero { padding: 44px 0 20px; }
.eyebrow { margin: 0 0 6px; font: 600 12px/1.4 ui-monospace, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.hero h1 { font-size: clamp(32px, 6vw, 52px); line-height: 1.05; letter-spacing: -.035em; margin: 0 0 14px; }
.lede { font-size: 18.5px; color: var(--muted); max-width: 68ch; margin: 0 0 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 18px 0 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-size: 26px; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 13.5px; }
section.block { padding: 32px 0 12px; border-top: 1px solid var(--line); }
section.block > h2 { font-size: 26px; letter-spacing: -.025em; margin: 0 0 6px; }
section.block > h2 + p { color: var(--muted); max-width: 72ch; margin: 0 0 18px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 4px 0; color: var(--muted); font-size: 14.5px; }
.card ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 14.5px; }
.formula { font: 600 20px/1.4 ui-monospace, Menlo, monospace; letter-spacing: -.01em; margin: 6px 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; }
.scroll { overflow-x: auto; }
.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
footer.foot { border-top: 1px solid var(--line); margin-top: 36px; padding: 18px 0 40px; color: var(--muted); font-size: 14px; }

/* ---------- buttons, inputs, pills, chips ---------- */
button, .btn {
  font: 500 14px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px;
}
button:hover, .btn:hover { border-color: var(--ink); }
button.primary, .btn.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
button:disabled { opacity: .5; cursor: not-allowed; }
button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
input[type="text"], input[type="password"], input[type="number"], select {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 10px; min-height: 38px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
label { font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--soft); color: var(--ink); white-space: nowrap;
}
.chip.yes { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.chip.no { color: var(--muted); }
.chip.cant { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.chip.inferred { background: transparent; border-style: dashed; color: var(--muted); font-style: italic; }
.chip.landlord { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.chip.change { background: var(--accent); border-color: var(--accent); color: var(--on-ink); font-weight: 600; }
.msg { min-height: 1.4em; font-size: 14px; }
.msg.err { color: var(--bad); }

/* ---------- maps ---------- */
.mapbox { position: relative; height: 420px; border-radius: 18px; overflow: hidden; border: 1px solid var(--line); background: var(--soft); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.ramp { height: 10px; flex: 1; min-width: 120px; border-radius: 999px;
  background: linear-gradient(90deg, #440154, #3b528b, #21918c, #5ec962, #fde725); }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---------- /map app shell ---------- */
body.app-page { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.app { flex: 1; min-height: 0; display: grid; grid-template-columns: 400px 1fr; }
.panel { overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg); padding: 14px 16px 40px; }
#map { position: relative; min-height: 0; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 12px; }
.modes button { justify-content: center; padding: 7px 6px; }
.pane h2 { font-size: 17px; margin: 4px 0 8px; }
.pane .hint { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.field { margin: 10px 0; }
.field label { display: flex; justify-content: space-between; margin-bottom: 4px; }
.stops { list-style: none; margin: 10px 0 0; padding: 0; }
.stops li { display: grid; grid-template-columns: 30px 1fr; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.stops li:hover .addr { text-decoration: underline; }
.stops .num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  background: var(--route); color: var(--on-ink); }
.stops .addr { font-weight: 600; font-size: 14.5px; }
.stops .meta, .stops .opener { font-size: 13px; color: var(--muted); }
.stops .opener { font-style: italic; color: var(--ink); }
.rep-h { font-size: 14px; margin: 14px 0 0; display: flex; gap: 8px; align-items: center; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.stop-marker { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font: 700 12px system-ui, sans-serif;
  color: var(--on-ink); background: var(--route); border: 2px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer; }
.start-marker { width: 18px; height: 18px; border-radius: 50%; background: var(--ink); border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--ink); }

/* door card */
.door { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; margin-bottom: 14px; }
.door-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.door h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.score-big { white-space: nowrap; font-size: 34px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.score-big small { font-size: 14px; color: var(--muted); font-weight: 500; }
.door h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 6px; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 92px 1fr 64px; align-items: center; gap: 8px; font-size: 13.5px; }
.bar .track { height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.evidence { list-style: none; margin: 0; padding: 0; }
.evidence li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.evidence li:last-child { border-bottom: 0; }
.evidence .src { display: block; font-size: 12.5px; color: var(--muted); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.thumbs figure { margin: 0; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); }
.thumbs figcaption { font-size: 12.5px; color: var(--muted); text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.close { min-height: 30px; padding: 3px 10px; }

@media (max-width: 768px) {
  body.app-page { height: auto; overflow: auto; }
  .app { display: flex; flex-direction: column; }
  #map { height: 52vh; min-height: 300px; order: 1; }
  .panel { order: 2; border-right: 0; border-top: 1px solid var(--line); overflow: visible; padding-bottom: 60px; }
  .bar { grid-template-columns: 80px 1fr 56px; }
}

/* ---------- eval charts ---------- */
.chart { width: 100%; height: auto; display: block; font-size: 12px; }
.chart text { fill: var(--ink); }
.chart .axis { stroke: var(--line); }
.chart .lbl { fill: var(--muted); }
.chart .b0 { fill: var(--accent); }
.chart .b1 { fill: var(--glow); }
.chart .b2 { fill: var(--wire); }
.chart .whisker { stroke: var(--ink); stroke-width: 1.4; }
.chart .ref { stroke: var(--bad); stroke-dasharray: 4 3; }
.key-b0 { background: var(--accent); } .key-b1 { background: var(--glow); } .key-b2 { background: var(--wire); }
.keyrow { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
details.raw { margin-top: 10px; }
details.raw pre { max-height: 360px; overflow: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 10px; font-size: 12.5px; }
.notrun { border-left: 3px solid var(--warn); }

/* ---------- utilities (no inline style attributes: the CSP has no 'unsafe-inline' for styles) ---------- */
.mt-6 { margin-top: 6px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }
.narrow { max-width: 460px; } .grow { flex: 1; } .bar-top.full { max-width: none; }
.landlord-swatch { background: var(--landlord); }
.chip.unconfirmed { background: transparent; border-style: dotted; color: var(--warn); }
.stops .src { font-size: 12px; color: var(--muted); }

/* ---------- QA round 1 (M1-T008) ---------- */
.table-card.scroll { overflow-x: auto; } /* D-05: the sources table scrolls sideways at 375 px instead of clipping */
.stat b { white-space: nowrap; } /* D-13: a date never wraps mid-value */
.stat.pass { border-color: var(--ok); }
.stat.pass span { color: var(--ok); }
.stat.miss { border-color: var(--bad); background: var(--bad-bg); }
.stat.miss b, .stat.miss span { color: var(--bad); }
.chart .rowlbl { fill: var(--ink); font-size: 12.5px; }
.chart .axis.zero { stroke: var(--wire); }
h3.chart-h { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 4px; }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
.thumbs a { display: block; border-radius: 10px; }
/* D-01: #card scroll-margin moved to the QA round 2 block below (measured header height) */
@media (max-width: 640px) {
  /* D-09: tap targets at least 44 px, and a compact two-row header on a phone */
  button, .btn, .top nav a, input[type="password"], input[type="text"], select { min-height: 44px; }
  .theme-toggle { width: 44px; height: 44px; }
  .top nav a { display: inline-flex; align-items: center; padding: 6px 10px; font-size: 13.5px; }
  .bar-top { padding-top: 6px; padding-bottom: 6px; gap: 2px 8px; flex-wrap: wrap; }
  .brand { font-size: 15px; gap: 8px; }
  .brand i { width: 14px; height: 14px; }
  #signout { margin-left: auto; padding: 6px 10px; font-size: 13px; }
  #signout + .theme-toggle { margin-left: 0; }
  .stops li { min-height: 44px; }
}

/* ---------- QA round 2 (M1-T012) ---------- */
/* D-10 / QA2-04: a chip wraps inside the card at 375 px instead of running past its edge */
.door .chip { white-space: normal; max-width: 100%; }
.door .src.caveat { color: var(--warn); }
.stops .src.caveat { color: var(--warn); }
.stops .check { white-space: nowrap; }
.door .check { white-space: nowrap; }
.change-note { margin: 0 0 8px; }
.door .back { display: none; }
/* QA2-REP-01: MapLibre's zoom buttons keep their square stack (the site's pill button style is undone for them) */
.maplibregl-ctrl-group button {
  border-radius: 0; border: 0; padding: 0; min-height: 0; background-color: transparent; display: block;
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
/* D-01 / QA2-01: anything scrolled to sits below the sticky header, whose height common.js measures (--head-h) */
#card, [id] { scroll-margin-top: calc(var(--head-h, 64px) + 8px); }
/* stop markers: a 44 px tap area round a smaller dot (D-09) */
/* (.maplibregl-marker is position:absolute, which already anchors the ::after tap area) */
.stop-marker::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; }
@media (max-width: 768px) {
  /* D-02 / R2-D-01 / DA2-04: on a phone the door card is a bottom sheet over the page; the page never scrolls away
     from the stop list, and the sheet's top always stays below the sticky header */
  #card.open {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    max-height: calc(100dvh - var(--head-h, 64px) - 8px); overflow-y: auto; overscroll-behavior: contain;
    background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(0, 0, 0, .25);
    border-radius: 18px 18px 0 0; padding: 8px 10px 16px;
  }
  #card.open .door { margin-bottom: 0; }
  .door .back { display: inline-flex; margin: 0 0 8px; min-height: 44px; }
}
@media (max-width: 640px) {
  /* D-09 / QA2-03 / R2-D-09 / DA2-07: every tap target at least 44 px */
  .brand { min-height: 44px; }
  .close, #signout { min-height: 44px; min-width: 44px; }
  .maplibregl-ctrl-group button { width: 44px; height: 44px; }
  input[type="range"] { min-height: 44px; }
  input[type="checkbox"] { width: 22px; height: 22px; margin: 0 8px 0 0; vertical-align: middle; }
  .field label { min-height: 44px; align-items: center; }
  .stop-marker { width: 28px; height: 28px; font-size: 13px; }
  .stop-marker::after { inset: -8px; }
}

/* ---------- QA round 3 (M1-T016) ---------- */
/* QA3-PLN-04: which inputs scored a drawn area, in the caveat colour */
.msg.warn { color: var(--warn); }
.stops .chip.landlord { margin: 2px 0; }
