:root {
  color-scheme: light;
  --surface: #fcfcfb;
  --surface-2: #f4f3ef;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6e69;
  --hairline: #e1e0d9;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  /* data colors: shared with the map style in app.js */
  --risk-hidden: #eb6834;
  --risk-hidden-future: #f5b08f;
  --risk-fema: #1baf7a;
  --risk-none: #d6d5cf;
  --sw-now: #256abf;
  --sw-2080: #9ec5f4;
  --dot: #0b0b0b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --hairline: #2c2c2a;
    --ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19;
  --surface-2: #242422;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #9a998f;
  --hairline: #2c2c2a;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
#map { position: absolute; inset: 0; }

#panel {
  position: absolute;
  top: 16px; left: 16px; bottom: 16px;
  width: 360px;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 2;
}
#panel header { position: relative; padding: 16px 44px 12px 16px; border-bottom: 1px solid var(--hairline); }
#panel h1 { margin: 0 0 4px; font-size: 18px; line-height: 1.25; }
.lede { margin: 0; color: var(--text-secondary); font-size: 13px; }
#collapse {
  position: absolute; top: 12px; right: 10px;
  width: 28px; height: 28px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-secondary); font-size: 16px; cursor: pointer;
}
#collapse:hover { background: var(--surface-2); }
#panel.collapsed #panel-body { display: none; }
#panel.collapsed { bottom: auto; }
#panel.collapsed #collapse span[aria-hidden] { display: inline-block; transform: rotate(-90deg); }

#panel-body { overflow-y: auto; padding: 4px 16px 16px; }
section { padding: 12px 0; border-bottom: 1px solid var(--hairline); }
section:last-of-type { border-bottom: 0; }
.section-title {
  display: block; margin: 0 0 8px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-muted);
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.stat .value { display: block; font-size: 22px; font-weight: 600; line-height: 1.15; }
.stat .label { display: block; font-size: 12px; color: var(--text-secondary); }

select {
  width: 100%; padding: 6px 8px; font: inherit; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 6px;
}
.row select { width: auto; margin-left: auto; max-width: 55%; }

.legend { list-style: none; margin: 0; padding: 0; }
.legend.ramp { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; margin-top: 10px; gap: 2px; }
.legend.ramp .bin { height: 10px; border-radius: 2px; background: var(--c); }
.legend.ramp .tick { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-top: 3px; }
.legend.keys li, .check, .row { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--text-primary); }
.check, .row { cursor: pointer; }
.check input { margin: 0; accent-color: var(--accent); }
.swatch { flex: none; width: 14px; height: 14px; border-radius: 3px; background: var(--c); }
.swatch.hatch {
  border: 1px solid #898781;
  background: repeating-linear-gradient(135deg, transparent 0 3px, #898781 3px 4px);
}
.swatch.dot { width: 10px; height: 10px; margin: 0 2px; border-radius: 50%; background: var(--dot); box-shadow: 0 0 0 2px #fff; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--text-muted); }
.hint[hidden] { display: none; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-muted); padding: 4px 0; border-bottom: 1px solid var(--hairline); }
td { padding: 5px 0; border-bottom: 1px solid var(--hairline); }
td button { all: unset; cursor: pointer; color: var(--text-primary); }
td button:hover, td button:focus-visible { text-decoration: underline; }
td .boro { color: var(--text-muted); font-size: 11px; margin-left: 4px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.about { padding-top: 12px; color: var(--text-secondary); font-size: 12.5px; }
.about summary { cursor: pointer; font-weight: 600; color: var(--text-primary); font-size: 13px; }
.about p { margin: 8px 0 0; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.data-notice { margin: 0; padding: 10px 16px; font-size: 13px; background: #fff4e5; color: #5c3b00; border-bottom: 1px solid var(--hairline); }
.data-notice[hidden] { display: none; }
.data-notice a { color: inherit; font-weight: 600; }

/* guide link + address search */
.guide-link { display: inline-block; margin-top: 8px; font-size: 12.5px; color: var(--accent); text-decoration: none; }
.guide-link:hover { text-decoration: underline; }
#search { position: relative; margin: 12px 0 0; }
#q {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 6px;
}
#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  list-style: none; margin: 0; padding: 4px 0;
  background: var(--surface); border: 1px solid var(--ring); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
#results li { padding: 7px 10px; cursor: pointer; font-size: 13px; }
#results li[aria-selected="true"], #results li:hover { background: var(--surface-2); }
#results li .boro { color: var(--text-muted); font-size: 12px; margin-left: 4px; }
.search-status { margin: 6px 0 0; font-size: 12px; color: var(--text-muted); min-height: 0; }
.search-status:empty { display: none; }

/* popups */
.maplibregl-popup-content {
  background: var(--surface); color: var(--text-primary);
  border-radius: 8px; padding: 12px 14px; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--text-muted); font-size: 18px; padding: 2px 8px; }
.pop h3 { margin: 0 0 2px; font-size: 14px; padding-right: 16px; }
.pop .sub { color: var(--text-muted); font-size: 12px; margin-bottom: 8px; }
.pop dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
.pop dt { color: var(--text-secondary); }
.pop dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.pop .tag { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 8px; font-weight: 600; }
.pop .tag::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--c); }

@media (max-width: 640px) {
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: 12px 12px 0 0; }
  #panel.collapsed { bottom: 0; }
  .stat .value { font-size: 19px; }
}
