  :root {
    --bg: #f6f7f9; --fg: #1c2430; --muted: #66707d; --panel: #ffffff;
    --border: #d9dee5; --accent: #0b6bcb; --street-main: #d8261c;
    --hover: #eef2f8; --shadow: 0 4px 18px rgba(20, 30, 45, .14);
    --bar-h: 54px; --scrim: rgba(246, 247, 249, .72);
  }
  :root[data-theme="dark"] {
    --bg: #101418; --fg: #e8ecf1; --muted: #98a2ad; --panel: #1a2027;
    --border: #2c3540; --accent: #5aa9f0; --street-main: #ff7a5c;
    --hover: #232c35; --shadow: 0 4px 18px rgba(0, 0, 0, .5);
    --bar-h: 54px; --scrim: rgba(16, 20, 24, .72);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #101418; --fg: #e8ecf1; --muted: #98a2ad; --panel: #1a2027;
      --border: #2c3540; --accent: #5aa9f0; --street-main: #ff7a5c;
      --hover: #232c35; --shadow: 0 4px 18px rgba(0, 0, 0, .5);
      --bar-h: 54px; --scrim: rgba(16, 20, 24, .72);
    }
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  .spinner {
    width: 26px; height: 26px; border: 3px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin .9s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  #boot {
    position: fixed; inset: 0; z-index: 5000; display: flex; flex-direction: column;
    gap: 10px; align-items: center; justify-content: center;
    background: var(--bg); color: var(--fg); text-align: center; padding: 20px;
  }
  #boot .boot-t { font-weight: 700; }
  #boot .boot-s { color: var(--muted); font-size: 13px; }
  #mapload {
    position: absolute; inset: 0; z-index: 800; display: flex; flex-direction: column;
    gap: 10px; align-items: center; justify-content: center;
    background: var(--scrim); color: var(--fg); font-weight: 600;
    backdrop-filter: blur(2px);
  }
  #mapload[hidden] { display: none; }  /* ID rule above would otherwise beat [hidden] */
  body {
    margin: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh;
    background: var(--bg); color: var(--fg);
    font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  }

  /* ---------- top bar ---------- */
  .topbar {
    display: flex; gap: 8px; align-items: center; padding: 8px 10px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    flex-wrap: wrap; z-index: 1200; position: relative;
  }
  .brand { font-weight: 700; font-size: 14px; letter-spacing: .02em;
           white-space: nowrap; padding: 2px 6px 2px 2px; }
  .brand a { color: inherit; text-decoration: none; display: inline-flex;
             align-items: center; gap: 8px; }
  .brand img { height: 26px; width: auto; display: block; border-radius: 6px; }
  .search-wrap { position: relative; flex: 1 1 220px; min-width: 160px; }
  input, select {
    font: inherit; font-size: 16px; color: var(--fg); background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
    min-width: 0; max-width: 100%;
  }
  input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
  select { flex: 0 1 190px; cursor: pointer; }
  .drop {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1300;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; display: none;
  }
  .drop.open { display: block; }
  .drop .it { padding: 8px 12px; cursor: pointer; }
  .drop .it:hover, .drop .it.sel { background: var(--hover); }
  .drop .it small { color: var(--muted); display: block; }

  /* ---------- map ---------- */
  #mapwrap { position: relative; flex: 1; min-height: 0; }
  #map { position: absolute; inset: 0; background: var(--bg); }
  html.dark .maplibregl-canvas {
    filter: brightness(.82) invert(1) contrast(2.7) hue-rotate(188deg) saturate(.4) brightness(.88);
  }
  .hint {
    position: absolute; z-index: 900; left: 50%; top: 38%; transform: translate(-50%, -50%);
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow); padding: 18px 22px; text-align: center; max-width: 300px;
  }
  .hint b { display: block; margin-bottom: 4px; }
  .hint span { color: var(--muted); font-size: 13px; }
    .maplibregl-popup-content {
    background: var(--panel); color: var(--fg);
    font: 13px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
    border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow);
  }
  .maplibregl-popup-close-button {
    color: var(--muted); font-size: 18px; padding: 2px 7px;
  }
  .maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--panel); }
  .maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--panel); }
  .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--panel); }
  .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--panel); }
  .geo-dot, .rg-dot {
    width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: default;
  }
  .geo-dot { background: #0b6bcb; }
  .rg-dot { background: #d8261c; }
  .toast {
    position: absolute; z-index: 1400; left: 50%; bottom: 20px; transform: translateX(-50%);
    background: var(--panel); color: var(--fg); border: 1px solid var(--border);
    border-radius: 10px; box-shadow: var(--shadow); padding: 10px 16px; display: none;
  }

  /* ---------- legend: desktop side panel / mobile bottom sheet ---------- */
  #sheet {
    position: absolute; z-index: 1000; display: flex; flex-direction: column;
    background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
    right: 10px; top: 10px; max-height: calc(100% - 20px); width: 330px;
    border-radius: 12px; overflow: hidden;
  }
  #sheet[hidden] { display: none; }
  #sheet-bar {
    display: flex; align-items: center; gap: 8px; width: 100%; min-height: var(--bar-h);
    padding: 8px 12px; background: none; border: 0; cursor: pointer; text-align: left;
    color: var(--fg); font: inherit; flex: 0 0 auto;
  }
  #sheet-bar .t { flex: 1; min-width: 0; }
  #sh-title { display: block; font-weight: 700; font-size: 15px;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #sh-sub { color: var(--muted); font-size: 12.5px; }
  #sh-area { display: block; color: var(--muted); font-size: 11.5px; margin-top: 1px; }
  .chev { flex: 0 0 auto; transition: transform .25s; color: var(--muted); }
  #sheet.expanded .chev { transform: rotate(180deg); }
  #sheet-body {
    display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
    max-height: 0; overflow: hidden; transition: max-height .28s ease;
  }
  #sheet.expanded #sheet-body { max-height: none; }
  #sheet-body .scroll {
    overflow-y: auto; flex: 1 1 auto; min-height: 0;
    padding: 0 6px 6px; -webkit-overflow-scrolling: touch;
  }
  #filter { width: calc(100% - 16px); margin: 2px 8px 8px; display: none; flex: 0 0 auto; }
  #filter.show { display: block; }
  .lg-h { margin: 10px 6px 4px; font-weight: 700; font-size: 12px; color: var(--muted);
          text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border);
          padding-bottom: 3px; }
  .lg-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px;
            border-radius: 8px; cursor: pointer; }
  .lg-row:hover { background: var(--hover); }
  .lg-row .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden;
                text-overflow: ellipsis; }
  .lg-row .km { color: var(--muted); font-size: 12px; white-space: nowrap; }
  .lg-row.nogeo .nm { color: var(--muted); font-style: italic; }

  /* HADS ad unit: hidden until an ad actually fills the slot */
  .hads-unit {
    display: none; margin: 8px 8px 0; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 8px; min-height: 76px; font-size: 12.5px; flex: 0 0 auto;
  }
  .hads-unit.hads-filled { display: block; }
  .hads-attr {
    display: block; font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 3px; text-decoration: none;
  }
  .hads-title {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; font-size: 13.5px; line-height: 1.3; margin-bottom: 2px;
  }
  .hads-text {
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; margin: 0 0 4px; color: var(--muted); line-height: 1.35;
  }
  .hads-url { color: var(--accent); text-decoration: none; font-size: 12px; }
  .sk {
    display: inline-block; height: 9px; border-radius: 4px; background: var(--border);
    animation: hads-pulse 1.2s ease-in-out infinite;
  }
  .sk--title { width: 62%; height: 12px; }
  .sk--text { width: 100%; margin-bottom: 4px; }
  .sk--short { width: 45%; }
  @keyframes hads-pulse { 50% { opacity: .45; } }

  .brand .dim { color: var(--muted); font-weight: 400; }
  .pop-sep { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
  .street-info .info-stub, .street-info .info-loading { color: var(--muted); }
  .street-info .info-stub { font-style: italic; }

  @media (max-width: 720px) {
    .brand { flex: 1 1 auto; }
    .search-wrap { flex: 1 1 100%; order: 3; }
    select { flex: 1 1 45%; }
    #sheet {
      left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: none;
      border-radius: 14px 14px 0 0; border-bottom: 0;
    }
    #sheet.expanded #sheet-body { max-height: 46vh; }
  }

  /* page footer (under the map, always visible) */
  #pagefoot {
    flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 2px 6px;
    align-items: center; justify-content: center;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--panel); border-top: 1px solid var(--border);
    color: var(--muted); font-size: 11.5px; z-index: 1100;
  }
  #pagefoot a { color: var(--muted); }

  .chk {
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
    font-size: 12.5px; color: var(--muted); cursor: pointer; user-select: none;
  }
  .chk input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; cursor: pointer; }
