:root {
  color-scheme: light;
  --plane: #faf5ea;
  --surface: #fffdf7;
  --surface-2: #f2ead8;
  --text: #2a1f14;
  --text-2: #6b5a46;
  --text-3: #9a8a74;
  --border: #e6dbc4;
  --accent: #b5401f;
  --accent-2: #e09a1a;
  --on-accent: #fffaf0;
  --chip-off: #f2ead8;
  --shadow: 0 1px 2px rgba(60, 40, 10, 0.05), 0 10px 28px rgba(60, 40, 10, 0.07);
  --sea: #e3eef0;
  --state-fill: #fbf6ea;
  --state-line: #c9b996;
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --plane: #17120c;
    --surface: #211a12;
    --surface-2: #2c2318;
    --text: #f5ead6;
    --text-2: #c9b89c;
    --text-3: #8f7f68;
    --border: #3a2e20;
    --accent: #f0794f;
    --accent-2: #f2b84a;
    --on-accent: #1a120a;
    --chip-off: #2c2318;
  --sea: #121a1d;
  --state-fill: #241c13;
  --state-line: #4a3c2a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --plane: #17120c;
  --surface: #211a12;
  --surface-2: #2c2318;
  --text: #f5ead6;
  --text-2: #c9b89c;
  --text-3: #8f7f68;
  --border: #3a2e20;
  --accent: #f0794f;
  --accent-2: #f2b84a;
  --on-accent: #1a120a;
  --chip-off: #2c2318;
  --sea: #121a1d;
  --state-fill: #241c13;
  --state-line: #4a3c2a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--plane);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }

/* ---------- masthead ---------- */
.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  font-size: 24px;
}
.masthead h1 { margin: 0; font: 600 22px/1.15 var(--font-display); letter-spacing: -0.01em; }
.masthead h1 span { color: var(--accent); }
.tagline { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.masthead-actions { display: flex; gap: 8px; flex: none; }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
#filters-toggle { display: none; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 16px 24px;
  height: calc(100vh - 73px - 64px);
  min-height: 560px;
}
.sidebar, .list-wrap, .map-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.sidebar { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.map-wrap { overflow: hidden; position: relative; }
#map { position: absolute; inset: 0; background: var(--sea); }
.leaflet-interactive:focus { outline: none; }
.state-tip {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 12px; font-weight: 600; padding: 3px 8px;
}
.state-tip::before { display: none; }
.list-wrap { display: flex; flex-direction: column; overflow: hidden; }

/* ---------- stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--surface-2); border-radius: 10px; padding: 10px 8px; text-align: center;
}
.stat strong { display: block; font: 600 22px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field.two label { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-label { font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
.field-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 12px; font-weight: 700; cursor: pointer; }
input[type='search'], select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--plane);
}
input[type='search']:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px 5px 7px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--chip-off); color: var(--text-2);
  font-size: 12.5px; font-weight: 600; line-height: 1.2;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.chip .n { font-variant-numeric: tabular-nums; color: var(--text-3); font-weight: 500; }
.chip[aria-pressed='true'] {
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  border-color: var(--c); color: var(--text);
}
.chip[aria-pressed='false'] { opacity: 0.6; }
.chip[aria-pressed='false'] .e { filter: grayscale(1); }

/* year histogram + dual range */
.histo { display: flex; align-items: flex-end; gap: 2px; height: 40px; }
.histo i {
  flex: 1; min-height: 2px; border-radius: 2px 2px 0 0;
  background: var(--accent-2); opacity: 0.9;
}
.histo i.out { background: var(--border); opacity: 1; }
.range { position: relative; height: 22px; margin-top: -6px; }
.range input {
  position: absolute; inset: 0; width: 100%; margin: 0;
  pointer-events: none; background: none; -webkit-appearance: none; appearance: none;
}
.range input::-webkit-slider-thumb {
  pointer-events: auto; -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); cursor: pointer;
}
.range input::-moz-range-thumb {
  pointer-events: auto; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); cursor: pointer;
}
.range input::-webkit-slider-runnable-track { height: 22px; background: none; }
.range::before {
  content: ''; position: absolute; left: 0; right: 0; top: 10px; height: 2px; background: var(--border);
}

.reset { align-self: flex-start; }

.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.bars li button {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  position: relative; padding: 5px 8px; border: 0; border-radius: 6px; background: none;
  cursor: pointer; text-align: left; font-size: 13px; overflow: hidden;
}
.bars li button::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: var(--w);
  background: color-mix(in srgb, var(--accent-2) 22%, transparent); border-radius: 6px; z-index: 0;
}
.bars li button > * { position: relative; }
.bars li button:hover { background: var(--surface-2); }
.bars li button.on::before { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.bars .n { font-variant-numeric: tabular-nums; color: var(--text-2); font-weight: 600; }

/* ---------- results ---------- */
.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.list-head h2 { margin: 0; font: 600 17px var(--font-display); }
.list-head select { width: auto; padding: 5px 8px; font-size: 13px; }
.results { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.results li button {
  width: 100%; display: grid; grid-template-columns: 32px 1fr; gap: 10px; align-items: center;
  padding: 8px; border: 0; border-radius: 10px; background: none; cursor: pointer; text-align: left;
}
.results li button:hover, .results li button.active { background: var(--surface-2); }
.results .e { font-size: 20px; text-align: center; }
.results .t { font-weight: 600; font-size: 14px; line-height: 1.25; }
.results .s { font-size: 12px; color: var(--text-2); }
.results .empty { padding: 24px 12px; color: var(--text-2); text-align: center; font-size: 14px; }

/* ---------- map markers & popups ---------- */
.pin {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--c);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  font-size: 16px; line-height: 1;
}
.pin.region { border-style: dashed; }
.cluster {
  display: grid; place-items: center; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 88%, transparent);
  color: var(--on-accent); font-weight: 800; font-size: 13px;
  border: 3px solid color-mix(in srgb, var(--accent-2) 70%, var(--surface));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-popup-content { margin: 14px 16px; min-width: 220px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-3); }
.pop .k { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); }
.pop h3 { margin: 4px 0 6px; font: 600 18px/1.2 var(--font-display); }
.pop dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 8px 0; font-size: 13px; }
.pop dt { color: var(--text-3); }
.pop dd { margin: 0; }
.pop .note { font-size: 12px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 6px 8px; margin: 6px 0; }
.pop a { color: var(--accent); font-weight: 600; font-size: 13px; text-decoration: none; }
.pop a:hover { text-decoration: underline; }
.leaflet-control-attribution { font-size: 10px; }
:root[data-theme='dark'] .leaflet-control-attribution,
:root[data-theme='dark'] .leaflet-bar a { background: var(--surface); color: var(--text-2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .leaflet-control-attribution,
  :root:not([data-theme='light']) .leaflet-bar a { background: var(--surface); color: var(--text-2); }
}

/* ---------- footer ---------- */
.foot { padding: 0 24px 18px; color: var(--text-3); font-size: 12px; max-width: 1100px; }
.foot p { margin: 0; }
.dash-key {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px dashed var(--text-2); vertical-align: -2px;
}

/* ---------- drawer (mobile only) ---------- */
.drawer-head, .drawer-foot { display: none; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  width: 100%; padding: 12px 16px; font-size: 15px;
}
.btn.primary:hover { color: var(--on-accent); filter: brightness(1.05); }
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 800; margin-left: 4px;
}
.badge[hidden] { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 320px; height: auto; }
  .sidebar { grid-row: 1 / span 2; max-height: calc(100vh - 110px); }
  .map-wrap { min-height: 480px; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  .masthead { padding: 10px 16px; position: sticky; top: 0; z-index: 1100; }
  .brand-mark { width: 38px; height: 38px; font-size: 21px; border-radius: 10px; }
  .tagline { display: none; }
  .masthead h1 { font-size: 18px; }
  .masthead h1 span { display: block; font-size: 13px; font-family: var(--font); font-weight: 600; }
  .btn { min-height: 40px; padding: 8px 14px; }
  #filters-toggle { display: inline-flex; align-items: center; }

  .layout { display: flex; flex-direction: column; padding: 12px 16px; gap: 12px; height: auto; min-height: 0; }

  /* filters become a full-screen drawer over the map */
  .sidebar {
    position: fixed; inset: 0; z-index: 2000;
    max-height: none; border-radius: 0; border: 0;
    padding: 0 16px; gap: 20px;
    transform: translateY(100%); visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
    overscroll-behavior: contain;
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform 0.25s ease; }
  .drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 2; margin: 0 -16px; padding: 12px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .drawer-head h2 { margin: 0; font: 600 19px var(--font-display); }
  .drawer-foot {
    display: block; position: sticky; bottom: 0; margin: auto -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  body.drawer-open { overflow: hidden; }

  input[type='search'], select { font-size: 16px; padding: 11px 12px; }
  .chip { padding: 8px 12px 8px 9px; font-size: 14px; }
  .chips { gap: 8px; }
  .range { height: 32px; }
  .range input::-webkit-slider-runnable-track { height: 32px; }
  .range::before { top: 15px; }
  .range input::-webkit-slider-thumb { width: 26px; height: 26px; }
  .range input::-moz-range-thumb { width: 22px; height: 22px; }
  .bars li button { padding: 10px; font-size: 15px; }

  .map-wrap { height: 58vh; height: 58dvh; min-height: 340px; }
  .list-wrap { overflow: visible; }
  .list-head { position: sticky; top: 59px; z-index: 5; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; }
  .results { overflow: visible; flex: none; }
  .results li button { padding: 11px 8px; }
  .results .t { font-size: 15px; }
  .results .s { font-size: 13px; }

  .leaflet-popup-content { margin: 12px 14px; min-width: 0; }
  .pop h3 { font-size: 17px; }
  .pop a { display: inline-block; padding: 6px 0; font-size: 14px; }
  .leaflet-bar a { width: 36px !important; height: 36px !important; line-height: 36px !important; }

  .foot { padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
}
