:root {
  --bg: #ffffff; --fg: #1a1a1a; --muted: #666; --panel: rgba(255,255,255,.95); --border: #ddd;
  --none: #c8c8c8; --link: #c2410c; --mask: #1d2229; --mask-edge: #3a4250; --select: #111; --hover: #444;
  --s1: #fde4d0; --s2: #fdb88a; --s3: #f7864d; --s4: #e0531f; --s5: #a8320b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212; --fg: #eee; --muted: #aaa; --panel: rgba(28,28,28,.95); --border: #3a3a3a;
    --none: #4a4a4a; --link: #fb923c; --mask: #0b0d10; --mask-edge: #2a2f36; --select: #fff; --hover: #ccc;
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --fg: #eee; --muted: #aaa; --panel: rgba(28,28,28,.95); --border: #3a3a3a;
  --none: #4a4a4a; --link: #fb923c; --mask: #0b0d10; --mask-edge: #2a2f36; --select: #fff; --hover: #ccc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; }
.bar { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.bar h1 { font-size: 17px; margin: 0; flex: 1 1 auto; }
#search { flex: 0 1 260px; min-width: 0; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--fg); font: inherit; }
/* Map and its overlay panels share one positioned box, so panels sit relative to the map
   (not the page) and never collide with the header when it wraps on small screens. */
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--mask); }
/* No browser focus box around clicked shapes; selection is drawn as an outline instead. */
.leaflet-interactive:focus, .leaflet-container path:focus { outline: none; }
.legend { position: absolute; right: 12px; bottom: 28px; z-index: 500; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 12px; width: 240px; }
.legend h2 { font-size: 12px; margin: 0 0 6px; }
.legend .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.legend .ramp { height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,.15); margin: 4px 0 2px; }
.legend .ticks { position: relative; height: 14px; margin: 0 6px 6px; font-size: 10.5px; color: var(--muted); }
.legend .ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.15); flex: none; }
.popup a, .info a { color: var(--link); }
.info-btn { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg);
  color: var(--fg); font: italic 600 15px/1 Georgia, serif; cursor: pointer; }
.info-btn[aria-expanded="true"] { background: var(--fg); color: var(--bg); }
.info { position: absolute; top: 10px; right: 10px; z-index: 1000; width: min(340px, calc(100% - 20px));
  max-height: calc(100% - 20px); overflow: auto; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; font-size: 13px; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.info[hidden] { display: none; }
.info-head { display: flex; justify-content: space-between; align-items: center; }
.info h2 { font-size: 15px; margin: 0; }
.info-close { border: none; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 2px; }
.info dl { margin: 8px 0 0; }
.info dt { font-weight: 600; margin-top: 8px; }
.info dd { margin: 2px 0 0; color: var(--muted); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--fg); }
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; }
.popup h3 { margin: 0; font-size: 16px; }
.popup .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.popup .sub { border-top: 1px solid var(--border); padding: 7px 0 2px; }
.popup .sub a.name { font-weight: 600; font-size: 14px; text-decoration: none; }
.popup .sub a.name:hover { text-decoration: underline; }
.popup .stat { font-size: 12.5px; }
.popup .ratio { font-weight: 600; }
.popup .note { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.popup .none { color: var(--muted); font-style: italic; }
.popup .also { margin-top: 8px; font-size: 12px; color: var(--muted); }
.hood-label { background: none; border: none; box-shadow: none; font-weight: 600; color: var(--fg); }
@media (max-width: 600px) {
  .legend { right: 8px; bottom: 24px; max-width: 170px; padding: 8px; }
  .bar { gap: 8px; padding: 8px 12px; }
  .bar h1 { font-size: 15px; flex-basis: calc(100% - 46px); }
  #search { flex: 1 1 auto; order: 3; }
}

.legend .ticks span.max { transform: translateX(-100%); font-weight: 600; color: var(--fg); }
.legend .legend-max { font-size: 11px; color: var(--muted); margin: -2px 0 6px; }
.boroughs { position: absolute; left: 54px; top: 10px; z-index: 500; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 12px; width: 250px; max-height: calc(100% - 150px); overflow: auto; }
.boroughs summary { font-weight: 600; cursor: pointer; font-size: 13px; }
.boroughs .bnote { color: var(--muted); font-size: 11px; margin: 2px 0 6px; }
.boroughs .brow { padding: 5px 0; border-top: 1px solid var(--border); }
.boroughs .bhead { display: flex; justify-content: space-between; gap: 8px; }
.boroughs .bhead a { color: var(--link); font-weight: 600; text-decoration: none; }
.boroughs .bsub, .boroughs .muted { color: var(--muted); font-size: 11px; }
.boroughs .meter { height: 5px; background: var(--border); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.boroughs .meter span { display: block; height: 100%; border-radius: 3px; }
@media (max-width: 600px) {
  .boroughs { left: 52px; top: 10px; width: auto; max-width: calc(100% - 62px); }
  .boroughs details:not([open]) { width: max-content; }
}
.legend .ticks span:first-child { transform: none; }
