:root {
  --map-height: 520px;
}

.map {
  height: var(--map-height);
  width: 100%;
  border-radius: 0.5rem;
}

.map.map-full {
  /* explore.html overrides height via body + #map for mobile-friendly dvh */
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
}

/* Make Leaflet tooltips look more like “labels” */
.leaflet-tooltip.label-tooltip {
  background: rgba(20, 20, 20, 0.9);
  color: #fff;
  border: 0;
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.leaflet-tooltip.label-tooltip::before {
  display: none; /* remove the little pointer to look like a floating label */
}

/* Leaflet sets `max-width: none !important` on images inside the map container.
   Override that for popup content so observation images actually fit the popup. */
.leaflet-popup.obs-tour-popup .leaflet-popup-content-wrapper {
  border-radius: 10px;
  overflow: visible;
}

.leaflet-popup.obs-tour-popup .leaflet-popup-close-button {
  display: none;
}

.leaflet-popup.obs-tour-popup .leaflet-popup-content {
  width: min(420px, calc(100vw - 56px)) !important;
  margin: 0;
  overflow: visible;
}

.leaflet-popup-content .obs-popup {
  position: relative;
  box-sizing: border-box;
  min-width: min(280px, calc(100vw - 84px));
  padding: 14px 14px 18px;
  color: #212529;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  overflow: visible;
}

.leaflet-popup-content .obs-popup-close {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: rgba(33, 37, 41, 0.08);
  color: #212529;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.leaflet-popup-content .obs-popup-close:hover,
.leaflet-popup-content .obs-popup-close:focus-visible {
  background: rgba(33, 37, 41, 0.14);
}

.leaflet-popup-content .obs-popup-kicker {
  padding-right: 36px;
  color: #6c757d;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.leaflet-popup-content .obs-guide-name {
  padding-right: 36px;
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 900;
}

.leaflet-popup-content .obs-species-title {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.25;
  font-weight: 750;
}

.leaflet-popup-content .obs-image-frame {
  margin-top: 10px;
  border-radius: 8px;
  overflow: hidden;
  background: #f1f3f5;
}

.leaflet-popup-content img.obs-img {
  width: 100% !important;
  max-width: 100% !important;
  max-height: 300px !important;
  height: auto !important;
  object-fit: contain;
  display: block;
}

.leaflet-popup-content .obs-link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 750;
}

.leaflet-popup-content .obs-link-row a {
  min-width: 0;
  word-break: break-word;
}

.leaflet-popup-content .obs-meta {
  margin-top: 8px;
  color: #6c757d;
  font-size: 11px;
  line-height: 1.3;
}

.leaflet-popup-content .obs-description {
  margin-top: 8px;
  color: #495057;
  font-size: 12px;
  line-height: 1.35;
}

.leaflet-popup-content .obs-listen-btn {
  margin-top: 10px;
  border: 0;
  border-radius: 8px;
  background: #0d6efd;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  padding: 10px 12px;
}

.leaflet-popup-content .obs-listen-btn:hover,
.leaflet-popup-content .obs-listen-btn:focus-visible {
  background: #0b5ed7;
}

.leaflet-popup-content .obs-audio-iframe-window {
  /* Manual controls: visible height and amount cropped from the top. */
  --audio-iframe-crop-top: 200px;
  width: 100%;
  height: 150px;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 8px;
  background: #fff;
}

.leaflet-popup-content .obs-audio-iframe {
  display: block;
  width: 100%;
  height: 420px;
  border: 0;
  transform: translateY(calc(-1 * var(--audio-iframe-crop-top)));
}

.leaflet-popup-content .obs-popup-audio {
  margin-top: 10px;
}

.leaflet-popup-content .obs-popup-audio-block {
  margin-top: 8px;
}

.leaflet-popup-content .obs-popup-audio-block:first-child {
  margin-top: 0;
}

.leaflet-popup-content .obs-popup-audio-block--mp3 {
  padding: 8px;
  border: 1px solid rgba(13, 110, 253, 0.14);
  border-radius: 8px;
  background: rgba(13, 110, 253, 0.06);
}

.leaflet-popup-content .obs-popup-audio-label {
  margin-bottom: 5px;
  color: #495057;
  font-size: 11px;
  font-weight: 800;
}

.leaflet-popup-content .obs-popup-joel {
  position: absolute;
  right: -96px;
  bottom: -80px;
  width: 200px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.24));
}

/* Tooltip thumbnail for observations */
.leaflet-tooltip.label-tooltip .obs-thumb {
  display: flex;
  gap: 8px;
  align-items: center;
}

.leaflet-tooltip.label-tooltip img.obs-thumb-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.leaflet-tooltip.label-tooltip .obs-thumb-text {
  font-weight: 600;
  line-height: 1.2;
}

/* Always-visible map text labels (A–G descriptions) */
.map-text-label {
  /* User request: black text, and no "black dot/pill" behind it */
  background: transparent;
  color: #000;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  white-space: nowrap;
  /* light outline for readability on imagery/streets */
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.95),
    0 0 6px rgba(255, 255, 255, 0.85);
  transform: translate(-50%, -50%); /* center on the coordinate */
}

/* Explore panel: Map key (red/blue/green dots + nearest lines) */
.map-tools {
  position: fixed;
  left: 12px;
  top: 104px;
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.map-tools-tabs {
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.map-tools-tab {
  width: 88px;
  min-height: 54px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  color: #212529;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  -webkit-tap-highlight-color: transparent;
}

.map-tools-tab:hover,
.map-tools-tab:focus-visible,
.map-tools-tab.is-active {
  background: #0d6efd;
  color: #fff;
  outline: none;
}

.map-tools-tab-icon {
  font-size: 18px;
  line-height: 1;
}

.map-tools-tab-label {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
}

.map-tools-panel {
  width: min(360px, calc(100vw - 132px));
  max-height: min(66vh, 560px);
  overflow: hidden;
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.map-tools.is-collapsed .map-tools-panel {
  display: none;
}

.map-tools-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.map-tools-panel-title {
  font-size: 14px;
  font-weight: 850;
  line-height: 1.2;
  color: #212529;
}

.map-tools-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: rgba(33, 37, 41, 0.08);
  color: #212529;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.map-tools-close:hover,
.map-tools-close:focus-visible {
  background: rgba(33, 37, 41, 0.14);
  outline: none;
}

.map-tools-view {
  max-height: calc(min(66vh, 560px) - 53px);
  overflow: auto;
}

.map-key-float {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 2000;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  padding: 8px 10px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.map-tools .map-key-float,
.map-tools .audio-guide-panel,
.map-tools .panel {
  position: static;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  z-index: auto;
  width: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
}

.map-tools .map-key-float {
  padding: 10px;
}

.map-tools .neighbors-panel {
  padding: 12px;
}

.map-tools .neighbors-panel-header {
  display: none;
}

.map-tools .neighbors-panel-body {
  display: grid;
  gap: 14px;
  overflow: visible;
}

.map-tools .neighbors-panel-body > div {
  margin-top: 0 !important;
}

.map-tools .panel-muted {
  margin-bottom: 5px;
  color: #6c757d;
  font-size: 12px;
  line-height: 1.2;
}

.map-tools .panel-row {
  margin: 0 -4px;
  padding: 7px 4px;
  gap: 8px;
  border-radius: 8px;
}

.map-tools .panel-row-name {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

.map-tools .panel-row-dist {
  flex: 0 0 auto;
  font-size: 12px;
}

.map-tools #neighbors-selected {
  font-size: 15px;
  font-weight: 850;
  line-height: 1.25;
}

.audio-guide-panel {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 2000;
  width: min(340px, calc(100vw - 24px));
  max-height: min(44vh, 380px);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.map-tools .audio-guide-header {
  display: none;
}

.audio-guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.audio-guide-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
  font-size: 14px;
  color: #212529;
  line-height: 1.2;
}

.audio-guide-count {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #198754;
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

.audio-guide-body {
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding: 10px;
}

.map-tools .audio-guide-body {
  border-top: 0;
}

.intro-audio-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(13, 110, 253, 0.16);
  border-radius: 10px;
  background: rgba(13, 110, 253, 0.06);
  color: #212529;
  cursor: pointer;
}

.intro-audio-toggle-title {
  display: block;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.2;
}

.intro-audio-toggle-help {
  display: block;
  margin-top: 2px;
  color: #6c757d;
  font-size: 11px;
  line-height: 1.2;
}

.intro-audio-toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: #0d6efd;
}

.audio-guide-help,
.audio-guide-empty {
  color: #6c757d;
  font-size: 12px;
}

.audio-guide-list {
  display: grid;
  gap: 7px;
  max-height: calc(min(44vh, 380px) - 92px);
  overflow: auto;
  padding-right: 2px;
}

.map-tools .audio-guide-list {
  max-height: none;
}

.species-guide {
  padding: 10px;
}

.species-guide-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: #212529;
  font-size: 14px;
  font-weight: 850;
}

.species-guide-search-label {
  display: block;
  margin-bottom: 4px;
  color: #495057;
  font-size: 11px;
  font-weight: 800;
}

.species-guide-search {
  box-sizing: border-box;
  width: 100%;
  min-height: 42px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(33, 37, 41, 0.2);
  border-radius: 9px;
  background: #fff;
  color: #212529;
  font: inherit;
  font-size: 14px;
}

.species-guide-search:focus {
  border-color: #0d6efd;
  outline: 2px solid rgba(13, 110, 253, 0.2);
}

.species-guide-list {
  display: grid;
  gap: 7px;
  max-height: calc(min(66vh, 560px) - 190px);
  margin-top: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.audio-guide-item {
  width: 100%;
  display: block;
  padding: 8px 9px;
  border: 1px solid rgba(25, 135, 84, 0.22);
  border-radius: 10px;
  background: rgba(25, 135, 84, 0.08);
  color: #15251b;
  text-align: left;
  cursor: pointer;
}

.audio-guide-item:hover,
.audio-guide-item:focus-visible {
  background: rgba(25, 135, 84, 0.16);
  outline: none;
}

.audio-guide-name {
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
}

.audio-guide-meta {
  display: block;
  margin-top: 2px;
  color: #52635a;
  font-size: 11px;
}

/* Map title badge (region name) */
.map-region-badge {
  position: fixed;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 2000;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  padding: 8px 12px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  color: #212529;
  text-align: center;
  max-width: min(520px, calc(100vw - 24px));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-region-subtitle {
  margin-left: 8px;
  font-weight: 650;
  color: #6c757d;
}

.map-key-float > summary {
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 13px;
  color: #212529;
  list-style: none;
}

.map-key-float > summary::-webkit-details-marker {
  display: none;
}

.map-key-float > summary::after {
  content: "▾";
  float: right;
  color: #6c757d;
}

.map-key-float[open] > summary::after {
  content: "▴";
}

.map-key-float[open] {
  padding-bottom: 10px;
}

.map-key {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-key-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.map-key-text {
  font-size: 13px;
  line-height: 1.25;
  color: #212529;
}

.map-key-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  margin-top: 3px; /* align with first line of text */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  flex: 0 0 12px;
}

.map-key-red {
  background: #dc3545;
}

.map-key-blue {
  background: #0d6efd;
}

.map-key-orange {
  background: #fd7e14;
}

.map-key-green {
  background: #198754;
}

.map-key-line {
  width: 18px;
  height: 0;
  margin-top: 9px; /* align with text line */
  border-top: 3px solid;
  border-radius: 999px;
  flex: 0 0 18px;
}

.map-key-green-line {
  border-top-color: #198754;
}

/* -------------------------------------------
   Tour guide widget (avatar + attached bubble)
   ------------------------------------------- */
.nfy-guide-icon {
  /* Leaflet adds inline positioning; keep our widget responsive */
  background: transparent;
  border: 0;
}

.nfy-guide-wrap {
  position: relative;
  width: 1px;
  height: 1px;
  display: block;
  /* gap: 10px; */
  pointer-events: auto;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.18));
}

.nfy-guide-avatar {
  position: absolute;
  left: 0;
  top: 0;
  width: 200px;
  height: auto; /* do not force a height */
  display: block;
  user-select: none;
  transform: translate(-50%, -50%);
}

@media (max-width: 768px) {
  .map-tools {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
  }

  .map-tools-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .map-tools-tab {
    width: auto;
    min-height: 48px;
    border-radius: 12px;
  }

  .map-tools-panel {
    width: 100%;
    max-height: 42vh;
  }

  .map-tools-view {
    max-height: calc(42vh - 53px);
  }
}

@media (max-width: 480px) {

  .audio-guide-panel {
    bottom: 68px;
    max-height: 34vh;
  }

  .nfy-guide-avatar {
    width: 112px;
  }

  .leaflet-popup-content .obs-popup-joel {
    right: -42px;
    bottom: -32px;
    width: 112px;
  }
}

@media (max-width: 320px) {
  .map-tools {
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .map-tools-tabs {
    gap: 5px;
  }

  .map-tools-tab {
    min-height: 42px;
    border-radius: 10px;
  }

  .map-tools-tab-icon {
    font-size: 15px;
  }

  .map-tools-tab-label {
    font-size: 10px;
  }

  .map-tools-panel {
    max-height: 38vh;
    border-radius: 12px;
  }

  .map-tools-panel-header {
    padding: 7px 9px;
  }

  .map-tools-panel-title {
    font-size: 13px;
  }

  .map-tools-close {
    width: 28px;
    height: 28px;
    font-size: 20px;
  }

  .map-tools-view {
    max-height: calc(38vh - 43px);
  }

  .map-tools .neighbors-panel,
  .map-tools .map-key-float {
    padding: 9px;
  }

  .map-tools .neighbors-panel-body {
    gap: 10px;
  }

  .map-tools .panel-muted,
  .map-key-text,
  .audio-guide-help,
  .audio-guide-empty,
  .intro-audio-toggle-help,
  .audio-guide-meta {
    font-size: 11px;
  }

  .intro-audio-toggle {
    margin-bottom: 8px;
    padding: 7px 8px;
    gap: 8px;
  }

  .intro-audio-toggle-title {
    font-size: 11px;
  }

  .intro-audio-toggle input {
    width: 18px;
    height: 18px;
  }

  .map-tools #neighbors-selected {
    font-size: 13px;
  }

  .map-tools .panel-row {
    padding: 5px 3px;
  }

  .map-tools .panel-row-name,
  .audio-guide-name {
    font-size: 12px;
  }

  .map-tools .panel-row-dist {
    font-size: 11px;
  }

  .map-tools #route-list {
    font-size: 11px !important;
    line-height: 1.25 !important;
  }

  .audio-guide-body {
    padding: 8px;
  }

  .audio-guide-list {
    gap: 5px;
  }

  .species-guide-list {
    max-height: calc(38vh - 145px);
    min-height: 80px;
    gap: 5px;
  }

  .audio-guide-item {
    padding: 6px 7px;
    gap: 6px;
    border-radius: 8px;
  }

  .map-key {
    gap: 6px;
  }

  .map-key-item {
    gap: 8px;
  }
}

.nfy-guide-bubble {
  position: absolute;
  left: 110px;
  top: 0;
  transform: translateY(-50%);
  width: 240px; /* "vertical" feel like the reference */
  min-height: 0;
  padding: 14px 14px 12px 14px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.nfy-guide-bubble--media {
  width: 260px;
}

.nfy-guide-bubble::before {
  /* speech pointer from bubble to avatar */
  content: "";
  position: absolute;
  left: -10px;
  top: 56%;
  width: 18px;
  height: 18px;
  background: rgba(255, 255, 255, 0.98);
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  transform: translateY(-50%) rotate(45deg);
}

@media (max-width: 480px) {
  .nfy-guide-bubble,
  .nfy-guide-bubble--media {
    left: 50px;
    width: 160px;
    padding: 10px 10px 9px;
  }
}

@media (max-width: 320px) {
  .nfy-guide-bubble,
  .nfy-guide-bubble--media {
    left: 38px;
    width: 125px;
    padding: 9px 9px 8px;
  }
}

.nfy-guide-title {
  font-weight: 900;
  font-size: 13px;
  color: #212529;
  margin-bottom: 6px;
}

.nfy-guide-msg {
  font-size: 12px;
  line-height: 1.28;
  color: #212529;
  white-space: pre-wrap;
}

.nfy-guide-audio {
  margin-top: 8px;
}

.nfy-guide-audio--mp3 {
  padding: 8px;
  border: 1px solid rgba(13, 110, 253, 0.14);
  border-radius: 14px;
  background: rgba(13, 110, 253, 0.06);
}

.nfy-guide-audio-label {
  margin-bottom: 5px;
  color: #495057;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.nfy-guide-audio--joel {
  position: relative;
  z-index: 2;
}

.nfy-guide-audio-control {
  width: 100%;
  min-height: 40px;
  height: auto;
  display: block;
}

/* Docked mode: attach the guide widget to the observation popup (bottom-right) */
.leaflet-popup {
  overflow: visible; /* allow docked widget to render outside popup bounds */
}

.nfy-guide-dock {
  position: absolute;
  left: 70%;
  bottom: 0;
  /* margin-left: 8px; */
  /* margin-bottom: 8px; */
  transform: translateY(30px);
  z-index: 9999;
  pointer-events: auto;
}
