/* lakes-hydro-lab — Sprint 2 — design v0.1
 *
 * Aesthetic: "Atmospheric scientific instrument".
 * Editorial broadsheet feel — Fraunces serif display + IBM Plex Sans body + Mono numerics.
 * Light parchment ground, deep flood-water teal accent, peat-amber for historical events.
 * Sharp 1px hairlines, no rounded cards, tabular numbers in mono.
 * Deliberately distinct from sister project LTV-5m's navy + gold palette.
 */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght,SOFT@0,9..144,300..900,0..100;1,9..144,300..900,0..100&family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');

:root {
  /* surface / ink */
  --paper:        #f6f4ef;   /* main parchment ground */
  --paper-bright: #fdfcf9;   /* card / panel surface */
  --paper-deep:   #ede9df;   /* deeper inset (status bar) */
  --ink:          #111317;   /* primary text, max contrast */
  --ink-sub:      #54595f;   /* secondary text */
  --ink-faint:    #8b8f95;   /* tertiary */
  --hair:         #d8d3c8;   /* hairline borders */
  --hair-strong:  #b8b1a3;   /* slightly stronger rules */

  /* the two project accents — deliberately not navy/gold */
  --water:        #0a6a7a;   /* deep flood-water teal — hero accent */
  --water-mid:    #1c8a9c;   /* hover state */
  --water-tint:   #d7e9ec;   /* soft layer-active background */
  --water-haze:   #eaf2f3;   /* subtlest tint for hover */

  --peat:         #c47533;   /* warm peat amber — historic events / warnings */
  --peat-deep:    #8a4f1c;   /* hover for amber */
  --peat-tint:    #f3e3d2;

  --ok:           #2f7a52;   /* sprint-done indicator */
  --live:         #c44a4a;   /* "live" red for future real-time data */

  --font-display: 'Fraunces', 'Times New Roman', serif;
  --font-body:    'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'IBM Plex Mono', 'SF Mono', Menlo, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  width: 100vw;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Skip link — invisible until focused (Tab from URL bar reveals it).
 * Lets keyboard users jump past the masthead + sidebar straight to the map. */
.skip-link {
  position: absolute;
  top: -100px;
  left: 8px;
  z-index: 10000;
  padding: 10px 16px;
  background: var(--water);
  color: var(--paper-bright);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 4px;
  border: 2px solid var(--paper-bright);
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 8px;
  outline: 2px solid var(--peat);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Global focus-visible — make tab order obvious without distracting
 * mouse users. Applies to buttons, links, and the map region. */
*:focus-visible {
  outline: 2px solid var(--water);
  outline-offset: 2px;
}

a {
  color: var(--water);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  transition: color 0.15s ease, border-color 0.15s ease;
}

a:hover {
  color: var(--water-mid);
}

/* =========================================================
 * TOP BAR — masthead-style with build stamp
 * ========================================================= */
.masthead {
  background: var(--paper-bright);
  border-bottom: 1px solid var(--hair-strong);
  padding: 0;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 340px 1fr auto;
  align-items: stretch;
}

.masthead-brand {
  padding: 18px 22px 14px;
  border-right: 1px solid var(--hair);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-title {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 144, 'SOFT' 30, 'wght' 600;
  font-size: 26px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.brand-title em {
  font-style: italic;
  font-variation-settings: 'opsz' 144, 'SOFT' 80, 'wght' 500;
  color: var(--water);
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 6px;
}

.masthead-meta {
  padding: 18px 22px 14px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.tagline {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 36, 'wght' 400;
  font-style: italic;
  font-size: 18px;
  color: var(--ink-sub);
  line-height: 1.2;
  max-width: 520px;
}

.masthead-stamp {
  border-left: 1px solid var(--hair);
  padding: 14px 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  background: var(--paper-deep);
}

.mobile-menu-btn,
.mobile-sidebar-backdrop {
  display: none;
}

.stamp-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.stamp-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stamp-value.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stamp-value.live::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--water);
  animation: water-pulse 2s ease-in-out infinite;
}

@keyframes water-pulse {
  0%, 100% { opacity: 1.0; box-shadow: 0 0 0 0 rgba(10, 106, 122, 0.35); }
  50%      { opacity: 0.55; box-shadow: 0 0 0 5px rgba(10, 106, 122, 0); }
}

/* =========================================================
 * MAIN — sidebar + map
 * ========================================================= */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
}

/* =========================================================
 * EMBED MODE — ?embed=1 query param
 * Map fills the full viewport; masthead + sidebar + intro card hidden.
 * Used by journalists / blogs to iframe a specific view of the dashboard.
 * The URL hash (#l=...&v=...&p=...) still applies so the embedded view
 * can be locked to a particular layer set + zoom + point.
 * ========================================================= */
body.embed-mode .masthead,
body.embed-mode .sidebar,
body.embed-mode .intro-card,
body.embed-mode .skip-link,
body.embed-mode .guide-me-btn {
  display: none !important;
}
body.embed-mode .main {
  grid-template-columns: 1fr;   /* sidebar gone, map gets all the space */
}
body.embed-mode {
  /* Lose the wood-grain frame around the map so the embed looks clean */
  background: var(--ink);
}

/* =========================================================
 * PRINT MODE — @media print + body.print-prepared
 * Triggered by the "Save image" button. Hides chrome, expands the map
 * to fill the printable area, ensures the readout strip + attribution
 * line carry through to the printed page. Works around R2's lack of
 * CORS by using the browser's native print rendering (which has no
 * canvas-taint constraint).
 * ========================================================= */
@media print {
  /* Hide all the UI chrome */
  .masthead,
  .sidebar,
  .intro-card,
  .skip-link,
  .guide-me-btn,
  .detail-panel,
  .event-modal,
  .map-toast,
  .warning-banner,
  .data-status-panel,
  .leaflet-control-zoom {
    display: none !important;
  }
  /* Reset layout to map-only, full-bleed */
  html, body {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }
  body { display: block !important; }
  .main {
    display: block !important;
    grid-template-columns: 1fr !important;
  }
  #map {
    width: 100% !important;
    height: 92vh !important;     /* leave room for attribution */
    page-break-inside: avoid;
  }
  /* Keep the readout strip + scale bar visible — they're useful on the printed page */
  .map-readout,
  .map-scale-pair,
  .leaflet-control-scale,
  .leaflet-control-attribution {
    display: block !important;
    color: #000 !important;
    background: rgba(255, 255, 255, 0.9) !important;
  }
  /* Make sure Leaflet panes print their backgrounds (off by default in many browsers) */
  .leaflet-tile-pane,
  .leaflet-overlay-pane,
  .leaflet-marker-pane,
  .leaflet-shadow-pane {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
/* Class applied just before window.print() — gives the map a beat to
 * re-render at print dimensions before the dialog opens. */
body.print-prepared #map { transition: none !important; }

.field-sheet-print {
  display: none;
}

.field-notes-print {
  display: none;
}

@media print {
  body.field-sheet-prepared #map {
    height: 60vh !important;
    border-bottom: 1px solid #999;
  }

  body.field-sheet-prepared .map-readout {
    display: none !important;
  }

  body.field-sheet-prepared .field-sheet-print {
    display: block !important;
    page-break-before: always;
    padding: 14mm 12mm;
    color: #111;
    background: #fff;
    font-family: 'IBM Plex Sans', Arial, sans-serif;
    font-size: 10.5pt;
    line-height: 1.35;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .fs-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    padding-bottom: 8mm;
    border-bottom: 1px solid #999;
  }

  .fs-eyebrow,
  .fs-generated,
  .fs-card h3,
  .fs-card dt {
    font-family: 'IBM Plex Mono', monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .fs-eyebrow,
  .fs-generated {
    font-size: 8pt;
    color: #555;
  }

  .fs-header h1 {
    margin: 2mm 0 0;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 24pt;
    font-weight: 500;
  }

  .fs-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5mm;
    margin-top: 7mm;
  }

  .fs-card {
    border: 1px solid #bbb;
    padding: 5mm;
    break-inside: avoid;
  }

  .fs-card h2 {
    margin: 0 0 4mm;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 15pt;
    font-weight: 500;
  }

  .fs-card h3 {
    margin: 5mm 0 2mm;
    font-size: 7.5pt;
    color: #555;
  }

  .fs-card dl {
    margin: 0;
  }

  .fs-card dl div {
    display: grid;
    grid-template-columns: 29mm 1fr;
    gap: 4mm;
    padding: 1.5mm 0;
    border-top: 1px solid #e1e1e1;
  }

  .fs-card dl div:first-child {
    border-top: none;
  }

  .fs-card dt {
    font-size: 7.5pt;
    color: #555;
  }

  .fs-card dd {
    margin: 0;
    font-weight: 600;
  }

  .fs-layer-list,
  .fs-checklist {
    margin: 0;
    padding-left: 4.5mm;
  }

  .fs-layer-list li,
  .fs-checklist li {
    margin: 1.3mm 0;
  }

  .fs-caveat,
  .fs-share {
    margin-top: 6mm;
    padding: 4mm 5mm;
    border: 1px solid #aaa;
    break-inside: avoid;
  }

  .fs-caveat {
    border-left: 5px solid #0a6a7a;
  }

  .fs-share {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 8pt;
    overflow-wrap: anywhere;
  }

  body.field-notes-prepared #map,
  body.field-notes-prepared .map-scale-pair,
  body.field-notes-prepared .map-readout,
  body.field-notes-prepared .floating-legend,
  body.field-notes-prepared .field-sheet-print {
    display: none !important;
  }

  body.field-notes-prepared .field-notes-print {
    display: block !important;
    color: #111;
    background: #fff;
    font-family: 'IBM Plex Sans', Arial, sans-serif;
    font-size: 10pt;
    line-height: 1.32;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .fn-print-page {
    min-height: 268mm;
    padding: 12mm;
    page-break-after: always;
  }

  .fn-print-page:last-child {
    page-break-after: auto;
  }

  .fn-print-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    padding-bottom: 7mm;
    border-bottom: 1px solid #999;
  }

  .fn-print-eyebrow,
  .fn-print-generated,
  .fn-print-number,
  .fn-print-body .fn-meta-key {
    font-family: 'IBM Plex Mono', monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .fn-print-eyebrow,
  .fn-print-generated {
    font-size: 8pt;
    color: #555;
  }

  .fn-print-header h1 {
    margin: 2mm 0 0;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 23pt;
    font-weight: 500;
  }

  .fn-print-grid {
    display: grid;
    gap: 5mm;
    margin-top: 7mm;
  }

  .fn-print-grid-one {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: 120mm 1fr;
  }

  .fn-print-box-overview {
    grid-column: 1 / -1;
  }

  .fn-print-grid-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, 1fr);
  }

  .fn-print-box {
    position: relative;
    min-height: 68mm;
    padding: 7mm 6mm 6mm;
    border: 1px solid #aaa;
    break-inside: avoid;
  }

  .fn-print-box h2 {
    margin: 0 0 4mm;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 14pt;
    font-weight: 500;
  }

  .fn-print-number {
    position: absolute;
    top: 4mm;
    right: 5mm;
    width: 8mm;
    height: 8mm;
    border: 1px solid #777;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 8pt;
    color: #555;
  }

  .fn-print-body {
    font-size: 9.6pt;
    color: #111;
    overflow-wrap: anywhere;
  }

  .fn-print-body p {
    margin: 0 0 2.5mm;
  }

  .fn-print-body ul {
    margin: 0;
    padding-left: 4.5mm;
  }

  .fn-print-body li {
    margin: 1.5mm 0;
  }

  .fn-meta-list {
    display: grid;
    gap: 1.4mm;
    margin: 0;
  }

  .fn-meta-row {
    display: grid;
    grid-template-columns: minmax(22mm, 30mm) minmax(0, 1fr);
    gap: 4mm;
    padding-top: 1.4mm;
    border-top: 1px solid #e1e1e1;
    min-width: 0;
  }

  .fn-meta-row:first-child {
    border-top: none;
  }

  .fn-meta-key {
    font-size: 7pt;
    color: #555;
  }

  .fn-meta-value {
    font-weight: 600;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .fn-lined-body {
    min-height: 55mm;
    background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 8mm, #ddd 8.2mm);
  }
}

/* ============= SIDEBAR ============= */
.sidebar {
  background: var(--paper-bright);
  border-right: 1px solid var(--hair-strong);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--hair);
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--hair-strong);
}

.sidebar section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--hair);
  animation: sidebar-in 600ms ease-out backwards;
}

.sidebar section:nth-child(1) { animation-delay: 50ms;  }
.sidebar section:nth-child(2) { animation-delay: 100ms; }
.sidebar section:nth-child(3) { animation-delay: 160ms; }
.sidebar section:nth-child(4) { animation-delay: 220ms; }
.sidebar section:nth-child(5) { animation-delay: 280ms; }

/* =========================================================
 * SEARCH SECTION — top of sidebar, find places + rivers
 * ========================================================= */
.search-section { padding: 14px 22px; }
.search-eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.search-wrap { position: relative; }
#map-search {
  width: 100%;
  padding: 9px 30px 9px 12px;
  font-family: var(--font-sans, system-ui);
  font-size: 13px;
  color: var(--ink);
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  border-radius: 3px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
#map-search:focus {
  border-color: var(--water);
  background: white;
}
#map-search::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}
.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--hair);
  color: var(--ink-sub);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.search-clear[hidden] { display: none; }
.search-clear:hover { background: var(--hair-strong); color: var(--ink); }

/* Results dropdown — appears below the input. Keyboard navigable. */
.search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  border-radius: 3px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.search-results[hidden] { display: none; }
.search-results li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  border-radius: 2px;
}
.search-results li:hover,
.search-results li.active,
.search-results li[aria-selected="true"] { background: var(--water-tint); }
.search-results .sr-kind {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 2px;
  flex-shrink: 0;
}
.search-results .sr-kind-place { background: #ede0c8; color: #5a3a0e; }
.search-results .sr-kind-river { background: #d7e9ec; color: #06414a; }
.search-results .sr-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.search-results .sr-name {
  font-weight: 500;
  overflow-wrap: anywhere;
}
.search-results .sr-context {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--ink-faint);
  line-height: 1.25;
}
.search-results .sr-empty {
  padding: 12px;
  color: var(--ink-faint);
  font-style: italic;
  font-size: 12px;
  cursor: default;
}
.search-results .sr-empty:hover { background: transparent; }

/* Section header inside the results dropdown ("Recent" before history,
 * could be used for "Suggestions" later). */
.search-results .sr-section {
  padding: 6px 12px 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: default;
}
.search-results .sr-section:hover { background: transparent; }

/* Flash effect — when user selects a river from search, all its segments
 * pulse for a couple of seconds so they can see WHERE on the map it is. */
@keyframes river-flash {
  0%, 100% { stroke-width: 2;   stroke-opacity: 0.85; }
  50%      { stroke-width: 6.5; stroke-opacity: 1;   filter: drop-shadow(0 0 4px #1976d2); }
}
.leaflet-interactive.river-flash {
  animation: river-flash 0.55s ease-in-out 3;
}

.search-focus-marker {
  background: transparent !important;
  border: 0 !important;
}
.search-focus-marker span {
  position: relative;
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--paper-bright);
  background: var(--water);
  box-shadow: 0 0 0 2px rgba(10, 106, 122, 0.45), 0 4px 12px rgba(0,0,0,0.24);
}
.search-focus-marker span::after {
  content: '';
  position: absolute;
  inset: -7px;
  border: 1px solid rgba(10, 106, 122, 0.48);
  border-radius: 50%;
  animation: search-pulse 1.4s ease-out infinite;
}
@keyframes search-pulse {
  from { transform: scale(0.7); opacity: 0.75; }
  to { transform: scale(1.35); opacity: 0; }
}
.search-popup .leaflet-popup-content-wrapper {
  border-radius: 4px;
}
.search-popup .leaflet-popup-content {
  margin: 14px 16px 15px;
  min-width: 210px;
}
.leaflet-popup-pane {
  z-index: 900;
}
.search-popup-card {
  color: var(--ink);
}
.sp-eyebrow {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--water);
}
.sp-title {
  margin-top: 3px;
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.15;
}
.sp-context,
.sp-note {
  margin-top: 4px;
  color: var(--ink-sub);
  font-size: 11.5px;
  line-height: 1.35;
}
.sp-context {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--water);
}
.sp-action {
  appearance: none;
  border: 1px solid var(--water);
  background: var(--water);
  color: var(--paper-bright);
  margin-top: 9px;
  min-height: 34px;
  padding: 0 11px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.sp-action:hover,
.sp-action:focus-visible {
  background: var(--water-mid, #1a6573);
  outline: 2px solid var(--water-tint);
  outline-offset: 2px;
}

@keyframes sidebar-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-eyebrow {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.section-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--water);
  letter-spacing: 0.06em;
}

.section-title {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 36, 'wght' 600;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}

.section-lede {
  font-size: 12.5px;
  color: var(--ink-sub);
  line-height: 1.55;
  margin-bottom: 14px;
}

/* ----- LAYER CARDS ----- */
.layer-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;          /* 1px gap reveals --hair as separator */
  background: var(--hair);
  border: 1px solid var(--hair);
}

.layer-card {
  background: var(--paper-bright);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 12px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease;
}

.layer-card:hover {
  background: var(--water-haze);
}

.layer-card.active {
  background: var(--water-tint);
}

.layer-card input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink-sub);
  margin-top: 2px;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.layer-card input[type="checkbox"]:checked {
  background: var(--water);
  border-color: var(--water);
}

.layer-card input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 4px;
  width: 5px;
  height: 9px;
  border: solid var(--paper-bright);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

.layer-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.layer-id {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
}

.layer-name {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 36, 'wght' 500;
  font-size: 15px;
  letter-spacing: -0.005em;
  color: var(--ink);
  line-height: 1.15;
}

.layer-cite {
  font-size: 11px;
  font-style: italic;
  color: var(--ink-sub);
  line-height: 1.4;
}

.layer-card.active .layer-id {
  color: var(--water);
}

.layer-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid var(--hair-strong);
  flex-shrink: 0;
}

.swatch-dem {
  background: linear-gradient(135deg, #5e3f1f 0%, #afc483 45%, #305a82 100%);
}

.swatch-hand {
  background: linear-gradient(135deg, #fff3a8 0%, #e07a3b 50%, #3b2461 100%);
}

.swatch-streams {
  background: linear-gradient(135deg, #f8fbff 0%, #266daa 100%);
}

.swatch-slope {
  background: linear-gradient(135deg, #000004 0%, #b73779 50%, #fcfdbf 100%);
}

.swatch-twi {
  background: linear-gradient(135deg, #440154 0%, #21908c 50%, #fde725 100%);
}

/* ----- ROADMAP ----- */
.roadmap {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.roadmap li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  padding: 7px 0;
  font-size: 12.5px;
  color: var(--ink-sub);
  position: relative;
  border-bottom: 1px dashed var(--hair);
}

.roadmap li:last-child {
  border-bottom: none;
}

.roadmap li .num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  padding-top: 1px;
}

.roadmap li.done {
  color: var(--ok);
}

.roadmap li.done .num {
  color: var(--ok);
}

.roadmap li.done::after {
  content: '✓';
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ok);
  position: absolute;
  right: 0;
  top: 7px;
}

.roadmap li.active {
  color: var(--ink);
  font-weight: 500;
}

.roadmap li.active .num {
  color: var(--water);
}

.roadmap li.active::after {
  content: '→';
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--water);
  position: absolute;
  right: 0;
  top: 6px;
  animation: roadmap-arrow 2.4s ease-in-out infinite;
}

@keyframes roadmap-arrow {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(3px); }
}

/* ----- ATTRIBUTION ----- */
.attribution {
  font-size: 11px;
  color: var(--ink-faint);
  line-height: 1.55;
  border-top: 1px solid var(--hair);
  padding-top: 14px;
  margin-top: 6px;
}

.attribution strong {
  color: var(--ink-sub);
  font-weight: 500;
}

/* =========================================================
 * MAP
 * ========================================================= */
.map-pane {
  position: relative;
  background: var(--paper-deep);
}

#map {
  width: 100%;
  height: 100%;
  background: var(--paper-deep);
  cursor: crosshair;
}

body.field-capture-active {
  background: #161511;
}

body.field-capture-active .main {
  grid-template-columns: 1fr;
}

body.field-capture-active .sidebar,
body.field-capture-active .intro-card,
body.field-capture-active .guide-me-btn,
body.field-capture-active .warning-banner,
body.field-capture-active .data-status-panel,
body.field-capture-active .detail-panel,
body.field-capture-active .field-notes-panel,
body.field-capture-active .floating-legend,
body.field-capture-active .map-readout,
body.field-capture-active .map-scale-pair {
  display: none !important;
}

body.field-capture-active .map-pane {
  display: grid;
  place-items: center;
  padding: 78px 42px 96px;
  background:
    linear-gradient(rgba(17, 19, 23, 0.50), rgba(17, 19, 23, 0.50)),
    var(--paper-deep);
}

body.field-capture-active #map {
  width: min(var(--capture-max-width), calc((100dvh - 214px) * var(--capture-ratio)));
  height: auto;
  aspect-ratio: var(--capture-aspect);
  border: 2px solid var(--paper-bright);
  box-shadow: 0 18px 52px rgba(0,0,0,0.34);
  cursor: grab;
}

body.field-capture-active.capture-frame-large {
  --capture-aspect: 170 / 95;
  --capture-ratio: 1.789;
  --capture-max-width: min(1160px, calc(100vw - 96px));
}

body.field-capture-active.capture-frame-landscape {
  --capture-aspect: 82 / 55;
  --capture-ratio: 1.491;
  --capture-max-width: min(900px, calc(100vw - 116px));
}

body.field-capture-active.capture-frame-portrait {
  --capture-aspect: 82 / 95;
  --capture-ratio: 0.863;
  --capture-max-width: min(560px, calc(100vw - 140px));
}

.field-capture-toolbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 1800;
  width: min(720px, calc(100vw - 36px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 12px 34px rgba(0,0,0,0.24);
  color: var(--ink);
}

.field-capture-toolbar[hidden] {
  display: none;
}

.field-capture-eyebrow {
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--water);
}

.field-capture-toolbar h3 {
  margin: 2px 0 1px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
}

.field-capture-toolbar p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink-sub);
}

.field-capture-actions {
  display: flex;
  gap: 7px;
  flex-shrink: 0;
}

.fc-btn {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--hair-strong);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.fc-btn:hover {
  border-color: var(--water);
  background: var(--water-haze);
}

.fc-btn-primary {
  color: var(--paper-bright);
  background: var(--water);
  border-color: var(--water);
}

/* Leaflet light-paper overrides */
.leaflet-container {
  background: var(--paper-deep) !important;
  font-family: var(--font-mono) !important;
  font-size: 11px !important;
}

/* Image-overlay fade-in was attempted (CSS keyframes + JS setOpacity dance)
 * but kept overriding Leaflet's per-layer inline opacity (e.g. 0.62 for
 * HAND, 0.55 for hand-dense). The real cause of the "jerky/stagey" preset
 * transition was image-load latency, not pop-in. The R2 pre-warm in main.js
 * (right after wireLayer) solves it cleanly — bytes land in HTTP cache
 * before any preset click, so the WebPs render instantly. Fade-in deferred
 * until a future session if visible jitter remains in field testing. */

.leaflet-control-attribution {
  background: rgba(253, 252, 249, 0.92) !important;
  color: var(--ink-sub) !important;
  font-family: var(--font-mono) !important;
  font-size: 10px !important;
  border: 1px solid var(--hair) !important;
  border-radius: 0 !important;
  padding: 3px 8px !important;
}

.leaflet-control-attribution a {
  color: var(--water) !important;
  border-bottom: none !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--hair-strong) !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.leaflet-control-zoom a {
  background: var(--paper-bright) !important;
  color: var(--ink) !important;
  border: none !important;
  border-bottom: 1px solid var(--hair) !important;
  font-family: var(--font-mono) !important;
  font-weight: 400 !important;
  border-radius: 0 !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 30px !important;
}

.leaflet-control-zoom a:last-child {
  border-bottom: none !important;
}

.leaflet-control-zoom a:hover {
  background: var(--water-haze) !important;
  color: var(--water) !important;
}

/* =========================================================
 * CUSTOM BNG SCALE BARS — horizontal beside zoom +, vertical below zoom -
 * ========================================================= */
.leaflet-control-scale {
  display: none !important;
}
.map-scale-pair {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 620;
  pointer-events: none;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.map-scale {
  position: absolute;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(253, 252, 249, 0.8);
}
.map-scale-horizontal {
  top: 20px;
  left: 58px;
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: end;
  gap: 6px;
}
.map-scale-vertical {
  top: 86px;
  left: 19px;
}
.scale-axis {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--water);
  text-transform: uppercase;
  line-height: 1;
  padding-bottom: 1px;
}
.scale-label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
}
.scale-rule {
  position: relative;
  background: rgba(253, 252, 249, 0.82);
}
.scale-rule-horizontal {
  width: 86px;
  height: 8px;
  border-left: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
.scale-rule-horizontal::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -2px;
  height: 6px;
  border-left: 1px solid rgba(17, 19, 23, 0.62);
}
.scale-v-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.scale-rule-vertical {
  width: 8px;
  height: 86px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
}
.scale-rule-vertical::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -2px;
  width: 6px;
  border-top: 1px solid rgba(17, 19, 23, 0.62);
}
.map-scale-vertical .scale-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

/* =========================================================
 * MAP OVERLAY READOUT — floating BNG / zoom display
 * ========================================================= */
.map-readout {
  position: absolute;
  bottom: 56px;      /* lifted clear of the attribution line */
  left: 18px;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 28px;
  z-index: 500;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}

.readout-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.readout-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
}

.readout-value {
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* =========================================================
 * STATUS PILL — top right floating "build state"
 * ========================================================= */
.build-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--water);
  color: var(--water);
}

.build-pill.error {
  border-color: var(--live);
  color: var(--live);
}

.build-pill.ok {
  border-color: var(--ok);
  color: var(--ok);
}

/* =========================================================
 * INLINE TYPE HELPERS
 * ========================================================= */
.lede em {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink);
}

code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--paper-deep);
  padding: 1px 5px;
  color: var(--water);
  border: 1px solid var(--hair);
}

details.info-box {
  background: var(--paper);
  border: 1px solid var(--hair);
  padding: 0;
  margin-bottom: 12px;
}

details.info-box summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-sub);
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.15s ease;
}

details.info-box summary:hover {
  background: var(--water-haze);
  color: var(--water);
}

details.info-box summary::after {
  content: '+';
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--ink-faint);
}

details.info-box[open] summary::after {
  content: '−';
  color: var(--water);
}

details.info-box[open] summary {
  border-bottom: 1px solid var(--hair);
}

details.info-box .info-body {
  padding: 12px 14px 14px;
  font-size: 12px;
  color: var(--ink-sub);
  line-height: 1.55;
}

details.info-box .info-body p + p {
  margin-top: 8px;
}

/* =========================================================
 * RESPONSIVE — tablet (≤900 px) and phone (≤600 px)
 * ========================================================= */
@media (max-width: 900px) {
  .masthead {
    grid-template-columns: 1fr;
  }
  .masthead-brand,
  .masthead-meta,
  .masthead-stamp {
    border: none;
    padding: 12px 18px;
  }
  .masthead-stamp {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: wrap;
  }
  .tagline { font-size: 15px; max-width: none; }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    /* Cap tighter on mobile — the map is the main thing, not the sidebar.
     * 40vh leaves enough room for the search box + layer presets + a peek
     * at the first few layer cards, the rest scrolls within the sidebar. */
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--hair-strong);
  }
  /* Cursor readout — wrap to two/three rows */
  .map-readout {
    flex-wrap: wrap;
    gap: 14px;
    padding: 10px 12px;
    bottom: 50px;
  }
  /* Side panels become more compact */
  .detail-panel,
  .intro-card,
  .data-status-panel,
  .field-notes-panel {
    width: calc(100vw - 36px);
    max-width: 360px;
  }
  /* Event modal becomes nearly full-screen */
  .event-modal-card {
    padding: 20px 22px 24px;
    max-height: 92vh;
  }
}
@media (max-width: 600px) {
  .brand-title { font-size: 22px; }
  .brand-sub { font-size: 9px; }
  .tagline { font-size: 13px; }
  .sidebar { max-height: 50vh; }
  .sidebar section { padding: 14px 18px; }
  .section-lede { font-size: 12px; }
  .layer-card { padding: 10px 12px; gap: 10px; }
  .layer-name { font-size: 14px; }
  .layer-cite { font-size: 11.5px; }

  /* Guide-me button — icon-only on phone */
  .guide-me-btn { padding: 8px 12px; font-size: 10px; }

  /* Cursor readout — slim down further */
  .map-readout {
    bottom: 44px; left: 8px; right: 8px;
    gap: 10px; padding: 8px 10px;
    font-size: 11px;
  }
  .readout-label { font-size: 8px; }
  .readout-value { font-size: 12px; }

  /* Detail / intro / status panels: full-screen-ish overlay */
  .detail-panel,
  .intro-card,
  .data-status-panel,
  .field-notes-panel {
    top: auto;
    bottom: 0; left: 0; right: 0;
    width: 100vw; max-width: none;
    max-height: 70vh;
    border-radius: 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.18);
  }
  .ds-list li {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .ds-list .ds-source {
    flex-basis: calc(100% - 64px);
    overflow-wrap: anywhere;
  }
  .ds-list .ds-detail {
    flex: 1 1 100%;
    max-width: none;
    margin-left: 56px;
    padding-left: 0;
    text-align: left;
    white-space: nowrap;
  }
  .event-modal { padding: 12px; }
  .event-modal-content .em-headline { font-size: 22px; }
  .event-modal-content .em-stats { grid-template-columns: 1fr; }

  /* Place markers — hide minor places + shrink major to dot-only on very small */
  .place-marker { font-size: 9.5px; padding: 1px 4px; }

  /* Forecast links — single column */
  .extras-grid { grid-template-columns: 1fr; }
}

/* =========================================================
 * LEGEND
 * ========================================================= */
.legend-group {
  margin: 14px 0;
  padding: 14px 14px 13px;
  background: var(--paper-bright);
  border: 1px solid var(--hair);
  border-radius: 2px;
}
.legend-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
}
.legend-title {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.legend-unit {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 9px;
  font-weight: 400;
  color: var(--ink-faint);
  text-transform: none;
  letter-spacing: 0;
}
.legend-desc-btn {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--hair);
  border-radius: 3px;
  background: var(--paper);
  color: var(--water);
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
}
.legend-desc-btn:hover {
  background: var(--water-tint);
  color: var(--water);
  border-color: var(--water);
}
.legend-bar {
  height: 12px;
  width: 100%;
  border: 1px solid var(--hair-strong);
}
.legend-bar-hand {
  background: linear-gradient(to right, #fff3a8 0%, #f7c948 20%, #e07a3b 40%, #9c4a2d 60%, #5d3a8e 80%, #3b2461 100%);
}
.legend-bar-slope {
  background: linear-gradient(to right, #000004 0%, #50127b 25%, #b63679 50%, #fb8861 75%, #fcfdbf 100%);
}
.legend-bar-twi {
  background: linear-gradient(to right, #440154 0%, #3b528b 25%, #21908c 50%, #5ec962 75%, #fde725 100%);
}
.legend-ticks {
  display: flex;
  justify-content: space-between;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 10px;
  color: var(--ink-sub);
  margin-top: 4px;
}
.legend-ticks-scale {
  position: relative;
  display: block;
  height: 16px;
  margin-top: 5px;
}
.legend-ticks-scale span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}
.legend-ticks-scale span:first-child {
  transform: translateX(0);
}
.legend-ticks-scale span:last-child {
  transform: translateX(-100%);
}
.legend-interp {
  font-size: 11.5px;
  color: var(--ink-sub);
  margin-top: 7px;
  line-height: 1.45;
}
.legend-interp strong {
  color: var(--ink);
  font-weight: 600;
}

/* =========================================================
 * FLOATING ACTIVE-LAYER LEGEND
 * Small, map-side, and tied to the currently visible analytical colour layer.
 * ========================================================= */
.floating-legend {
  position: absolute;
  right: 18px;
  bottom: 56px;
  z-index: 650;
  width: 272px;
  padding: 12px 14px 11px;
  background: rgba(253, 252, 249, 0.94);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  font-family: var(--font-body);
  color: var(--ink);
  pointer-events: none;
  backdrop-filter: blur(2px);
}
.floating-legend[hidden] {
  display: none;
}
body.map-popup-open .floating-legend {
  display: none;
}
.detail-panel:not([hidden]) ~ .floating-legend,
.data-status-panel:not([hidden]) ~ .floating-legend,
.field-notes-panel:not([hidden]) ~ .floating-legend {
  display: none;
}
body.map-popup-open .intro-card {
  display: none;
}
.floating-legend-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.fl-eyebrow {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.fl-title {
  margin-top: 1px;
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 36, 'wght' 600;
  font-size: 16px;
  line-height: 1.1;
}
.fl-unit {
  flex: 0 0 auto;
  padding-top: 2px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--water);
  text-transform: uppercase;
}
.fl-bar {
  height: 12px;
  border: 1px solid var(--hair-strong);
}
.fl-ticks {
  position: relative;
  height: 17px;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--ink-sub);
}
.fl-ticks span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}
.fl-ticks span:first-child {
  transform: translateX(0);
}
.fl-ticks span:last-child {
  transform: translateX(-100%);
}
.fl-note {
  margin-top: 5px;
  padding-top: 7px;
  border-top: 1px solid rgba(184, 177, 163, 0.65);
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink-sub);
}

/* =========================================================
 * FIRST-TIME INTRO CARD (top-right of map)
 * ========================================================= */
.intro-card {
  position: absolute;
  top: 70px;             /* below the guide-me button */
  right: 18px;
  width: 320px;
  z-index: 1000;
  padding: 18px 22px 16px;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 6px 22px rgba(0,0,0,0.10);
  border-radius: 3px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}
.intro-card.dismissed {
  display: none;
}
.intro-card h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 8px;
  color: var(--ink);
}
.intro-card p {
  margin: 0 0 8px;
  color: var(--ink-sub);
}
.intro-card p:last-child {
  margin-bottom: 0;
}
.intro-card strong {
  color: var(--ink);
  font-weight: 600;
}
.intro-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--ink-faint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
}
.intro-close:hover {
  background: var(--paper-deep);
  color: var(--ink);
  border-color: var(--hair-strong);
}

/* Lake + built-up swatches */
.swatch-lakes {
  background: linear-gradient(135deg, #2a6f9c 0%, #5fb5d6 100%);
}
.swatch-builtup {
  background: linear-gradient(135deg, #b88a5a 0%, #d9b48a 100%);
}

/* Leaflet vector overlay styling — class on layerGroup applied via SVG */
.layer-lakes path { stroke: #1d557c; stroke-width: 0.5; fill: #4d8eba; fill-opacity: 0.55; }
.layer-builtup path { stroke: #6e3e1c; stroke-width: 0.4; fill: #b88a5a; fill-opacity: 0.40; }
.place-marker { font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: #2a2118; }
.place-marker-major { font-weight: 600; font-size: 11px; }

/* Place markers — visual hierarchy */
.place-marker-wrapper { background: transparent !important; border: none !important; }
.place-marker {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: #2a2118;
  background: rgba(253, 252, 249, 0.78);
  padding: 1px 5px;
  border-radius: 2px;
  white-space: nowrap;
  border: 1px solid rgba(180, 175, 165, 0.45);
}
.place-marker-major {
  font-weight: 600;
  font-size: 11px;
  background: rgba(253, 252, 249, 0.92);
  border-color: rgba(110, 62, 28, 0.5);
}
.place-marker-minor {
  color: #54595f;
  font-size: 9.5px;
}

.swatch-historic { background: linear-gradient(135deg, #b71c1c 0%, #ef9a9a 100%); }

/* =========================================================
 * "GUIDE ME" BUTTON — top-right of map, sits above intro card
 * ========================================================= */
.guide-me-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 1001;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--water);
  color: white;
  border: 1px solid var(--water);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  transition: background 0.15s ease, transform 0.1s ease;
}
.guide-me-btn:hover {
  background: var(--water-mid);
  transform: translateY(-1px);
  color: white;
}
.guide-me-btn em {
  font-style: normal;
  font-weight: 400;
  font-size: 14px;
  line-height: 1;
  margin-left: -2px;
}
.guide-me-icon {
  font-size: 14px;
  line-height: 1;
}
/* When the intro card is showing, the guide button moves below it */
.intro-card:not(.dismissed) ~ .guide-me-btn,
.intro-card:not(.dismissed) + .guide-me-btn {
  /* If intro shows above, guide stays in top-right corner — they're both there */
  /* Actually let me change the order so guide is always visible */
}
.intro-cta {
  margin-top: 12px !important;
  padding-top: 10px;
  border-top: 1px solid var(--hair);
  font-size: 12px !important;
}
.intro-cta a {
  color: var(--water);
  font-weight: 600;
  border-bottom: 1px solid var(--water);
}

/* =========================================================
 * LAYER MASTER CONTROLS — All on / All off / Reset
 * ========================================================= */
/* Layer presets — three large semantic-snap buttons. Stacked vertically
 * on narrow screens, two columns on roomier widths. Each button has an
 * icon, a bold label, and a smaller subtitle explaining the contents. */
.layer-presets {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.preset-btn {
  display: grid;
  grid-template-columns: 22px 1fr;
  grid-template-rows: auto auto;
  align-items: baseline;
  column-gap: 10px;
  row-gap: 2px;
  padding: 9px 12px;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  border-radius: 3px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease,
              transform 0.06s ease;
}
.preset-btn:hover {
  background: var(--water-tint);
  border-color: var(--water);
}
.preset-btn:active {
  transform: translateY(1px);
}
.preset-btn .preset-icon {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 18px;
  color: var(--water);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  text-align: center;
}
.preset-btn .preset-label {
  font-family: 'Fraunces', serif;
  font-variation-settings: 'opsz' 36, 'wght' 600;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.1;
}
.preset-btn .preset-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  line-height: 1.3;
}
.preset-btn:hover .preset-label { color: var(--water); }
.preset-btn:hover .preset-sub   { color: var(--water-mid, #1a6573); }

/* Active preset (matches current layer state). Slightly deeper than hover so
 * it stays readable when the cursor leaves the card. */
.preset-btn.is-active {
  background: var(--water-tint);
  border-color: var(--water);
  box-shadow: inset 3px 0 0 var(--water);
}
.preset-btn.is-active .preset-label { color: var(--water); }
.preset-btn.is-active .preset-sub   { color: var(--water-mid, #1a6573); }
.preset-btn.is-active .preset-icon  { color: var(--water); }

/* Power-user fallback strip — small text-only buttons under the presets.
 * "Reset" is most useful; All on / All off are deliberately demoted. */
.layer-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.layer-ctrl-btn {
  flex: 1;
  padding: 5px 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-sub);
  background: transparent;
  border: 1px solid var(--hair);
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.layer-ctrl-btn:hover {
  background: var(--water-tint);
  color: var(--water);
  border-color: var(--water);
}
.layer-ctrl-btn:active {
  transform: translateY(1px);
}
.layer-ctrl-btn#btn-default {
  /* Reset is the most useful of the three — give it a touch more weight */
  font-weight: 600;
  color: var(--ink);
}

/* Gauges swatch + Leaflet marker styling */
.swatch-gauges {
  background: radial-gradient(circle at 50% 50%, #c44a4a 0%, #c44a4a 50%, #fff 51%, #fff 100%);
  border: 1px solid var(--hair-strong);
}
.ea-gauge-marker {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--live);  /* "live" red — same hue as the masthead pulse */
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(196, 74, 74, 0.6), 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.ea-gauge-marker:hover { transform: scale(1.4); }
.ea-gauge-marker.loading { background: #999; }
.ea-gauge-popup .ga-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 2px;
}
/* ↗ Wikipedia link beside the gauge station name — same subtle treatment
 * as the place-name link in the click-to-detail panel. Faint until hover. */
.ea-gauge-popup .ga-title .ga-wiki {
  display: inline-block;
  margin-left: 5px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  text-decoration: none;
  border-radius: 2px;
  vertical-align: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}
.ea-gauge-popup .ga-title .ga-wiki:hover,
.ea-gauge-popup .ga-title .ga-wiki:focus-visible {
  background: var(--water-tint);
  color: var(--water);
  outline: none;
}
.ea-gauge-popup .ga-river {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--water);
  margin-bottom: 8px;
}
.ea-gauge-popup .ga-level {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin: 4px 0;
}
.ea-gauge-popup .ga-stamp {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--ink-faint);
}
.ea-gauge-popup .ga-loading {
  color: var(--ink-faint);
  font-style: italic;
  font-size: 11px;
}
.ea-gauge-popup .ga-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  color: var(--water);
}

/* Range badge — coloured pill that tells you whether the current reading
 * sits at the high end, low end, or middle of the last 24 hours.
 * Three colours; intentionally honest (no scary red unless verified high). */
.ea-gauge-popup .ga-range {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 4px 0 6px;
  padding: 5px 9px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
}
.ea-gauge-popup .ga-range-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.10em;
}
.ea-gauge-popup .ga-range-detail {
  font-size: 9.5px;
  opacity: 0.85;
}
.ea-gauge-popup .ga-range-high { background: #fce4e4; color: #7f0000; }
.ea-gauge-popup .ga-range-mid  { background: #eef3f6; color: #04313a; }
.ea-gauge-popup .ga-range-low  { background: #e7f0e7; color: #2c5e34; }
/* Stale = gauge hasn't reported in >24h. Don't make it red (not a flood
 * warning) — distinct grey-amber so users know "this is old data, not a
 * current alert". */
.ea-gauge-popup .ga-range-stale { background: #f5ede0; color: #6b4a1e; }
.ea-gauge-popup .ga-level-stale {
  color: var(--ink-faint);
  /* Crossbar through the number — communicates "this isn't live" */
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: rgba(0,0,0,0.35);
}

/* Sparkline — 24h trend microchart inside the gauge popup. */
.ea-gauge-popup .ga-spark {
  display: block;
  margin: 4px 0 2px;
  background: #fbfaf6;
  border: 1px solid var(--hair);
  border-radius: 2px;
}
.ea-gauge-popup .ga-spark-axis {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: 8.5px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.ea-gauge-popup .ga-spark-axis .ga-spark-mid {
  text-transform: uppercase;
  letter-spacing: 0.10em;
}

/* =========================================================
 * EVENT MODAL — click a historic flood polygon → opens with case-study detail
 * ========================================================= */
.event-modal {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.event-modal[hidden] { display: none; }
.event-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 20, 20, 0.55);
  backdrop-filter: blur(2px);
}
.event-modal-card {
  position: relative;
  max-width: 720px; max-height: 86vh;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  overflow-y: auto;
  padding: 28px 36px 32px;
  font-family: var(--font-body);
  animation: event-modal-in 200ms ease-out;
}
@keyframes event-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.event-modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px;
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--ink-faint);
  font-size: 20px; line-height: 1;
  cursor: pointer; border-radius: 50%;
  font-family: var(--font-body);
}
.event-modal-close:hover {
  background: var(--paper-deep); color: var(--ink); border-color: var(--hair-strong);
}
.event-modal-content .em-eyebrow {
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--peat); margin-bottom: 8px;
}
.event-modal-content .em-headline {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 144, 'wght' 600;
  font-size: 32px; line-height: 1.05; color: var(--ink);
  margin-bottom: 4px;
}
.event-modal-content .em-tagline {
  font-family: var(--font-display); font-style: italic;
  font-size: 17px; color: var(--ink-sub);
  margin-bottom: 18px;
}
.event-modal-content .em-summary {
  font-size: 14px; color: var(--ink); line-height: 1.55;
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--peat-tint);
  border-left: 3px solid var(--peat);
}
.event-modal-content .em-stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  font-size: 13px;
  margin-bottom: 16px;
}
.event-modal-content .em-stat-label {
  font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-sub);
  align-self: start; padding-top: 2px;
}
.event-modal-content .em-stat-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.event-modal-content .em-meta {
  display: flex; gap: 14px;
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--ink-faint); letter-spacing: 0.06em;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--hair);
}
.event-modal-content .em-source {
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--ink-faint); margin-top: 12px;
}
.event-modal-content .em-source code {
  background: var(--paper-deep);
  padding: 1px 4px;
  font-size: 10px;
  border-radius: 2px;
}

/* Minor-event variant — when no rich case study matches */
.event-modal-content.em-minor .em-headline { font-size: 22px; }
.event-modal-content.em-minor .em-eyebrow { color: var(--water); }

/* Forecast links — external sources block */
.forecast-links {
  display: flex; flex-direction: column;
  border: 1px solid var(--hair);
  background: var(--paper-bright);
  margin-top: 4px;
}
.forecast-link {
  display: flex; flex-direction: column;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hair);
  text-decoration: none; color: var(--ink);
  transition: background 0.15s ease;
  position: relative;
}
.forecast-link:last-child { border-bottom: none; }
.forecast-link:hover { background: var(--water-haze); color: var(--ink); }
.forecast-link .fl-name {
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 36, 'wght' 600;
  font-size: 13.5px;
  color: var(--ink);
  margin-bottom: 2px;
}
.forecast-link .fl-meta {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.04em;
  color: var(--ink-sub);
}
.forecast-link .fl-arrow {
  position: absolute; top: 50%; right: 14px;
  transform: translateY(-50%);
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--water);
}
.forecast-link:hover .fl-arrow { color: var(--water-mid); transform: translateY(-50%) translateX(2px); }

/* =========================================================
 * CLICK-TO-DETAIL PANEL — right side of map, opens on any map click
 * ========================================================= */
.detail-panel {
  position: absolute;
  top: 70px;
  right: 18px;
  width: 320px;
  max-height: min(70vh, calc(100dvh - 310px));
  z-index: 1100;        /* above intro card, below modal */
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  border-radius: 3px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  overflow-y: auto;
  padding: 16px 20px;
  animation: detail-in 200ms ease-out;
}
.detail-panel[hidden] { display: none; }
@keyframes detail-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: none; }
}
.detail-close {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px;
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--ink-faint);
  font-size: 16px; line-height: 1;
  cursor: pointer; border-radius: 50%;
}
.detail-close:hover {
  background: var(--paper-deep); color: var(--ink);
}
.detail-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--water);
  margin-bottom: 4px;
}
.detail-coords {
  font-family: var(--font-mono);
  font-size: 14px; font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--hair);
}
.detail-section {
  margin: 10px 0;
  padding-top: 10px;
  border-top: 1px solid var(--hair);
}
.detail-section:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.detail-section:empty { display: none; }
.detail-section h4 {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin-bottom: 4px;
}
.detail-section .ds-value {
  font-family: 'Fraunces', serif;
  font-variation-settings: 'opsz' 36, 'wght' 500;
  font-size: 18px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Wikipedia "↗" link beside a place name in the detail panel.
 * Subtle until hovered — not a distraction, just a discoverable hint
 * for users curious about a place. */
.detail-section .ds-value .dp-wiki {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-faint);
  text-decoration: none;
  border-radius: 2px;
  transition: background 0.15s ease, color 0.15s ease;
  vertical-align: 2px;
}
.detail-section .ds-value .dp-wiki:hover,
.detail-section .ds-value .dp-wiki:focus-visible {
  background: var(--water-tint);
  color: var(--water);
  outline: none;
}
.detail-section .ds-note {
  font-size: 12px;
  color: var(--ink-sub);
  margin-top: 2px;
}
.dp-summary-grid {
  display: grid;
  gap: 7px;
}
.dp-evidence {
  border: 1px solid var(--hair);
  border-left-width: 4px;
  background: var(--paper);
  padding: 8px 10px;
}
.dp-evidence-calm {
  border-left-color: var(--ok);
}
.dp-evidence-neutral {
  border-left-color: var(--hair-strong);
}
.dp-evidence-watch {
  border-left-color: #c47533;
}
.dp-evidence-caution {
  border-left-color: var(--live);
}
.dp-evidence-key {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
}
.dp-evidence-main {
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.15;
  color: var(--ink);
}
.dp-evidence-note {
  margin-top: 3px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--ink-sub);
}
.detail-section .ds-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 2px;
  text-transform: uppercase;
}
.ds-badge-safe       { background: #d9e9d9; color: #1d4a1d; }
.ds-badge-low        { background: #e2e6c8; color: #4a4a1d; }
.ds-badge-at-risk    { background: #f3e3d2; color: #6e3e1c; }
.ds-badge-floodplain { background: #efd5d5; color: #7f1d1d; }
.ds-badge-flooded    { background: #ef9a9a; color: #5f0000; }
.detail-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--hair);
  letter-spacing: 0.04em;
}
.detail-section a {
  color: var(--water);
}
.detail-action {
  appearance: none;
  border: 1px solid var(--water);
  background: var(--water);
  color: var(--paper-bright);
  margin: 8px 0 6px;
  min-height: 34px;
  padding: 0 11px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.detail-action:hover,
.detail-action:focus-visible {
  background: var(--water-mid, #1a6573);
  outline: 2px solid var(--water-tint);
  outline-offset: 2px;
}

/* When the click-to-detail panel is open, push the intro card down further */
.detail-panel:not([hidden]) ~ .intro-card {
  display: none;   /* hide intro while detail panel is showing */
}

/* =========================================================
 * DATA STATUS — masthead pill + clickable panel
 * ========================================================= */
.data-status-btn {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  background: var(--paper-bright);
  border: 1px solid var(--hair);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-sub);
  cursor: pointer;
  border-radius: 12px;
  text-transform: uppercase;
}
.data-status-btn:hover { background: var(--water-haze); }

/* Share-view button — same pill geometry as data-status, sits next to it. */
.share-view-btn {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--paper-bright);
  border: 1px solid var(--water);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--water);
  cursor: pointer;
  border-radius: 12px;
  text-transform: uppercase;
  transition: background 0.15s ease, color 0.15s ease;
}
.share-view-btn:hover { background: var(--water); color: var(--paper-bright); }
.share-view-btn:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }

.ds-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
  transition: background 0.2s ease;
}
.ds-dot.ok   { background: var(--ok); }
.ds-dot.warn { background: var(--peat); }
.ds-dot.fail { background: var(--live); }

.data-status-panel {
  position: absolute;
  top: 78px;
  right: 18px;
  width: 360px;
  z-index: 1200;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  border-radius: 3px;
  padding: 18px 22px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 13px;
  color: var(--ink);
  max-height: min(70vh, calc(100dvh - 310px));
  overflow-y: auto;
}
.data-status-panel[hidden] { display: none; }
.ds-panel-close {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px;
  background: transparent; border: 1px solid var(--hair);
  color: var(--ink-faint); font-size: 16px;
  cursor: pointer; border-radius: 50%;
}
.ds-panel-close:hover { background: var(--paper-deep); color: var(--ink); }
.data-status-panel h3 {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 500;
  margin: 0 0 6px 0;
}

.field-notes-panel {
  position: absolute;
  top: 78px;
  right: 18px;
  width: 430px;
  z-index: 1250;
  background: var(--paper-bright);
  border: 1px solid var(--hair-strong);
  box-shadow: 0 8px 30px rgba(0,0,0,0.16);
  border-radius: 3px;
  padding: 18px 22px 20px;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 13px;
  color: var(--ink);
  max-height: min(76vh, calc(100dvh - 180px));
  overflow-y: auto;
}
.field-notes-panel[hidden] { display: none; }
.field-notes-close {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px;
  background: transparent; border: 1px solid var(--hair);
  color: var(--ink-faint); font-size: 16px;
  cursor: pointer; border-radius: 50%;
}
.field-notes-close:hover { background: var(--paper-deep); color: var(--ink); }
.field-notes-eyebrow {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.18em;
  color: var(--water);
  text-transform: uppercase;
  padding-right: 42px;
}
.field-notes-panel h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  margin: 3px 42px 6px 0;
}
.field-notes-intro {
  margin: 0 0 12px;
  color: var(--ink-sub);
  font-size: 12px;
  line-height: 1.45;
}
.field-notes-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0 0 12px;
}
.fn-action-btn {
  min-height: 34px;
  border: 1px solid var(--hair-strong);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.fn-action-btn:hover {
  border-color: var(--water);
  background: var(--water-haze);
}
.fn-action-primary {
  grid-column: 1 / -1;
  color: var(--paper-bright);
  background: var(--water);
  border-color: var(--water);
}
.field-notes-slots {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.fn-builder-slot {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  padding: 10px 11px;
  background: var(--paper);
  border: 1px solid var(--hair);
}
.fn-slot-number {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--water);
  border-radius: 50%;
  color: var(--water);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}
.fn-builder-slot h4 {
  margin: 0 0 3px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
}
.fn-slot-body {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-sub);
}
.fn-slot-body .fn-meta-list {
  display: grid;
  gap: 3px;
}
.fn-slot-body .fn-meta-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 7px;
  border-top: 1px solid rgba(184, 177, 163, 0.65);
  padding-top: 3px;
}
.fn-slot-body .fn-meta-row:first-child {
  border-top: none;
  padding-top: 0;
}
.fn-slot-body .fn-meta-key {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.fn-slot-body .fn-meta-value {
  color: var(--ink);
  font-weight: 600;
}
.fn-text-label {
  display: block;
  margin: 10px 0 5px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--water);
}
.field-notes-panel textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  padding: 9px 10px;
  border: 1px solid var(--hair-strong);
  background: var(--paper);
  color: var(--ink);
  font: 12px/1.45 var(--font-sans);
}
.field-notes-panel textarea:focus {
  outline: 2px solid var(--water);
  outline-offset: 1px;
  background: var(--paper-bright);
}
.ds-panel-intro {
  font-size: 12px;
  color: var(--ink-sub);
  margin-bottom: 12px;
  line-height: 1.5;
}
.ds-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-sub);
}
.ds-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  border: 1px solid var(--hair);
  background: var(--paper);
}
.ds-list {
  list-style: none;
  margin: 0; padding: 0;
  border: 1px solid var(--hair);
}
.ds-list li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--hair);
}
.ds-list li:last-child { border-bottom: none; }
.ds-list li > .ds-dot {
  margin-top: 4px;
}
.ds-list .ds-source {
  flex: 1;
  min-width: 0;
  color: var(--ink);
  display: grid;
  gap: 2px;
}
.ds-source-label {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.2;
  color: var(--ink);
}
.ds-source-code {
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.25;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}
.ds-source-meaning {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 10.5px;
  line-height: 1.3;
  color: var(--ink-sub);
}
.ds-list .ds-detail {
  flex: 0 0 auto;
  max-width: 76px;
  margin-left: auto;
  font-family: var(--font-mono);
  color: var(--ink-faint);
  font-size: 10px;
  line-height: 1.25;
  text-align: right;
  overflow-wrap: anywhere;
}
.ds-list .ds-type,
.ds-legend .ds-type {
  flex: 0 0 auto;
  min-width: 46px;
  padding: 2px 5px;
  border: 1px solid var(--hair);
  border-radius: 2px;
  font-size: 8.5px;
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
}
.ds-legend .ds-type {
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 50%;
}
.ds-type-live    { background: #ffe5e5; color: #7f1d1d; border-color: #ef9a9a; }
.ds-type-derived { background: #e8f0db; color: #39491d; border-color: #c9d8aa; }
.ds-type-static  { background: #edf0f2; color: #39464d; border-color: #cfd8dc; }
.ds-type-r2      { background: #dff0f3; color: #04313a; border-color: #9ccbd3; }
.ds-panel-hint {
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* Warning zones swatch + active-warning banner */
.swatch-warning-zones {
  background: linear-gradient(135deg, #c47533 0%, #f3e3d2 100%);
  border: 1px solid var(--peat);
}

/* Named-rivers swatch — distinct from the algorithmic streams swatch
 * (which is solid blue) by using a gradient that hints at "named/curated"
 * vs "raw". Diagonal blue-to-deep-water reads as a flowing waterway. */
.swatch-waterways {
  background: linear-gradient(135deg, #1976d2 0%, #04313a 100%);
  border: 1px solid #1976d2;
}

/* OSM named rivers — heavier line than the algorithmic streams so users
 * can tell them apart on the map. Tooltip label uses the same monospace
 * voice as the rest of the dashboard. */
.leaflet-tooltip.waterway-tooltip {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #1976d2;
  color: #04313a;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.leaflet-tooltip.waterway-tooltip::before { display: none; }
.warning-banner {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1500;
  background: var(--live);
  color: white;
  padding: 10px 22px;
  border-radius: 22px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 6px 18px rgba(196, 74, 74, 0.4);
  cursor: pointer;
  animation: warning-pulse 2.5s ease-in-out infinite;
}
.warning-banner[hidden] { display: none; }
@keyframes warning-pulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(196, 74, 74, 0.4); }
  50%      { box-shadow: 0 6px 22px rgba(196, 74, 74, 0.8); }
}

/* =========================================================
 * MAP TOAST — short, dismiss-after-2s confirmation messages
 * Bottom-centre of the map, doesn't block anything.
 * Used by Share view, Reset-to-default, point-share confirmations.
 * ========================================================= */
.map-toast {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 1400;
  max-width: 92%;
  padding: 9px 16px 9px 14px;
  background: var(--ink);
  color: var(--paper-bright);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;   /* never blocks map clicks */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}
.map-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.map-toast[hidden] { display: none; }
.map-toast .toast-icon {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--water);
  flex-shrink: 0;
}
.map-toast.toast-success .toast-icon { background: var(--ok, #4caf50); }
.map-toast.toast-info    .toast-icon { background: var(--water); }
.map-toast.toast-share   .toast-icon { background: #1976d2; }
.map-toast .toast-link {
  color: var(--paper-bright);
  text-decoration: underline;
  font-size: 10.5px;
  opacity: 0.85;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
 * MOBILE MAP-FIRST LAYOUT
 * ========================================================= */
@media (max-width: 900px) {
  html,
  body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .masthead {
    position: relative;
    z-index: 1800;
    display: flex;
    align-items: center;
    height: 56px;
    min-height: 56px;
    padding: 0;
    border-bottom: 1px solid var(--hair-strong);
    box-shadow: 0 1px 8px rgba(0,0,0,0.08);
  }

  .masthead-brand {
    flex: 1 1 auto;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 0 8px 0 10px;
    border-right: none;
  }

  .mobile-menu-btn {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: var(--paper-bright);
    border: 1px solid var(--hair-strong);
    border-radius: 4px;
    cursor: pointer;
  }

  .mobile-menu-btn span {
    width: 18px;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
    transition: transform 0.16s ease, opacity 0.16s ease;
  }

  .mobile-menu-btn[aria-expanded="true"] span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .mobile-menu-btn[aria-expanded="true"] span:nth-child(2) {
    opacity: 0;
  }

  .mobile-menu-btn[aria-expanded="true"] span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  .brand-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 20px;
    letter-spacing: 0;
  }

  .brand-sub,
  .masthead-meta,
  .masthead-stamp .stamp-label,
  .masthead-stamp .stamp-value,
  .share-view-btn {
    display: none;
  }

  .masthead-stamp {
    flex: 0 0 auto;
    padding: 0 10px 0 0;
    border-left: none;
    background: transparent;
    align-items: center;
  }

  .data-status-btn {
    margin-top: 0;
    max-width: 132px;
    height: 34px;
    padding: 0 9px;
    border-radius: 18px;
    white-space: nowrap;
    overflow: hidden;
  }

  .data-status-btn .ds-label {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main {
    display: block;
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .map-pane {
    width: 100%;
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
    min-height: 0;
  }

  #map {
    height: 100%;
  }

  body.embed-mode .map-pane {
    height: 100vh;
    height: 100dvh;
  }

  body.field-capture-active .map-pane {
    padding: 70px 18px 138px;
  }

  body.field-capture-active.capture-frame-large,
  body.field-capture-active.capture-frame-landscape {
    --capture-max-width: calc(100vw - 36px);
  }

  body.field-capture-active.capture-frame-portrait {
    --capture-max-width: min(340px, calc(100vw - 58px));
  }

  .field-capture-toolbar {
    bottom: 10px;
    width: calc(100vw - 20px);
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
  }

  .field-capture-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .fc-btn {
    min-height: 42px;
    padding: 0 7px;
    font-size: 8.5px;
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 56px 0 0 0;
    z-index: 1600;
    display: block;
    background: rgba(17, 19, 23, 0.34);
    backdrop-filter: blur(1px);
  }

  .mobile-sidebar-backdrop[hidden] {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    z-index: 1700;
    width: min(88vw, 370px);
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
    max-height: none;
    border-right: 1px solid var(--hair-strong);
    border-bottom: none;
    box-shadow: 12px 0 36px rgba(0,0,0,0.22);
    transform: translateX(calc(-100% - 16px));
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s ease;
    -webkit-overflow-scrolling: touch;
  }

  body.mobile-controls-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar section {
    padding: 15px 16px;
  }

  .search-section {
    position: sticky;
    top: 0;
    z-index: 3;
    padding-top: 14px;
    background: var(--paper-bright);
    box-shadow: 0 1px 0 var(--hair);
  }

  #map-search {
    min-height: 42px;
    font-size: 14px;
  }

  .search-clear {
    width: 28px;
    height: 28px;
  }

  .search-results li {
    padding: 10px 12px;
  }

  .sp-action {
    width: 100%;
    min-height: 42px;
  }

  .preset-btn {
    min-height: 58px;
    padding: 11px 12px;
  }

  .layer-controls {
    gap: 7px;
  }

  .layer-ctrl-btn {
    min-height: 40px;
  }

  .layer-card {
    min-height: 52px;
    padding: 11px 12px;
  }

  .layer-card input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }

  .layer-card input[type="checkbox"]:checked::after {
    top: 2px;
    left: 6px;
    width: 6px;
    height: 10px;
  }

  .guide-me-btn {
    top: 12px;
    right: 12px;
    min-height: 40px;
    padding: 0 12px;
    font-size: 10px;
  }

  .warning-banner {
    top: 60px;
    width: calc(100% - 24px);
    max-width: 420px;
    padding: 9px 14px;
    text-align: center;
    white-space: normal;
  }

  .leaflet-control-zoom a {
    width: 38px !important;
    height: 38px !important;
    line-height: 36px !important;
  }

  .map-scale-horizontal {
    top: 20px;
    left: 62px;
    gap: 5px;
  }

  .map-scale-vertical {
    top: 94px;
    left: 22px;
  }

  .scale-axis {
    display: none;
  }

  .scale-label {
    font-size: 9px;
  }

  .map-toast {
    bottom: 96px;
    max-width: calc(100% - 20px);
    white-space: normal;
  }

  body.mobile-bottom-sheet-open .map-toast {
    bottom: calc(62vh + 14px);
    bottom: calc(62dvh + 14px);
  }

  .leaflet-popup-content {
    max-width: 260px;
  }

  .map-readout {
    left: 8px;
    right: 8px;
    bottom: 10px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 8px;
    padding: 8px 10px;
  }

  .readout-block {
    min-width: 0;
    gap: 0;
  }

  .readout-label {
    font-size: 7.5px;
    letter-spacing: 0.08em;
  }

  .readout-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10.5px;
  }

  .intro-card {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-width: none;
    max-height: 42vh;
    padding: 14px 42px 14px 16px;
    overflow-y: auto;
  }

  .intro-card h3 {
    font-size: 16px;
  }

  .intro-card p {
    font-size: 12.5px;
  }

  .detail-panel,
  .data-status-panel,
  .field-notes-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: none;
    max-height: 62vh;
    border-radius: 6px 6px 0 0;
    border-left: none;
    border-right: none;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.20);
  }

  .detail-close,
  .ds-panel-close,
  .field-notes-close,
  .intro-close {
    width: 42px;
    height: 42px;
    font-size: 20px;
  }

  .detail-close,
  .ds-panel-close,
  .field-notes-close {
    top: 9px;
    right: 9px;
  }

  .detail-eyebrow,
  .detail-coords,
  .field-notes-eyebrow,
  .data-status-panel h3,
  .field-notes-panel h3,
  .ds-panel-intro {
    padding-right: 48px;
  }

  .detail-action {
    width: 100%;
    min-height: 42px;
  }

  .data-status-panel,
  .field-notes-panel {
    padding: 18px 18px 20px;
  }

  .ds-list li {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .ds-list .ds-source {
    flex-basis: calc(100% - 64px);
    overflow-wrap: anywhere;
  }

  .ds-list .ds-detail {
    flex: 1 1 100%;
    max-width: none;
    margin-left: 56px;
    padding-left: 0;
    text-align: left;
    white-space: nowrap;
  }

  .event-modal {
    padding: 10px;
  }

  .event-modal-card {
    width: 100%;
    max-height: 92vh;
    padding: 22px 20px 24px;
  }

  .event-modal-content .em-headline {
    font-size: 24px;
  }

  .intro-card:not(.dismissed) ~ .map-readout,
  .detail-panel:not([hidden]) ~ .map-readout,
  .data-status-panel:not([hidden]) ~ .map-readout,
  .field-notes-panel:not([hidden]) ~ .map-readout {
    display: none;
  }

  .floating-legend {
    top: 116px;
    right: 12px;
    bottom: auto;
    width: min(230px, calc(100vw - 24px));
    padding: 10px 11px 9px;
  }

  .fl-title {
    font-size: 14px;
  }

  .fl-note {
    display: none;
  }

  .intro-card:not(.dismissed) ~ .floating-legend,
  .detail-panel:not([hidden]) ~ .floating-legend,
  .data-status-panel:not([hidden]) ~ .floating-legend,
  .field-notes-panel:not([hidden]) ~ .floating-legend {
    display: none;
  }
}

@media (max-width: 430px) {
  .brand-title {
    font-size: 18px;
  }

  .data-status-btn {
    max-width: 112px;
    font-size: 8.5px;
  }

  .sidebar {
    width: min(92vw, 370px);
  }

  .guide-me-btn {
    gap: 5px;
    padding: 0 10px;
  }
}

/* Respect reduced-motion preference — disable pulsing + decorative
 * animations for users with vestibular sensitivities. The warning
 * remains visible; it just doesn't oscillate. */
@media (prefers-reduced-motion: reduce) {
  .warning-banner,
  .guide-me-arrow,
  .sidebar,
  .event-modal-card,
  .detail-panel {
    animation: none !important;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}
