/* Waystation styles (linked from index.html). */
:root {
  --panel-bg: #ffffff;
  --panel-fg: #1d2421;
  --muted: #5d6b64;
  --accent: #2f6b4f;
  --border: #d8dfdb;
  --shadow: 0 2px 10px rgba(0,0,0,.25);
}
@media (prefers-color-scheme: dark) {
  :root {
    --panel-bg: #1f2a24;
    --panel-fg: #e8efeb;
    --muted: #a3b2aa;
    --accent: #7cc4a0;
    --border: #3a4a42;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1f2a24; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#map { position: fixed; inset: 0; height: 100dvh; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

.fab {
  position: fixed; z-index: 3;
  width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: var(--panel-bg); color: var(--panel-fg); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 22px; height: 22px; }
#layers-btn { top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); }

/* Search bar between the layers button and the map controls */
#search {
  position: fixed; z-index: 3;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(62px + env(safe-area-inset-left)); right: calc(62px + env(safe-area-inset-right));
  max-width: 420px;
}
#search-input {
  width: 100%; height: 44px; padding: 0 40px 0 12px; border: 0; border-radius: 10px;
  background: var(--panel-bg); color: var(--panel-fg); box-shadow: var(--shadow);
  font: inherit; font-size: 16px; /* 16px keeps iOS from zooming in on focus */
  -webkit-appearance: none; appearance: none;
}
#search-input::-webkit-search-cancel-button { display: none; }
#search-clear {
  position: absolute; right: 0; top: 0; width: 44px; height: 44px; border: 0; background: none;
  color: var(--muted); font-size: 22px; cursor: pointer;
}
#search-results {
  margin: 6px 0 0; padding: 0; list-style: none; max-height: 55dvh; overflow-y: auto;
  background: var(--panel-bg); color: var(--panel-fg); border-radius: 10px; box-shadow: var(--shadow);
}
#search-results:empty { display: none; }
#search-results li { padding: 10px 12px; min-height: 44px; border-top: 1px solid var(--border); cursor: pointer; }
#search-results li:first-child { border-top: 0; }
#search-results li:hover, #search-results li[aria-selected="true"] { background: rgba(127,127,127,.12); }
#search-results small { display: block; color: var(--muted); }
#search-results .status { cursor: default; color: var(--muted); }

#sidebar {
  position: fixed; z-index: 4;
  top: 0; left: 0; bottom: 0; width: min(300px, 85vw);
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  background: var(--panel-bg); color: var(--panel-fg); box-shadow: var(--shadow);
  transform: translateX(-105%); transition: transform .2s ease;
  overflow-y: auto;
}
#sidebar.open { transform: none; }
#sidebar header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#sidebar h1 { font-size: 18px; margin: 0; }
#close-btn { position: static; box-shadow: none; }
#spots-list { list-style: none; margin: 0; padding: 0; }
#spots-list li { display: flex; align-items: center; border-top: 1px solid var(--border); }
#spots-list .go { flex: 1; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 10px 0; min-height: 44px; cursor: pointer; }
#spots-list .go small { display: block; color: var(--muted); }
#spots-list .del { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
#spots-list .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
#trip-list { list-style: none; margin: 0; padding: 0; }
#trip-list li { display: flex; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--border); }
#trip-list .turns { flex-basis: 100%; margin: 0 0 8px 36px; font-size: 13px; }
#trip-list .turns summary { color: var(--accent); cursor: pointer; min-height: 32px; display: flex; align-items: center; }
#trip-list .turns ol { margin: 4px 0 0; padding-left: 20px; }
#trip-list .turns li { display: list-item; border-top: 0; padding: 3px 0; }
#trip-list .turns small { color: var(--muted); }
#trip-list .go { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 8px 0; min-height: 44px; cursor: pointer; }
#trip-list .go small { display: block; color: var(--muted); }
#trip-list .icon { width: 40px; height: 44px; flex: none; border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; display: grid; place-items: center; text-decoration: none; }
#trip-list .icon:disabled { opacity: .3; cursor: default; }
#trip-list .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.trip-num { flex: none; width: 24px; height: 24px; border-radius: 50%; background: #d81b60; color: #fff; font-size: 13px; font-weight: 600; display: grid; place-items: center; }
.trip-total { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.trip-total:empty { display: none; }
.trip-actions { flex-wrap: wrap; }
.spots-actions [hidden] { display: none; }
#birdalerts-list { list-style: none; margin: 0; padding: 0; }
#birdalerts-list li { display: flex; align-items: center; border-top: 1px solid var(--border); }
#birdalerts-list .go { flex: 1; min-width: 0; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 8px 0; min-height: 44px; cursor: pointer; }
#birdalerts-list .go small { display: block; color: var(--muted); }
#birdalerts-list .del, #birdalerts-list .edit { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
#birdalerts-list .edit { font-size: 17px; }
#birdalerts-list .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
#birdalerts-status:empty { display: none; }
#offline-list { list-style: none; margin: 0; padding: 0; }
#offline-list li { display: flex; align-items: center; border-top: 1px solid var(--border); }
#offline-list .go { flex: 1; min-width: 0; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 8px 0; min-height: 44px; cursor: pointer; }
#offline-list .go small { display: block; color: var(--muted); }
#offline-list .resume { border: 1px solid var(--border); background: none; color: var(--accent); font: inherit; font-size: 13px; min-height: 36px; border-radius: 8px; padding: 0 10px; cursor: pointer; }
#offline-list .del { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
#offline-list .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
#offline-progress progress { width: 100%; height: 10px; accent-color: var(--accent); margin-top: 8px; }
/* Under the search box; the measure bar takes that spot while measuring */
#offline-banner {
  position: fixed; z-index: 3; left: calc(10px + env(safe-area-inset-left));
  top: calc(62px + env(safe-area-inset-top)); padding: 8px 14px; border-radius: 20px;
  background: #37474f; color: #fff; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap;
}
#offline-banner[hidden], #measure-bar:not([hidden]) ~ #offline-banner { display: none; }
.trip-marker { width: 44px; height: 44px; padding: 0; border: 0; background: none; display: grid; place-items: center; cursor: pointer; }
.trip-marker span {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; background: #d81b60; color: #fff;
  font: 600 13px/1 system-ui, sans-serif; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center;
}
.popup-actions .in-trip { color: #d81b60; border-color: #f3bcd0; cursor: default; }
.spots-actions { display: flex; gap: 8px; margin: 6px 0 4px; }
.spots-actions button, .spots-actions .as-button {
  border: 1px solid var(--border); background: none; color: var(--accent); font: inherit; font-size: 13px;
  padding: 0 12px; min-height: 36px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center;
}
.popup-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 6px; margin-top: 8px; }
.popup-actions button, .popup-actions a {
  border: 1px solid #c9d3ce; background: #fff; color: #2f6b4f; font: inherit; font-size: 13px; text-decoration: none; white-space: nowrap;
  padding: 0 6px; min-height: 40px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
/* Sun, moon, elevation and coordinates: one summary line that opens */
.popup-more { margin-top: 6px; border-top: 1px solid #e3e8e5; padding-top: 6px; font-size: 13px; color: #5d6b64; }
.popup-more summary { cursor: pointer; list-style: none; min-height: 28px; display: flex; align-items: center; gap: 2px; }
.popup-more summary::-webkit-details-marker { display: none; }
.popup-more summary::after { content: "▸"; margin-left: auto; font-size: 11px; transition: transform .15s; }
.popup-more[open] summary::after { transform: rotate(90deg); }
:root.night .popup-more { border-top-color: var(--border); color: var(--muted); }
.popup-alert-title.star::before { background: #ffd600; border-radius: 50%; box-shadow: 0 0 0 1.5px #212121; }
details.group { border-top: 1px solid var(--border); }
details.group:first-of-type { border-top: 0; }
details.group > summary {
  display: flex; align-items: center; gap: 8px; min-height: 48px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before { content: "▸"; font-size: 12px; transition: transform .15s; }
details.group[open] > summary::before { transform: rotate(90deg); }
details.group > summary .badge { margin-left: auto; font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 12px; }
details.group > .layer:first-of-type, details.group > #spots-list li:first-child { border-top: 1px solid var(--border); }
details.group[open] { padding-bottom: 6px; }
.layer { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); cursor: pointer; }
.layer input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.layer small { display: block; color: var(--muted); }
.opacity { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.opacity input { flex: 1; accent-color: var(--accent); }

/* Measure mode: a bar under the search box, clear of the map controls on the right */
#measure-bar {
  position: fixed; z-index: 3;
  top: calc(62px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left)); right: calc(62px + env(safe-area-inset-right));
  max-width: 420px; padding: 8px 10px;
  background: var(--panel-bg); color: var(--panel-fg); border-radius: 10px; box-shadow: var(--shadow);
}
#measure-bar[hidden] { display: none; }
#measure-total { font-size: 14px; }
#measure-total b { font-size: 17px; }
#measure-total small { color: var(--muted); }
.measure-actions { display: flex; gap: 6px; margin-top: 6px; }
.measure-actions button {
  flex: 1; min-height: 44px; border: 1px solid var(--border); border-radius: 8px;
  background: none; color: var(--accent); font: inherit; font-size: 14px; cursor: pointer;
}
.measure-actions button:disabled { color: var(--muted); opacity: .5; cursor: default; }
.measure-actions #measure-done { background: var(--accent); color: var(--panel-bg); border-color: var(--accent); }
#measure-btn[aria-pressed="true"] { background: #ff6d00; color: #fff; }
#measure-btn svg { width: 22px; height: 22px; display: block; margin: auto; }
/* Radar loop: play/stop button (only while radar is on) with the frame's time beside it. */
.radar-ctrl { position: relative; overflow: visible; }
.radar-ctrl[hidden] { display: none; }
#radar-btn { color: #1565c0; }
#radar-btn[aria-pressed="true"] { background: #1565c0; color: #fff; }
#radar-btn svg { width: 22px; height: 22px; display: block; margin: auto; }
.radar-time {
  position: absolute; right: 52px; top: 50%; transform: translateY(-50%); white-space: nowrap;
  padding: 4px 8px; border-radius: 6px; background: rgba(21,101,192,.9); color: #fff;
  font-size: 13px; font-variant-numeric: tabular-nums; box-shadow: var(--shadow); pointer-events: none;
}
.radar-time[hidden] { display: none; }
.radar-spin {
  display: block; width: 18px; height: 18px; margin: auto; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: radar-spin .8s linear infinite;
}
@keyframes radar-spin { to { transform: rotate(360deg); } }

.maplibregl-ctrl-group button { width: 44px; height: 44px; }
.maplibregl-ctrl-top-right { top: env(safe-area-inset-top); right: env(safe-area-inset-right); }
/* Base map credit (one line); the full list is under "Data credits" in the sidebar. */
.maplibregl-ctrl-bottom-right { right: env(safe-area-inset-right); bottom: env(safe-area-inset-bottom); }
.maplibregl-ctrl.base-credit {
  margin: 0; padding: 2px 6px; border-radius: 6px 0 0 0; max-width: 70vw;
  background: rgba(255,255,255,.75); color: #333; font-size: 11px; line-height: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.maplibregl-ctrl.base-credit a { color: inherit; }
#credits-list { margin: 0; padding: 4px 0 10px 18px; font-size: 13px; color: var(--muted); }
#credits-list li { margin: 4px 0; }
#credits-list b { color: var(--panel-fg); font-weight: 600; }
#credits-list a { color: var(--accent); }
.maplibregl-popup-content { font-size: 14px; padding: 10px 28px 10px 12px; max-width: 80vw; max-height: 60vh; overflow-y: auto; }
.maplibregl-popup-close-button { width: 32px; height: 32px; font-size: 20px; }
.popup-agency { font-weight: 600; font-size: 15px; }
.popup-meta { color: #5d6b64; font-size: 12px; margin-top: 2px; }
.bird-list { margin: 4px 0 2px; padding-left: 16px; font-size: 13px; }
.bird-list span { color: #5d6b64; }
.bird-list small { color: #5d6b64; font-size: 11px; }
.popup-section + .popup-section { border-top: 1px solid #d8dfdb; margin-top: 8px; padding-top: 8px; }
.popup-route { font-weight: 600; }
.popup-access { margin: 4px 0 0; padding: 0; list-style: none; font-size: 13px; }
.popup-access b { font-weight: 600; }
.popup-alert + .popup-alert { margin-top: 8px; }
.popup-alert-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.popup-alert-title::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: #c0392b; flex: none; }
.popup-alert-title.sig-A::before { background: #e6a700; }
.popup-alert-title.sig-Y::before, .popup-alert-title.sig-S::before { background: #6c7a89; }
.popup-alert-title.geo::before { background: var(--swatch); }
.popup-alert-title.fire::before { background: #d32f2f; }
.popup-alert-title.wx::before { background: #1e88e5; border-radius: 50%; }
.popup-alert-title.tide::before { background: #00838f; border-radius: 50%; }
.popup-alert-title.smoke::before { background: #8d6e63; border-radius: 50%; }
.popup-alert-title.snow::before { background: #90caf9; border-radius: 50%; box-shadow: 0 0 0 1.5px #1565c0; }
ul.forecast { margin: 4px 0 2px; padding: 0; list-style: none; font-size: 13px; }
ul.forecast li { padding: 2px 0; }
ul.forecast li + li, ul.forecast.extra { border-top: 1px dotted #d8dfdb; }
ul.forecast.extra { margin-top: 0; }
.popup-alert-title.dot::before { background: var(--swatch); border-radius: 50%; }
.popup-point + .popup-point { margin-top: 8px; }
.more-btn { border: 0; background: none; padding: 6px 4px; margin: -6px 0; font: inherit; color: #2f6b4f; text-decoration: underline; cursor: pointer; }
.popup-alert details, .popup-section > details { margin-top: 4px; font-size: 13px; }
.popup-alert summary, .popup-section > details summary { cursor: pointer; color: #2f6b4f; padding: 4px 0; }
.popup-alert-text { white-space: pre-wrap; margin: 4px 0 0; font: inherit; }

/* Quick views (layer presets) at the top of the layer list */
.presets { padding: 8px 0 10px; border-top: 1px solid var(--border); }
.presets-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.presets-row { display: flex; flex-wrap: wrap; gap: 6px; }
.presets-row button {
  min-height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--panel-bg); color: var(--panel-fg); font: inherit; font-size: 14px; cursor: pointer;
}
.presets-row button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Layer list: find box, "i" for descriptions, opacity only for layers that are on */
.layer-filter { padding: 4px 0 8px; }
.layer-filter input {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-bg); color: var(--panel-fg); font: inherit; font-size: 16px; /* 16px: iOS doesn't zoom */
}
.layer[hidden], details.group[hidden], .presets[hidden] { display: none; }
.layer .layer-name { display: block; }
.layer .layer-note[hidden] { display: none; }
.layer .opacity { display: none; }
.layer.on.expanded .opacity { display: flex; }
.info-btn {
  flex: none; width: 36px; height: 36px; margin: -6px -4px 0 0; border: 1px solid var(--border); border-radius: 50%;
  background: none; color: var(--muted); font: italic 600 15px/1 Georgia, serif; cursor: pointer;
}
.info-btn.open { border-color: var(--accent); color: var(--accent); }

/* Nearby list: a sheet at the bottom of the screen */
#nearby, #mapkey {
  position: fixed; z-index: 4; left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right));
  bottom: calc(8px + env(safe-area-inset-bottom)); max-width: 460px; max-height: 55dvh; overflow: auto;
  background: var(--panel-bg); color: var(--panel-fg); border-radius: 12px; box-shadow: var(--shadow); padding: 4px 12px 8px;
}
#nearby[hidden], #mapkey[hidden] { display: none; }
#nearby header, #mapkey header { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--panel-bg); }
#nearby-close, #mapkey-close { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 26px; cursor: pointer; }
.nearby-from { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
#nearby-list { list-style: none; margin: 0; padding: 0; }
#nearby-list li { border-top: 1px solid var(--border); }
#nearby-list li.empty { padding: 10px 0; color: var(--muted); font-size: 14px; }
#nearby-list button {
  display: grid; grid-template-columns: 1fr auto; gap: 0 10px; width: 100%; min-height: 48px; padding: 6px 0;
  border: 0; background: none; color: var(--panel-fg); font: inherit; text-align: left; cursor: pointer;
}
#nearby-list .nb-name { font-weight: 600; }
#nearby-list small { grid-column: 1; color: var(--muted); }
#nearby-list .nb-dist { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--accent); font-weight: 600; white-space: nowrap; }
#nearby-btn[aria-pressed="true"], #mapkey-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }
#nearby-btn svg, #mapkey-btn svg { width: 22px; height: 22px; display: block; margin: auto; }

/* Saved spot notes: stars, note and photos in the popup; the editor sheet */
.stars { color: #f9a825; letter-spacing: 1px; }
.spot-note { white-space: pre-line; color: inherit; }
.spot-photos { display: flex; gap: 6px; overflow-x: auto; margin: 6px 0 2px; }
.spot-photos img { height: 72px; width: auto; border-radius: 6px; display: block; }
#spot-editor {
  position: fixed; z-index: 6; left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right));
  bottom: calc(8px + env(safe-area-inset-bottom)); max-width: 460px; max-height: 85dvh; overflow: auto;
  background: var(--panel-bg); color: var(--panel-fg); border-radius: 12px; box-shadow: var(--shadow); padding: 4px 12px 12px;
}
#spot-editor[hidden] { display: none; }
#spot-editor header { display: flex; align-items: center; justify-content: space-between; }
#spot-editor-close { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 26px; cursor: pointer; }
.se-field { display: block; margin: 8px 0; font-size: 13px; color: var(--muted); }
.se-field input[type=text], .se-field textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-bg); color: var(--panel-fg); font: inherit; font-size: 16px; /* 16px: iOS doesn't zoom */
}
#se-rating { display: flex; gap: 2px; margin-top: 2px; }
#se-rating button { width: 44px; height: 44px; border: 0; background: none; color: #f9a825; font-size: 28px; cursor: pointer; padding: 0; }
#se-photos { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
#se-photos figure { position: relative; margin: 0; }
#se-photos img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; display: block; background: var(--border); }
#se-photos figure button {
  position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: #212121; color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.se-add { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 8px; color: var(--accent); cursor: pointer; }
.se-add[hidden] { display: none; }
.se-actions { display: flex; justify-content: flex-end; }
#se-save { min-height: 44px; padding: 0 24px; border: 0; border-radius: 8px; background: var(--accent); color: var(--panel-bg); font: inherit; font-weight: 600; cursor: pointer; }

/* Dark (night) base map: dark buttons, panels and popups so the screen doesn't glare in camp */
:root.night {
  --panel-bg: #1f2a24; --panel-fg: #e8efeb; --muted: #a3b2aa; --accent: #7cc4a0; --border: #3a4a42;
}
:root.night .maplibregl-ctrl-group { background: var(--panel-bg); }
:root.night .maplibregl-ctrl-group button { color: var(--panel-fg); }
:root.night .maplibregl-ctrl-group button + button { border-top-color: var(--border); }
:root.night .maplibregl-ctrl-icon { filter: invert(1); }
:root.night .maplibregl-ctrl.base-credit, :root.night .maplibregl-ctrl-scale { background: rgba(31,42,36,.85); color: var(--panel-fg); border-color: var(--muted); }
:root.night .maplibregl-popup-content { background: var(--panel-bg); color: var(--panel-fg); }
:root.night .maplibregl-popup-tip { border-top-color: var(--panel-bg); border-bottom-color: var(--panel-bg); }
:root.night .maplibregl-popup-close-button { color: var(--panel-fg); }
:root.night .popup-meta, :root.night .popup-meta small { color: var(--muted); }
:root.night .popup-actions button, :root.night .popup-actions a { background: var(--panel-bg); color: var(--accent); border-color: var(--border); }
:root.night .maplibregl-popup-content a { color: var(--accent); }

/* Panel tabs: Layers | My stuff, kept at the top while the panel scrolls */
#sidebar header { position: sticky; top: calc(-12px - env(safe-area-inset-top)); z-index: 2; background: var(--panel-bg); padding: calc(12px + env(safe-area-inset-top)) 0 4px; margin-top: calc(-12px - env(safe-area-inset-top)); flex-wrap: wrap; }
.side-tabs {
  flex: 1 0 100%; display: flex; gap: 4px; padding: 4px; margin: 8px 0 6px;
  background: var(--border); border-radius: 12px;
}
.side-tabs button {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--muted);
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.side-tabs button[aria-selected="true"] { background: var(--panel-bg); color: var(--panel-fg); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.tab-badge:empty { display: none; }
.tab-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--panel-bg); font-size: 12px; display: inline-grid; place-items: center; }
.tab-panel[hidden] { display: none; }
.maplibregl-ctrl-group[hidden], .maplibregl-ctrl-group button[hidden] { display: none; }

/* Phones: popups become a sheet along the bottom of the screen (a pin marks the tapped spot, app.js) */
@media (max-width: 600px) {
  .maplibregl-popup {
    position: fixed !important; top: auto !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    transform: none !important; max-width: none !important; width: 100%; z-index: 3;
    display: block !important;
  }
  .maplibregl-popup-tip { display: none; }
  .maplibregl-popup-content {
    width: 100%; box-sizing: border-box; max-width: none; max-height: 48dvh; border-radius: 16px 16px 0 0;
    padding: 18px 16px calc(12px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    box-shadow: 0 -2px 16px rgba(0,0,0,.25);
  }
  .maplibregl-popup-content::before { /* grab-bar look */
    content: ""; position: sticky; top: -12px; display: block; width: 40px; height: 4px; margin: -10px auto 8px;
    border-radius: 2px; background: #c9d3ce;
  }
  .maplibregl-popup-close-button { top: 6px; right: 6px; width: 40px; height: 40px; font-size: 24px; }
  .popup-actions { grid-template-columns: repeat(4, 1fr); }
  .maplibregl-popup-content { transition: max-height .2s ease; overscroll-behavior: contain; }
  .maplibregl-popup-content.expanded { max-height: 88dvh; }
  .maplibregl-popup-content.dragging { transition: none; overflow: hidden; }
}

/* In-app dialogs and notices (ui.js) */
.ui-dialog-back {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.ui-dialog {
  width: min(380px, 100%); background: var(--panel-bg); color: var(--panel-fg); border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); padding: 18px 18px 12px;
}
.ui-dialog h2 { margin: 0 0 8px; font-size: 17px; }
.ui-dialog p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.ui-dialog input {
  width: 100%; min-height: 44px; padding: 0 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-bg); color: var(--panel-fg); font: inherit; font-size: 16px; /* 16px: iOS doesn't zoom */
}
.ui-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.ui-dialog-actions button {
  min-height: 44px; min-width: 88px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.ui-dialog-actions .ok { background: var(--accent); border-color: var(--accent); color: var(--panel-bg); }
#toast {
  position: fixed; z-index: 21; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  display: flex; align-items: center; gap: 12px; width: max-content; max-width: calc(100vw - 32px);
  padding: 10px 14px; border-radius: 12px; background: #263238; color: #fff; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { border: 0; background: none; color: #80cbc4; font: inherit; font-weight: 700; min-height: 36px; cursor: pointer; white-space: nowrap; }
.welcome .ui-dialog p { color: var(--panel-fg); font-size: 15px; line-height: 1.45; }
.welcome-dots { display: flex; justify-content: center; gap: 6px; margin: 4px 0 12px; }
.welcome-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.welcome-dots span.on { background: var(--accent); }

/* Bird alert species picker (birdalerts.js) */
.bird-pick { display: flex; flex-direction: column; max-height: 86dvh; }
.bird-pick > p { margin-bottom: 8px; }
.bp-rare { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.bp-rare small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.bird-pick input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.bp-head { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 0 6px; font-size: 14px; }
.bp-count { color: var(--muted); font-size: 12px; }
.bird-pick .bp-find { margin-bottom: 6px; }
.bp-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 120px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.bp-list li { border-top: 1px solid var(--border); }
.bp-list li:first-child { border-top: 0; }
.bp-list label { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.bp-list .empty { padding: 12px 0; color: var(--muted); font-size: 13px; }
.bird-pick .bp-note { font-size: 12px; margin: 6px 0 10px; }

/* Bottom tab bar (phones). Things that sat at the bottom edge move up above it. */
#tabbar { display: none; }
@media (max-width: 600px) {
  /* --screen-gap (ui.js): the band an iPhone Home Screen app leaves below the page. Safari won't draw
     anything there but the page background, so the bar stays above it, skips the home-indicator
     padding the band already covers, and the background matches the bar so the two read as one. */
  :root { --tabbar-pad: max(0px, calc(env(safe-area-inset-bottom) - var(--screen-gap, 0px))); --tabbar-h: calc(52px + var(--tabbar-pad)); }
  html, body { background: var(--panel-bg); }
  #tabbar {
    display: flex; position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
    padding: 0 env(safe-area-inset-right) var(--tabbar-pad) env(safe-area-inset-left);
    background: var(--panel-bg); border-top: 1px solid var(--border); box-shadow: 0 -1px 8px rgba(0,0,0,.08);
  }
  #tabbar button {
    flex: 1; position: relative; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11px; font-weight: 600;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; padding: 0;
  }
  #tabbar svg { width: 24px; height: 24px; }
  #tabbar button[aria-current="page"] { color: var(--accent); }
  #tabbar .tab-badge { position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px; }
  /* the layers and nearby buttons live in the bar on phones */
  #layers-btn, .maplibregl-ctrl-group:has(> #nearby-btn) { display: none; }
  #search { left: calc(10px + env(safe-area-inset-left)); }
  .side-tabs { display: none; } /* the tab bar switches Layers / My stuff */
  #sidebar { bottom: var(--tabbar-h); width: 100vw; padding-bottom: 12px; box-shadow: none; }
  .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: var(--tabbar-h); }
  .maplibregl-popup { bottom: var(--tabbar-h) !important; }
  .maplibregl-popup-content { padding-bottom: 12px; max-height: calc(48dvh - 30px); }
  .maplibregl-popup-content.expanded { max-height: calc(100dvh - var(--tabbar-h) - 90px); }
  /* Bottom sheets: full width above the tab bar, rounded top, a grab bar; swipe down closes (ui.js) */
  #nearby.sheet, #mapkey.sheet, #spot-editor.sheet { /* ids: outrank each sheet's own desktop rule */
    left: 0; right: 0; bottom: var(--tabbar-h); max-width: none; border-radius: 16px 16px 0 0;
    padding: 0 16px 12px; box-shadow: 0 -2px 16px rgba(0,0,0,.25); transition: transform .18s ease; overscroll-behavior: contain;
  }
  .sheet.dragging { transition: none; }
  .sheet > header { position: sticky; top: 0; z-index: 1; background: var(--panel-bg); padding-top: 10px; }
  .sheet > header::before {
    content: ""; position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 2px; background: #c9d3ce;
  }
  #toast { bottom: calc(var(--tabbar-h) + 12px); }
}

/* Map key (mapkey.js) */
#mapkey section { border-top: 1px solid var(--border); padding: 8px 0 6px; }
#mapkey h3 { margin: 0 0 4px; font-size: 14px; }
#mapkey ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 12px; }
#mapkey li { display: flex; align-items: center; gap: 8px; min-height: 26px; font-size: 13px; }
#mapkey li.mk-text, #mapkey li.mk-bar, #mapkey li.mk-wide { grid-column: 1 / -1; }
#mapkey .mk-text, .mk-zoom { color: var(--muted); font-size: 12px; }
.mk-zoom { margin: 0 0 4px; }
.mk-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.mk-fill { flex: none; width: 22px; height: 14px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.mk-img { flex: none; width: 22px; height: 22px; background: #fff; border-radius: 3px; }
#mapkey li.mk-bar { flex-direction: column; align-items: stretch; gap: 2px; }
.mk-grad { height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.mk-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }

/* Long-press menu (dropped pin) */
.pin-title { font-weight: 700; font-size: 15px; margin-right: 28px; }
.pin-actions { grid-template-columns: repeat(4, 1fr); }

/* Motion: sheets slide up, dialogs and popups ease in, buttons give under a finger, the pin drops. */
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialog-in { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pin-drop { 0% { transform: translateY(-18px); } 70% { transform: translateY(2px); } 100% { transform: none; } }
#nearby, #mapkey, #spot-editor { animation: sheet-up .2s ease-out; }
.maplibregl-popup-content { animation: fade-in .15s ease-out; }
.ui-dialog-back { animation: fade-in .15s ease-out; }
.ui-dialog { animation: dialog-in .18s ease-out; }
.drop-pin svg { animation: pin-drop .28s ease-out; transform-origin: bottom center; }
.popup-actions button, .popup-actions a, .fab, .maplibregl-ctrl-group button, #tabbar button, .presets button, .ui-dialog-actions button {
  transition: transform .08s ease;
}
.popup-actions button:active, .popup-actions a:active, .fab:active, .maplibregl-ctrl-group button:active,
#tabbar button:active, .presets button:active, .ui-dialog-actions button:active { transform: scale(.94); }
@media (max-width: 600px) {
  .maplibregl-popup-content { animation: sheet-up .22s ease-out; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
/* Wide screens: the key sits at the right, clear of the open layer panel */
@media (min-width: 601px) {
  #mapkey, #nearby { left: auto; right: calc(10px + env(safe-area-inset-right)); width: 360px; bottom: 40px; max-height: calc(100dvh - 330px); }
}

/* RV size form (trip.js) */
.rv-form .rv-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; font-weight: 600; font-size: 15px; }
.rv-form .rv-field span { display: flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 400; }
.rv-form .rv-field input { width: 110px; margin: 0; text-align: right; }
.rv-form .rv-error { color: #c62828; margin: 4px 0 8px; }
.route-credit { color: var(--muted); font-size: 11px; }
.route-credit a { color: inherit; }

/* What's new card (whatsnew.js) */
.whatsnew .ui-dialog { max-height: 80dvh; overflow-y: auto; }
.whatsnew h3 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.whatsnew ul { margin: 0 0 4px; padding-left: 20px; font-size: 15px; line-height: 1.4; }
.whatsnew li { margin: 4px 0; }
.whatsnew .ui-dialog-actions { margin-top: 14px; }

/* Settings and Help & tips (My stuff) */
.setting { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 0; border-top: 1px solid var(--border); cursor: pointer; }
.setting:first-of-type { border-top: 0; }
.setting > span { flex: 1; }
.setting small { display: block; color: var(--muted); font-size: 12px; }
.setting input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.setting button {
  border: 1px solid var(--border); background: none; color: var(--accent); font: inherit; font-size: 13px;
  padding: 0 12px; min-height: 36px; border-radius: 8px; cursor: pointer; flex: none;
}
.tips { margin: 4px 0 8px; padding-left: 18px; font-size: 14px; line-height: 1.4; }
.tips li { margin: 6px 0; }
.help-sub { margin: 14px 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
/* RV fit line in campground popups */
.rv-fit { font-weight: 600; }
.rv-fit small { font-weight: 400; color: var(--muted); }
.rv-fit-ok::before { content: "✓ "; color: #2e7d32; }
.rv-fit-tight::before { content: "⚠ "; color: #ef6c00; }
.rv-fit-no::before { content: "✗ "; color: #c62828; }
.maplibregl-popup-content > .popup-section:first-child { padding-right: 30px; } /* clear of the close button */
