:root {
  --ink: #2b2430; --ink2: #5b5160; --paper: #f6efdc; --paper2: #eadfc2; --paper3: #dccfa9;
  --water: #1f6fb5; --hot: #b8402a; --ok: #2f7d3b;
  --c-colorado: #2a78d6; --c-ground: #eb6834; --c-instate: #1baf7a; --c-reclaimed: #eda100;
  --c-ag: #008300; --c-muni: #e87ba4; --c-ind: #6250d6;
  --pixel: 'Silkscreen', ui-monospace, 'SF Mono', Menlo, monospace;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --shadow: 4px 4px 0 rgba(43, 36, 48, .55);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; touch-action: manipulation; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; background: #cfc4a6; color: var(--ink); font: 15px/1.5 var(--body); overflow: hidden; }
#app { position: fixed; inset: 0; overflow: hidden; -webkit-user-select: none; user-select: none; }
#panelBody, #tourText { -webkit-user-select: text; user-select: text; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; outline: none; display: block; }
#map.drag { cursor: grabbing; } #map.hot { cursor: pointer; }
#map:focus-visible { box-shadow: inset 0 0 0 3px var(--water); }

.plate { position: absolute; background: var(--paper); border: 2px solid var(--ink); box-shadow: var(--shadow); }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--water); outline-offset: 2px; }
h1, h2, h3, .px { font-family: var(--pixel); font-weight: 400; letter-spacing: .02em; }

/* --- top HUD --------------------------------------------------------- */
#hud { position: absolute; top: 12px; left: 12px; display: flex; gap: 10px; align-items: stretch; pointer-events: none; }
#hud .plate { position: static; pointer-events: auto; }
.title { padding: 8px 14px 9px; background: var(--ink); color: var(--paper); }
.title h1 { margin: 0; font-size: 20px; line-height: 1.15; text-transform: uppercase; color: #9fd0ff; }
.title p { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.stats { display: flex; gap: 0; padding: 0; }
.stats div { padding: 7px 12px; border-left: 2px solid var(--paper3); display: flex; flex-direction: column; justify-content: center; }
.stats div:first-child { border-left: 0; }
.stats b { font-family: var(--pixel); font-weight: 400; font-size: 15px; line-height: 1.2; }
.stats span { font-size: 11px; color: var(--ink2); white-space: nowrap; }

/* --- layers toolbar -------------------------------------------------- */
#layers { top: 86px; left: 12px; width: 178px; padding: 6px; }
#layersToggle { display: none; }
#layerList { display: grid; gap: 3px; }
.layerBtn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 6px; background: var(--paper2); border: 2px solid var(--ink); text-align: left;
  font-family: var(--pixel); font-size: 11px; line-height: 1.2; box-shadow: inset -2px -2px 0 rgba(0,0,0,.18), inset 2px 2px 0 rgba(255,255,255,.6); }
.layerBtn canvas { width: 22px; height: 22px; image-rendering: pixelated; flex: none; }
.layerBtn[aria-pressed=true] { background: #bfe0ff; box-shadow: inset 2px 2px 0 rgba(0,0,0,.25); }
.layerBtn[aria-pressed=false] { color: var(--ink2); }
.layerBtn[aria-pressed=false] canvas { filter: grayscale(1) opacity(.55); }
.layerBtn:hover { background: #fff7d6; } .layerBtn[aria-pressed=true]:hover { background: #d4eaff; }
.season { display: flex; margin-top: 6px; border: 2px solid var(--ink); }
.season button { flex: 1; border: 0; background: var(--paper2); font-family: var(--pixel); font-size: 11px; padding: 5px 0; }
.season button.on { background: var(--ink); color: var(--paper); }

#zoom { right: 372px; bottom: 14px; display: flex; flex-direction: column; }
#zoom button { width: 34px; height: 32px; border: 0; background: var(--paper); font-family: var(--pixel); font-size: 18px; line-height: 1; padding: 0; }
#zoom button + button { border-top: 2px solid var(--ink); } #zoom button[hidden] { display: none; } #zoom button:hover { background: #fff7d6; }

/* --- side panel ------------------------------------------------------ */
#panel { top: 12px; right: 12px; bottom: 12px; width: 348px; display: flex; flex-direction: column; }
#panelHandle { display: none; }
#panelBody { overflow-y: auto; padding: 14px 16px 18px; flex: 1; overscroll-behavior: contain; }
#panelBody h2 { font-size: 19px; line-height: 1.2; margin: 2px 0 6px; text-wrap: balance; }
#panelBody h3 { font-size: 12px; text-transform: uppercase; margin: 18px 0 6px; color: var(--ink2); }
#panelBody p { margin: 0 0 10px; }
#panelBody a { color: #1558a0; }
.back { display: block; border: 0; background: none; padding: 0; margin: 0 0 8px; font-family: var(--pixel); font-size: 11px; color: #1558a0; }
.kind { display: inline-flex; align-items: center; gap: 6px; font-family: var(--pixel); font-size: 11px; text-transform: uppercase; color: var(--ink2); }
.kind canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.lede { font-size: 15.5px; }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0 12px; }
.stat { background: var(--paper2); border: 2px solid var(--ink); padding: 6px 8px; }
.stat b { display: block; font-family: var(--pixel); font-weight: 400; font-size: 16px; line-height: 1.25; }
.stat span { font-size: 12px; color: var(--ink2); line-height: 1.3; display: block; }
.stat.wide { grid-column: 1 / -1; }
.note { background: #fff7d6; border-left: 4px solid var(--c-reclaimed); padding: 7px 10px; font-size: 13.5px; margin: 10px 0; }
.note.hot { border-left-color: var(--hot); background: #fbe6dc; }
.srcs { font-size: 12px; color: var(--ink2); margin-top: 14px; border-top: 2px dotted var(--paper3); padding-top: 8px; }
.srcs a { color: var(--ink2); }
.btn { display: inline-block; background: var(--paper2); border: 2px solid var(--ink); padding: 5px 10px; font-family: var(--pixel); font-size: 11px; box-shadow: 2px 2px 0 rgba(43,36,48,.5); }
.btn:hover { background: #fff7d6; } .primary { background: var(--water); color: #fff; } .primary:hover { background: #2a82cf; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 4px; }
.chip { background: var(--paper2); border: 2px solid var(--ink); padding: 2px 7px; font-size: 12.5px; }
.chip:hover { background: #fff7d6; }

/* droplet pictogram: one drop = 100,000 acre-feet */
.picto { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; margin: 6px 0 8px; }
.drop { aspect-ratio: 1; border: 2px solid var(--ink); border-radius: 0 55% 55% 55%; transform: rotate(45deg) scale(.78); background: var(--c); transition: opacity .15s; }
.picto.dim .drop:not(.hl) { opacity: .22; }
.drop.tiny { transform: none; border: 2px dotted var(--ink2); border-radius: 50%; background: none; display: grid; place-items: center; }
.drop.tiny b { display: block; width: calc(var(--s) * 78%); aspect-ratio: 1; background: var(--c); border-radius: 0 55% 55% 55%; transform: rotate(45deg); }
.keyrow.sub i { width: 8px; height: 8px; margin: 0 2px; border-radius: 50%; }
.keyrow { display: flex; align-items: baseline; gap: 8px; width: 100%; border: 0; background: none; padding: 3px 4px; text-align: left; border-radius: 2px; }
.keyrow:hover, .keyrow.hl { background: var(--paper2); }
.keyrow i { width: 12px; height: 12px; border: 2px solid var(--ink); background: var(--c); flex: none; transform: translateY(1px); }
.keyrow b { font-weight: 600; flex: 1; } .keyrow span { font-variant-numeric: tabular-nums; color: var(--ink2); font-size: 13px; white-space: nowrap; }
.seg { display: flex; border: 2px solid var(--ink); margin: 8px 0 2px; }
.seg button { flex: 1; border: 0; background: var(--paper2); font-family: var(--pixel); font-size: 11px; padding: 6px 2px; }
.seg button.on { background: var(--ink); color: var(--paper); }

/* reservoir gauge + slider */
.gauge { position: relative; height: 26px; border: 2px solid var(--ink); background: repeating-linear-gradient(90deg, var(--paper2) 0 9px, var(--paper3) 9px 10px); margin: 6px 0 2px; }
.gauge i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--c-colorado); border-right: 2px solid var(--ink); }
.gauge em { position: absolute; right: 6px; top: 2px; font: 400 12px var(--pixel); }
.gcap { font-size: 12px; color: var(--ink2); margin-bottom: 10px; }
input[type=range] { width: 100%; accent-color: var(--water); margin: 4px 0; }
.tier { border: 2px solid var(--ink); padding: 8px 10px; background: var(--paper2); margin: 6px 0; }
.tier b.px { font-size: 15px; }
.bars { display: grid; gap: 4px; margin: 8px 0; }
.bar { display: grid; grid-template-columns: 96px 1fr 62px; gap: 6px; align-items: center; font-size: 12.5px; }
.bar i { display: block; height: 14px; background: var(--c, var(--water)); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar i.cut { background: repeating-linear-gradient(135deg, var(--hot) 0 4px, #e9a595 4px 8px); }
.bar span:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink2); }
.spark { width: 100%; height: auto; display: block; margin: 6px 0; }
.spark text { font: 11px var(--body); fill: var(--ink2); }

/* --- tour -------------------------------------------------------------- */
#tourStart { white-space: nowrap; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 9px 16px; font-family: var(--pixel); font-size: 13px; margin-left: -90px; }
#tour { left: 50%; bottom: 18px; transform: translateX(-50%); width: min(560px, calc(100vw - 420px)); padding: 12px 14px 10px; margin-left: -90px; }
#tourText h3 { margin: 0 0 4px; font-size: 15px; } #tourText p { margin: 0; }
.tourNav { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.tourNav button { border: 2px solid var(--ink); background: var(--paper2); font-family: var(--pixel); font-size: 11px; padding: 5px 9px; }
.tourNav .primary { background: var(--water); color: #fff; }
#tourDots { flex: 1; display: flex; gap: 4px; justify-content: center; }
#tourDots i { width: 8px; height: 8px; border: 2px solid var(--ink); background: var(--paper); } #tourDots i.on { background: var(--ink); }

#legend { left: 202px; top: 86px; padding: 7px 9px; font-size: 12px; max-width: 220px; }
#legend .px { font-size: 11px; display: block; margin-bottom: 4px; }
#legend .ramp { display: flex; } #legend .ramp i { flex: 1; height: 12px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
#legend .ramp i:first-child { border-left: 2px solid var(--ink); } #legend .ramp i:last-child { border-right: 2px solid var(--ink); }
#legend .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink2); }
#legend p { margin: 5px 0 0; color: var(--ink2); line-height: 1.35; }
#legend .sw { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--ink); vertical-align: -2px; margin-right: 5px; }

#scale { position: absolute; left: 14px; bottom: 14px; font: 11px var(--pixel); color: var(--ink); display: flex; align-items: center; gap: 6px; text-shadow: 0 0 3px #fff, 0 0 3px #fff; pointer-events: none; }
#scaleBar { display: block; height: 6px; border: 2px solid var(--ink); border-top: 0; }
#tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); font-size: 12.5px; padding: 3px 8px; white-space: nowrap; z-index: 5; transform: translate(12px, 14px); }
#tip small { opacity: .75; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: #cfc4a6; font: 16px var(--pixel); z-index: 9; }

/* --- narrow screens: panel becomes a bottom sheet ---------------------- */
@media (max-width: 820px), (max-height: 520px) {
  #hud { right: 12px; top: calc(10px + env(safe-area-inset-top)); } .stats { display: none; } .title h1 { font-size: 16px; } .title p { display: none; }
  /* layers: a closed button by default; opens as a two-column sheet that never runs under the bottom panel */
  #layers { top: calc(56px + env(safe-area-inset-top)); width: auto; padding: 0; z-index: 6; }
  #layersToggle { display: block; border: 0; background: none; font-family: var(--pixel); font-size: 12px; min-height: 42px; padding: 0 12px; }
  #layers.closed #layerList, #layers.closed .season { display: none; }
  #layers:not(.closed) { width: min(350px, calc(100vw - 24px)); padding: 0 6px 6px; max-height: calc(54dvh - 70px); overflow-y: auto; }
  #layerList { grid-template-columns: 1fr 1fr; gap: 4px; } .layerBtn { min-height: 40px; }
  .season button { min-height: 38px; }
  #zoom { right: 12px; top: calc(10px + env(safe-area-inset-top)); bottom: auto; }
  #zoom button { width: 42px; height: 42px; }
  /* bottom sheet */
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 46vh; height: 46dvh; border-width: 2px 0 0; box-shadow: 0 -4px 0 rgba(43,36,48,.35); transition: height .2s; padding-bottom: env(safe-area-inset-bottom); }
  #panel.touring { height: 54vh; height: 54dvh; }
  #panel.min { height: calc(64px + env(safe-area-inset-bottom)); } #panel.max { height: 82vh; height: 82dvh; }
  #panelHandle { display: block; height: 30px; border: 0; background: none; flex: none; position: relative; touch-action: none; cursor: grab; }
  #panelHandle::after { content: ''; position: absolute; left: 50%; top: 10px; width: 48px; height: 5px; margin-left: -24px; background: var(--ink); }
  #panelBody { padding-top: 2px; }
  #panelBody .btn, .chip, .seg button { min-height: 38px; } .chip { padding: 6px 9px; } .back { padding: 8px 0; margin: 0; }
  .keyrow { padding: 7px 4px; } .srcs a { display: inline-block; padding: 3px 0; }
  input[type=range] { height: 34px; margin: 0; }
  /* tour start sits beside the Layers button, off the map's centre */
  #tourStart { left: 96px; top: calc(56px + env(safe-area-inset-top)); bottom: auto; transform: none; margin: 0; min-height: 46px; padding: 0 12px; font-size: 11px; }
  /* during the tour the steps dock into the top of the sheet, so nothing floats over the map */
  #panel > #tour { position: static; transform: none; width: auto; margin: 0; border: 0; border-bottom: 2px solid var(--ink); box-shadow: none; background: #fff7d6; padding: 6px 14px 10px; flex: none; }
  #panel.min > #tour { display: none; }
  #tourText h3 { font-size: 13px; } #tourText p { font-size: 14px; line-height: 1.4; }
  .tourNav { margin-top: 8px; } .tourNav button { min-height: 40px; padding: 5px 12px; } #tourExit { min-width: 40px; }
  #scale { display: none; } #legend { left: 12px; right: auto; top: auto; bottom: calc(46dvh + 10px); max-width: 200px; }
  #panel.min ~ #legend { bottom: calc(74px + env(safe-area-inset-bottom)); } #panel.touring ~ #legend { bottom: calc(54dvh + 10px); }
}
/* phones held sideways: the sheet moves to the right-hand side */
@media (max-height: 520px) and (min-width: 560px) and (orientation: landscape) {
  #panel, #panel.touring, #panel.min, #panel.max { top: 0; left: auto; right: 0; bottom: 0; width: 46vw; height: auto; border-width: 0 0 0 2px; box-shadow: -4px 0 0 rgba(43,36,48,.35); padding-right: env(safe-area-inset-right); }
  #panelHandle { display: none; } #panel.min > #tour { display: block; } #panelBody { padding-top: 12px; }
  #hud { left: calc(12px + env(safe-area-inset-left)); } #layers { left: calc(12px + env(safe-area-inset-left)); } #tourStart { left: calc(96px + env(safe-area-inset-left)); }
  #layers:not(.closed) { max-height: calc(100dvh - 66px); width: min(350px, calc(54vw - 24px)); }
  #zoom { right: calc(46vw + 10px); }
  #legend, #panel.min ~ #legend, #panel.touring ~ #legend { bottom: 10px; left: calc(12px + env(safe-area-inset-left)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
