/* ==========================================================================
   Map-first UI
   The map fills the screen; everything else is quiet, floating chrome:
   - phones: a draggable bottom sheet (peek / half / full -- see ui.js)
   - 760px and up: a floating card, top-left
   - MapLibre's zoom/compass/geolocate/attribution: a slim column, top-right
   ========================================================================== */

:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;

  --map-bg: #f3f2ee;               /* app.js overrides this with the chosen map style's background */
  --surface: rgb(255 255 255 / .9);
  --surface-solid: #fff;
  --surface-2: #f2f4f6;
  --surface-3: #e7eaee;
  --hairline: rgb(16 24 32 / .09);
  --text: #14191f;
  --text-2: #56616c;
  --text-3: #8a949e;
  --accent: #0f7a5c;
  --accent-hover: #0c6a50;
  --accent-contrast: #fff;
  --accent-soft: rgb(15 122 92 / .11);
  --danger: #b4281c;

  --trail-open: #1d9a52;
  --trail-partial: #c7771a;
  --trail-closed: #c4352a;
  --trail-unknown: #8a949e;
  --grade-blue: #1a6fe0;           /* same colours app.js draws the trails in */
  --grade-red: #e0311a;
  --grade-black: #161616;
  --grade-black-ring: transparent;

  --shadow-float: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .12);
  --shadow-sheet: 0 -1px 0 rgb(0 0 0 / .04), 0 -6px 28px rgb(0 0 0 / .14);
  --blur: saturate(180%) blur(18px);
  --ctrl-icon-filter: none;

  --r-s: 10px;
  --r-m: 14px;
  --r-l: 22px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --gutter: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Dark mode: an explicit choice (persisted in localStorage, applied before
   first paint by the inline script in index.html's <head> to avoid a flash
   of the wrong theme) always wins; otherwise it follows the OS preference.
   The same block is repeated for both cases since CSS can't share it. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --map-bg: #15181b;
    --surface: rgb(27 30 34 / .88);
    --surface-solid: #1b1e22;
    --surface-2: #25292e;
    --surface-3: #30353b;
    --hairline: rgb(255 255 255 / .08);
    --text: #eef1f3;
    --text-2: #a6afb8;
    --text-3: #77818a;
    --accent: #3fcf9b;
    --accent-hover: #5ad9aa;
    --accent-contrast: #05281c;
    --accent-soft: rgb(63 207 155 / .14);
    --danger: #f28b80;
    --trail-open: #4fd08a;
    --trail-partial: #f0a54c;
    --trail-closed: #f0786c;
    --trail-unknown: #77818a;
    --grade-black-ring: rgb(255 255 255 / .55);
    --shadow-float: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .45);
    --shadow-sheet: 0 -1px 0 rgb(255 255 255 / .04), 0 -8px 30px rgb(0 0 0 / .5);
    --ctrl-icon-filter: invert(1);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --map-bg: #15181b;
  --surface: rgb(27 30 34 / .88);
  --surface-solid: #1b1e22;
  --surface-2: #25292e;
  --surface-3: #30353b;
  --hairline: rgb(255 255 255 / .08);
  --text: #eef1f3;
  --text-2: #a6afb8;
  --text-3: #77818a;
  --accent: #3fcf9b;
  --accent-hover: #5ad9aa;
  --accent-contrast: #05281c;
  --accent-soft: rgb(63 207 155 / .14);
  --danger: #f28b80;
  --trail-open: #4fd08a;
  --trail-partial: #f0a54c;
  --trail-closed: #f0786c;
  --trail-unknown: #77818a;
  --grade-black-ring: rgb(255 255 255 / .55);
  --shadow-float: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .45);
  --shadow-sheet: 0 -1px 0 rgb(255 255 255 / .04), 0 -8px 30px rgb(0 0 0 / .5);
  --ctrl-icon-filter: invert(1);
}

/* --- Base ------------------------------------------------------------------ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--map-bg); color: var(--text); }
#map { position: fixed; inset: 0; background: var(--map-bg); }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
svg { flex: none; }

/* Buttons are scoped to our own chrome so MapLibre's control/popup buttons
   keep their own styling. */
.panel button,
.update-banner button {
  -webkit-tap-highlight-color: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 0; font: inherit; font-weight: 600; cursor: pointer;
  transition: background-color .15s, color .15s, transform .1s, opacity .15s;
}
.panel button:active:not(:disabled) { transform: scale(.97); }
.panel button:disabled { cursor: wait; opacity: .55; }
.panel button:focus-visible,
.update-banner button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.panel button svg { width: 1.1em; height: 1.1em; }
[hidden] { display: none !important; }

/* --- Panel: shared by the sheet and the desktop card ---------------------- */
.panel {
  position: fixed; z-index: 2;
  display: flex; flex-direction: column;
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  color: var(--text);
  overflow: hidden;
}
.sheet-grabber { display: flex; justify-content: center; padding: 8px 0 2px; }
.sheet-grabber span { width: 36px; height: 5px; border-radius: 3px; background: var(--surface-3); }

.panel-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 8px 12px 12px 16px; }
.brand { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { min-width: 0; }
h1 { font-size: 1.06rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }

.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .75rem; margin-top: 1px; font-size: .8rem; color: var(--text-2); line-height: 1.35; }
.summary-item { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.summary-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--trail-unknown); }
.summary-dot.open { background: var(--trail-open); }
.summary-dot.partial { background: var(--trail-partial); }
.summary-dot.closed { background: var(--trail-closed); }
/* Map-centre grid reference. Its line is always reserved (even when blank
   outside GB) so the header -- and the phone sheet's peek height -- don't
   jump as the map crosses the coast; tabular figures stop it jittering
   while panning. */
.grid-ref { display: flex; align-items: baseline; gap: .4rem; min-height: 1.35em; margin-top: 1px; font-size: .8rem; line-height: 1.35; color: var(--text-2); white-space: nowrap; }
.grid-ref-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.grid-ref-value { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .02em; }
.grid-ref.is-empty .grid-ref-label { visibility: hidden; }
.title-row { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.offline-badge {
  display: inline-flex; align-items: center; gap: .2rem; padding: 2px 7px 2px 5px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: .68rem; font-weight: 700; white-space: nowrap;
}
.offline-badge svg { width: 11px; height: 11px; }

.panel-header-actions { display: flex; align-items: center; gap: 4px; }
/* #theme-toggle and #panel-toggle get their glyph text (☾/☀, ▾/▸) set by
   app.js; the text is hidden and replaced by crisp masked icons chosen from
   the state app.js already exposes (aria-label / aria-expanded). */
.panel .icon-button {
  position: relative; width: 36px; height: 36px; padding: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  font-size: 0; line-height: 0;
}
.panel .icon-button:hover { background: var(--surface-3); color: var(--text); }
.panel .icon-button::before {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
  transition: transform .25s var(--ease);
}
#theme-toggle { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z'/%3E%3C/svg%3E"); }
#theme-toggle[aria-label="Switch to light mode"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2.5v2M12 19.5v2M4.6 4.6 6 6M18 18l1.4 1.4M2.5 12h2M19.5 12h2M4.6 19.4 6 18M18 6l1.4-1.4'/%3E%3C/svg%3E"); }
#panel-toggle { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }

#panel-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 16px 20px;
}

/* --- Sections -------------------------------------------------------------- */
.sheet-section { padding-top: 14px; }
.sheet-section + .sheet-section { margin-top: 10px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin: 0 2px 8px; }
h2 { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.card { background: var(--surface-2); border-radius: var(--r-m); padding: 14px; }

.grade-key { display: flex; gap: .7rem; list-style: none; margin: 0; padding: 0; font-size: .74rem; color: var(--text-2); }
.grade-key li { display: inline-flex; align-items: center; gap: .3rem; }
.grade-dot { width: 9px; height: 9px; border-radius: 50%; }
.grade-dot.blue { background: var(--grade-blue); }
.grade-dot.red { background: var(--grade-red); }
.grade-dot.black { background: var(--grade-black); box-shadow: 0 0 0 1.5px var(--grade-black-ring); }

.status { min-height: 1.2em; font-size: .84rem; line-height: 1.4; color: var(--text-2); }
.status.error { color: var(--danger); }
/* Kept in the layout (not display:none) while empty so screen readers still
   announce it as a live region when app.js fills it in. */
#share-status:empty { min-height: 0; margin: 0; }
.intro { font-size: .88rem; line-height: 1.45; color: var(--text-2); }
.footnote { margin: 8px 2px 0; font-size: .76rem; color: var(--text-3); }

/* --- Trail status (rendered by app.js) ------------------------------------ */
.trail-status > .status { margin: 0 2px 8px; font-size: .78rem; color: var(--text-3); }
.trail-status > .status.error { color: var(--danger); font-size: .84rem; }
.trail-status h3 { margin: 12px 2px 6px; font-size: .9rem; font-weight: 650; color: var(--text); }
.trail-status h3:first-of-type { margin-top: 4px; }
.trail-list { list-style: none; margin: 0; padding: 0; background: var(--surface-2); border-radius: var(--r-m); overflow: hidden; }
.trail-list .trail-row { padding: 11px 14px; }
.trail-list .trail-row + .trail-row,
.trail-list .trail-note + .trail-row { border-top: 1px solid var(--hairline); }
.trail-row { display: flex; align-items: center; gap: .6rem; font-size: .88rem; color: var(--text-2); }
.trail-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--trail-unknown); }
.trail-open .trail-dot { background: var(--trail-open); box-shadow: 0 0 0 3px color-mix(in srgb, var(--trail-open) 20%, transparent); }
.trail-partial .trail-dot { background: var(--trail-partial); box-shadow: 0 0 0 3px color-mix(in srgb, var(--trail-partial) 20%, transparent); }
.trail-closed .trail-dot { background: var(--trail-closed); box-shadow: 0 0 0 3px color-mix(in srgb, var(--trail-closed) 20%, transparent); }
.trail-name { flex: 1 1 auto; min-width: 0; color: var(--text); font-weight: 550; }
.trail-grade { flex: none; padding: 2px 7px; border-radius: 999px; background: var(--surface-3); font-size: .7rem; font-weight: 600; color: var(--text-2); }
.trail-state { flex: none; min-width: 4.5em; text-align: right; font-size: .78rem; font-weight: 650; color: var(--text-2); }
.trail-open .trail-state { color: var(--trail-open); }
.trail-partial .trail-state { color: var(--trail-partial); }
.trail-closed .trail-state { color: var(--trail-closed); }
.trail-note { list-style: none; padding: 0 14px 11px 33px; margin-top: -5px; font-size: .78rem; font-style: italic; color: var(--text-3); }
.trail-status > .legend { margin: 8px 2px 0; font-size: .76rem; color: var(--text-3); }
.trail-status > .legend a { color: var(--text-2); }

/* --- Weather (rendered by app.js) ----------------------------------------- */
.weather-row { display: flex; align-items: center; gap: .65rem; font-size: 1.02rem; font-weight: 650; color: var(--text); }
.weather-icon { font-size: 1.7rem; line-height: 1; }
.weather-detail { margin-top: 6px; font-size: .84rem; color: var(--text-2); }
.weather .status { margin-top: 6px; font-size: .76rem; color: var(--text-3); }
.weather .status.error { color: var(--danger); font-size: .84rem; margin-top: 0; }
.weather > .status:only-child { margin-top: 0; }

/* --- Offline & sharing ---------------------------------------------------- */
.primary-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.panel button.primary,
.panel button.secondary { width: 100%; min-height: 48px; padding: 0 16px; border-radius: 12px; font-size: .95rem; }
.panel button.primary { background: var(--accent); color: var(--accent-contrast); }
.panel button.primary:hover:not(:disabled) { background: var(--accent-hover); }
.panel button.secondary { background: var(--surface-3); color: var(--text); }
.panel button.secondary:hover { color: var(--danger); }
progress {
  display: block; width: 100%; height: 6px; margin-top: 12px;
  -webkit-appearance: none; appearance: none; border: 0; border-radius: 3px;
  background: var(--surface-3); overflow: hidden; accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--surface-3); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 3px; }
.offline-card #status { margin-top: 10px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip-row:not(:has(.chip:not([hidden]))) { display: none; }
.panel button.chip {
  min-height: 38px; padding: 0 14px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: .84rem;
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.panel button.chip:hover { background: var(--surface-3); }
/* app.js rewrites the fullscreen button's text ("Full screen" / "Exit full
   screen"), so its icon comes from CSS rather than an inline <svg>. */
.chip-fullscreen::before {
  content: ""; width: 1.1em; height: 1.1em; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5'/%3E%3C/svg%3E") center / contain no-repeat;
}
#share-status { margin: 8px 2px 0; }

/* --- Map style picker (buttons built by app.js) -------------------------- */
.style-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.panel button.style-option {
  flex-direction: column; gap: 6px; padding: 6px 4px 8px; border-radius: var(--r-m);
  background: var(--surface-2); color: var(--text-2); font-size: .74rem; font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.panel button.style-option:hover { background: var(--surface-3); }
.panel button.style-option[aria-pressed="true"] { color: var(--text); background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.style-swatch { display: block; width: 100%; aspect-ratio: 8 / 5; border-radius: 9px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--hairline); }
.panel .style-swatch svg { display: block; width: 100%; height: 100%; }
.style-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
#map-style-blurb:empty { display: none; }
.setting-toggle { display: flex; align-items: flex-start; gap: 10px; margin-top: 12px; font-size: .84rem; color: var(--text-2); cursor: pointer; }
.setting-toggle strong { color: var(--text); font-weight: 650; }
.setting-toggle input { flex: none; width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); }

/* --- Phones: bottom sheet --------------------------------------------------- */
@media (max-width: 759px) {
  .panel {
    left: var(--safe-left); right: var(--safe-right); bottom: 0;
    height: 50dvh; max-height: calc(100dvh - var(--safe-top) - 48px);
    padding-bottom: var(--safe-bottom);
    border-radius: var(--r-l) var(--r-l) 0 0;
    box-shadow: var(--shadow-sheet);
    transition: height .34s var(--ease);
  }
  /* Before ui.js has taken over (or if it fails), fall back to a plain
     collapse: header only. Once enhanced, ui.js sets explicit pixel heights
     for each snap point so the sheet can animate between them. */
  .panel.collapsed { height: auto; }
  .panel.collapsed:not(.sheet-enhanced) #panel-body { display: none; }
  .panel.sheet-dragging { transition: none; }
  .panel.sheet-enhanced .sheet-grabber,
  .panel.sheet-enhanced .panel-header { touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
  .panel.sheet-dragging .sheet-grabber,
  .panel.sheet-dragging .panel-header { cursor: grabbing; }
  .panel.sheet-enhanced .panel-header-actions { cursor: default; }
  /* Chevron points the way the sheet will move: down to minimise, up to open. */
  #panel-toggle[aria-expanded="false"]::before { transform: rotate(180deg); }
  #panel-body { padding-bottom: 24px; }

  .update-banner { left: calc(var(--gutter) + var(--safe-left)); right: calc(var(--gutter) + var(--safe-right)); }

  /* With the sheet pulled all the way up, the map controls would only peek
     out from behind it -- fade them out until it comes back down. */
  .maplibregl-ctrl-bottom-right { transition: opacity .2s; }
  body:has(.panel[data-snap="full"]) .maplibregl-ctrl-bottom-right { opacity: 0; pointer-events: none; }
  body:has(.panel[data-snap="full"]) .maplibregl-ctrl-bottom-right * { pointer-events: none; }
}

/* --- 760px and up: floating card, top-left ------------------------------- */
@media (min-width: 760px) {
  .panel {
    top: calc(var(--gutter) + var(--safe-top)); left: calc(var(--gutter) + var(--safe-left));
    width: 372px; max-height: calc(100dvh - 2 * var(--gutter) - var(--safe-top) - var(--safe-bottom));
    border-radius: var(--r-l);
    box-shadow: var(--shadow-float);
  }
  .sheet-grabber { display: none; }
  .panel-header { padding: 14px 12px 14px 14px; }
  .panel.collapsed #panel-body { display: none; }
  /* Card collapses upward, so the chevron flips: up to minimise, down to open. */
  #panel-toggle[aria-expanded="true"]::before { transform: rotate(180deg); }

  .update-banner { left: 50%; transform: translateX(-50%); max-width: 28rem; }
}

/* --- Update banner ---------------------------------------------------------- */
.update-banner {
  position: fixed; z-index: 4; top: calc(var(--gutter) + var(--safe-top));
  display: flex; align-items: center; gap: .6rem;
  padding: 8px 8px 8px 16px; border-radius: 999px;
  background: var(--text); color: var(--surface-solid);
  font-size: .88rem; font-weight: 550;
  box-shadow: var(--shadow-float);
  animation: banner-in .35s var(--ease);
}
.update-banner span { flex: 1 1 auto; }
.update-banner button { min-height: 34px; padding: 0 14px; border-radius: 999px; background: var(--accent); color: var(--accent-contrast); font-size: .84rem; }
.update-banner button.secondary { width: 34px; padding: 0; background: rgb(127 127 127 / .25); color: inherit; }
@keyframes banner-in { from { opacity: 0; translate: 0 -12px; } }

/* --- MapLibre controls: slim column, top-right ---------------------------- */
/* All three controls are added to "bottom-right" by app.js; the container is
   moved to the top-right and stacked vertically -- out of the sheet's way on
   phones, and clear of the card on desktop. */
.maplibregl-ctrl-bottom-right {
  top: calc(var(--gutter) + var(--safe-top)); bottom: auto; right: calc(var(--gutter) + var(--safe-right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.maplibregl-ctrl-bottom-right .maplibregl-ctrl { float: none; margin: 0; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group:not(:has(.maplibregl-ctrl-geolocate)) { order: 1; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group:has(.maplibregl-ctrl-geolocate) { order: 2; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib { order: 3; }

/* Zoom-in / zoom-out / compass stay one joined pill (MapLibre's native
   layout), geolocate its own rounded square. The group clips its children,
   so there are no per-button corners at all -- nothing for MapLibre's own
   :focus:first-child / :last-child rules to square off after a click. */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group {
  overflow: hidden; border-radius: var(--r-m);
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group:not(:empty) { box-shadow: var(--shadow-float); }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button { width: 44px; height: 44px; background-color: transparent; border-radius: 0; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button + button { border-top: 1px solid var(--hairline); }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button:focus,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button:focus:first-child,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button:focus:last-child,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button:focus:only-child { border-radius: 0; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
@media (hover: hover) {
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button:not(:disabled):hover { background-color: var(--surface-3); }
}
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group .maplibregl-ctrl-icon { background-size: 26px; filter: var(--ctrl-icon-filter); }
/* GeolocateControl's active-tracking (blue) and background/error (orange-red)
   icon states are meaningful colour cues -- excluded from the dark-mode
   invert so they keep their real colour. */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-geolocate-active .maplibregl-ctrl-icon,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-geolocate-active-error .maplibregl-ctrl-icon,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-geolocate-background .maplibregl-ctrl-icon,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-geolocate-background-error .maplibregl-ctrl-icon { filter: none; }

.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib,
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact {
  background-color: var(--surface); color: var(--text-2);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  box-shadow: var(--shadow-float);
}
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib a { color: var(--text); }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib-button { filter: var(--ctrl-icon-filter); }

/* --- Trail-info popup (maplibregl.Popup, built by app.js) ----------------- */
.maplibregl-popup-content {
  padding: 14px 16px; border-radius: var(--r-m);
  background: var(--surface-solid); color: var(--text-2);
  box-shadow: var(--shadow-float);
  font-size: .86rem;
}
.maplibregl-popup-close-button {
  top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2); font-size: 1rem; line-height: 1;
}
.maplibregl-popup-close-button:hover { background: var(--surface-3); color: var(--text); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--surface-solid); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--surface-solid); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface-solid); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface-solid); }
.trail-popup h3 { margin: 0 30px 2px 0; font-size: 1rem; font-weight: 700; color: var(--text); }
.trail-popup-type { margin-bottom: 10px; font-size: .76rem; color: var(--text-3); }
.trail-popup .trail-row { gap: .5rem; font-size: .86rem; }
.trail-popup .trail-row .trail-state { min-width: 0; text-align: left; }
.trail-popup .trail-note { margin: 8px 0 0; padding: 0; }
.trail-popup-source { margin-top: 8px; font-size: .72rem; color: var(--text-3); }
.trail-popup .status { font-size: .84rem; }

@media (prefers-reduced-motion: reduce) {
  .panel, .panel .icon-button::before, .update-banner { transition: none; animation: none; }
}
