/* Nelson Field Guide — look and feel
   Cream paper, forest and lake tones, serif headings, one pin colour per layer. */

:root {
  --cream: #F3EEE2;
  --paper: #FBF8F1;
  --ink: #1F2A26;
  --muted: #5B665F;
  --forest: #3F6B4A;
  --lake: #5E8CA0;
  --line: #DED6C4;
  --shadow: 0 10px 30px rgba(31, 42, 38, .16), 0 2px 6px rgba(31, 42, 38, .08);
  --radius: 16px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; min-width: 0; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.5 var(--sans); color: var(--ink); background: var(--cream); overflow: hidden; }
#map { position: fixed; inset: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--forest); }
:focus-visible { outline: 3px solid var(--lake); outline-offset: 2px; }

/* ---------- Top card ---------- */
.topcard {
  position: absolute; z-index: 5;
  top: calc(14px + env(safe-area-inset-top)); left: 14px;
  width: min(380px, calc(100vw - 28px));
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 16px 12px;
}
.brand h1 { font: 600 26px/1.05 var(--serif); margin: 0; letter-spacing: -.01em; }
.brand p { margin: 4px 0 12px; color: var(--muted); font-size: 14px; }

.search { position: relative; }
.search input {
  width: 100%; height: 44px; padding: 0 14px; font: 16px var(--sans);
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
#results {
  position: absolute; left: 0; right: 0; top: 48px; z-index: 6; margin: 0; padding: 6px;
  list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 300px; overflow-y: auto;
}
#results li { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 8px; cursor: pointer; }
#results li:hover, #results li[aria-selected="true"] { background: var(--cream); }
#results .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#results small { color: var(--muted); margin-left: auto; font-size: 13px; white-space: nowrap; }
#results .none { color: var(--muted); cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; overflow-x: auto; padding: 12px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px; min-height: 36px;
  padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 14px; white-space: nowrap;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip[aria-pressed="false"] { background: transparent; color: var(--muted); }
.chip[aria-pressed="false"] i { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }
.chip span { color: var(--muted); font-size: 12px; }

/* ---------- Tools ---------- */
.tools {
  position: absolute; z-index: 4; left: 14px; bottom: calc(86px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; flex-wrap: wrap;
}
.tool {
  min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--paper); box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
}
.tool[aria-pressed="true"]#btnPick { background: var(--ink); color: var(--paper); }

/* ---------- Pins ---------- */
.pin {
  width: 34px; height: 44px; cursor: pointer; border: 0; padding: 0; background: none;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.28));
  transition: transform .15s ease;
}
.pin svg { display: block; width: 100%; height: 100%; }
.pin:hover, .pin.active { transform: scale(1.18) translateY(-3px); }
.pin.active { z-index: 3; }
.pin.hidden { display: none; }

/* ---------- Panel ---------- */
.panel {
  position: absolute; z-index: 7; top: 14px; right: 14px; bottom: 150px;
  width: min(400px, calc(100vw - 28px));
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(calc(100% + 30px)); transition: transform .3s ease;
}
.panel.open { transform: none; }
.handle { display: none; }
.close {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 40px; height: 40px;
  border-radius: 50%; border: 0; background: rgba(251,248,241,.92); font-size: 24px; line-height: 1;
}
.hero { position: relative; aspect-ratio: 16 / 10; background: var(--c); overflow: hidden; }
.hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero svg { width: 100%; height: 100%; display: block; }
.pbody { padding: 18px 20px 24px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--c);
}
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.pbody h2 { font: 600 28px/1.1 var(--serif); margin: 6px 0 10px; letter-spacing: -.01em; }
.pbody p { margin: 0 0 18px; }
.btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 44px;
  padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 600;
}
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.checked { margin-top: 16px; font-size: 13px; color: var(--muted); }

/* ---------- Toast + credits ---------- */
.toast {
  position: absolute; z-index: 8; left: 50%; bottom: 64px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 12px 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; font-size: 14px;
  max-width: calc(100vw - 28px);
}
.toast[hidden] { display: none; }
.toast code { font-size: 14px; }
.toast button { min-height: 36px; border-radius: 8px; border: 0; padding: 0 12px; background: var(--paper); color: var(--ink); font-weight: 600; }

.credits {
  position: absolute; z-index: 3; left: 14px; bottom: calc(12px + env(safe-area-inset-bottom));
  max-width: min(560px, calc(100vw - 300px));
  background: rgba(251,248,241,.9); border-radius: 10px; padding: 6px 10px;
  font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap;
}
.credits a { font-weight: 600; }
.maplibregl-ctrl-attrib { font: 12px var(--sans); max-width: 260px; }

/* ---------- Phones: bottom sheet ---------- */
@media (max-width: 700px) {
  .topcard { left: 10px; right: 10px; width: auto; padding: 12px 12px 8px; top: calc(10px + env(safe-area-inset-top)); }
  .brand h1 { font-size: 21px; }
  .brand p { display: none; }
  .brand { margin-bottom: 8px; }
  .chips { flex-wrap: nowrap; }
  .tools { left: auto; right: 10px; bottom: calc(62px + env(safe-area-inset-bottom)); flex-direction: column; align-items: flex-end; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { display: none; }
  .tool { min-height: 40px; padding: 0 12px; font-size: 13px; }
  .credits { left: 10px; max-width: calc(100vw - 20px); bottom: calc(8px + env(safe-area-inset-bottom)); }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 88vh;
    border-radius: 20px 20px 0 0; border-bottom: 0;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: translateY(calc(100% - min(58vh, 100%))); }
  .panel.open.full { transform: none; }
  .handle {
    display: block; position: sticky; top: 0; z-index: 3; width: 100%; height: 26px;
    border: 0; background: var(--paper);
  }
  .handle::after { content: ""; display: block; margin: 9px auto 0; width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
  .close { top: 30px; }
  .pbody h2 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .pin { transition: none; }
}
