:root {
  --bg: #f4f1ea; --panel: #fffdf8; --ink: #1d1f22; --muted: #6b6a66; --line: #ddd7cb;
  --accent: #e2561f;
  --Kitchener: #2f6fdf; --Waterloo: #c58a00; --Cambridge: #1f9d6b; --Guelph: #9b4dca;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517; --panel: #1c1d20; --ink: #ecebe7; --muted: #9b9a95; --line: #2e2f33;
    --Kitchener: #6c9cff; --Waterloo: #e2b23a; --Cambridge: #3fc28d; --Guelph: #c088ef;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 "IBM Plex Sans", system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }

header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 16px; letter-spacing: .01em; }
.brand span { font-size: 12px; color: var(--muted); }
nav { display: flex; gap: 4px; align-items: center; }
nav button, nav a { border: 1px solid transparent; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); text-decoration: none; font-size: 13px; }
nav button.on { border-color: var(--line); color: var(--ink); background: var(--bg); }
nav a { font-family: "IBM Plex Mono", monospace; font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.stat { background: var(--panel); padding: 12px 20px; }
.stat b { display: block; font: 500 22px/1.1 "IBM Plex Mono", monospace; }
.stat span { font-size: 12px; color: var(--muted); }
.stat i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 20px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
#q { flex: 1 1 260px; min-width: 0; padding: 7px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.toggle { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

main { display: grid; grid-template-columns: 1fr 400px; height: calc(100vh - 220px); min-height: 480px; border-top: 1px solid var(--line); }
#map { height: 100%; background: var(--bg); }
aside { overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); }
.count { position: sticky; top: 0; background: var(--panel); padding: 10px 16px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); z-index: 1; }
ol { list-style: none; margin: 0; padding: 0; }
#list li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
#list li:hover, #list li.sel { background: var(--bg); }
.row1 { display: flex; justify-content: space-between; gap: 8px; }
.addr { font-weight: 600; }
.file { font: 12px "IBM Plex Mono", monospace; color: var(--muted); white-space: nowrap; }
.meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.desc { font-size: 13px; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); margin-right: 6px; }
.pill.open { border-color: var(--accent); color: var(--accent); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.events { max-width: 820px; margin: 0 auto; padding: 16px 20px 40px; }
#tab-changes { display: block; height: auto; border: 0; }
.events li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.events .when { font: 12px "IBM Plex Mono", monospace; color: var(--muted); }
.events .what { font-weight: 600; margin: 2px 0; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); max-width: 520px; margin: 0 auto; }

.leaflet-popup-content { font: 13px/1.45 "IBM Plex Sans", sans-serif; max-width: 300px; }
.leaflet-popup-content a { color: var(--accent); }
footer { padding: 16px 20px 24px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

@media (max-width: 860px) {
  header { padding: 12px 16px; }
  .bar, .stat { padding-left: 16px; padding-right: 16px; }
  main { grid-template-columns: 1fr; grid-template-rows: 50vh auto; height: auto; }
  aside { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .brand span { display: none; }
}

a.brand { color: inherit; text-decoration: none; }
main.page { display: block; height: auto; min-height: 0; max-width: 1100px; margin: 0 auto; padding: 8px 20px 40px; border: 0; }
.page h1 { font-size: 26px; line-height: 1.2; margin: 6px 0 8px; }
.page h2 { font-size: 15px; margin: 28px 0 8px; }
.page p { max-width: 68ch; }
.page a { color: var(--accent); }
.crumbs { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.crumbs a { color: var(--muted); }
.lede { color: var(--muted); margin: 0 0 8px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 32px; align-items: start; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 16px 0 0; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
#minimap { height: 320px; border: 1px solid var(--line); border-radius: 8px; margin-top: 16px; }
.page .events { padding: 0; margin: 0; max-width: none; }
.list li { border-bottom: 1px solid var(--line); padding: 10px 0; }
.list li a { display: flex; justify-content: space-between; gap: 8px; color: var(--ink); text-decoration: none; }
.list li a:hover .addr { color: var(--accent); }
.streets { list-style: none; padding: 0; columns: 4 200px; column-gap: 24px; font-size: 13px; }
.streets li { break-inside: avoid; padding: 2px 0; }
.streets span { color: var(--muted); font-family: "IBM Plex Mono", monospace; font-size: 11px; }
.ext { font-weight: 500; }
@media (max-width: 860px) {
  .cols { grid-template-columns: 1fr; gap: 0; }
  main.page { padding: 4px 16px 32px; }
  nav { flex-wrap: wrap; justify-content: flex-end; }
  nav a, nav button { padding: 4px 8px; }
}
