:root {
  --panel: rgba(251, 249, 244, 0.90);
  --panel-strong: rgba(255, 254, 251, 0.97);
  --text: #17241f;
  --muted: #67756f;
  --primary: #21624f;
  --primary-2: #3f8f74;
  --route-1: #1f8a70;
  --route-2: #5f6ad4;
  --route-3: #c6862a;
  --accent: #cfb16c;
  --high: #d85768;
  --high-text: #b94053;
  --low-bg: rgba(31, 138, 112, 0.12);
  --high-bg: rgba(216, 87, 104, 0.12);
  --border: rgba(28, 60, 49, 0.12);
  --shadow: 0 24px 60px rgba(17, 35, 28, 0.16);
  --soft: rgba(33, 98, 79, 0.07);
  --chip: rgba(255,255,255,0.7);
}

* { box-sizing: border-box; }
html, body, #map { width: 100%; height: 100%; margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  overflow: hidden;
  background: #edf1eb;
}
button, input { font: inherit; }
button { cursor: pointer; }
#map { background: #e7ebe5; }
.hidden { display: none !important; }

body.dark {
  --panel: rgba(18, 27, 24, 0.90);
  --panel-strong: rgba(21, 31, 27, 0.98);
  --text: #f1f5f2;
  --muted: #aebbb5;
  --primary: #73b89f;
  --primary-2: #5ad0ad;
  --route-1: #5ad0ad;
  --route-2: #8490ff;
  --route-3: #ffbf60;
  --accent: #dec27f;
  --high: #ff8697;
  --high-text: #ffadb9;
  --low-bg: rgba(90, 208, 173, 0.16);
  --high-bg: rgba(255, 134, 151, 0.16);
  --border: rgba(255,255,255,.12);
  --shadow: 0 24px 60px rgba(0,0,0,.42);
  --soft: rgba(255,255,255,.05);
  --chip: rgba(255,255,255,0.06);
}

.glass-panel {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.08);
}

.brand-card {
  position: fixed;
  z-index: 1000;
  top: 18px;
  left: 22px;
  width: fit-content;
  max-width: min(430px, calc(100vw - 110px));
  min-height: 68px;
  padding: 10px 16px 10px 12px;
  border-radius: 24px;
  display: flex;
  align-items: center;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #4ba083 0%, var(--primary) 75%);
  box-shadow:
    0 10px 24px rgba(33,98,79,.24),
    inset 0 1px 0 rgba(255,255,255,.18);
}

/* Simple brand mark requested for the final UI: one large, bold S. */
.brand-letter {
  color: #ffffff;
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.08em;
  text-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.brand h1 { margin: 0; font-size: 24px; line-height: 1.02; letter-spacing: -.025em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; font-weight: 700; white-space: nowrap; letter-spacing: .02em; }

.theme-fab {
  position: fixed;
  z-index: 1000;
  top: 18px;
  right: 22px;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: var(--text);
  font-size: 21px;
  line-height: 1;
}
.theme-fab:hover {
  transform: translateY(-2px) rotate(-4deg);
  box-shadow: 0 18px 42px rgba(17,35,28,.20);
}

.panel-kicker {
  margin-bottom: 6px;
  color: var(--primary-2);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .18em;
}

.search-panel,
.route-summary {
  position: fixed;
  z-index: 1000;
  top: 108px;
  width: min(375px, calc(100vw - 44px));
  border-radius: 30px;
  padding: 22px;
}
.search-panel { left: 22px; }
.route-summary { right: 22px; }
.search-panel h2,
.route-summary h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.panel-intro { margin: 8px 0 18px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.journey-field {
  position: relative;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: start;
}
.field-marker {
  width: 30px;
  height: 30px;
  margin-top: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--primary);
  border: 4px solid color-mix(in srgb, var(--panel-strong) 85%, transparent);
  box-shadow: 0 0 0 1px var(--primary);
  font-size: 10px;
  font-weight: 900;
}
.destination-marker { background: #b17e32; box-shadow: 0 0 0 1px #b17e32; }
.field-content label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.journey-connector {
  width: 34px;
  height: 24px;
  display: grid;
  place-items: center;
  gap: 2px;
}
.journey-connector span {
  width: 2px;
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--primary) 45%, transparent);
}
.search-row { display: flex; gap: 8px; }
.search-row input {
  min-width: 0;
  flex: 1;
  height: 54px;
  padding: 0 16px;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 16px;
  outline: none;
}
.search-row input:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}
.secondary-button {
  width: 54px;
  flex: 0 0 54px;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  background: var(--panel-strong);
  font-size: 20px;
}
.button-icon { display: inline-block; transform: translateY(1px); }
.primary-button,
.chip { border: 0; font-weight: 800; }
.route-search-button {
  width: 100%;
  min-height: 54px;
  margin-top: 18px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 12px 28px rgba(33,98,79,.22);
}
.route-search-button:hover { filter: brightness(1.03); transform: translateY(-1px); }
.quick-actions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 10px 13px;
  border-radius: 999px;
  color: var(--text);
  background: var(--chip);
  border: 1px solid var(--border);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.chip-icon { font-size: 12px; }

.search-field { position: relative; }
.search-results {
  position: absolute;
  z-index: 1400;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 230px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}
.result-item {
  width: 100%;
  padding: 10px 11px;
  border: 0;
  border-radius: 11px;
  color: var(--text);
  background: transparent;
  text-align: left;
  font-size: 12px;
  line-height: 1.35;
}
.result-item strong { display: block; margin-bottom: 2px; }
.result-item span { color: var(--muted); }
.result-item:hover { background: var(--soft); }
.result-empty { padding: 12px 11px; color: var(--muted); font-size: 12px; }

.close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: var(--soft);
}
.route-summary-head {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 14px;
  padding-right: 38px;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.summary-grid > div {
  min-height: 72px;
  padding: 12px 10px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel-strong) 80%, transparent);
  text-align: center;
}
.summary-grid span { display: block; font-size: 15px; font-weight: 900; }
.summary-grid small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.sensory-text-low { color: var(--route-1); }
.sensory-text-high { color: var(--high); }

.route-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.route-options-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--muted);
  background: var(--soft);
  font-size: 11px;
}
.route-option {
  width: 100%;
  min-height: 92px;
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  background: #ffffff;
  text-align: left;
}
.route-option:hover { transform: translateY(-1px); }
.route-option.selected {
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow:
    inset 0 0 0 3px rgba(35, 40, 38, 0.65),
    0 10px 28px rgba(20, 40, 30, 0.14);
  transform: translateY(-2px);
}
body.dark .route-option.selected {
  background: var(--panel-strong);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.88),
    0 10px 28px rgba(0, 0, 0, 0.32);
  transform: translateY(-2px);
}
.route-swatch {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  color: #23483d;
  background: #ffffff;
  border: 1px solid rgba(23, 36, 31, .10);
  box-shadow: 0 5px 14px rgba(20, 40, 30, .08);
}
.route-swatch::before,
.route-swatch::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 999px;
}
.route-swatch::before { width: 22px; height: 6px; transform: rotate(-28deg); }
.route-swatch::after { width: 9px; height: 9px; right: 10px; top: 10px; }
.route-copy {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 5px;
}
.route-option-main { display: flex; align-items: center; gap: 7px; min-width: 0; }
.route-option-main strong {
  font-size: 14px;
  white-space: nowrap;
}
.route-option-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.recommended-badge {
  width: fit-content;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font-size: 9px;
  line-height: 1;
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}
.sensory-badge {
  justify-self: end;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
}
.sensory-low { color: var(--route-1); background: var(--low-bg); border: 1px solid color-mix(in srgb, var(--route-1) 40%, transparent); }
.sensory-high { color: var(--high-text); background: var(--high-bg); border: 1px solid color-mix(in srgb, var(--high) 40%, transparent); }
.route-option.route-1,
.route-option.route-2,
.route-option.route-3 {
  border-left: 1px solid var(--border);
}
.route-option.route-1 .route-swatch,
.route-option.route-2 .route-swatch,
.route-option.route-3 .route-swatch {
  color: #23483d;
  background: #ffffff;
}
body.dark .route-swatch {
  color: #23483d;
  background: #ffffff;
  border-color: rgba(255,255,255,.20);
}
body.dark .route-option {
  background: var(--surface);
}
.alert-message { margin-top: 12px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.legend {
  position: fixed;
  z-index: 900;
  left: 22px;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border-radius: 999px;
  font-size: 11px;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; display: inline-block; border-radius: 50%; }
.low { background: #45a98d; }
.medium { background: #e6a235; }
.high { background: #d65364; }
.toast {
  position: fixed;
  z-index: 2000;
  left: 50%;
  top: 100px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  background: #172129;
  box-shadow: var(--shadow);
  font-size: 12px;
}

.safe-space-icon-wrapper,
.endpoint-icon-wrapper {
  background: transparent;
  border: 0;
}
.safe-space-marker,
.endpoint-marker {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 14px 14px 14px 5px;
  color: white;
  box-shadow: 0 8px 18px rgba(0,0,0,.22);
}
.safe-space-marker {
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.88);
  font-size: 15px;
  font-weight: 900;
}
.safe-space-marker.park { background: linear-gradient(135deg, #2b8c6b, #5cb88e); }
.safe-space-marker.library { background: linear-gradient(135deg, #4e72b8, #6f97db); }
.safe-space-marker.quiet { background: linear-gradient(135deg, #6a8c7d, #88aa98); }
.endpoint-marker.start { background: linear-gradient(135deg, var(--route-1), color-mix(in srgb, var(--route-1) 70%, white)); }
.endpoint-marker.end { background: linear-gradient(135deg, var(--route-3), color-mix(in srgb, var(--route-3) 70%, white)); }
.endpoint-marker { font-size: 13px; font-weight: 900; border: 2px solid rgba(255,255,255,.9); }

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--panel-strong);
  color: var(--text);
}
.leaflet-control-container .leaflet-routing-container { display: none; }
.leaflet-overlay-pane svg { overflow: visible; }
.crowd-zone { transition: fill-opacity .2s ease; }
.crowd-zone:hover { fill-opacity: .32; }
.crowd-pulse { transform-box: fill-box; transform-origin: center; animation: crowd-expand 2.2s ease-out infinite; }
.crowd-pulse-medium { animation-duration: 1.9s; }
.crowd-pulse-high { animation-duration: 1.45s; }

@keyframes crowd-expand {
  0% { stroke-opacity: .45; fill-opacity: .10; transform: scale(.68); }
  70% { stroke-opacity: .12; fill-opacity: .02; }
  100% { stroke-opacity: 0; fill-opacity: 0; transform: scale(1.16); }
}

body.dark .leaflet-control-zoom-in,
body.dark .leaflet-control-zoom-out,
body.dark .leaflet-control-attribution { filter: brightness(.88) contrast(1.08); }

@media (prefers-reduced-motion: reduce) {
  .crowd-pulse { animation: none; }
  .route-option, .route-search-button { transition: none; }
}

@media (max-width: 1220px) {
  .search-panel, .route-summary { width: 340px; }
}

@media (max-width: 980px) {
  .route-summary { top: auto; bottom: 16px; left: 22px; right: 22px; width: auto; }
  .search-panel { width: 360px; }
}

@media (max-width: 760px) {
  .brand-card { top: 10px; left: 10px; max-width: calc(100vw - 82px); border-radius: 20px; }
  .brand p { display: none; }
  .theme-fab { top: 10px; right: 10px; width: 48px; height: 48px; border-radius: 16px; }
  .search-panel { left: 10px; right: 10px; top: 92px; width: auto; padding: 16px; border-radius: 22px; }
  .panel-intro { display: none; }
  .route-summary { left: 10px; right: 10px; bottom: 10px; top: auto; width: auto; padding: 16px; border-radius: 22px; max-height: 44vh; overflow: auto; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
  .legend { display: none !important; }
}
