:root {
  --paper: #ffffff;
  --ink: #1c2230;
  --ink-2: #4a5263;
  --ink-3: #6b7383;
  --rule: #dde1e8;
  --wash: #f2f4f7;
  --map-bg: #eef0f3;
  --shadow: 0 1px 2px rgba(28, 34, 48, .08), 0 4px 14px rgba(28, 34, 48, .06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #171b24;
  --ink: #e8ebf1;
  --ink-2: #b4bac7;
  --ink-3: #8f96a5;
  --rule: #2d3341;
  --wash: #212631;
  --map-bg: #1b1f27;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--map-bg);
  color: var(--ink);
  font: 400 14px/1.4 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#map { position: absolute; inset: 0; z-index: 0; }   /* keeps Leaflet's pane z-indexes below the panels */

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }

.panel {
  position: absolute;
  z-index: 2;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* Title */
.title {
  top: 12px; left: 12px;
  display: flex; align-items: flex-start; gap: 14px;
  padding: 11px 12px 11px 16px;
  max-width: min(440px, calc(100% - 24px));
}
.title h1 { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 600; letter-spacing: -.005em; }
.title p { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); }
.icon-btn {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 6px; color: var(--ink-2);
}
.icon-btn:hover { background: var(--wash); color: var(--ink); }
.embed .title { display: none; }

/* Legend */
.legend {
  top: 12px; right: 12px; width: 280px;
  max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
}
.legend-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px; border-bottom: 1px solid var(--rule); }
.legend.collapsed .legend-head { border-bottom-color: transparent; }
.legend-toggle {
  flex: 1; display: flex; align-items: baseline; gap: 8px;
  padding: 6px 8px; border-radius: 6px; text-align: left;
}
.legend-toggle:hover { background: var(--wash); }
.legend-name { font-weight: 600; font-size: 14px; }
.legend-summary { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.chev { margin-left: auto; align-self: center; color: var(--ink-3); transition: transform .15s; }
.legend.collapsed .chev { transform: rotate(-90deg); }
.text-btn { font-size: 13px; font-weight: 500; color: var(--ink); padding: 6px 8px; border-radius: 6px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule); }
.text-btn:hover { background: var(--wash); text-decoration-color: currentColor; }

.legend-body { overflow-y: auto; padding: 4px 8px 10px; overscroll-behavior: contain; }
.legend.collapsed .legend-body { display: none; }
.hint { margin: 6px 8px 4px; font-size: 12.5px; color: var(--ink-3); }

.group { margin-top: 8px; }
.group-btn {
  display: flex; width: 100%; align-items: baseline; justify-content: space-between;
  padding: 5px 8px; border-radius: 6px; font-weight: 600; font-size: 13px;
}
.group-btn:hover { background: var(--wash); }
.cat {
  display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px;
  width: 100%; padding: 4px 8px; border-radius: 6px; text-align: left; font-size: 13px;
  transition: opacity .12s;
}
.cat:hover { background: var(--wash); }
.dot {
  width: 11px; height: 11px; border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--paper), 0 0 0 2.5px color-mix(in srgb, var(--ink) 18%, transparent);
}
.count, .group-count { color: var(--ink-3); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.filtering .cat[aria-pressed="false"] { opacity: .38; }
.filtering .cat[aria-pressed="false"]:hover { opacity: .75; }
.cat[aria-pressed="true"] .label { font-weight: 500; }

/* Clusters: v4.1's solid circles in the color of the biggest vertical */
.cl-wrap { background: none; border: 0; }
.cl {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-variant-numeric: tabular-nums;
  border: 2px solid rgba(255, 255, 255, .9); box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}
:root[data-theme="dark"] .cl { border-color: rgba(255, 255, 255, .4); box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }

/* Leaflet chrome in the page's tokens */
.leaflet-container { background: var(--map-bg); font: inherit; }
.leaflet-popup-content-wrapper, .mix-tip {
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 10px 12px; font: 400 13px/1.4 "IBM Plex Sans", system-ui, sans-serif; min-width: 200px; }
.leaflet-popup-tip { background: var(--paper); box-shadow: none; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-3); width: 26px; height: 26px; font: 18px/24px system-ui, sans-serif; }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--ink); }
.mix-tip { padding: 10px 12px; font: 400 13px/1.4 "IBM Plex Sans", system-ui, sans-serif; min-width: 200px; white-space: normal; }
.mix-tip::before { display: none; }
.leaflet-popup-content p, .mix-tip p { margin: 0; }
.leaflet-popup-content .pop-title, .mix-tip .pop-title { font-weight: 600; margin: 0 22px 4px 0; }
.mix-tip .pop-title { margin-right: 0; }
.pop-sub { color: var(--ink-2); margin: 0; }
.leaflet-popup-content .pop-city { font-weight: 600; margin: 10px 0 3px; }
.pop-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 1px 0; }
.pop-row .dot { width: 9px; height: 9px; }
.pop-row .n { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.leaflet-popup-content .pop-more, .mix-tip .pop-more { color: var(--ink-3); margin: 4px 0 0; }
.pop-names { margin: 2px 0 6px 18px; padding: 0; color: var(--ink-2); font-size: 12px; }

.leaflet-bar { border: 1px solid var(--rule) !important; box-shadow: var(--shadow) !important; border-radius: 8px; overflow: hidden; }
.leaflet-bar a { background: var(--paper); color: var(--ink); border-bottom-color: var(--rule); }
.leaflet-bar a:hover { background: var(--wash); color: var(--ink); }
.leaflet-bar a.leaflet-disabled { background: var(--paper); color: var(--ink-3); opacity: .5; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--paper) 80%, transparent) !important; color: var(--ink-2); font-size: 11px; }
.leaflet-control-attribution a { color: inherit; }
.leaflet-bottom.leaflet-left { margin-bottom: 0; }

.notice {
  position: absolute; z-index: 2; left: 50%; bottom: 36px; transform: translateX(-50%);
  margin: 0; padding: 8px 12px; max-width: calc(100% - 24px);
  background: var(--paper); color: var(--ink-2); border: 1px solid var(--rule); border-radius: 8px;
  box-shadow: var(--shadow); font-size: 13px;
}

/* Phones and narrow embeds: legend becomes a bottom sheet */
@media (max-width: 700px) {
  .title { right: 12px; max-width: none; padding: 9px 8px 9px 12px; }
  .title h1 { font-size: 15px; }
  .title p { font-size: 12.5px; }
  .legend {
    top: auto; bottom: 0; right: 0; left: 0; width: auto;
    max-height: 62%;
    border-radius: 12px 12px 0 0; border-bottom: 0;
  }
  .legend-head { padding: 6px 8px; }
  .chev { transform: none; }
  .legend.collapsed .chev { transform: rotate(180deg); }
  .leaflet-bottom { bottom: 52px; }
  .notice { bottom: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
