@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ============================================
   DESIGN TOKENS
   ============================================ */

:root {
  --ink:           #1C2218;
  --ink-soft:      #3D4438;
  --ink-muted:     #7A8472;
  --ink-faint:     #B8C0B0;

  --cream:         #F4F1EA;
  --cream-dark:    #EAE6DC;
  --cream-deeper:  #DDD8CC;

  --forest:        #2E5E3A;
  --forest-light:  #3F7A4E;
  --forest-pale:   #D6E8DA;

  --gold:          #C4862A;
  --gold-pale:     #F5E9D0;
  --gold-border:   rgba(196, 134, 42, 0.25);

  --rust:          #B8452A;
  --rust-pale:     #F5DDD5;

  --water:         #2A4F6E;
  --water-pale:    #D0DDE8;

  --radius:        14px;
  --radius-sm:     8px;
  --radius-xs:     6px;

  --shadow:        0 2px 12px rgba(28,34,24,0.10), 0 1px 3px rgba(28,34,24,0.07);
  --shadow-lg:     0 8px 32px rgba(28,34,24,0.14), 0 2px 8px rgba(28,34,24,0.08);

  --font:          'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:          'DM Mono', 'Courier New', monospace;
}

/* ============================================
   BASE
   ============================================ */

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink);
}

button {
  cursor: pointer;
  font-family: var(--font);
}

button:focus {
  outline: 2px solid var(--forest);
  outline-offset: 2px;
}

/* ============================================
   MAP
   ============================================ */

#map {
  height: 100%;
  width: 100%;
}

/* ============================================
   SEARCH BAR (bottom)
   ============================================ */

#controls {
  position: absolute;
  bottom: env(safe-area-inset-bottom, 24px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;

  background: white;
  padding: 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(28,34,24,0.08);

  display: flex;
  gap: 8px;
  width: min(92vw, 540px);
  transition: box-shadow 0.3s ease;
}

#controls:hover {
  box-shadow: 0 12px 40px rgba(28,34,24,0.18);
}

#controls input {
  flex: 1;
  padding: 11px 16px;
  font-family: var(--font);
  font-size: 16px; /* CRITICAL: prevents iOS zoom */
  border: 1.5px solid var(--cream-deeper);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  background: var(--cream);
  color: var(--ink);
}

#controls input:focus {
  border-color: var(--forest);
  background: white;
}

#controls input::placeholder {
  color: var(--ink-faint);
}

#controls button {
  padding: 11px 22px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  background: var(--forest);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  letter-spacing: 0.01em;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

#controls button:hover {
  background: var(--forest-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(46, 94, 58, 0.28);
}

#controls button:active {
  transform: translateY(0);
}

/* ============================================
   LAYER LIST
   ============================================ */

#layerList {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 76px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 1000;

  background: white;
  padding: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(28,34,24,0.08);
  font-family: var(--font);
  font-size: 13px;

  max-width: min(45vw, 220px);
  max-height: 40vh;
  overflow-y: auto;
}

#layerList strong {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-family: var(--mono);
}

#layers > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 8px;
  margin: 4px 0;
  background: var(--cream);
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease;
  gap: 6px;
  font-weight: 500;
  color: var(--ink-soft);
}

#layers > div:hover {
  background: var(--cream-dark);
}

#layers button {
  background: transparent;
  border: none;
  color: var(--ink-faint);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  transition: color 0.15s ease, background-color 0.15s ease;
  flex-shrink: 0;
}

#layers button:hover {
  color: var(--rust);
  background: var(--rust-pale);
}

/* ============================================
   DETAILS & COMPARE PANELS
   ============================================ */

#details, #compare {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  z-index: 2001;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(28,34,24,0.07);
  display: none;
  max-height: 60%;
  overflow: auto;
  padding: 0;
  font-family: var(--font);
}

#details {
  bottom: 110px;
  width: min(90%, 440px);
}

#compare {
  top: 10%;
  width: min(95%, 820px);
  padding: 24px;
}

/* ---- Details inner layout ---- */

.details-header {
  padding: 20px 20px 14px 20px;
  border-bottom: 1px solid var(--cream);
}

.details-name-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}

.details-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.3px;
  line-height: 1.3;
}

.details-close-btn {
  background: var(--cream);
  border: none;
  color: var(--ink-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
  margin-left: auto;
}

.details-close-btn:hover {
  background: var(--cream-dark);
  color: var(--ink);
}

.details-rating {
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
}

.details-rating .star {
  color: var(--gold);
}

.details-rating .review-count {
  color: var(--ink-faint);
  font-size: 12px;
}

/* Source badges */
.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.source-badge.google { background: var(--water-pale); color: var(--water); }
.source-badge.osm    { background: var(--forest-pale); color: var(--forest); }
.source-badge.ebird  { background: var(--rust-pale); color: var(--rust); }

/* Action buttons row */
.details-actions {
  display: flex;
  gap: 7px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--cream);
}

.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 6px;
  border-radius: 10px;
  border: 1.5px solid var(--cream-deeper);
  background: var(--cream);
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
}

.action-btn:hover {
  background: var(--cream-dark);
  border-color: var(--ink-faint);
  transform: translateY(-1px);
}

.action-btn.primary {
  background: var(--forest);
  border-color: var(--forest);
  color: white;
}

.action-btn.primary:hover {
  background: var(--forest-light);
  border-color: var(--forest-light);
}

.action-btn .btn-icon {
  font-size: 16px;
  line-height: 1;
}

/* Details body */
.details-body {
  padding: 12px 20px 18px 20px;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--cream);
  font-family: var(--font);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-icon {
  font-size: 14px;
  width: 18px;
  flex-shrink: 0;
  text-align: center;
  margin-top: 1px;
}

.detail-text {
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.detail-text a {
  color: var(--water);
  text-decoration: none;
  word-break: break-all;
}

.detail-text a:hover {
  text-decoration: underline;
}

/* ---- Compare panel ---- */

#compare strong {
  font-size: 18px;
  color: var(--ink);
  font-family: var(--font);
}

#compare hr {
  border: none;
  border-top: 1px solid var(--cream-deeper);
  margin: 12px 0;
}

#compare > div button {
  background: var(--cream);
  border: 1px solid var(--cream-deeper);
  color: var(--ink-soft);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}

#compare > div button:hover {
  background: var(--cream-dark);
}

#compare table {
  margin-top: 16px;
  border-collapse: collapse;
  width: 100%;
}

#compare table th {
  background: var(--cream);
  padding: 10px 12px;
  font-weight: 600;
  text-align: left;
  border: 1px solid var(--cream-deeper);
  font-size: 13px;
  color: var(--ink-soft);
}

#compare table td {
  padding: 9px 12px;
  border: 1px solid var(--cream-deeper);
  font-size: 13px;
  color: var(--ink-soft);
}

/* ============================================
   FOOTNOTE
   ============================================ */

#footnote {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 76px);

  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-muted);
  background: rgba(244, 241, 234, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 4px 10px;
  border-radius: 20px;
  z-index: 999;
  pointer-events: none;
  border: 1px solid rgba(28,34,24,0.08);
}

/* ============================================
   HELP BUTTON
   ============================================ */

#helpButton {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 10px + 34px + 12px);
  z-index: 1000;

  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--forest);
  color: var(--forest);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#helpButton:hover {
  background: var(--forest);
  color: white;
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(46, 94, 58, 0.3);
}

@media (max-width: 600px) {
  #helpButton {
    width: 36px;
    height: 36px;
    font-size: 17px;
    left: calc(env(safe-area-inset-left, 0px) + 10px + 26px + 8px);
  }
}

/* ============================================
   HELP MODAL
   ============================================ */

#helpModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1002;

  background: white;
  padding: 28px;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(28,34,24,0.22);
  border: 1px solid rgba(28,34,24,0.07);

  max-width: min(90vw, 500px);
  max-height: 80vh;
  overflow-y: auto;

  display: none;
}

#helpModal.show {
  display: block;
}

#helpModal h2 {
  margin: 0 0 20px 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#helpModal h3 {
  color: var(--forest);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--mono);
  margin: 20px 0 8px 0;
}

#helpModal p, #helpModal ul {
  color: var(--ink-soft);
  line-height: 1.65;
  margin: 6px 0;
  font-size: 14px;
}

#helpModal ul {
  padding-left: 18px;
}

#helpModal li {
  margin: 5px 0;
}

#helpModal code {
  background: var(--cream);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--forest);
  border: 1px solid var(--cream-deeper);
}

#helpModal .closeHelp {
  background: var(--cream);
  border: 1px solid var(--cream-deeper);
  color: var(--ink-muted);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
}

#helpModal .closeHelp:hover {
  background: var(--cream-dark);
  color: var(--ink);
}

/* ============================================
   MODAL OVERLAY
   ============================================ */

#helpOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(28, 34, 24, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 1001;
  display: none;
}

#helpOverlay.show {
  display: block;
}

/* ============================================
   LOADING SPINNER
   ============================================ */

#loadingSpinner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;

  background: white;
  padding: 22px 30px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(28,34,24,0.07);

  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;

  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
}

#loadingSpinner.show {
  display: flex;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--cream-deeper);
  border-top-color: var(--forest);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================
   AFFILIATE BUTTONS
   ============================================ */

.affiliate-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--cream-deeper);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.affiliate-btn {
  width: 100%;
  justify-content: center;
  background: var(--gold-pale);
  border: 1px solid var(--gold-border) !important;
  color: var(--gold) !important;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 9px 14px;
  border-radius: 9px;
  transition: all 0.15s ease;
}

.affiliate-btn:hover {
  background: #EDD89A !important;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(196, 134, 42, 0.18);
}

.affiliate-btn .btn-icon {
  margin-right: 4px;
}

/* affiliateDisclosure banner removed — disclosure now lives in help modal */
#affiliateDisclosure { display: none; }

/* ============================================
   SHARE BUTTON
   ============================================ */

#shareBtn {
  background: transparent;
  border: 1px solid var(--cream-deeper);
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.03em;
}

#shareBtn:hover {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
  #controls {
    width: calc(100vw - 24px);
    padding: 8px;
  }

  #controls input {
    padding: 10px 14px;
  }

  #controls button {
    padding: 10px 18px;
  }

  #layerList {
    max-height: 40vh;
    overflow-y: auto;
    max-width: min(60vw, 200px);
  }

  #details {
    width: calc(100vw - 24px);
    bottom: 100px;
  }

  #compare {
    width: calc(100vw - 24px);
    padding: 16px;
  }
}

/* ============================================
   MARKER LABELS & TOOLTIPS
   ============================================ */

/* ── Hover tooltip (Feature 1) ── */
/* Leaflet applies .doogle-tooltip to the tooltip container */
.doogle-tooltip {
  background: rgba(28, 34, 24, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 9px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(28,34,24,0.22);
  pointer-events: none;
}

/* Remove Leaflet's default tooltip arrow/border */
.doogle-tooltip::before {
  display: none;
}

.leaflet-tooltip.doogle-tooltip {
  border: none;
  box-shadow: 0 2px 8px rgba(28,34,24,0.22);
}

/* ── Persistent zoom label (Feature 2) ── */
/* .doogle-label is the inner div inside the DivIcon */
.doogle-label {
  position: relative;
  transform: translateX(-50%);         /* centre horizontally over the dot */
  display: inline-block;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--ink-soft);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  padding: 3px 7px;
  border-radius: 20px;
  border-left: 3px solid var(--dot-color, #2E5E3A);
  box-shadow: 0 1px 4px rgba(28,34,24,0.14);
  pointer-events: none;
  animation: labelFadeIn 0.18s ease forwards;
}

@keyframes labelFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(3px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================
   SEARCH RADIUS PANEL
   ============================================ */

/* ── Toggle button — top-left, next to the help button ── */
#radiusToggleBtn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  /* helpButton sits at: 10px + 34px zoom + 12px gap = 56px from left
     We add another 44px (helpButton width) + 8px gap               */
  left: calc(env(safe-area-inset-left, 0px) + 10px + 34px + 12px + 44px + 8px);
  z-index: 1000;

  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  height: 44px;
  width: 44px;

  background: white;
  border: 2px solid var(--forest);
  border-radius: 50%;
  box-shadow: var(--shadow);

  color: var(--forest);
  transition: all 0.2s ease;
}

#radiusToggleBtn:hover {
  background: var(--forest);
  color: white;
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(46, 94, 58, 0.3);
}

#radiusToggleBtn.active {
  background: var(--forest);
  color: white;
  box-shadow: 0 4px 14px rgba(46, 94, 58, 0.3);
}

/* ── Collapsible panel — drops down from below the toggle button ── */
#radiusPanel {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 64px);
  left: calc(env(safe-area-inset-left, 0px) + 10px);
  z-index: 999;

  width: min(92vw, 480px);

  max-height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: max-height 0.28s ease, opacity 0.22s ease;
}

#radiusPanel.open {
  max-height: 130px;
  opacity: 1;
  pointer-events: auto;
}

#radiusPanelInner {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(28,34,24,0.08);
  padding: 14px 18px 16px;
}

/* ── Panel header row ── */
#radiusPanelHeader {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

#radiusPanelTitle {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  flex: 1;
}

/* Live radius readout */
#radiusLabel {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--forest);
  min-width: 38px;
  text-align: right;
}

/* Circle visibility toggle */
#radiusCircleBtn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  border: 1.5px solid var(--cream-deeper);
  border-radius: var(--radius-xs);
  color: var(--ink-muted);
  padding: 0;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

#radiusCircleBtn:hover {
  background: var(--cream-dark);
  color: var(--ink-soft);
}

#radiusCircleBtn.active {
  background: var(--forest-pale);
  border-color: var(--forest);
  color: var(--forest);
}

/* ── Slider ── */
#radiusSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--cream-deeper);
  outline: none;
  cursor: pointer;
  margin-bottom: 8px;
}

#radiusSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--forest);
  border: 2.5px solid white;
  box-shadow: 0 1px 4px rgba(28,34,24,0.25);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#radiusSlider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--forest);
  border: 2.5px solid white;
  box-shadow: 0 1px 4px rgba(28,34,24,0.25);
  cursor: pointer;
}

#radiusSlider::-webkit-slider-thumb:hover,
#radiusSlider:focus::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(46,94,58,0.35);
}

/* ── Tick labels ── */
#radiusTicks {
  display: flex;
  justify-content: space-between;
  padding: 0 2px;
}

#radiusTicks span {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.15s ease;
  user-select: none;
}

#radiusTicks span:hover {
  color: var(--ink-muted);
}

#radiusTicks span.active {
  color: var(--forest);
  font-weight: 500;
}

/* ── Mobile ── */
@media (max-width: 600px) {
  #radiusToggleBtn {
    /* zoom(26px) + gap(8px) + helpButton(36px) + gap(8px) */
    left: calc(env(safe-area-inset-left, 0px) + 10px + 26px + 8px + 36px + 8px);
    width: 36px;
    height: 36px;
  }

  #radiusPanel {
    width: calc(100vw - 24px);
  }
}