:root {
  --ink: #17201f;
  --muted: #65706d;
  --paper: #f7f5ed;
  --panel: rgba(250, 249, 243, 0.94);
  --panel-strong: rgba(250, 249, 243, 0.82);
  --panel-soft: rgba(255, 255, 255, 0.38);
  --line: rgba(23, 32, 31, 0.14);
  --accent: #9b3d33;
  --accent-2: #287d78;
  --gold: #b28835;
  --charcoal: #354147;
  --shadow: 0 20px 54px rgba(19, 27, 26, 0.18);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #dfe4df;
}

button,
input {
  font: inherit;
}

.app-shell,
.map-stage,
#map {
  width: 100vw;
  height: 100vh;
}

.map-stage {
  position: relative;
  overflow: hidden;
}

#map {
  z-index: 0;
  background: #dfe4df;
}

.topbar,
.search-panel,
.control-panel,
.layer-dock,
.detail-panel,
.source-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  position: absolute;
  z-index: 600;
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px 16px;
  border-radius: 8px;
  background: rgba(250, 249, 243, 0.92);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.22rem, 3.8vw, 2rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  line-height: 1.16;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(23, 32, 31, 0.18);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
}

.icon-button:hover {
  border-color: rgba(155, 61, 51, 0.5);
  color: var(--accent);
  background: rgba(255, 255, 255, 0.78);
}

.icon-button svg {
  width: 19px;
  height: 19px;
}

.control-panel {
  position: absolute;
  z-index: 550;
  top: 108px;
  left: 18px;
  width: min(340px, calc(100vw - 36px));
  max-height: calc(100vh - 126px);
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: rgba(250, 249, 243, 0.9);
}

.search-panel {
  position: absolute;
  z-index: 650;
  top: 108px;
  left: 50%;
  width: min(560px, calc(100vw - 760px));
  min-width: 500px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(250, 249, 243, 0.94);
  transform: translateX(-50%);
}

.layer-dock {
  position: absolute;
  z-index: 640;
  right: 18px;
  bottom: 132px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(250, 249, 243, 0.92);
}

.panel-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.overlap-readout {
  padding: 9px 10px;
  border: 1px solid rgba(40, 125, 120, 0.24);
  border-radius: 8px;
  color: #22332f;
  background: rgba(40, 125, 120, 0.09);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.25;
}

.overlap-readout.is-peak {
  border-color: rgba(155, 61, 51, 0.34);
  background: rgba(155, 61, 51, 0.1);
}

.person-search {
  margin: 0;
}

.search-section {
  padding: 0;
}

.search-field {
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 0 14px;
  border: 1px solid rgba(23, 32, 31, 0.16);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.52),
    0 8px 20px rgba(23, 32, 31, 0.08);
}

.search-field:focus-within {
  border-color: rgba(40, 125, 120, 0.5);
  background: rgba(255, 255, 255, 0.82);
}

.search-field svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.4;
}

.search-field input {
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 1.04rem;
  font-weight: 900;
}

.search-field input::placeholder {
  color: rgba(101, 112, 109, 0.82);
}

.search-results {
  display: none;
  gap: 8px;
  max-height: min(44vh, 430px);
  margin-top: 10px;
  overflow: auto;
}

.search-results.is-open {
  display: grid;
}

.search-result {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 70px;
  padding: 8px 10px;
  border: 1px solid rgba(23, 32, 31, 0.1);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.34);
  cursor: pointer;
  text-align: left;
}

.search-result:hover {
  border-color: rgba(155, 61, 51, 0.4);
  background: rgba(255, 255, 255, 0.7);
}

.search-result-avatar {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  color: white;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.24), transparent 31%),
    var(--search-color);
  box-shadow:
    inset 0 0 0 1px rgba(23, 32, 31, 0.18),
    0 0 0 2px color-mix(in srgb, var(--search-color) 72%, white);
  flex: 0 0 auto;
  font-size: 0.74rem;
  font-weight: 950;
}

.search-result-avatar.has-portrait {
  background-color: var(--search-color);
  background-image: var(--search-portrait-image);
  background-position: var(--search-portrait-position, 50% 36%);
  background-size: var(--search-portrait-size, cover);
}

.search-result-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.search-result-name,
.search-result-meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-name {
  font-size: 0.94rem;
  font-weight: 950;
}

.search-result-meta,
.empty-search {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.empty-search {
  margin: 0;
  padding: 8px 2px 0;
}

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

.layer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.layer-button {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid rgba(23, 32, 31, 0.13);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.42);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 900;
  text-align: left;
}

.layer-button:hover {
  border-color: rgba(155, 61, 51, 0.42);
  background: rgba(255, 255, 255, 0.66);
}

.layer-button.is-active {
  border-color: rgba(155, 61, 51, 0.64);
  color: white;
  background: linear-gradient(135deg, rgba(155, 61, 51, 0.92), rgba(40, 125, 120, 0.82));
}

.layer-button svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
}

.layer-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-dock .layer-actions {
  grid-template-columns: 1fr;
}

.layer-dock .layer-button {
  grid-template-columns: 1fr;
  justify-items: center;
  width: 54px;
  min-height: 54px;
  padding: 0;
  text-align: center;
}

.layer-dock .layer-button span {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
  white-space: nowrap;
}

.layer-dock .layer-button svg {
  width: 23px;
  height: 23px;
}

.city-stats {
  display: grid;
  gap: 8px;
}

.city-stat {
  display: grid;
  grid-template-columns: 1fr minmax(44px, auto);
  gap: 6px 12px;
  width: 100%;
  min-height: 50px;
  padding: 9px 10px;
  border: 1px solid rgba(23, 32, 31, 0.12);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  text-align: left;
}

.city-stat:hover {
  border-color: rgba(155, 61, 51, 0.4);
  background: rgba(255, 255, 255, 0.58);
}

.city-stat-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  font-size: 0.82rem;
  font-weight: 800;
}

.city-stat-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.city-stat-main span,
.city-stat-percent {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.city-stat-bar {
  grid-column: 1 / -1;
  align-self: center;
  height: 9px;
  border-radius: 999px;
  background: rgba(23, 32, 31, 0.11);
  box-shadow: inset 0 1px 2px rgba(23, 32, 31, 0.08);
  overflow: hidden;
}

.city-stat-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  transform-origin: left center;
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.city-stat-percent {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  justify-self: end;
}

.empty-stats {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--ink);
  font-size: 0.94rem;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-2);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.segmented-four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segmented-six {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segment {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
}

.segment.is-active {
  color: white;
  background: var(--accent);
}

.detail-panel,
.source-panel {
  position: absolute;
  z-index: 660;
  right: 18px;
  top: 108px;
  width: min(410px, calc(100vw - 36px));
  max-height: calc(100vh - 126px);
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: rgba(250, 249, 243, 0.96);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(calc(100% + 36px));
  transition:
    transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 220ms ease;
  will-change: transform;
}

.detail-panel.is-open,
.source-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
}

.close-detail {
  float: right;
  margin: -6px -6px 8px 12px;
}

.detail-panel p,
.source-panel p {
  color: #33413d;
  font-size: 0.94rem;
  line-height: 1.55;
}

.detail-panel dl {
  display: grid;
  grid-template-columns: minmax(94px, auto) 1fr;
  gap: 8px 12px;
  margin: 16px 0 0;
  font-size: 0.88rem;
}

.detail-panel dt {
  color: var(--muted);
  font-weight: 800;
}

.detail-panel dd {
  margin: 0;
}

.detail-people {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.detail-people:empty {
  display: none;
}

.detail-people .search-result {
  grid-template-columns: 44px 1fr;
  min-height: 56px;
}

.detail-people .search-result-avatar {
  width: 42px;
  height: 42px;
}

.detail-back {
  justify-self: start;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 850;
}

.detail-back:hover {
  background: #ffffff;
}

.detail-sources {
  display: grid;
  gap: 5px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.source-kicker {
  margin: 0;
  color: var(--muted) !important;
  font-size: 0.72rem !important;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.source-panel ul {
  display: grid;
  gap: 9px;
  padding-left: 18px;
  margin-bottom: 0;
}

.source-panel li {
  color: #33413d;
  font-size: 0.9rem;
  line-height: 1.4;
}

.source-panel a,
.detail-sources a {
  color: #8d2d24;
  font-weight: 800;
}

.map-tooltip {
  position: absolute;
  z-index: 500;
  top: 0;
  left: 0;
  display: grid;
  gap: 2px;
  max-width: 260px;
  padding: 7px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 10px 26px rgba(19, 27, 26, 0.18);
  font-size: 0.8rem;
  line-height: 1.25;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  will-change: transform;
}

.map-tooltip.is-visible {
  opacity: 1;
}

.map-tooltip strong {
  font-weight: 900;
}

.map-tooltip span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.maplibregl-ctrl-group {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px !important;
  background: var(--panel-strong) !important;
  box-shadow: var(--shadow) !important;
}

.maplibregl-ctrl-bottom-right {
  right: 8px;
  bottom: 8px;
}

body:not(.is-ready) .control-panel,
body:not(.is-ready) .layer-dock {
  opacity: 0;
}

.control-panel,
.layer-dock {
  transition: opacity 400ms ease;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
  }
}

/* Compact map chrome */
:root {
  --shadow: 0 4px 18px rgba(19, 27, 26, 0.08);
  --panel: rgba(250, 249, 246, 0.97);
  --accent: #28746b;
}
.app-shell, .map-stage, #map { height: 100dvh; }
.topbar {
  top: 16px; left: 16px; right: 16px;
  min-height: 64px; padding: 10px 12px; gap: 16px;
  border-radius: 12px; background: var(--panel);
}
.brand { flex: 0 0 auto; }
h1 { font-size: 1.35rem; line-height: 1.1; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.72rem; }
.topbar-actions { gap: 4px; }
.icon-button { background: transparent; border-color: transparent; }
.icon-button:focus-visible, .segment:focus-visible, .layer-button:focus-visible,
.city-stat:focus-visible, summary:focus-visible, .search-result:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}
.panel-toggle[aria-expanded="true"] { background: #e7eeea; color: var(--accent); }
.search-panel {
  position: relative; inset: auto; transform: none;
  flex: 1 1 360px; width: auto; min-width: 0; max-width: 520px;
  padding: 0; margin: 0 auto; border: 0; box-shadow: none; background: transparent;
}
.search-field {
  min-height: 42px; grid-template-columns: 18px 1fr; gap: 8px;
  padding: 0 12px; background: #f0f1ed; border-color: transparent; box-shadow: none;
}
.search-field svg { width: 18px; height: 18px; stroke-width: 2; }
.search-field input { font-size: 0.88rem; font-weight: 400; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0;
  padding: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
}
.control-panel {
  top: 92px; left: 16px; width: 280px;
  max-height: calc(100dvh - 112px); padding: 16px;
  border-radius: 12px; background: var(--panel);
}
[hidden] { display: none !important; }
.section-title { font-size: 0.73rem; font-weight: 600; text-transform: none; color: var(--muted); }
.segmented { padding: 0; border: 0; background: transparent; gap: 5px; }
.segmented-six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.segment { font-size: 0.8rem; font-weight: 500; border: 1px solid var(--line); min-height: 36px; }
.segment:hover { background: #edf1ec; }
.segment.is-active { background: var(--accent); border-color: var(--accent); color: white; }
.layer-button { min-height: 36px; padding: 0 9px; font-size: 0.78rem; font-weight: 500; gap: 6px; box-shadow: none; }
.layer-button svg { width: 17px; height: 17px; }
.layer-button.is-active { background: #e7eeea; color: var(--accent); border-color: #b7cdc4; }
.city-stats-section summary { font-size: 0.82rem; font-weight: 500; cursor: pointer; padding: 2px 0; }
.city-stats-section[open] summary { margin-bottom: 12px; }
.city-stats { gap: 4px; }
.city-stat { border: 0; padding: 7px 0; background: transparent; min-height: 40px; }
.city-stat-bar { height: 3px; box-shadow: none; }
.city-stat-bar span { background: var(--accent); }
.city-stat-main, .city-stat-main span, .city-stat-percent { font-weight: 500; }
.overlap-readout, .overlap-readout.is-peak {
  margin-top: 14px; padding: 0; border: 0; background: transparent;
  color: var(--muted); font-size: 0.7rem; font-weight: 400; line-height: 1.6;
}
.detail-panel, .source-panel { top: 92px; max-height: calc(100dvh - 112px); border-radius: 12px; }
.search-result-name { font-weight: 600; }
.search-result-meta, .empty-search { font-weight: 400; }
@media (max-width: 860px) {
  .topbar { top: 10px; left: 10px; right: 10px; gap: 8px; padding: 8px; flex-wrap: wrap; }
  .brand { flex: 1; }
  .brand h1 { font-size: 1.2rem; }
  .icon-button { width: 36px; height: 36px; }
  .search-panel { order: 4; flex: 1 0 100%; max-width: none; }
  .control-panel { top: 130px; left: 10px; width: min(280px, calc(100vw - 20px)); max-height: calc(100dvh - 150px); }
  .detail-panel, .source-panel { top: 130px; right: 10px; width: min(410px, calc(100vw - 20px)); max-height: calc(100dvh - 150px); }
}
