/* ---------- 1. Settings: change these to restyle the map ---------- */
.blm {
  /* Brand */
  --blm-bg: #FAFBF6;        /* page cream; also the sea */
  --blm-ink: #001362;       /* navy: text, outlines */
  --blm-accent: #1B30D9;    /* links, focus ring */
  --blm-muted: #6B6B6B;     /* secondary text */
  --blm-rule: #D9D9D2;      /* hairlines */
  --blm-land: #E4E5DD;      /* land that is not a priority basin */
  --blm-serif: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  --blm-sans: Inter, "Helvetica Neue", Arial, sans-serif;
  /* Water stress classes, low to extremely high. Ordered light to dark so the
     order still reads without colour vision. The Water Action Hub's own colours,
     if a closer match to WRI's maps is wanted:
     #FFFF88, #FEE60C, #FD870A, #FC0008, #850003, arid #6D6D6D. */
  --blm-c1: #F4E6A2;
  --blm-c2: #EEC04C;
  --blm-c3: #E58A2F;
  --blm-c4: #CC3F27;
  --blm-c5: #7A0F12;
  --blm-arid: #A2A29A;      /* Arid and low water use */
  --blm-other: #CDCDC5;     /* no data */
}

/* ---------- 2. Layout and type ---------- */
.blm { box-sizing: border-box; margin: 0 auto; max-width: 80rem; padding: clamp(2rem, 5vw, 4.5rem) clamp(1rem, 4vw, 2.5rem); background: var(--blm-bg); color: var(--blm-ink); font-family: var(--blm-sans); font-size: 1rem; line-height: 1.5; }
.blm *, .blm *::before, .blm *::after { box-sizing: inherit; }
.blm-eyebrow { margin: 0 0 .5rem; font-size: .8125rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--blm-accent); }
.blm-title { margin: 0 0 .75rem; max-width: 22ch; font-family: var(--blm-serif); font-weight: 600; font-size: clamp(1.75rem, 3.6vw, 2.75rem); line-height: 1.1; }
.blm-lead { margin: 0 0 1.75rem; max-width: 62ch; font-size: 1.0625rem; }
.blm a { color: var(--blm-accent); text-underline-position: from-font; }
.blm :focus-visible { outline: 2px solid var(--blm-accent); }
.blm-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- 3. Controls (shown once the script is running) ---------- */
.blm-controls { display: none; }
.blm-js .blm-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem 1.5rem; margin: 0 0 .75rem; }
.blm-field-wide { flex: 1 0 100%; }
.blm-field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.blm-label, .blm-field > legend { padding: 0; font-size: .8125rem; font-weight: 600; }
.blm-field > legend { margin-bottom: .25rem; }
.blm-chips { display: flex; flex-wrap: wrap; gap: .375rem; }
.blm-chip { position: relative; }
.blm-chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.blm-chip span { display: inline-flex; align-items: center; gap: .4rem; min-height: 2.25rem; padding: .25rem .625rem; border: 1px solid var(--blm-ink); background: var(--blm-bg); font-size: .875rem; line-height: 1.2; }
.blm-chip b { font-weight: 600; }
.blm-chip input:checked + span { background: var(--blm-ink); color: var(--blm-bg); }
.blm-chip input:focus-visible + span { outline: 2px solid var(--blm-accent); }
.blm-chip input:hover + span { border-color: var(--blm-accent); }
.blm-select { min-height: 2.25rem; max-width: 100%; padding: .25rem .5rem; border: 1px solid var(--blm-ink); border-radius: 0; background: var(--blm-bg); color: var(--blm-ink); font: inherit; font-size: .875rem; }
.blm-status { display: none; margin: 0 0 .75rem; font-size: .8125rem; color: var(--blm-muted); }
.blm-js .blm-status { display: block; }

/* Colour keys */
.blm-sw { display: inline-block; flex: none; width: .75rem; height: .75rem; border: 1px solid var(--blm-ink); vertical-align: -.0625rem; }
.blm-sw.blm-c1 { background: var(--blm-c1); } .blm-sw.blm-c2 { background: var(--blm-c2); } .blm-sw.blm-c3 { background: var(--blm-c3); }
.blm-sw.blm-c4 { background: var(--blm-c4); } .blm-sw.blm-c5 { background: var(--blm-c5); }
.blm-sw.blm-arid { background: var(--blm-arid); } .blm-sw.blm-other { background: var(--blm-other); }
.blm-chip input:checked + span .blm-sw { border-color: var(--blm-bg); }

/* ---------- 4. Map ---------- */
.blm-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
.blm-stage { position: relative; aspect-ratio: 4 / 3; border: 1px solid var(--blm-rule); background: var(--blm-bg); overflow: hidden; }
.blm-svg { display: block; width: 100%; height: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.blm-js .blm-svg { cursor: grab; }
.blm-svg.is-dragging { cursor: grabbing; }
.blm-land { fill: var(--blm-land); stroke: none; }
.blm-basin, .blm-dot { stroke: var(--blm-bg); stroke-width: .8px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.blm-js .blm-basin, .blm-js .blm-dot { cursor: pointer; }
svg .blm-c1 { fill: var(--blm-c1); } svg .blm-c2 { fill: var(--blm-c2); } svg .blm-c3 { fill: var(--blm-c3); }
svg .blm-c4 { fill: var(--blm-c4); } svg .blm-c5 { fill: var(--blm-c5); }
svg .blm-arid { fill: var(--blm-arid); } svg .blm-other { fill: var(--blm-other); }
.blm-hatchline { fill: none; stroke: var(--blm-bg); stroke-width: 2.4; stroke-linecap: square; }
.blm-hatch .blm-hatchline { stroke-width: 5; }
.blm-basin.is-hover, .blm-dot.is-hover { stroke: var(--blm-ink); stroke-width: 1.4px; }
.blm-basin.is-selected, .blm-dot.is-selected { stroke: var(--blm-ink); stroke-width: 2.4px; }
.blm-basin.is-dim, .blm-dot.is-dim { fill-opacity: .1; stroke-opacity: .25; pointer-events: none; }
.blm-dot { display: none; stroke: var(--blm-ink); stroke-width: 1px; }
.blm-dot.is-small { display: inline; }
.blm-hit { fill: none; stroke: none; pointer-events: all; cursor: pointer; display: none; }
.blm-hit.is-small { display: inline; }
.blm-hit.is-dim { pointer-events: none; }

.blm-zoom { display: none; }
.blm-js .blm-zoom { position: absolute; top: .5rem; right: .5rem; display: flex; flex-direction: column; }
.blm-btn { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; margin: 0 0 -1px; padding: 0; border: 1px solid var(--blm-ink); border-radius: 0; background: var(--blm-bg); color: var(--blm-ink); cursor: pointer; }
.blm-btn:hover { background: var(--blm-ink); color: var(--blm-bg); }
.blm-btn[disabled] { color: var(--blm-rule); border-color: var(--blm-rule); background: var(--blm-bg); cursor: default; }
.blm-btn svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: square; }
.blm-gesture { display: none; }
@media (hover: none) and (pointer: coarse) { .blm-js .blm-gesture { display: block; position: absolute; left: .5rem; bottom: .5rem; margin: 0; padding: .125rem .375rem; background: var(--blm-bg); font-size: .75rem; color: var(--blm-muted); } }

.blm-tip { position: absolute; z-index: 2; left: 0; top: 0; max-width: 16rem; padding: .375rem .5rem; border: 1px solid var(--blm-ink); background: var(--blm-bg); font-size: .8125rem; line-height: 1.3; pointer-events: none; }
.blm-tip[hidden] { display: none; }
.blm-tip strong { display: block; font-weight: 600; }

/* ---------- 5. Detail panel ---------- */
.blm-panel { display: none; }
.blm-js .blm-panel { display: block; min-width: 0; padding: 1rem 0 0; border-top: 1px solid var(--blm-ink); }
.blm-panel:focus { outline: none; }
.blm-p-region { margin: 0 0 .25rem; font-size: .8125rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--blm-muted); }
.blm-p-official { margin: -.5rem 0 .75rem; font-size: .8125rem; color: var(--blm-muted); }
.blm-p-name { margin: 0 0 .75rem; font-family: var(--blm-serif); font-weight: 600; font-size: 1.5rem; line-height: 1.15; }
.blm-p-cond { display: flex; align-items: center; gap: .5rem; margin: 0 0 .25rem; font-weight: 600; }
.blm-p-cond .blm-sw { width: 1rem; height: 1rem; }
.blm-p-text { margin: 0 0 .5rem; font-size: .9375rem; }
.blm-p-mix { display: block; width: 100%; height: .75rem; margin: .875rem 0 .5rem; border: 1px solid var(--blm-ink); }
.blm-p-key { display: grid; grid-template-columns: auto 1fr auto; gap: .125rem .5rem; align-items: center; margin: 0 0 1rem; padding: 0; list-style: none; font-size: .8125rem; }
.blm-p-key li { display: contents; }
.blm-p-key .blm-num { text-align: right; font-variant-numeric: tabular-nums; }
.blm-p-facts { margin: 0 0 1rem; padding: .75rem 0 0; border-top: 1px solid var(--blm-rule); font-size: .875rem; }
.blm-p-facts dt { margin: 0; font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--blm-muted); }
.blm-p-facts dd { margin: 0 0 .625rem; }
.blm-p-actions { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; font-size: .875rem; }
.blm-link-btn { min-height: 1.5rem; padding: 0; border: 0; background: none; color: var(--blm-accent); font: inherit; text-decoration: underline; text-underline-position: from-font; cursor: pointer; }
.blm-hint { margin: 0 0 .5rem; font-family: var(--blm-serif); font-size: 1.25rem; line-height: 1.25; }

/* ---------- 6. Notes and table ---------- */
.blm-more { margin: 1.5rem 0 0; border-top: 1px solid var(--blm-rule); }
.blm-more > summary { padding: .75rem 0; font-weight: 600; cursor: pointer; }
.blm-more + .blm-more { margin-top: 0; }
.blm-notes { margin: 0 0 1rem; padding: 0 0 0 1.125rem; max-width: 72ch; font-size: .9375rem; }
.blm-notes li { margin: 0 0 .5rem; }
.blm-scroll { position: relative; overflow-x: auto; margin: 0 0 1rem; }
.blm-table { width: 100%; min-width: 46rem; border-collapse: collapse; font-size: .875rem; }
.blm-table caption { text-align: left; padding: 0 0 .5rem; color: var(--blm-muted); }
.blm-table th, .blm-table td { padding: .375rem .75rem .375rem 0; border-bottom: 1px solid var(--blm-rule); text-align: left; vertical-align: top; font-weight: 400; }
.blm-table thead th { border-bottom-color: var(--blm-ink); font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.blm-table tbody th { font-weight: 600; }
.blm-table .blm-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.blm-table td.blm-cond { white-space: nowrap; }
.blm-table tr[hidden] { display: none; }
.blm-source { margin: 1rem 0 0; max-width: 80ch; font-size: .8125rem; color: var(--blm-muted); }

/* ---------- 7. Wider screens ---------- */
@media (min-width: 44rem) { .blm-stage { aspect-ratio: 2 / 1; } }
@media (min-width: 62rem) {
  .blm-js .blm-body { grid-template-columns: minmax(0, 1fr) 19rem; gap: 2rem; align-items: start; }
  .blm-stage { aspect-ratio: 3600 / 1900; }
  .blm-js .blm-panel { padding-top: .875rem; }
}
@media (prefers-reduced-motion: reduce) { .blm * { scroll-behavior: auto; } }
@media print { .blm-controls, .blm-zoom, .blm-status, .blm-gesture { display: none; } .blm-more > * { display: block; } }

/* ---------- 8. Legend under the map ---------- */
.blm-mapcol { min-width: 0; }
.blm-legend { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin: .75rem 0 0; padding: 0; list-style: none; font-size: .8125rem; }
.blm-legend li { display: inline-flex; align-items: center; gap: .375rem; }
.blm-sw-hatch { padding: 0; }
