:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --accent: #0071e3; --accent-soft: rgba(0, 113, 227, .12); --on-accent: #fff;
  --card: rgba(255, 255, 255, .86); --card-solid: #fff; --seg-on: #fff;
  --text: #0f172a; --text-2: #3c4757; --text-3: #5b6676;
  --line: rgba(15, 23, 42, .09); --fill: rgba(15, 23, 42, .05); --fill-2: rgba(15, 23, 42, .1);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .08), 0 18px 40px rgba(15, 23, 42, .12);
  --r: 16px; --pw: 392px; --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #4da3ff; --accent-soft: rgba(77, 163, 255, .16); --on-accent: #06192e;
    --card: rgba(23, 25, 31, .84); --card-solid: #1b1e25; --seg-on: rgba(255, 255, 255, .14);
    --text: #f2f4f7; --text-2: #c9d0da; --text-3: #9ba5b3;
    --line: rgba(255, 255, 255, .09); --fill: rgba(255, 255, 255, .06); --fill-2: rgba(255, 255, 255, .13);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35), 0 24px 56px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font: 14px/1.45 var(--font); background: #0b0f14; color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.i { width: 18px; height: 18px; flex: none; display: block; }
.card { background: var(--card); -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
#map { position: absolute; inset: 0; }
.maplibregl-map { font-family: var(--font); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card-solid); font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s, transform .15s; }
.btn:hover { background: var(--fill); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { height: 32px; padding: 0 12px; }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 10px; background: none; color: var(--text-2); cursor: pointer; flex: none; transition: background .15s; }
.icon-btn:hover { background: var(--fill); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#topleft { position: fixed; top: 16px; left: 16px; width: 340px; z-index: 4; display: flex; flex-direction: column; gap: 8px; }
#search { overflow: hidden; }
#search:focus-within { box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
.sbox { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 14px; color: var(--text-3); }
#q { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 15px; color: var(--text); }
#q::placeholder { color: var(--text-3); }
#results { list-style: none; margin: 0; padding: 4px 6px 6px; border-top: 1px solid var(--line); max-height: 336px; overflow-y: auto; }
#results li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
#results li[aria-selected=true] { background: var(--accent-soft); }
#results li > span:first-child { flex: 1; min-width: 0; }
#results b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#results small { color: var(--text-3); font-size: 12px; }
#results .empty { color: var(--text-3); cursor: default; }
.pct { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
#results .gh { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); padding: 8px 10px 2px; cursor: default; }
.shead { display: flex; align-items: center; gap: 8px; padding: 12px 12px 0 16px; }
.shead h2 { flex: 1; margin: 0; font-size: 15.5px; white-space: nowrap; font-weight: 700; letter-spacing: -.01em; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 999px; border: 0; background: var(--accent-soft);
  color: var(--accent); font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip .i { width: 16px; height: 16px; }
.chip:hover { filter: brightness(1.1); }
#regions { display: flex; flex-wrap: wrap; gap: 6px; }
#regions .chip { background: var(--card-solid); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--line); }
body.drawing #regions, body.story #regions { display: none; }
.isl-l { margin: 4px 0 0; padding-left: 16px; font-size: 12.5px; line-height: 1.45; }
.isl-l li { margin: 0 0 6px; }
.isl-l small { display: block; color: var(--text-3); }
.serr { margin: 0; padding: 0 16px 12px; font-size: 12.5px; color: #c2410c; }
#topleft { max-height: calc(100vh - 32px); width: 360px; }
#search, #brand { flex: none; }
#place { overflow-y: auto; min-height: 0; padding: 16px; overscroll-behavior: contain; }
#place header { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
#place header > div { flex: 1; min-width: 0; }
#place header b { display: block; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.vbig { display: flex; gap: 12px; align-items: flex-start; }
.badge { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; }
.badge .i { width: 22px; height: 22px; }
.vbig b { display: block; font-size: 17px; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; }
.vbig small { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.lead { font-size: 13px; color: var(--text-2); margin: 12px 0 0; }
.lead b { color: var(--text); }
.sec { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.sec h4 { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.sec h4 .upd { margin-left: auto; font-weight: 400; font-size: 11.5px; color: var(--text-3); }
.depth { display: flex; align-items: baseline; gap: 8px; }
.summary { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--fill); font-size: 13px; font-weight: 500; }
.lvlpill { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.fstats { display: flex; gap: 16px; margin-top: 8px; }
.spark { width: 100%; height: 64px; display: block; margin-top: 10px; }
.spark rect { fill: var(--accent); }
.spark text { fill: var(--text-3); font-size: 9px; font-family: var(--font); }
.spark line { stroke: var(--line); }
.btn.wide { width: 100%; text-decoration: none; margin-top: 4px; }
.links { list-style: none; padding: 0; margin: 8px 0 0; }
.links li + li { margin-top: 6px; }
.links a { color: var(--accent); font-weight: 500; font-size: 13px; text-decoration: none; }
.links a:hover { text-decoration: underline; }
.q { display: inline-grid; place-items: center; width: 17px; height: 17px; padding: 0; margin-left: 4px; border-radius: 50%; border: 0; vertical-align: 1px;
  background: var(--fill-2); color: var(--text-2); font-size: 11px; font-weight: 700; line-height: 1; cursor: help; }
.q:hover, .q:focus-visible { background: var(--accent); color: var(--on-accent); }
#tipbox { position: fixed; z-index: 10; max-width: 260px; padding: 10px 12px; border-radius: 12px; background: var(--card-solid); color: var(--text); box-shadow: var(--shadow);
  border: 1px solid var(--line); font-size: 12.5px; line-height: 1.45; pointer-events: none; }
#brand { align-self: flex-start; padding: 10px 14px; }
#brand h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
#brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-3); }

#drawbar { position: fixed; top: 16px; left: 392px; right: calc(var(--pw) + 68px); z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 14px; font-size: 13px; color: var(--text-2); }
#drawbar > span:nth-child(2) { flex: 1; }
#dbanner { position: fixed; top: 16px; left: 392px; right: calc(var(--pw) + 68px); z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 14px; font-size: 13px; border-left: 6px solid var(--lvl, #f28c28); }
#dbanner { flex-wrap: wrap; }
#dbanner p { flex: 1 1 220px; min-width: 0; margin: 0; font-size: 12.5px; line-height: 1.4; }
#dbanner > .i { color: var(--lvl); flex: none; }
#dbanner .btn { flex: none; text-decoration: none; }
body.drawing #dbanner { display: none; }
.dleg { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.dleg span { display: inline-flex; align-items: center; gap: 6px; }
.dleg i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.dleg .hot { background: #6a00a8; outline: 2px solid #c56cf0; outline-offset: -2px; }
.dstat { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--text-3); }
.dstat span { flex: 1; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.tools .btn { padding: 0 6px; gap: 6px; font-size: 12.5px; }

#panel { position: fixed; top: 16px; right: 16px; bottom: 16px; width: 360px; z-index: 4; display: flex; flex-direction: column; overflow: hidden;
  transition: transform .25s var(--ease), opacity .2s, visibility 0s; }
body.collapsed #panel { transform: translateX(calc(100% + 24px)); opacity: 0; visibility: hidden; transition: transform .25s var(--ease), opacity .2s, visibility 0s .25s; }
#handle { display: none; }
.ph { display: flex; align-items: center; gap: 4px; padding: 12px 10px 8px 12px; flex: none; }
#tabs { flex: 1; display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--fill); }
#tabs button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px; border: 0; border-radius: 9px;
  background: none; color: var(--text-3); font-size: 11.5px; font-weight: 500; cursor: pointer; transition: background .15s, color .15s; }
#tabs button:hover { color: var(--text); }
/* Width follows the label (Embalses/Análisis are the longest), so labels never spill into the next tab */
#tabs button { flex: 1 1 auto; }
#tabs button > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tabs button.on { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
#lang { font-size: 12px; font-weight: 600; }
#panel section { flex: 1; overflow-y: auto; padding: 4px 16px 24px; overscroll-behavior: contain; }
#panel h3 { margin: 20px 0 8px; font-size: 13px; font-weight: 600; }
.group { background: var(--fill); border-radius: 12px; padding: 4px; }
.tg { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 12px; padding: 10px 10px; border-radius: 10px; cursor: pointer; }
.tg + .tg { border-top: 1px solid var(--line); border-radius: 0; }
.tx b { display: block; font-weight: 500; font-size: 13.5px; }
.tx small { color: var(--text-3); font-size: 12px; }
.sw { appearance: none; -webkit-appearance: none; margin: 0; width: 38px; height: 22px; border-radius: 11px; background: var(--fill-2); position: relative; cursor: pointer; transition: background .2s; }
.sw::before { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s var(--ease); }
.sw:checked { background: var(--accent); }
.sw:checked::before { transform: translateX(16px); }
.sl { padding: 8px 10px 10px; border-top: 1px solid var(--line); }
.frow { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
output { font-variant-numeric: tabular-nums; color: var(--text-3); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 2px; margin: 8px 0; cursor: pointer;
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--p, 50%) 100% no-repeat, var(--fill-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.scale { display: flex; height: 8px; border-radius: 4px; overflow: hidden; }
.scale span { flex: 1; }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stale { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); margin-top: 8px; }

.note { margin: 12px 0; font-size: 12.5px; color: var(--text-2); }
.callout { display: flex; gap: 10px; padding: 12px; border-radius: 12px; background: var(--accent-soft); color: var(--text-2); font-size: 12.5px; margin-top: 8px; }
.callout p { margin: 0; }
.callout .i { color: var(--accent); }
.warn { padding: 10px 12px; border-radius: 12px; background: rgba(242, 140, 40, .14); }
.warn b { font-weight: 500; }
.field { padding: 10px; }
.field + .field { border-top: 1px solid var(--line); }
.flabel { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.range-row { display: flex; align-items: center; gap: 12px; }
.num { width: 72px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-solid); text-align: right; padding: 0 10px; font-variant-numeric: tabular-nums; }
.unit { color: var(--text-3); font-size: 12.5px; margin-left: -6px; }
.seg { display: flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--fill); }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: block; text-align: center; padding: 6px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--text-2); cursor: pointer; transition: background .15s; }
.seg input:checked + span { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
select { width: 100%; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-solid) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right 10px center / 16px no-repeat;
  appearance: none; -webkit-appearance: none; padding: 0 32px 0 10px; font-size: 13px; }
#rain-out { margin: 12px 0; padding: 14px 16px; border-radius: 14px; transition: background .2s; }
.lvl { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.lvl-sub { font-size: 12px; opacity: .85; margin-top: 2px; font-variant-numeric: tabular-nums; }

.basin { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; width: 100%; text-align: left; padding: 10px 10px; border: 0; border-radius: 10px; background: none; cursor: pointer; font-size: 13px; }
.basin:hover { background: var(--fill); }
.basin b { font-weight: 500; }
.basin .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--fill-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.basin small, .bhead { grid-column: 1 / -1; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.bhead { display: flex; justify-content: space-between; padding: 0 10px 4px; }
.basin.total { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; }
.basin.total b { font-weight: 700; }

#sources { list-style: none; padding: 0; margin: 8px 0 0; }
#sources li { padding: 12px; border-radius: 12px; background: var(--fill); margin-bottom: 8px; font-size: 12.5px; color: var(--text-2); }
#sources a { color: var(--accent); font-weight: 600; text-decoration: none; font-size: 13px; }
#sources a:hover { text-decoration: underline; }
#sources small { display: block; color: var(--text-3); margin-top: 4px; font-size: 11.5px; }
#method { padding-left: 18px; margin: 4px 0; font-size: 12.5px; color: var(--text-2); }
#method li { margin-bottom: 6px; }

.rfilters { display: grid; gap: 8px; margin-top: 8px; }
.field-s { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-solid); color: var(--text-3); }
.field-s input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 13.5px; color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rlist { list-style: none; padding: 0; margin: 8px 0 0; }
.res { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; width: 100%; text-align: left; padding: 10px; border: 0; border-radius: 10px; background: none; cursor: pointer; font-size: 13px; }
.res:hover { background: var(--fill); }
.res b { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.res .r2, .res .r3 { grid-column: 1 / -1; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.res .r3 { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.res .bar { grid-column: 1 / -1; }
.old { color: #b45309; }
.tag.low { background: #fde2e1; color: #9f1239; }
.tag.alert { background: #6a00a8; color: #fff; }
.drw { display: flex; align-items: center; gap: 8px; font-size: 13px; }
#viewpop { position: fixed; z-index: 7; width: 228px; padding: 12px; }
.vp-h { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.vp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.vp-b { display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--card-solid); font-size: 12px; font-weight: 500; cursor: pointer; }
.vp-b i { height: 34px; border-radius: 6px; display: block; }
.vp-b.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.vp-src { font-size: 10.5px; color: var(--text-3); margin-top: 8px; }
#basin-chip { align-self: flex-start; display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; }
#basin-chip small { display: block; font-size: 11px; color: var(--text-3); line-height: 1.1; }
#basin-chip b { font-size: 13.5px; }
.def .bar { position: relative; overflow: visible; }
.def .bar s { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--text); margin-left: -1px; }
.rlist li + li { border-top: 1px solid var(--line); }
#tabs button { font-size: 11px; padding: 6px 1px 5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.zone { padding: 12px; border-radius: 14px; background: var(--fill); margin-top: 12px; cursor: pointer; transition: background .15s; }
.zone:hover { background: var(--fill-2); }
.zone header { display: flex; align-items: center; gap: 4px; margin: -4px -4px 4px 0; }
.zname { flex: 1; min-width: 0; border: 1px solid transparent; border-radius: 8px; background: none; padding: 4px 6px; margin-left: -6px; font-size: 14px; font-weight: 600; }
.zname:hover, .zname:focus { border-color: var(--line); background: var(--card-solid); outline: none; }
.zrows { list-style: none; padding: 0; margin: 10px 0 0; }
.zrows li { display: grid; grid-template-columns: 10px 1fr auto; gap: 4px 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.zrows li + li { border-top: 1px solid var(--line); }
.zrows .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.zrows .bar, .zrows .zsub { grid-column: 2 / -1; }
.zsub { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.busy { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12.5px; margin: 8px 0; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--fill-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; }
.big small { font-size: 15px; font-weight: 500; color: var(--text-2); margin-left: -4px; }
.big .dot { width: 12px; height: 12px; }
.lbl { font-size: 12.5px; color: var(--text-2); }
.lbl small { color: var(--text-3); }
.src { font-size: 11px; color: var(--text-3); margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.tag { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--fill-2); color: var(--text-2); }

.maplibregl-popup-content { max-height: min(56vh, 520px); overflow-y: auto; background: var(--card-solid); color: var(--text); border-radius: 16px; padding: 16px 18px 12px; box-shadow: var(--shadow); font: 13px/1.45 var(--font); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip, .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip, .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--card-solid); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip, .maplibregl-popup-anchor-top-left .maplibregl-popup-tip, .maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--card-solid); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--card-solid); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--card-solid); }
.maplibregl-popup-close-button { top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 8px; font-size: 18px; color: var(--text-3); }
.maplibregl-popup-close-button:hover { background: var(--fill); }
.pk { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; padding-right: 24px; }
.pt { font-size: 16px; font-weight: 600; margin: 0 24px 8px 0; letter-spacing: -.01em; }
.meta { font-size: 12.5px; color: var(--text-2); margin-top: 8px; font-variant-numeric: tabular-nums; }
.verdict { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 6px; padding: 8px 10px; border-radius: 10px; background: var(--fill); font-weight: 600; }
.verdict .dot { margin-top: 4px; }
.verdict small { display: block; font-weight: 400; color: var(--text-3); }
.zones { list-style: none; padding: 0; margin: 0; }
.zones li { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-size: 12.5px; }
.zones li > span:not(.dot) { flex: 1; }
.zones small { color: var(--text-3); }
.zones b { font-weight: 500; font-variant-numeric: tabular-nums; }

#chart { position: fixed; left: 16px; bottom: calc(56px + var(--tl-h, 68px)); right: calc(var(--pw) + 16px); max-width: 760px; padding: 14px 16px 10px; z-index: 3; }
#chart header { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
#chart header > div:first-child { flex: 1; min-width: 160px; }
#chart-title { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
#chart-sub { color: var(--text-3); font-size: 12px; }
#chart-stats { display: flex; gap: 16px; }
.stat small { display: block; font-size: 11px; color: var(--text-3); }
.stat b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.now b { color: var(--accent); }
#chart-close { margin: -4px -6px 0 0; }
.cwrap { position: relative; margin-top: 8px; }
#chart-svg { width: 100%; height: 150px; display: block; touch-action: none; }
#chart-svg text { fill: var(--text-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
#chart-svg .grid { stroke: var(--line); }
#chart-svg .line { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; }
#chart-svg .cur { fill: var(--accent); stroke: var(--card-solid); stroke-width: 2; }
#chart-svg .halo { fill: var(--accent); opacity: .2; }
#chart-svg .xh { stroke: var(--text-3); stroke-dasharray: 3 3; }
#chart-tip { position: absolute; top: 0; pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap; padding: 6px 10px; border-radius: 8px;
  background: var(--card-solid); box-shadow: var(--shadow); font-size: 12px; font-variant-numeric: tabular-nums; }
#chart-tip span { color: var(--text-3); margin-left: 6px; }
#chart-src { display: block; font-size: 11px; color: var(--text-3); margin-top: 2px; }

#timeline { position: fixed; left: 16px; right: calc(var(--pw) + 16px); bottom: 48px; z-index: 3; display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
#timeline .seg span { padding: 4px 8px; font-size: 12px; }
#tl-play { width: 36px; height: 36px; border-radius: 50%; padding: 0; flex: none; }
#tl-speed { width: auto; height: 30px; font-size: 12px; padding: 0 26px 0 8px; flex: none; }
#tl-date { flex: none; width: 150px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
#tl-date small { display: block; font-size: 10.5px; line-height: 1.25; font-weight: 400; color: var(--text-3); }
#tl-track { flex: 1; min-width: 160px; display: flex; align-items: center; gap: 6px; }
#tl-range-wrap { flex: 1; position: relative; padding-bottom: 14px; }
#tl-range { margin: 6px 0 0; background: linear-gradient(90deg, var(--accent) 0 var(--hist), transparent var(--hist)),
  repeating-linear-gradient(90deg, var(--text-3) 0 4px, transparent 4px 8px) var(--hist) 0 / calc(100% - var(--hist)) 100% no-repeat, var(--fill-2); }
#tl-ticks { position: absolute; left: 0; right: 0; bottom: 0; height: 12px; font-size: 10px; color: var(--text-3); font-variant-numeric: tabular-nums; }
#tl-ticks i { position: absolute; top: -3px; width: 1px; height: 4px; background: var(--text-3); }
#tl-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
#tl-year { flex: none; width: 64px; height: 26px; padding: 0 6px; border-radius: 8px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
#tl-scen, #tl-rcp { flex: none; }
/* Below ~1800 px the controls leave the track too short for decade labels, so it takes its own row (cards above it follow --tl-h) */
@media (min-width: 761px) and (max-width: 1799px) {
  #timeline { flex-wrap: wrap; row-gap: 2px; }
  #tl-track { order: 9; flex-basis: 100%; }
  #tl-date { flex: 1; width: auto; min-width: 150px; }
}
#scen-badge { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 5; padding: 6px 14px; border-radius: 999px; background: #6a00a8; color: #fff;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; box-shadow: var(--shadow); pointer-events: none; text-align: center; }
#scen-badge small { display: block; font-weight: 500; letter-spacing: 0; font-size: 11px; opacity: .9; }
body.drawing #scen-badge { display: none; }
#chart-svg .band { fill: #6a00a8; opacity: .16; }
#chart-svg .fut { fill: none; stroke: #6a00a8; stroke-width: 1.75; stroke-dasharray: 5 4; }
#chart-svg .hz { fill: none; stroke: #c2410c; stroke-width: 1.75; stroke-dasharray: 2 3; }
#chart-svg .tlc { stroke: #6a00a8; stroke-width: 1.5; }
#coords { position: fixed; left: 16px; bottom: 16px; z-index: 2; padding: 5px 12px; border-radius: 999px; font-size: 11.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
#coords:empty { display: none; }
#panel-btn { position: fixed; top: 16px; right: 16px; z-index: 4; width: 44px; height: 44px; display: none; place-items: center; cursor: pointer; color: var(--text); }
body.collapsed #panel-btn { display: grid; }

.maplibregl-ctrl-top-right { top: 16px; right: var(--pw); transition: right .25s var(--ease); }
.maplibregl-ctrl-bottom-right { right: var(--pw); transition: right .25s var(--ease); }
body.collapsed { --pw: 0px; }
body.collapsed .maplibregl-ctrl-top-right { top: 68px; }
.maplibregl-ctrl-top-right .maplibregl-ctrl { margin: 0 16px 8px 0; }
.maplibregl-ctrl-group { border-radius: 12px !important; background: var(--card-solid) !important; box-shadow: var(--shadow) !important; overflow: hidden; }
.maplibregl-ctrl-group button { width: 36px; height: 36px; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group .home { display: grid; place-items: center; color: var(--text); }
.maplibregl-ctrl-attrib { background: var(--card) !important; color: var(--text-3); border-radius: 8px; font-size: 11px; }
.maplibregl-ctrl-attrib a { color: var(--text-2); }
.maplibregl-ctrl-scale { background: var(--card); border-color: var(--text-3); color: var(--text-2); font-size: 10.5px; }
@media (prefers-color-scheme: dark) {
  .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) hue-rotate(180deg); }
  .maplibregl-ctrl-attrib-button { filter: invert(1); }
}

/* Before/after comparator */
#cmp.maplibregl-map { position: absolute; inset: 0; pointer-events: none; }
#cmp-handle { position: fixed; top: 0; bottom: 0; width: 24px; margin-left: -12px; z-index: 2; cursor: ew-resize; touch-action: none; display: grid; place-items: center; }
#cmp-handle::before { content: ''; position: absolute; top: 0; bottom: 0; left: 11px; width: 2px; background: #fff; box-shadow: 0 0 6px rgba(0, 0, 0, .5); }
#cmp-handle span { position: relative; width: 34px; height: 34px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); }
#cmp-handle span::before { content: '‹ ›'; position: absolute; inset: 0; display: grid; place-items: center; color: #111; font-weight: 700; font-size: 15px; letter-spacing: 2px; }
#cmp-handle.drag span, #cmp-handle:focus-visible span { outline: 3px solid var(--accent); }
/* Just above the timeline: the top band holds the search card, warnings banner and draw bar; bottom cards (z 3) may cover them */
#cmp-labels { position: fixed; bottom: calc(48px + var(--tl-h, 68px)); left: 16px; right: calc(var(--pw) + 16px); z-index: 2; align-items: flex-end; display: flex; justify-content: space-between; gap: 12px; pointer-events: none; }
.cmp-lab { max-width: 48%; padding: 6px 10px; border-radius: 10px; background: var(--card); box-shadow: var(--shadow); font-size: 12px; pointer-events: auto; }
.cmp-lab.r { text-align: right; }
.cmp-lab b { display: block; }
.cmp-lab small { display: block; font-size: 10.5px; color: var(--text-3); line-height: 1.3; }
.cmp-lab a { color: var(--text-2); }
.flabel select { margin-top: 4px; }
#cmp-presets .btn { flex: 1 1 auto; }
/* Terrain profile */
#profile { position: fixed; left: 16px; bottom: calc(56px + var(--tl-h, 68px)); right: calc(var(--pw) + 16px); max-width: 760px; padding: 14px 16px 10px; z-index: 3; }
#profile header { display: flex; align-items: flex-start; gap: 16px; }
#profile header > div { flex: 1; min-width: 0; }
#profile-title { display: block; font-size: 15px; font-weight: 600; }
#profile-sub { color: var(--text-3); font-size: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
#profile-sub .dot { width: 8px; height: 8px; margin-left: 4px; }
#profile-svg { width: 100%; height: 160px; display: block; }
#profile-svg text { fill: var(--text-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
#profile-svg .grid { stroke: var(--line); }
#profile-svg .line { fill: none; stroke: var(--text); stroke-width: 1.75; stroke-linejoin: round; }
#profile-svg .pf-area { fill: var(--text-3); opacity: .22; }
#profile-svg .cur { fill: var(--accent); stroke: var(--card-solid); stroke-width: 2; }
#profile-svg .pf-low { fill: var(--accent); font-weight: 600; }
#profile-cap { margin: 4px 0 2px; font-size: 13px; font-weight: 600; }
#profile-src { display: block; font-size: 11px; color: var(--text-3); }
/* Stories */
.stories-box { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); }
.stories-box summary { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--accent); }
.stories-box summary b { color: var(--text); font-size: 13px; }
.stories-box .note { margin: 8px 0 0; }
.story-card { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left; padding: 12px 14px; margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-solid); cursor: pointer; }
.story-card:hover { border-color: var(--accent); }
.story-card small { color: var(--text-2); font-size: 12.5px; }
#story { position: fixed; top: 16px; left: 16px; width: 360px; max-height: calc(100vh - 200px); overflow-y: auto; z-index: 5; padding: 14px 16px 12px; }
body.story #topleft { display: none; }
/* The story card owns the left column, so the bottom cards start to its right */
body.story #profile, body.story #chart { left: 392px; }
#story header { display: flex; align-items: center; justify-content: space-between; }
#story h3 { margin: 4px 0 6px; font-size: 17px; letter-spacing: -.01em; }
#story p { margin: 0 0 8px; font-size: 13.5px; color: var(--text-2); }
.st-official { margin: -2px 0 10px; padding: 6px 10px; border-radius: 8px; border-left: 4px solid #c2410c; background: var(--fill); font-size: 12px; }
.st-official a { color: var(--accent); font-weight: 600; text-decoration: none; }
.st-src { margin: 4px 0 8px; padding: 8px 0 0 16px; border-top: 1px solid var(--line); font-size: 11px; color: var(--text-3); }
.st-src a { color: var(--text-2); }
#story footer { position: sticky; bottom: -12px; display: flex; align-items: center; gap: 8px; margin: 6px -16px -12px; padding: 8px 16px 12px; background: var(--card-solid); }
#story .dots { flex: 1; display: flex; justify-content: center; gap: 6px; }
#story .dots .dot { width: 9px; height: 9px; padding: 0; border: 0; background: var(--fill-2); cursor: pointer; }
#story .dots .dot.on { background: var(--accent); }
/* Historical floods popup, citation */
.cnih { list-style: none; margin: 6px 0; padding: 0; font-size: 12px; }
.cnih li { padding: 4px 0; border-top: 1px solid var(--line); }
.cnih small { display: block; color: var(--text-3); }
.cite { margin: 6px 0 8px; padding: 10px 12px; border-radius: 10px; background: var(--fill); font-size: 12.5px; user-select: all; }
#report { position: fixed; inset: 0; z-index: 20; overflow-y: auto; background: #e9ecef; color: #111; color-scheme: light; }
.rp-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: #fff; border-bottom: 1px solid #d0d5db; color: #111; }
.rp-bar > span { flex: 1; }
.rp-bar .btn { background: #fff; color: #111; border-color: #c9ced6; }
.rp-bar .btn.primary { background: #0071e3; color: #fff; }
.rp-page { width: min(210mm, calc(100% - 32px)); margin: 16px auto 48px; padding: 14mm; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .12); font-size: 12px; line-height: 1.45; }
.rp-page header small { color: #555; text-transform: uppercase; letter-spacing: .05em; font-size: 10.5px; }
.rp-page h1 { margin: 2px 0 4px; font-size: 22px; }
.rp-page h2 { margin: 0 0 6px; font-size: 14px; border-bottom: 1px solid #ddd; padding-bottom: 3px; }
.rp-page section { margin-top: 14px; break-inside: avoid; }
.rp-page p { margin: 4px 0; }
.rp-page a { color: #0058b0; }
.rp-page figure { margin: 12px 0 0; break-inside: avoid; }
.rp-page img { width: 100%; max-height: 120mm; object-fit: cover; border-radius: 4px; display: block; }
.rp-page figcaption, .rp-small { font-size: 10.5px; color: #555; }
.rp-page table { width: 100%; border-collapse: collapse; margin-top: 4px; font-variant-numeric: tabular-nums; }
.rp-page th, .rp-page td { text-align: left; padding: 3px 6px; border-bottom: 1px solid #e3e3e3; vertical-align: top; }
.rp-page th { font-weight: 600; background: #f4f5f7; }
.rp-page ul { margin: 4px 0; padding-left: 18px; }
.rp-src li { font-size: 10.5px; margin-bottom: 2px; }
.rp-official { padding: 8px 10px; border: 2px solid #c2410c; border-radius: 6px; background: #fff4ec; }
.rp-verdict { padding: 6px 10px; border-left: 5px solid #4f8a5b; background: #f4f5f7; }
.rp-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.rp-disc { color: #444; }
body.reporting > :not(#report) { visibility: hidden; }
@page { size: A4; margin: 12mm; }
@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  body > :not(#report) { display: none !important; }
  #report { position: static; overflow: visible; background: #fff; }
  .rp-bar { display: none; }
  .rp-page { width: auto; margin: 0; padding: 0; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; animation-iteration-count: 1 !important; }
}

/* "¿De dónde viene tu agua?" */
.sup-sys b { display: block; font-size: 14px; font-weight: 600; }
.sup-sys small { display: block; font-size: 12px; color: var(--text-3); }
.sup .lead { margin: 6px 0 4px; }
.sup-list { list-style: none; padding: 0; margin: 4px -10px; }
.sup-tot { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; padding: 8px 10px; border-radius: 10px; background: var(--fill); }
.sup-tot .big { font-size: 22px; }
.sup-tot small { font-size: 11.5px; color: var(--text-3); }
.sup-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.sup-chips span { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--text-2); }
.sup-cites small { display: block; font-size: 11px; color: var(--text-3); }
#sources li.cov { background: var(--accent-soft); color: var(--text); }

/* "¿Vas a comprar o alquilar aquí?" */
.hm-mode { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin: 0 0 6px; cursor: pointer; }
.hm-mode b { display: block; font-size: 13px; font-weight: 600; }
.hm-mode small { display: block; font-size: 11.5px; color: var(--text-3); }
.hm-mode .sw { flex: none; }
.hm-sum { margin-top: 6px; overflow-wrap: anywhere; }
.hm-rows { list-style: none; margin: 8px 0 0; padding: 0; }
.hm-row { padding: 10px 0; }
.hm-row + .hm-row { border-top: 1px solid var(--line); }
.hm-h { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.hm-h .dot { width: 14px; height: 14px; }
.hm-tag { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.hm-tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.hm-v { margin-top: 4px; font-size: 13px; overflow-wrap: anywhere; }
.hm-v b { display: block; font-weight: 600; }
.hm-s, .hm-ctx { display: block; font-size: 12px; color: var(--text-2); margin-top: 2px; overflow-wrap: anywhere; }
.hm-ctx { margin: 6px 0 0; padding: 6px 10px; border-radius: 10px; background: var(--fill); }
.hm-row details summary { display: flex; align-items: center; min-height: 44px; font-size: 12.5px; font-weight: 500; color: var(--accent); cursor: pointer; }
.hm-row details .note { margin: 0 0 4px; }
.hm-ck { margin: 12px 0 4px; font-size: 13px; font-weight: 600; }
.hm-check { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); }
.hm-check li { padding: 4px 0; overflow-wrap: anywhere; }
.hm-check a { color: var(--accent); font-weight: 500; text-decoration: none; }
.hm-disc { margin-bottom: 0; }
@media (max-width: 760px), (max-height: 500px) {
  .hm-check a, .hm-s a { display: inline-flex; align-items: center; min-height: 44px; }
}

/* Phone layout (portrait, and landscape phones: wide but short). Same query as util.js `mobile`.
   Thin header with the search bar, map controls in a column on the right, the timeline as one row above the sheet's peek,
   and one bottom sheet (#panel) holding the tabs plus every result card; ui.js snaps it between peek / half / full */
#sheet-head, #tl-more { display: none; }
@media (max-width: 760px), (max-height: 500px) {
  :root, body.collapsed { --pw: 0px; }
  :root { --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom); --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
    --hdr: calc(56px + var(--sat)); --peek: calc(88px + var(--sab)); --sw: 100vw; -webkit-text-size-adjust: 100%; }
  html, body { overscroll-behavior: none; }
  #brand, #coords, #panel-btn, body.collapsed #panel-btn, #panel-close { display: none; }
  #regions { margin-right: 52px; }
  body:is([data-sheet=half], [data-sheet=full]) #regions { display: none; }
  #regions .chip { height: 36px; padding: 0 14px; }

  /* Header: search + locate + language in one 48 px row */
  #topleft, body.story #topleft { display: flex; top: calc(8px + var(--sat)); left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); width: auto; max-height: none; z-index: 7; }
  #search { display: grid; grid-template-columns: 1fr auto auto; align-items: center; padding-right: 2px; border-radius: 14px; }
  #search .shead { display: contents; }
  #search .shead h2 { display: none; }
  .sbox { grid-row: 1; grid-column: 1; height: 48px; padding: 0 4px 0 14px; }
  #q { font-size: 16px; }
  #locate { grid-row: 1; grid-column: 2; width: 44px; height: 44px; padding: 0; justify-content: center; background: none; }
  #locate .i { width: 20px; height: 20px; }
  #locate > span { display: none; }
  #search #lang { grid-row: 1; grid-column: 3; width: 44px; height: 44px; }
  #results, #loc-err { grid-column: 1 / -1; }
  #results { max-height: 55vh; max-height: 55dvh; }
  #results li { min-height: 48px; }

  /* Map controls: a 44 px column on the right, under the header */
  .maplibregl-ctrl-top-right, body.collapsed .maplibregl-ctrl-top-right { top: calc(var(--hdr) + 8px); right: calc(8px + var(--sar)); }
  .maplibregl-ctrl-top-right .maplibregl-ctrl { margin: 0 0 8px 0; }
  .maplibregl-ctrl-group button { width: 44px; height: 44px; }
  /* Attribution as the "i" button, scale next to it, both above the timeline */
  .maplibregl-ctrl-bottom-right { right: calc(8px + var(--sar)); bottom: calc(var(--peek) + var(--tl-h, 56px) + 16px); display: flex; align-items: flex-end; gap: 8px; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin: 0; }
  .maplibregl-ctrl-attrib.maplibregl-compact { min-height: 44px; padding: 4px 44px 4px 8px; border-radius: 22px; margin: 0; max-width: calc(100vw - 32px); }
  .maplibregl-ctrl-attrib.maplibregl-compact:not(.maplibregl-compact-show) { padding: 0; width: 44px; }
  .maplibregl-ctrl-attrib-button { width: 44px !important; height: 44px !important; border-radius: 22px !important; background-position: center; background-repeat: no-repeat; }
  .maplibregl-ctrl-scale { margin-bottom: 10px !important; }

  /* The sheet */
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: calc(100vh - var(--hdr) - 8px); height: calc(100dvh - var(--hdr) - 8px);
    border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: var(--sab); z-index: 6; transition: transform .3s var(--ease); }
  body #panel, body.collapsed #panel { opacity: 1; visibility: visible; transition: transform .3s var(--ease); }
  body[data-sheet=full] #panel { transform: none; }
  body[data-sheet=half] #panel { transform: translateY(max(0px, calc(100% - 50vh))); transform: translateY(max(0px, calc(100% - 50dvh))); }
  body[data-sheet=peek] #panel { transform: translateY(calc(100% - var(--peek))); }
  #panel.dragging { transition: none; }
  #handle { display: block; flex: none; height: 20px; border: 0; background: none; cursor: grab; touch-action: none; position: relative; }
  #handle::before { content: ''; position: absolute; left: 50%; top: 8px; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--fill-2); }
  #sheet-head { display: flex; align-items: center; gap: 8px; height: 68px; padding: 0 8px 12px 18px; flex: none; touch-action: none; cursor: grab; }
  #sheet-title { flex: 1; min-width: 0; }
  #sheet-title b, #sheet-title small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #sheet-title b { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
  #sheet-title small { font-size: 12.5px; color: var(--text-3); }
  .ph { padding: 0 0 8px; }
  /* Tabs: a horizontally scrolling segmented bar */
  #tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 12px; scroll-padding: 0 12px; }
  #tabs::-webkit-scrollbar { display: none; }
  #tabs button { flex: 1 0 auto; min-width: 72px; min-height: 48px; padding: 6px 10px; font-size: 12px; justify-content: center; }
  #panel section { padding: 4px 16px 24px; }
  /* At half height the bottom of the sheet is off screen: pad the scroller so its end can still be scrolled into view */
  body[data-sheet=half] #panel section { padding-bottom: calc(50vh - var(--hdr) + 16px); padding-bottom: calc(50dvh - var(--hdr) + 16px); }

  /* Result cards inside the sheet lose their floating chrome */
  #sheet-ctx > .card { position: static; inset: auto; width: auto; max-width: none; max-height: none; margin: 0 0 12px; padding: 0; overflow: visible;
    background: none; border: 0; border-radius: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; transform: none; z-index: auto; }
  #sheet-ctx > .card + .card, #sheet-pop:not(:empty) + .card { border-top: 1px solid var(--line); padding-top: 14px; }
  #sheet-ctx #basin-chip { align-self: auto; }
  #sheet-pop .maplibregl-popup-content { max-height: none; overflow: visible; background: none; box-shadow: none; padding: 0 0 12px; border-radius: 0; }
  #sheet-pop .maplibregl-popup-close-button { display: none; }
  #sheet-pop .pt, #sheet-pop .pk { margin-right: 0; padding-right: 0; }
  #sheet-ctx #chart-svg { height: 170px; touch-action: pan-y; }
  #sheet-ctx #profile-svg { height: 150px; }
  #sheet-ctx #story footer { position: static; margin: 10px 0 0; padding: 0; background: none; }
  #story .dots .dot { width: 24px; height: 44px; background: none; box-shadow: none; border-radius: 0; display: grid; place-items: center; }
  #story .dots .dot::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--fill-2); }
  #story .dots .dot.on::before { background: var(--accent); }

  /* Timeline: play, date, slider and ⋯ in one row just above the peek; the rest opens behind ⋯ */
  #timeline { left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); bottom: calc(var(--peek) + 8px); flex-wrap: nowrap; gap: 8px; row-gap: 6px; padding: 4px 4px 4px 4px; border-radius: 14px; }
  body:is([data-sheet=half], [data-sheet=full], .drawing, .story) #timeline { display: none; }
  #tl-play { width: 44px; height: 44px; }
  #tl-date { flex: 0 1 auto; width: auto; min-width: 0; max-width: 104px; font-size: 12.5px; }
  #tl-date small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #tl-track { order: 0; flex: 1 1 0; flex-basis: 0; min-width: 0; }
  /* The record part of the track is ~90 px on a phone: keep 2000 and 2020 */
  #tl-ticks span:nth-child(1), #tl-ticks span:nth-child(3) { display: none; }
  #tl-more { display: grid; place-items: center; font-size: 22px; line-height: 1; }
  #tl-more[aria-expanded=true] { background: var(--accent-soft); color: var(--accent); }
  #timeline:not(.more) :is(#tl-speed, #tl-year, #tl-scen, #tl-rcp, #tl-today) { display: none; }
  #timeline.more { flex-wrap: wrap; }
  /* Line break: the extras always start a second row, so the slider keeps its width */
  #timeline.more::before { content: ''; order: 9; flex-basis: 100%; height: 0; }
  #timeline.more :is(#tl-speed, #tl-year, #tl-scen, #tl-rcp, #tl-today) { order: 10; }
  #timeline.more #tl-speed { height: 44px; font-size: 16px; }
  #tl-year { width: 96px; height: 44px; font-size: 16px; border: 1px solid var(--line); background: var(--card-solid); border-radius: 10px; }
  #timeline .seg span { padding: 12px 10px; font-size: 13px; }

  /* Floating bits that remain over the map */
  #dbanner { top: calc(var(--hdr) + 8px); left: calc(8px + var(--sal)); right: calc(60px + var(--sar)); gap: 4px 8px; padding: 8px 4px 8px 12px; }
  #dbanner p { flex: 1 1 calc(100% - 30px); font-size: 12.5px; }
  #dbanner .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; white-space: normal; line-height: 1.15; font-size: 12.5px; text-align: center; }
  #scen-badge { top: auto; bottom: calc(var(--peek) + var(--tl-h, 56px) + 72px); max-width: calc(100vw - 32px); }
  #drawbar { top: auto; bottom: calc(var(--peek) + 8px); left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); flex-wrap: wrap; gap: 8px; }
  #drawbar > span:nth-child(2) { flex-basis: calc(100% - 40px); }
  #drawbar .btn { flex: 1; }
  #cmp-labels { bottom: calc(var(--peek) + var(--tl-h, 56px) + 72px); left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); }
  .cmp-lab small { display: none; }
  #cmp-handle { width: 44px; margin-left: -22px; }
  #cmp-handle::before { left: 21px; }
  #cmp-handle span { width: 44px; height: 44px; }
  #story { max-height: none; }

  /* Touch sizes: 44 px targets, 16 px inputs (iOS zooms into anything smaller) */
  .btn, .btn.sm { height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  select, .field-s, .num { height: 44px; font-size: 16px; }
  .field-s input, .num, .zname, input[type=number], input[type=search], input[type=text] { font-size: 16px; }
  .zname { min-height: 44px; }
  .seg span { padding: 12px 6px; }
  .stories-box summary { min-height: 44px; }
  .q { position: relative; }
  .q::after { content: ''; position: absolute; inset: -14px; }
  .vp-b { min-height: 64px; }
  input[type=range] { height: 32px; padding: 14px 0; margin: 0; background-clip: content-box; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -11px; }
  input[type=range]::-moz-range-thumb { width: 26px; height: 26px; }
  #tl-range { margin: 0; background-clip: content-box; }
  #tl-range-wrap { padding-bottom: 12px; }
  #tl-ticks { bottom: 0; }
}
/* Landscape phone: the sheet docks on the left, the timeline runs along the bottom right of it */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --sw: min(380px, 46vw); --hdr: calc(56px + var(--sat)); }
  #topleft, body.story #topleft { right: auto; width: calc(var(--sw) - 16px); }
  .maplibregl-ctrl-top-right, body.collapsed .maplibregl-ctrl-top-right { top: calc(8px + var(--sat)); }
  .maplibregl-ctrl-top-right .maplibregl-ctrl { margin: 0 0 6px 0; }
  .maplibregl-ctrl-bottom-right { bottom: calc(8px + var(--sab)); }
  .maplibregl-ctrl-scale { display: none; }
  /* Landscape is short: the middle snap shows three quarters of the height */
  body[data-sheet=half] #panel { transform: translateY(max(0px, calc(100% - 75vh))); transform: translateY(max(0px, calc(100% - 75dvh))); }
  body[data-sheet=half] #panel section { padding-bottom: max(16px, calc(25vh - var(--hdr) + 16px)); padding-bottom: max(16px, calc(25dvh - var(--hdr) + 16px)); }
  #panel { left: var(--sal); right: auto; width: var(--sw); }
  #timeline, body:is([data-sheet=half], [data-sheet=full]) #timeline { display: flex; left: calc(var(--sw) + 8px + var(--sal)); right: calc(60px + var(--sar)); bottom: calc(8px + var(--sab)); }
  body:is(.drawing, .story) #timeline { display: none; }
  #dbanner { top: calc(8px + var(--sat)); left: calc(var(--sw) + 8px + var(--sal)); right: calc(60px + var(--sar)); }
  #dbanner p { flex-basis: 200px; }
  #dbanner .btn { flex: none; }
  #scen-badge { left: calc(var(--sw) + (100vw - var(--sw)) / 2); bottom: calc(var(--tl-h, 56px) + 16px); }
  #drawbar { left: calc(var(--sw) + 8px + var(--sal)); right: calc(60px + var(--sar)); bottom: calc(8px + var(--sab)); }
  #cmp-labels { left: calc(var(--sw) + 8px); right: 60px; bottom: calc(var(--tl-h, 56px) + 16px); }
}

/* Offline banner, saved-zone note and install row */
#offline { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-left: 6px solid #f28c28; font-size: 12.5px; }
#offline p, #sw-update p { margin: 0; flex: 1; }
#sw-update { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-left: 6px solid #0a84ff; font-size: 12.5px; }
#sw-update[hidden] { display: none; }
#offline .i, .offnote .i { color: #f28c28; }
.offnote { display: flex; gap: 10px; margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--fill); border-left: 4px solid #f28c28; font-size: 12.5px; }
.offnote .i { flex: none; margin-top: 1px; }
.offnote p { margin: 2px 0 0; }
.offnote .btn { margin-top: 8px; }
.inst { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 12px; }
.inst .note { margin: 0; }
.hm-v .btn { margin-top: 6px; }

/* Two-address comparison: columns while the card is wide enough, stacked (with the sticky A/B header) below ~300 px */
.ab { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font: 700 14px var(--font); color: #fff; border: 2.5px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
.ab.a, .pw-l.a { background: #0a84ff; }
.ab.b, .pw-l.b { background: #e8590c; }
.pw { container-type: inline-size; }
.pw > header { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.pw > header > div { flex: 1; min-width: 0; }
.pw > header b { font-size: 14px; font-weight: 600; }
.pw-head { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 0; background: var(--card-solid); border-bottom: 1px solid var(--line); }
.pw-c { display: flex; gap: 6px; align-items: flex-start; min-width: 0; }
.pw-c b { display: block; font-size: 12.5px; font-weight: 600; overflow-wrap: anywhere; }
.pw-c small { display: block; font-size: 11px; color: var(--text-3); }
.pw-l { flex: none; width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font: 700 11px var(--font); font-style: normal; color: #fff; }
.pw-row h5 { margin: 14px 0 4px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.pw-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pw-cell { min-width: 0; padding: 8px; border-radius: 10px; background: var(--fill); font-size: 12.5px; overflow-wrap: anywhere; }
.pw-cell > .pw-l { display: none; margin-bottom: 4px; }
.pw-cell .hm-tag { margin: 0 0 4px; }
.pw-cell b { display: block; font-weight: 600; }
.pw-pick { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 12.5px; }
.pw-pick b { flex: 1; font-weight: 600; }
.pw-pick .i { flex: none; color: var(--accent); }
@container (max-width: 300px) {
  .pw-head, .pw-pair { grid-template-columns: 1fr; gap: 4px; }
  .pw-head { padding: 6px 0; }
  .pw-cell > .pw-l { display: inline-grid; }
}

/* Tap-water hardness, drought status, sea level, groundwater, thermal waters */
.cls { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; background: var(--fill-2); color: var(--text); font-size: 11.5px; font-weight: 600; font-style: normal; }
.cls::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
em.tag { font-style: normal; margin-left: 6px; }
.tag.old { background: transparent; border: 1px solid #b7791f; color: #9a6700; }
.dr-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.dr-row small { display: block; font-size: 11.5px; color: var(--text-3); }
.dr-row b { font-weight: 600; }
.dr-row .dot { width: 12px; height: 12px; }
.dr-strip { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; margin: 6px 0 2px; }
.dr-strip i { height: 12px; border-radius: 2px; background: var(--c); }
.env-tbl { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 12.5px; }
.env-tbl th, .env-tbl td { padding: 5px 6px; text-align: left; border-top: 1px solid var(--line); font-weight: 500; }
.env-tbl th { color: var(--text-2); }
.env-tbl td b { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.env-tbl td small { color: var(--text-3); }
.gw-list, .th-facts, .th-safe { list-style: none; margin: 6px 0; padding: 0; font-size: 12.5px; }
.gw-list li { padding: 8px 0; border-top: 1px solid var(--line); }
.gw-list small { display: block; color: var(--text-3); }
.gw-list .cls { margin: 4px 4px 0 0; }
.th-facts li { padding: 2px 0; }
.th-safe { border-left: 3px solid #b7791f; padding-left: 10px; color: var(--text-2); }
.th-safe li { padding: 2px 0; }
.dleg .full { flex-basis: 100%; }
.dleg img { vertical-align: middle; margin-right: 6px; }
.tg.sub { padding-left: 0; border-top: 0; }

/* Desalination, transfers, gauges and water use by sector */
.mchart { width: 100%; height: auto; display: block; margin: 6px 0 2px; }
.mchart text { fill: var(--text-3); font-size: 9px; font-family: var(--font); }
.mchart text.mx { font-size: 9.5px; }
.mchart line { stroke: var(--line); }
.mchart rect.hi { stroke: var(--text); stroke-width: 1; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 11.5px; padding: 4px 10px; min-height: 28px; border: 0; border-radius: 999px; background: var(--accent-soft); color: var(--text); cursor: pointer; text-align: left; }
.chip-btn:hover { background: var(--fill-2); }
.ds-cap, .tr-fig, .gg-now { margin: 8px 0 4px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.gg-rt { margin: 10px 0 0; padding: 6px 10px; border-radius: 10px; background: var(--fill); font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.gg-q { text-align: center; } .gg-q th, .gg-q td { text-align: center; font-size: 11px; }
.dleg i[style*="repeating"] { margin-right: 6px; }
.us-leg { margin: 8px 0 10px; }
.us-row { margin: 0 0 10px; }
.us-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.us-h small { color: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; text-align: right; }
.us-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin-top: 4px; background: var(--fill-2); }
.us-bar i { display: block; height: 100%; }
.us-est { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }

/* Share card and embed dialogs */
dialog.modal { width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 14px 16px 12px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--card-solid); color: var(--text); box-shadow: var(--shadow); }
dialog.modal::backdrop { background: rgba(8, 12, 18, .55); }
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.m-head b { font-size: 16px; }
.sh-cv { display: block; width: 100%; height: auto; aspect-ratio: 1200 / 630; border-radius: 10px; border: 1px solid var(--line); }
.em-ctl { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0; font-size: 13px; }
.em-ctl select { margin-left: 4px; padding: 3px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-solid); }
.em-pv { display: block; width: 320px; max-width: 100%; height: 180px; margin: 4px 0 10px; border: 0; border-radius: 12px; }
.em-code { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--fill); color: var(--text); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }

/* Worldwide layers: data tiers and legend images */
.tiers { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 10px; }
.tiers li { display: flex; gap: 10px; align-items: flex-start; }
.tiers .dot { width: 12px; height: 12px; margin-top: 4px; flex: none; }
.tiers b { display: block; font-size: 13px; }
.tiers small { display: block; color: var(--text-3); font-size: 11.5px; }
.tiers li > span:last-child > span { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.dleg img[src*="GetLegendGraphic"] { background: #fff; border-radius: 8px; padding: 4px; max-width: 100%; height: auto; }
.sl > .flabel { display: block; margin-bottom: 6px; }
