:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f0ed;
  --stat-surface: #efebe6;
  --text: #222222;
  --muted: #6f6a64;
  --faint: #9b958f;
  --border: rgba(34, 34, 34, 0.12);
  --primary: #222222;
  --primary-strong: #111111;
  --primary-soft: #f4f0eb;
  --gold: #8f6a34;
  --rust: #9f5f3d;
  --green: #557b4a;
  --blue: #4d7185;
  --passage: #6f5b3e;
  --purple: #7a657f;
  --shadow: 0 16px 38px rgba(34, 34, 34, 0.08);
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.4rem;
  --font-body: "Satoshi", "Inter", sans-serif;
  --font-display: "Switzer", "Satoshi", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101010;
  --surface: #1c1c1c;
  --surface-2: #272727;
  --stat-surface: #2a2724;
  --text: #f2eee9;
  --muted: #aaa39a;
  --faint: #736c63;
  --border: rgba(242, 238, 233, 0.14);
  --primary: #f2eee9;
  --primary-strong: #ffffff;
  --primary-soft: #2d2a27;
  --gold: #d6a94e;
  --rust: #d98a68;
  --green: #8fbd78;
  --blue: #83b5d5;
  --purple: #b39ad1;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.leaflet-container {
  overflow: hidden;
  touch-action: pan-x pan-y;
  font-family: var(--font-body);
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile {
  user-select: none;
  -webkit-user-drag: none;
  max-width: none !important;
  max-height: none !important;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-control-zoom {
  margin: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.leaflet-control-zoom a {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

.leaflet-control-zoom a:last-child {
  border-bottom: 0;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
  margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
  padding: 0.65rem;
  text-align: left;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.leaflet-popup-content {
  margin: 0;
  min-width: 190px;
}

.leaflet-popup-tip-container {
  width: 40px;
  height: 20px;
  position: absolute;
  left: 50%;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 17px;
  height: 17px;
  padding: 1px;
  margin: -10px auto 0;
  transform: rotate(45deg);
}

.leaflet-popup-close-button {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.35rem 0.55rem;
  color: var(--muted);
  text-decoration: none;
}

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
  line-height: 1.55;
  color: var(--text);
  background:
    linear-gradient(180deg, #ffffff 0%, #ffffff 35%, #f7f5f2 100%);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  min-height: 44px;
}

button {
  cursor: pointer;
}

a {
  color: var(--primary-strong);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  transform: translateY(-150%);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  z-index: 10000;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header,
.app-shell {
  width: min(1440px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 48px;
  height: 48px;
  color: var(--primary);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
  line-height: 1.08;
}

h1 {
  font-size: clamp(1.4rem, 1.15rem + 0.9vw, 2.15rem);
}

h2 {
  font-size: clamp(1.25rem, 1.1rem + 0.65vw, 1.75rem);
}

h3 {
  font-size: 1.05rem;
}

.eyebrow {
  color: var(--primary-strong);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.theme-toggle,
.secondary-button,
.text-button {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.55rem 0.9rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.74rem;
  transition:
    border-color 180ms ease,
    background 180ms ease,
    color 180ms ease;
}

.secondary-button {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

:root[data-theme="dark"] .secondary-button {
  color: #102012;
}

.text-button {
  background: transparent;
}

.theme-toggle:hover,
.text-button:hover {
  border-color: var(--primary);
}

.secondary-button:hover {
  background: var(--primary-strong);
}

.app-shell {
  display: grid;
  gap: 1rem;
  padding-bottom: 2rem;
}

.intro-card,
.controls,
.map-panel,
.results-panel,
.notes {
  border: 1px solid var(--border);
  border-radius: 0;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow);
}

.intro-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: clamp(0.9rem, 2vw, 1.45rem);
}

.intro-card p:not(.eyebrow) {
  max-width: 68ch;
  color: var(--muted);
  margin-top: 0.55rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 0.6rem;
  align-self: end;
}

.stats div {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.8rem;
  background: var(--stat-surface);
}

.stats strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.controls {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr;
  gap: 0.7rem 1rem;
  padding: 0.85rem;
}

.search-box,
.controls label {
  display: grid;
  gap: 0.35rem;
}

.search-box span,
.controls label span,
legend {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 0.75rem;
}

.select-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto auto;
  align-items: end;
  gap: 0.6rem;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.status-message {
  grid-column: 1 / -1;
  min-height: 1.25rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.45rem 0.7rem;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  transition:
    border-color 180ms ease,
    background 180ms ease;
}

.chip[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, 0.86fr);
  gap: 1rem;
  height: 600px;
  min-height: 600px;
}

.map-panel {
  position: relative;
  overflow: hidden;
  height: 600px;
  min-height: 560px;
}

#map {
  width: 100%;
  height: 600px;
  min-height: 560px;
  background: var(--surface-2);
}

.legend {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  max-width: calc(100% - 2rem);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.55rem;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  display: inline-block;
}

.luxury { background: var(--gold); }
.chocolate { background: var(--rust); }
.design { background: var(--blue); }
.passage { background: var(--passage); }
.flea { background: var(--green); }
.concept { background: var(--purple); }
.quarter { background: var(--primary); }

.results-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 600px;
  min-height: 560px;
  overflow: hidden;
}

.results-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.8rem;
  border-bottom: 1px solid var(--border);
  padding: 1rem;
}

.results-header p:last-child {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.results-list {
  overflow: auto;
  padding: 0.75rem;
}

.place-card {
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
}

.place-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.place-top {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
}

.place-meta,
.place-tags,
.place-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.place-meta span,
.tag {
  border-radius: 0;
  background: var(--surface-2);
  color: var(--muted);
  padding: 0.22rem 0.48rem;
  font-size: 0.76rem;
}

.place-card address,
.place-card p {
  color: var(--muted);
  font-size: 0.9rem;
  font-style: normal;
  margin-top: 0.55rem;
}

.place-actions a,
.place-actions button {
  border: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--primary-strong);
  padding: 0.42rem 0.65rem;
  min-height: 38px;
  text-decoration: none;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.source-line {
  color: var(--faint) !important;
  font-size: 0.78rem !important;
}

.marker-pin {
  width: 32px;
  height: 32px;
  border: 2px solid white;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24);
}

.marker-pin span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transform: rotate(45deg);
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
}

.popup-title {
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.notes {
  padding: 1rem;
}

.notes p {
  color: var(--muted);
  margin-top: 0.45rem;
  max-width: 88ch;
}

.credit {
  font-size: 0.82rem;
}

@media (max-width: 980px) {
  .intro-card,
  .controls,
  .map-layout {
    grid-template-columns: 1fr;
  }

  .select-row {
    grid-template-columns: 1fr;
  }

  .map-layout {
    height: auto;
    min-height: 0;
  }

  .map-panel,
  #map,
  .results-panel {
    height: auto;
    min-height: 480px;
  }

  #map {
    height: 480px;
  }
}

@media (max-width: 620px) {
  .site-header,
  .app-shell {
    width: min(100% - 1rem, 1440px);
  }

  .site-header {
    align-items: start;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .stats {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .intro-card,
  .controls,
  .notes {
    border-radius: 0;
  }

  .theme-toggle {
    font-size: 0.85rem;
  }
}
