:root {
  --ink: #1C2E22;
  --ink-soft: #4A5C4E;
  --pine: #1F4D3A;
  --pine-dark: #16382B;
  --pine-light: #6FA08A;
  --cream: #F7F1E6;
  --paper: #FFFFFF;
  --gold: #C4A35A;
  --gold-dark: #8E6F2E;
  --berry: #8B2E3A;
  --nativity: #6B3FA0;
  --muted: #5c6b7a;
  --shadow: 0 8px 24px rgba(28, 46, 34, 0.14);
  --radius: 10px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100svh;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html {
  height: 100%;
  height: 100svh;
  height: var(--app-height, 100svh);
}
body {
  height: 100%;
  height: 100svh;
  height: var(--app-height, 100svh);
  max-height: 100%;
  max-height: 100svh;
  max-height: var(--app-height, 100svh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: "Trebuchet MS", "Segoe UI Rounded", ui-rounded, system-ui, sans-serif;
  margin: 0;
  line-height: 1.15;
  color: var(--ink);
}

a { color: var(--pine-dark); }
a:focus-visible, button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 8px 12px;
  z-index: 4000;
}
.skip:focus { left: 8px; top: 8px; }

.preview-banner {
  flex: 0 0 auto;
  background: var(--gold);
  color: var(--pine-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
  padding: 4px 10px;
  padding-top: max(4px, var(--safe-top));
}

/* ---------- Header ---------- */
header.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-height: var(--header-h);
  padding: 6px 10px;
  background: var(--cream);
  border-bottom: 1px solid #e2d6c0;
  z-index: 20;
}
header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  color: inherit;
}
header .brand .titles { min-width: 0; }
header .brand h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
header .brand p {
  margin: 1px 0 0;
  font-size: 0.68rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 520px) {
  header .brand p {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
  header .brand .sub-sep { display: none; }
  header .brand .sub-line { display: block; }
}
.header-actions { flex: 0 0 auto; }
.header-actions .primary {
  appearance: none;
  border: 0;
  background: var(--pine);
  color: #fff;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 999px;
  cursor: pointer;
}

/* ---------- Map ---------- */
#map {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: #d8e4dc;
}
.leaflet-container { font: inherit; background: #d8e4dc; }

.locate-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #c9d6df;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(28,46,34,0.15);
  line-height: 1;
}
#map.popup-open .locate-btn { z-index: 350; }

/* Pins */
.pin-wrap { background: transparent; border: 0; }
.pin {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(28,46,34,0.35);
}
.pin.village { background: var(--pine); }
.pin.lights { background: var(--gold); }
.pin.nativity { background: var(--nativity); }
.pin.santa { background: var(--berry); }
.pin.is-dim { filter: grayscale(0.45) opacity(0.7); }
.leaflet-marker-pane .pin-wrap { background: transparent; border: 0; }

/* Popups */
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.leaflet-popup-content {
  margin: 12px 36px 14px 14px;
  min-width: 0;
  max-width: var(--popup-max-w, 260px);
  font-size: 0.88rem;
  max-height: var(--popup-max-h, none);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.leaflet-container a.leaflet-popup-close-button {
  width: 44px;
  height: 44px;
  padding: 0;
  font: 700 28px/44px system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  text-align: center;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.leaflet-popup-scrolled {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.popup-card h3 {
  font-size: 1.02rem;
  font-weight: 800;
  margin: 0 0 2px;
}
.popup-card .host {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--pine-dark);
}
.popup-card .addr,
.popup-card .walk,
.popup-card .hours-note,
.popup-card .price,
.popup-card .notes {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.popup-card .price { font-weight: 700; color: var(--ink); }
.popup-card .hours {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  font-size: 0.8rem;
}
.popup-card .hours li {
  padding: 2px 0;
}
.popup-card .hours li.is-today {
  font-weight: 700;
  color: var(--ink);
  background: var(--cream);
  margin: 0 -6px;
  padding: 3px 6px;
  border-radius: 6px;
}
.popup-card .features {
  margin: 0 0 8px;
  padding: 0 0 0 1.1em;
  font-size: 0.8rem;
}
.popup-card .features li { margin: 0 0 2px; }
.popup-card .blurb {
  margin: 0 0 8px;
  font-size: 0.8rem;
}
.popup-card .links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 4px;
}
.popup-card .links a {
  font-weight: 700;
  font-size: 0.82rem;
}

/* Legend locked to the map */
.leaflet-bottom.leaflet-left {
  max-width: calc(100% - 8.75rem);
}
.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  max-width: 100%;
  margin: 0 0 8px 8px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(28, 46, 34, 0.12);
  border-radius: 8px;
  box-shadow: 0 1px 6px rgba(28, 46, 34, 0.16);
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.15;
  pointer-events: auto;
}
.map-legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 3px;
  vertical-align: -1px;
  border: 1px solid rgba(255,255,255,0.8);
  box-shadow: 0 0 0 1px rgba(28,46,34,0.15);
}
.map-legend .swatch.village { background: var(--pine); }
.map-legend .swatch.lights { background: var(--gold); }
.map-legend .swatch.nativity { background: var(--nativity); }
.map-legend .swatch.santa { background: var(--berry); }

@media (max-width: 719px) {
  .leaflet-bottom.leaflet-left {
    max-width: calc(100% - 16px);
  }
  .leaflet-bottom.leaflet-left .map-legend {
    flex-wrap: nowrap;
    font-size: 0.62rem;
    gap: 4px 7px;
    padding: 3px 7px;
    margin: 0 8px 22px 8px;
    border-radius: 6px;
  }
  .map-legend .swatch { width: 10px; height: 10px; }
}
@media (min-width: 720px) {
  .map-legend {
    font-size: 0.72rem;
    gap: 8px 12px;
    padding: 6px 10px;
  }
}

/* ---------- Dock ---------- */
.panel-toggle { display: none; }
.dock {
  background: var(--paper);
  border-top: 3px solid var(--pine);
  padding: 8px 12px 8px;
  z-index: 20;
  font-size: 0.85rem;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.dock-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px 10px;
  margin-bottom: 6px;
}
.filters .cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-right: 2px;
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--cream);
  border: 1px solid #e2d6c0;
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.seg.wrap { border-radius: 16px; }
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
}
.seg button[aria-pressed="true"] {
  background: var(--pine);
  color: #fff;
}
.results {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.results-head {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 4px 0 6px;
  color: var(--ink-soft);
}
.results-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.result-row {
  appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #efe6d6;
  background: transparent;
  color: inherit;
  padding: 8px 4px;
  cursor: pointer;
  font: inherit;
}
.result-row:last-child { border-bottom: 0; }
.result-row .name {
  font-weight: 800;
  font-size: 0.92rem;
}
.result-row .meta {
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.result-row.is-dim { opacity: 0.55; }
.result-row.is-selected { background: var(--cream); border-radius: 8px; }
.empty {
  color: var(--ink-soft);
  font-size: 0.86rem;
  padding: 8px 4px 12px;
}

/* ---------- Footer ---------- */
footer.partners {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--pine-dark);
  color: #fff;
  padding: 6px 12px;
  padding-bottom: max(6px, var(--safe-bottom));
  z-index: 20;
}
.partners .slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.partners .slot.visit {
  background: #fff;
  border-radius: 8px;
  padding: 3px 6px;
}
.partners .slot.mcm { gap: 6px; }
.partners .credit { font-size: 11px; opacity: .8; white-space: nowrap; }
.partners img { display: block; width: auto; }
.partners .visit img { height: 36px; max-width: 42vw; }
.partners .mcm img { height: 30px; max-width: 14vw; }

/* ---------- Drawer ---------- */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(28, 46, 34, 0.4);
  z-index: 80;
}
.drawer-backdrop.show { display: block; }
.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88dvh, 88svh);
  overflow: auto;
  background: var(--paper);
  border-radius: 16px 16px 0 0;
  z-index: 90;
  transform: translateY(110%);
  transition: transform 0.28s ease;
  padding: 8px 16px 24px;
  padding-bottom: max(24px, var(--safe-bottom));
  box-shadow: var(--shadow);
}
.drawer.open { transform: translateY(0); }
.drawer .handle {
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: #c3d0d6;
  margin: 4px auto 8px;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.drawer .close {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  width: 44px;
  height: 44px;
  cursor: pointer;
  color: var(--ink);
}
.drawer .body p { margin: 0 0 10px; }
.drawer .lede { font-size: 1.02rem; font-weight: 650; }
.drawer h3 { margin: 14px 0 6px; font-size: 0.95rem; }
.drawer .note { font-size: 0.78rem; color: var(--ink-soft); }
.drawer code { font-size: 0.86em; }

/* ---------- Mobile layout ---------- */
@media (max-width: 719px) {
  #map {
    flex: 0 0 auto;
    height: var(--map-height, clamp(160px, min(40dvh, 40svh), calc(var(--app-height, 100svh) - 22rem)));
    min-height: 0;
    max-height: calc(var(--app-height, 100svh) - 16rem);
    transition: height 0.32s ease;
  }
  .dock {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 10px 6px;
  }
  .dock-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    max-height: 80svh;
    opacity: 1;
    transition: max-height 0.32s ease, opacity 0.2s ease;
  }
  .panel-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    appearance: none;
    border: 0;
    background: transparent;
    width: 100%;
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 4px 6px;
    color: var(--ink);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
  }
  .panel-handle {
    display: block;
    width: 40px;
    height: 5px;
    border-radius: 999px;
    background: #c3d0d6;
  }
  .panel-toggle-text {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    min-height: 0;
  }
  .panel-summary {
    font-weight: 800;
    font-size: 0.84rem;
    color: var(--ink);
    text-align: left;
  }
  .panel-toggle-label {
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--pine-dark);
    white-space: nowrap;
  }
  body.panel-expanded .panel-toggle-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  body.panel-expanded .panel-toggle { padding: 10px 4px 2px; }
  body.panel-compact .dock {
    flex: 0 0 auto;
    overflow: hidden;
    padding: 0 12px 8px;
  }
  body.panel-compact .dock-body {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    flex: 0 0 0;
    min-height: 0;
    overflow: hidden;
  }
  body.panel-compact .panel-toggle {
    padding: 8px 4px 4px;
    min-height: 48px;
  }
  body.panel-compact #map { max-height: none; }
  body.panel-compact footer.partners { display: none; }
  body.panel-expanded .seg button {
    min-height: 40px;
    padding: 6px 11px;
    font-size: 0.8rem;
  }
  footer.partners {
    padding: 4px 10px;
    padding-bottom: max(4px, var(--safe-bottom));
  }
  .partners .visit img { height: 28px; }
  .partners .mcm img { height: 24px; }
  .partners .credit { font-size: 10px; }
  body.short-viewport {
    height: auto;
    min-height: var(--app-height, 100svh);
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.short-viewport .dock {
    flex: 0 0 auto;
    min-height: auto;
    overflow: visible;
  }
  body.short-viewport.panel-compact .dock { overflow: hidden; }
  body.short-viewport .results {
    flex: 0 0 auto;
    overflow: visible;
  }
  body.short-viewport .results-list {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  @media (prefers-reduced-motion: reduce) {
    #map, .dock-body { transition: none; }
  }
}

@media (min-width: 720px) {
  .panel-toggle { display: none !important; }
  header .brand p { white-space: normal; }
  .results-list {
    height: min(30vh, 248px);
    max-height: none;
  }
  .leaflet-popup-content { max-width: var(--popup-max-w, 300px); }
  .partners img { max-width: none; }
  .drawer {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: 400px;
    max-height: calc(100dvh - 32px);
    border-radius: 16px;
    padding-bottom: 8px;
  }
}

@media (min-width: 900px) {
  body {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 2fr;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "banner banner"
      "header header"
      "dock   map"
      "footer footer";
  }
  .preview-banner { grid-area: banner; }
  header.app-header { grid-area: header; }
  #map {
    grid-area: map;
    min-height: 0;
    height: auto;
  }
  .dock {
    grid-area: dock;
    min-height: 0;
    overflow: hidden;
    border-top: 0;
    border-right: 3px solid var(--pine);
    padding: 12px 14px 8px;
  }
  .filters { flex-shrink: 0; }
  .results {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  .results-head { flex-shrink: 0; }
  .results-list {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    max-height: none;
  }
  footer.partners {
    grid-area: footer;
    gap: 8px;
    padding: 6px max(12px, calc((100% - 280px) / 2));
  }
  .partners .slot.visit { padding: 3px 5px; border-radius: 7px; }
  .partners .slot.mcm { gap: 5px; }
  .partners .visit img { height: 30px; }
  .partners .mcm img { height: 26px; }
}
