/* ---------- fonts ----------
   Brand web fonts (2025 Brand Guide 3.3): Muli for headings, Open Sans for
   body. Self-hosted latin variable fonts; no third-party requests. */
@font-face {
  font-family: 'Mulish'; font-style: normal; font-weight: 200 1000;
  font-display: swap; src: url(../fonts/mulish-normal.woff2) format('woff2');
}
@font-face {
  font-family: 'Mulish'; font-style: italic; font-weight: 200 1000;
  font-display: swap; src: url(../fonts/mulish-italic.woff2) format('woff2');
}
@font-face {
  font-family: 'Open Sans'; font-style: normal; font-weight: 300 800;
  font-display: swap; src: url(../fonts/opensans-normal.woff2) format('woff2');
}
@font-face {
  font-family: 'Open Sans'; font-style: italic; font-weight: 300 800;
  font-display: swap; src: url(../fonts/opensans-italic.woff2) format('woff2');
}

/* ---------- tokens ----------
   Non-map colors follow the agency's 2025 Brand Guide: Ebb Blue and Gale
   Blue ramps for surfaces and accents, Jetty Gray for muted text. Map data
   colors (diverging/sequential ramps, basin classes) are approved data
   colors and are defined separately in config.js. */
:root {
  --ink: #25394f;            /* Ebb Blue, dark shade — dark accents & covers */
  --ink-2: #35516f;
  --terra: #435a2f;          /* Terra Green, dark shade — subtle outlines */
  --chalk: #dde7f0;          /* primary text on dark surfaces */
  --mist: #a0b2c5;           /* secondary text on dark surfaces */
  --glacial: #80a8cd;        /* Gale Blue — accent */
  --glacial-dim: #44688f;    /* Ebb Blue — accent on light surfaces */
  --field: #c7dbe9;          /* map background — water blue */
  --paper: #fcfdfd;          /* cards on the map */
  --paper-ink: #16222f;
  --paper-body: #25394f;    /* long-form body text on paper */
  --paper-mut: #656565;
  --line: #ced7e1;          /* hairline card border */
  --warn: #b2182b;          /* matches the map ramp's strongest red */
  --heading: 'Mulish', 'Segoe UI', system-ui, sans-serif;
  --sans: 'Open Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --rail-w: 380px;
  --shadow: 0 6px 24px rgba(12, 26, 35, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; }
body { font-family: var(--sans); color: var(--paper-ink); }

#app { display: flex; }

/* ---------- sidebar ---------- */
#sidebar {
  width: var(--rail-w);
  min-width: var(--rail-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(168deg, #fcfdfd 0%, #e9eff6 100%);
  color: var(--paper-body);
  border-right: 1px solid var(--line);
  z-index: 1000;
  box-shadow: 4px 0 20px rgba(22, 34, 47, .12);
}

.brand { padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
/* Official horizontal logo with text, as used on the agency website. */
.ecy-logo { display: block; width: 212px; height: auto; margin-bottom: 12px; }
.brand h1 {
  font-family: var(--heading); font-weight: 600; font-size: 27px;
  line-height: 1.12; color: var(--paper-ink);
}

/* journey rail */
#journey { padding: 12px 0 8px; overflow-y: auto; flex-shrink: 0; max-height: 38%; }
.chapter { margin-bottom: 2px; }
/* Chapter headings mirror the top-bar tabs (same type and selected pill)
   so the two navigations read as one system. */
.chapter-head {
  display: flex; align-items: baseline; gap: 8px;
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 6px 24px 5px; color: var(--paper-mut);
  font: 600 13px/1.2 var(--sans);
}
.chapter-head span { padding: 5px 10px; margin-left: -10px; border-radius: 7px; }
.chapter-head:hover span, .chapter-head:focus-visible span { background: #dde7f0; color: var(--paper-ink); }
.chapter.open .chapter-head span { background: var(--ink); color: #fff; }

.steps { list-style: none; }
.chapter:not(.open) .steps { display: none; }

/* the rail: a river course down the left of the steps */
.step button {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  color: var(--paper-mut); font: 400 13.5px/1.35 var(--sans);
  padding: 6px 16px 6px 46px; position: relative;
}
.step button::before {                       /* rail segment */
  content: ''; position: absolute; left: 29px; top: 0; bottom: 0; width: 2px;
  background: var(--line);
}
.step:first-child button::before { top: 50%; }
.step:last-child button::before { bottom: 50%; }
.step button::after {                        /* node */
  content: ''; position: absolute; left: 26px; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 50%;
  background: #fff; border: 2px solid #a0b2c5;
}
.step.visited button { color: #35516f; }
.step.visited button::after { background: var(--glacial-dim); border-color: var(--glacial-dim); }
.step.current button { color: var(--paper-ink); font-weight: 600; }
.step.current button::after {
  background: var(--glacial); border-color: var(--glacial);
  box-shadow: 0 0 0 4px rgba(128, 168, 205, .25);
}
.step button:hover, .step button:focus-visible { color: var(--paper-ink); }

/* narrative */
#narrative {
  flex: 1; overflow-y: auto; padding: 18px 24px 12px;
  border-top: 1px solid var(--line);
}
#narrative .kicker {
  font-size: 11px; letter-spacing: .04em;
  color: var(--glacial-dim); margin-bottom: 10px;
}
#narrative h2 {
  font-family: var(--heading); font-weight: 600; font-size: 22px; line-height: 1.22;
  color: var(--paper-ink); margin-bottom: 12px;
}
#narrative p { font-size: 13.5px; line-height: 1.6; color: var(--paper-body); margin-bottom: 10px; }
/* Terra Green rule under the definition: the brand's complementary green accent. */
#narrative .definition { color: #35516f; font-size: 13px; border-bottom: 1px solid rgba(67, 90, 47, .45); padding-bottom: 10px; }
#narrative p strong { color: var(--paper-ink); }
#narrative a { color: var(--glacial-dim); }
#narrative .hint {
  margin-top: 12px; padding: 10px 12px; border-left: 3px solid var(--glacial-dim);
  background: rgba(128, 168, 205, .12); color: var(--paper-body); font-size: 12.5px; line-height: 1.5;
}

/* step nav */
#stepnav {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 24px; border-top: 1px solid var(--line);
}
.progress {
  font-size: 11.5px; color: var(--paper-mut); white-space: nowrap;
  border: 0; background: none; font-family: var(--sans); cursor: default; padding: 8px 4px;
}

#sheet-grabber, #sheet-hint { display: none; }
.nav-btn {
  font: 600 13.5px var(--sans); padding: 10px 18px; border-radius: 6px;
  cursor: pointer; border: 1px solid transparent;
}
.nav-btn.solid { background: var(--glacial); color: var(--ink); border-color: var(--glacial); }
.nav-btn.solid:hover { background: #9fbdd9; }
.nav-btn.ghost { background: none; color: var(--paper-mut); border-color: var(--line); }
.nav-btn.ghost:hover { color: var(--paper-ink); border-color: #a0b2c5; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.nav-btn:focus-visible { outline: 2px solid var(--glacial-dim); outline-offset: 2px; }
#journey:focus-visible, #narrative:focus-visible { outline: 2px solid var(--glacial-dim); outline-offset: -2px; }
#drawer:focus-visible, #about-panel:focus-visible { outline: 2px solid var(--glacial-dim); outline-offset: -2px; }

/* ---------- stage / map ---------- */
#stage { position: relative; flex: 1; min-width: 0; container-type: inline-size; container-name: stage; }
#map { position: absolute; inset: 0; background: var(--field); transition: filter 0.6s ease; }
/* Soft focus while the layers finish their first render — removed by app.js. */
#map.map-veil { filter: blur(16px) saturate(0.9); }
.esri-view { font-family: var(--sans); }
.esri-view .esri-view-surface:focus-visible::after { outline: 2px solid var(--glacial-dim); }
#map-credit {
  position: absolute; left: 8px; bottom: 4px; z-index: 1050;
  font-size: 12px; color: var(--paper-mut);
  background: rgba(252, 253, 253, .8); padding: 2px 6px; border-radius: 4px;
}

/* unified top bar: topic tabs left, search cluster right */
#topbar {
  position: absolute; top: 16px; left: 16px; right: 16px; z-index: 1100;
  display: flex; justify-content: space-between; align-items: center;
  gap: 6px 10px; flex-wrap: wrap;   /* narrow windows wrap the search under the tabs */
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 8px; box-shadow: var(--shadow);
}
#map-tabs { display: flex; gap: 2px; }
.map-tab {
  border: 0; background: none; cursor: pointer; border-radius: 7px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 6px 6px; white-space: nowrap; color: var(--paper-mut);
}
.map-tab .tab-label { font: 600 13px var(--sans); }
.map-tab .tab-tip { font: 400 12px var(--sans); opacity: .8; }
.map-tab:hover { background: #dde7f0; color: var(--paper-ink); }
.map-tab[aria-pressed="true"] { background: var(--ink); color: #fff; }
.map-tab:focus-visible { outline: 2px solid var(--glacial-dim); outline-offset: 1px; }
.tab-divider { width: 1px; align-self: stretch; margin: 5px 3px; background: var(--line); }

/* sub-header: a full-width second row inside the bar, under the tabs */
#tab-subheader {
  flex-basis: 100%; margin: 0; padding: 1px 6px 2px;
  font-size: 12.5px; color: var(--paper-mut);
}

/* first-visit welcome: a card over the map; the sidebar stays visible */
#welcome[hidden] { display: none; }
#welcome {
  position: absolute; inset: 0; z-index: 2500;
  display: flex; overflow-y: auto;
  background: rgba(12, 26, 35, .45); padding: 20px;
}
/* auto margins center the card and keep its top reachable when it scrolls */
#welcome .wl-card {
  width: min(560px, 100%); margin: auto;
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow);
}
#welcome .wl-head {
  display: flex; align-items: center; gap: 16px;
  background: var(--ink); padding: 14px 22px;
}
#welcome .wl-head img { width: 148px; height: auto; flex-shrink: 0; }
#welcome .wl-head h2 { font-family: var(--heading); font-size: 23px; color: #fff; }
#welcome .wl-body { padding: 14px 22px 20px; }
#welcome .wl-body p { font-size: 13.5px; line-height: 1.55; margin: 8px 0; color: var(--paper-body); }
#welcome .wl-body h3 { font-size: 15px; margin: 16px 0 2px; color: var(--paper-ink); }
#wl-go {
  display: block; width: 100%; margin-top: 16px; padding: 12px;
  font: 600 14px var(--sans); color: var(--ink); cursor: pointer;
  background: var(--glacial); border: 1px solid var(--glacial); border-radius: 10px;
}
#wl-go:hover { background: #9fbdd9; }
#wl-go:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* search cluster (inside the top bar on desktop) */
#searchbox {
  margin-left: auto;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
}
.search-row { position: relative; display: flex; align-items: center; gap: 6px; }
#search-tip {
  margin: 0 0 0 2px; text-align: left;
  font-size: 12px; color: var(--paper-mut);
}

/* Progressive tightening, driven by the bar's ACTUAL available width (container
   queries on #stage), not viewport guesses — the sidebar offset is accounted for
   automatically. Thresholds are calibrated to measured content widths + buffer,
   so the browser's own flex-wrap never fires in an undesigned state:
     stage ≥ 1076px  → one row, tab tips shown   (content needs 1055 after trims)
     832 – 1075px    → one row, tips hidden
     < 832px         → two rows, search left-aligned under the tabs */
@container stage (max-width: 1075px) {
  .map-tab .tab-tip { display: none; }
  .map-tab { padding: 9px 12px 8px; }
}
@container stage (max-width: 831px) {
  #searchbox { flex-basis: 100%; margin-left: 0; }
}
#search {
  width: 170px; padding: 10px 14px; font: 14px var(--sans);
  border: 1px solid var(--line); border-radius: 8px; background: #f4f8fa;
  color: var(--paper-ink);
}
#search:focus { outline: 2px solid var(--glacial-dim); }
#search-results {
  position: absolute; top: 44px; left: 0; width: 250px; max-height: 260px; overflow-y: auto; z-index: 1200;
  list-style: none; background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
}
#search-results li { padding: 9px 14px; font-size: 13.5px; cursor: pointer; }
#search-results li:hover, #search-results li.active { background: #dde7f0; }
#search-results li .ws { color: var(--paper-mut); font-size: 12px; }
#btn-state, #btn-print {
  padding: 10px; font: 600 13px var(--sans); border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #f4f8fa; color: var(--paper-ink);
  white-space: nowrap;
}
#btn-state:hover, #btn-print:hover { background: #dde7f0; }

#print-header { display: none; }

/* timeline */
#timeline[hidden] { display: none; }
#timeline {
  /* right inset = legend width (320) + its edge margin (16) + matching gap (16) */
  position: absolute; bottom: 22px; left: 96px; right: 352px;
  width: fit-content; margin: 0 auto;
  z-index: 1100; display: flex; align-items: center; gap: 10px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; box-shadow: var(--shadow); max-width: calc(100% - 448px);
}
#btn-play {
  width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--ink); color: #fff; font-size: 12px; flex-shrink: 0;
}
#btn-play:hover { background: var(--ink-2); }
#decades { display: flex; gap: 4px; overflow-x: auto; }
/* Edge chevrons: visible only while the decade row can scroll that way,
   fading into the card so the cut-off chip shows through. */
.tl-cue {
  position: absolute; top: 1px; bottom: 1px; width: 34px; margin: 0;
  border: 0; cursor: pointer; color: var(--glacial-dim);
  font: 600 17px/1 var(--sans); padding: 0;
}
.tl-cue:hover { color: var(--paper-ink); }
.tl-cue:focus-visible { outline: 2px solid var(--glacial-dim); outline-offset: -2px; }
#tl-next {
  right: 1px; border-radius: 0 10px 10px 0;
  background: linear-gradient(to right, rgba(252, 253, 253, 0), var(--paper) 35%);
  text-align: right; padding-right: 10px;
}
#tl-prev {
  left: 57px; border-radius: 0;
  background: linear-gradient(to left, rgba(252, 253, 253, 0), var(--paper) 35%);
  text-align: left; padding-left: 10px;
}
.decade {
  border: 0; background: none; cursor: pointer; border-radius: 6px;
  font: 600 12.5px var(--sans); color: var(--paper-mut); padding: 8px 10px;
  white-space: nowrap;
}
.decade:hover { background: #dde7f0; color: var(--paper-ink); }
.decade[aria-selected="true"] { background: var(--ink); color: #fff; }
.decade:focus-visible { outline: 2px solid var(--glacial-dim); }

/* legend */
#legend {
  position: absolute; right: 16px; bottom: 22px; z-index: 1100;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; box-shadow: var(--shadow); width: 320px;
}
.legend .legend-title { font: 600 12px var(--sans); margin-bottom: 8px; color: var(--paper-ink); }
.legend .ramp { display: flex; height: 12px; border-radius: 3px; overflow: hidden; }
.legend .ramp span { flex: 1; }
/* Bin-boundary labels under the colorbar, on a single row; positions are set
   inline as percentages of the bar width. `start`/`end` pin the outermost
   labels. The legend width is sized so the longest label set (snowpack
   volumes) fits without collisions at this font size. */
.legend .edgelabels { position: relative; height: 15px; margin-top: 4px; font-size: 10px; color: var(--paper-mut); }
.legend .edgelabels span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.legend .edgelabels span.start { transform: none; }
.legend .edgelabels span.end { transform: translateX(-100%); }

/* When the stage can't fit the timeline beside the legend, stack the legend
   above the timeline and give the timeline the full width back. */
@container stage (max-width: 1050px) {
  #legend { bottom: 90px; }
  #timeline { right: 16px; max-width: calc(100% - 112px); }
}


.legend .legend-metric-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.legend .classes { display: grid; gap: 6px; }
.legend .classes .row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--paper-ink); }
.legend .swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.legend .swatch-icon {
  width: 18px; height: 18px; display: inline-flex;
  align-items: center; justify-content: center; color: #fff;
}
.legend .swatch-icon svg { width: 12px; height: 12px; }
.legend .nodata { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--paper-mut); margin-top: 8px; }
.legend .swatch-hatch {
  background: repeating-linear-gradient(45deg, #7d8c98 0 1.5px, #f0f2f4 1.5px 5px);
  border: 1px solid var(--line);
}
.legend .legend-metric { font-size: 11px; color: var(--paper-mut); margin: 2px 0 8px; }

/* tooltip */
#tooltip {
  position: absolute; z-index: 1300; pointer-events: none;
  background: var(--ink); color: #fff; border-radius: 8px; padding: 9px 12px;
  font-size: 12.5px; line-height: 1.45; box-shadow: var(--shadow); max-width: 240px;
}
#tooltip .tt-name { font-weight: 700; font-size: 13px; }
#tooltip .tt-val { color: #9fbdd9; }
#tooltip .tt-note { display: block; margin-top: 3px; font-style: italic; opacity: .75; max-width: 220px; }
#tooltip .tt-more { display: block; margin-top: 6px; font-size: 11px; opacity: .7; }

/* drawer */
#drawer {
  /* top clears the floating top bar (bottom edge ~117px) by the usual 16px */
  position: absolute; top: 133px; right: 16px; width: 320px; z-index: 1150;
  max-height: calc(100% - 370px);
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow-y: auto; padding: 20px;
}
/* The raised legend (stacked layouts) shares the right column with the
   drawer, so the drawer shortens to clear it; below 832px the search bar
   wraps to a second row and the top bar grows taller. */
@container stage (max-width: 1050px) {
  #drawer { max-height: calc(100% - 440px); }
}
@container stage (max-width: 831px) {
  #drawer { top: 174px; max-height: calc(100% - 480px); }
}
#drawer-close {
  position: absolute; top: 10px; right: 12px; border: 0; background: none;
  font-size: 22px; color: var(--paper-mut); cursor: pointer; line-height: 1;
}
#drawer-close:hover { color: var(--paper-ink); }
#drawer h3 { font-family: var(--heading); font-size: 21px; margin: 2px 0; }
#drawer .wria-no { font-size: 11.5px; letter-spacing: .03em; color: var(--paper-mut); }
#drawer .stat { margin-top: 14px; }
#drawer .stat .num { font-family: var(--heading); font-size: 26px; font-weight: 600; }
#drawer .stat .num.bad { color: var(--warn); }
#drawer .stat .lbl { font-size: 12px; color: var(--paper-mut); margin-top: 2px; line-height: 1.4; }
#drawer .basin-chip { margin-top: 6px; font-size: 12px; color: var(--paper-mut); }
#drawer .overview { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
#drawer-toggle {
  display: block; width: 100%; margin-top: 12px; padding: 8px 10px;
  font: 600 12.5px var(--sans); color: var(--paper-ink); text-align: center;
  background: #f4f8fa; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
#drawer-toggle:hover { background: #dde7f0; }
#drawer-toggle:focus-visible { outline: 2px solid var(--glacial-dim); }
#drawer .ovr-row {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12.5px; padding: 4px 0; color: var(--paper-ink);
}
#drawer .ovr-row span { color: var(--paper-mut); }
#drawer .spark { margin-top: 16px; }
#drawer .spark-title { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
#drawer .spark-note { font-size: 10px; color: var(--paper-mut); margin-top: 2px; }
#drawer svg text { font-family: var(--sans); }

/* about panel — sits UNDER the top bar so the tabs stay usable as the way out */
#about-panel {
  position: absolute; inset: 0; z-index: 1090; overflow-y: auto; margin-top: 5%;
  background: rgba(231, 237, 240, .97); padding: 110px clamp(24px, 8vw, 96px) 48px;
}
#about-panel .inner { max-width: 640px; }
#about-panel h2 { font-family: var(--heading); font-size: 30px; margin-bottom: 16px; }
#about-panel h3 { font-family: var(--heading); font-size: 19px; margin: 26px 0 8px; }
#about-panel p, #about-panel li { font-size: 14px; line-height: 1.65; color: var(--paper-body); margin-bottom: 8px; }
#about-panel ul { padding-left: 20px; }
#about-panel ul ul { margin: 6px 0 2px; }
#about-panel .cite { font-size: 12.5px; color: var(--paper-mut); }
#about-panel .cite a { color: var(--glacial-dim); word-break: break-all; }
#about-panel a { color: var(--glacial-dim); }
/* emphasized sub-points under "Why the high greenhouse gas scenario?" */
#about-panel .about-sub {
  font-weight: 600; color: var(--paper-ink); margin-top: 14px;
  border-bottom: 1px solid rgba(67, 90, 47, .45); padding-bottom: 4px;
}
#about-panel table.sources { border-collapse: collapse; margin: 10px 0 6px; width: 100%; }
#about-panel table.sources th, #about-panel table.sources td {
  border: 1px solid var(--line); padding: 7px 9px; text-align: left;
  font-size: 12.5px; line-height: 1.5; color: var(--paper-body); vertical-align: top;
}
#about-panel table.sources th { background: rgba(128, 168, 205, .14); color: var(--paper-ink); }

/* ---------- mobile (phones & portrait tablets): map canvas + bottom story
   sheet. Landscape phones are excluded — they use the desktop arrangement
   with the compact-chrome layer below, since a sideways phone has no room
   for the bottom-sheet stack. Keep this condition in sync with isMobile(). */
@media (max-width: 860px) and (orientation: portrait), (max-width: 540px) {
  :root { --sheet-h: 172px; }

  html, body, #app { height: 100dvh; }
  #app { display: block; }
  #stage { position: absolute; inset: 0; }

  /* story sheet (was the sidebar) — light iOS-style sheet over the map */
  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1300;
    width: auto; min-width: 0;
    height: var(--sheet-h);
    border-radius: 18px 18px 0 0;
    background: rgba(252, 253, 253, .94);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    backdrop-filter: blur(18px) saturate(1.4);
    border-right: 0; border-top: 1px solid var(--line);
    box-shadow: 0 -8px 30px rgba(22, 34, 47, .22);
    transition: height .28s cubic-bezier(.4, 0, .2, 1);
    overflow: hidden;
  }
  body.sheet-half #sidebar { height: min(44dvh, 420px); }
  body.sheet-up #sidebar { height: min(85dvh, 720px); }
  @media (prefers-reduced-motion: reduce) { #sidebar { transition: none; } }

  /* while the watershed card is open, the sheet shrinks to a mini nav bar */
  body.drawer-open { --sheet-h: 92px; }
  body.drawer-open #sidebar { height: var(--sheet-h); }
  body.drawer-open #narrative, body.drawer-open #sheet-grabber, body.drawer-open #sheet-hint { display: none; }

  /* the whole sheet is the drag surface (Apple Maps style); the journey list
     opts back into vertical scrolling, and the story does too once the sheet
     is at its full height (the drag handler hands the gesture to the scroll) */
  #sidebar { touch-action: none; }
  #sidebar #journey { touch-action: pan-y; }
  body.sheet-up #narrative { overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; }

  #sheet-grabber {
    display: block; width: 100%; padding: 14px 0 8px; background: none; border: 0;
    cursor: grab; position: relative;
  }
  /* widen the tap/flick target to ~44px without moving the layout (the
     sheet clips upward extension, so only reach downward over the hint) */
  #sheet-grabber::before { content: ''; position: absolute; left: 0; right: 0; top: 0; bottom: -16px; }
  #sheet-grabber .bar {
    display: block; width: 40px; height: 5px; margin: 0 auto; border-radius: 3px;
    background: rgba(68, 104, 143, .35);
  }
  #sheet-hint {
    display: block; margin: -4px 0 2px; font: 500 11px var(--sans);
    color: rgba(68, 104, 143, .75); text-align: center;
  }
  /* the up-hint shows at the resting peek height, the down-hint at full;
     the in-between detent needs neither */
  #sheet-hint .down { display: none; }
  body.sheet-half #sheet-hint { display: none; }
  body.sheet-up #sheet-hint .up { display: none; }
  body.sheet-up #sheet-hint .down { display: inline; }
  /* the story box starts below the grabber + hint stack (~48px) when the
     sheet is raised, so scrolled text never slides under the hint; the top
     fade softens the clip edge while scrolled */
  body.sheet-up #narrative {
    top: 50px;
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 16px);
    mask-image: linear-gradient(180deg, transparent 0, #000 16px);
  }
  /* the raised sheet's top edge would otherwise slice through the tip line */
  body.sheet-up #search-tip { visibility: hidden; }

  .brand { display: none; }

  /* journey hidden behind the "Stop X of Y" button; overlays the narrative when open */
  #journey { display: none; }
  body.journey-open #journey {
    display: block; max-height: none;
    position: absolute; top: 30px; bottom: 74px; left: 0; right: 0;
    overflow-y: auto; background: transparent; z-index: 2;
  }
  body.journey-open #narrative { visibility: hidden; }
  .step button { padding-top: 11px; padding-bottom: 11px; font-size: 15px; }
  .chapter-head { padding-top: 12px; padding-bottom: 10px; }

  #narrative {
    position: absolute; top: 30px; bottom: 74px; left: 0; right: 0;
    border-top: 0; padding: 8px 20px 12px;
    overflow: hidden;   /* the sheet moves instead of the story scrolling */
  }
  #narrative h2 { font-size: 20px; }
  #narrative p { font-size: 14px; }
  /* the search tip duplicates the visible search bar on phones */
  #narrative .hint { display: none; }

  #stepnav {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: inherit;
  }
  .nav-btn { padding: 12px 20px; border-radius: 12px; font-size: 15px; }
  .progress { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; min-height: 44px; }

  /* on phones the bar dissolves back into floating pieces */
  #topbar {
    display: contents;
  }
  /* no room for the sub-header once the bar dissolves */
  #tab-subheader { display: none; }

  /* topic tabs — iOS segmented control, centered at top */
  #map-tabs {
    position: absolute; z-index: 1100;
    top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px;
    justify-content: stretch; border-radius: 12px; padding: 4px;
    background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow);
  }
  .map-tab { flex: 1; text-align: center; padding: 13px 2px; border-radius: 9px; }  /* ≥44px touch target */
  .map-tab .tab-label { font-size: 12px; }
  .map-tab .tab-tip { display: none; }   /* segmented control stays compact */
  .tab-divider { display: none; }
  /* the tip floats directly over the map on phones: a light halo keeps it
     legible across dark map colors */
  #search-tip {
    font-size: 11px; color: var(--paper-body);
    text-shadow: 0 0 6px rgba(252, 253, 253, .95), 0 0 3px rgba(252, 253, 253, .95),
                 0 1px 2px rgba(252, 253, 253, .9);
  }

  /* search — full-width pill under the tabs */
  #searchbox {
    position: absolute; z-index: 1100;
    top: calc(max(10px, env(safe-area-inset-top)) + 58px);
    left: 12px; right: 12px;
    align-items: stretch; gap: 4px;
  }
  .search-row { width: 100%; }
  #search { flex: 1; width: auto; min-height: 44px; min-width: 0; }
  #search-results { width: 100%; top: 50px; }
  #btn-state, #btn-print { min-height: 44px; padding: 10px 12px; font-size: 12.5px; }

  /* timeline — chip row pinned above the sheet */
  #timeline {
    left: 0; right: 0; bottom: calc(var(--sheet-h) + 10px);
    max-width: none; width: auto; margin: 0 10px;
    border-radius: 12px; padding: 8px 10px;
    transition: bottom .28s cubic-bezier(.4, 0, .2, 1);
  }
  body.sheet-up #timeline, body.sheet-up #legend,
  body.sheet-half #timeline, body.sheet-half #legend { opacity: 0; pointer-events: none; }
  #btn-play { width: 40px; height: 40px; }
  #tl-prev { left: 63px; }   /* clears the larger play button */
  .decade { padding: 10px 12px; min-height: 40px; }

  /* legend — compact card above the timeline; wide enough for the
     single-row boundary labels */
  #legend {
    right: 10px; left: auto; bottom: calc(var(--sheet-h) + 76px);
    width: min(310px, calc(100vw - 20px)); padding: 9px 11px;
    transition: bottom .28s cubic-bezier(.4, 0, .2, 1);
  }
  #legend .legend-title { font-size: 10.5px; }
  #legend .edgelabels { font-size: 9px; }
  #legend .classes .row { font-size: 11px; }
  #legend .nodata { font-size: 10px; margin-top: 6px; }

  /* watershed details — compact card stacked above the timeline, which stays
     above the mini story bar; map strip and nav both remain usable */
  #drawer {
    position: fixed; top: auto; left: 10px; right: 10px;
    bottom: calc(var(--sheet-h) + 76px);
    width: auto; max-height: 32dvh; z-index: 1250; border-radius: 16px;
  }

  /* about — fills the map area under the chrome; the peek sheet keeps Back /
     Start over reachable and the tabs stay tappable above */
  #about-panel { padding: 178px 24px calc(var(--sheet-h) + 24px); }

  /* frosted band behind the tabs/search while About scrolls beneath them */
  body.about-open #stage::before {
    content: ''; position: fixed; top: 0; left: 0; right: 0; z-index: 1095;
    height: calc(max(10px, env(safe-area-inset-top)) + 140px);
    background: rgba(199, 219, 233, .72);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    backdrop-filter: blur(14px) saturate(1.2);
    border-bottom: 1px solid rgba(23, 36, 44, .08);
  }

  #map-credit { display: none; }
  #tooltip { display: none; }
  /* zoom buttons stay (single-pointer zoom alternative); hidden only while
     the sheet is raised or a watershed card is open */
  body.sheet-half .esri-ui, body.sheet-up .esri-ui,
  body.drawer-open .esri-ui { display: none; }
}

/* Collapsible legend — phones and short (landscape) screens only. Collapsed,
   the card shrinks to its title line so the map shows through. */
.legend-toggle { display: none; }
@media (max-width: 860px) and (orientation: portrait), (max-width: 540px), (max-height: 520px) {
  .legend-toggle {
    display: flex; align-items: center; justify-content: center;
    position: absolute; top: 0; right: 0; width: 50px; height: 44px;
    border: 0; background: none; cursor: pointer; color: var(--glacial-dim);
  }
  .legend-toggle::after { content: '▾'; font-size: 16px; }
  /* only the title row needs to clear the toggle; the ramp keeps full width */
  #legend:not(.collapsed) .legend-title { padding-right: 32px; }
  #legend.collapsed { width: auto; max-width: 230px; padding: 11px 48px 11px 13px; }
  #legend.collapsed > :not(.legend-toggle):not(.legend-title) { display: none; }
  #legend.collapsed .legend-title {
    margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #legend.collapsed .legend-toggle { height: 100%; }
  #legend.collapsed .legend-toggle::after { content: '▴'; }
}
body.printing .legend-toggle { display: none !important; }

/* ---------- short screens (landscape phones, squat windows): the desktop
   arrangement with compact chrome so the map keeps usable height ---------- */
@media (min-width: 541px) and (max-height: 520px) {
  :root { --rail-w: 248px; }
  /* the description area owns the rail's spare height: brand and journey
     stay as slim as legibility allows so a few story lines always show */
  .brand { padding: 8px 14px 6px; }
  .ecy-logo { width: 116px; margin-bottom: 4px; }
  .brand h1 { font-size: 15px; }
  #journey { padding: 4px 0 2px; max-height: 26%; min-height: 48px; }
  .chapter-head { padding-top: 4px; padding-bottom: 3px; }
  #narrative { padding: 8px 16px 8px; min-height: 64px; }
  #narrative h2 { font-size: 16px; margin-bottom: 6px; }
  #narrative .kicker { margin-bottom: 4px; }
  #stepnav { padding: 6px 14px; }
  .nav-btn { padding: 7px 12px; }
  #topbar { top: 10px; left: 10px; right: 10px; }
  #tab-subheader, #search-tip, .map-tab .tab-tip { display: none; }
  /* content-sized tabs distributed across the row: even rhythm without
     stretching short labels into oversized cells. Large system font sizes
     scroll the row sideways rather than growing the bar over the map. */
  #map-tabs {
    flex: 1; justify-content: space-between;
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
  }
  #map-tabs::-webkit-scrollbar { display: none; }
  .map-tab { flex: 0 0 auto; padding: 10px 10px 9px; }  /* ~40px touch target */
  .tab-divider { display: none; }
  #search { width: 150px; padding: 8px 12px; }
  #timeline { bottom: 10px; left: 72px; padding: 6px 10px; }
  .decade { padding: 7px 9px; font-size: 12px; }
  #btn-play { width: 30px; height: 30px; }
  #tl-prev { left: 47px; }
  #legend { bottom: 56px; right: 10px; }
  /* the top bar runs two rows at these widths (search wraps) */
  #drawer { top: 120px; right: 10px; width: 290px; padding: 16px; max-height: calc(100% - 186px); }
  /* the card and the legend share the right column; detail mode wins */
  body.drawer-open #legend { display: none; }
  #map-credit { font-size: 10px; }
}

/* print: the current map view as a one-page handout.
   Layout lives on body.printing (added on beforeprint, removed on afterprint) so the
   script can re-fit the map view to the print box before the dialog captures it. */
@media print {
  @page { size: landscape; margin: 10mm; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* screen-only overlays (frosted tab band on About, etc.) never print */
  #stage::before, #stage::after { content: none !important; }
}
body.printing-about #stage::before, body.printing #stage::before { content: none !important; }

/* ---------- print choice + report ---------- */
/* display:flex would otherwise defeat the hidden attribute */
#print-choice[hidden], #report-progress[hidden] { display: none; }
#print-choice {
  position: fixed; inset: 0; z-index: 3000; background: rgba(12, 26, 35, .45);
  display: flex; align-items: center; justify-content: center;
}
#print-choice .pc-card {
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px 24px; width: min(380px, calc(100vw - 32px));
}
#print-choice h3 { font-family: var(--heading); font-size: 20px; margin-bottom: 14px; }
#print-choice .pc-option {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px; font-family: var(--sans);
}
#print-choice .pc-option strong { display: block; font-size: 14px; color: var(--paper-ink); }
#print-choice .pc-option span { display: block; font-size: 12px; color: var(--paper-mut); margin-top: 2px; }
#print-choice .pc-option:hover { background: #dde7f0; border-color: var(--glacial-dim); }
#print-choice .pc-option:focus-visible, #print-choice .pc-cancel:focus-visible {
  outline: 2px solid var(--glacial-dim); outline-offset: 1px;
}
#print-choice .pc-cancel {
  background: none; border: 0; cursor: pointer; font: 600 12.5px var(--sans);
  color: var(--paper-mut); padding: 8px 4px 2px;
}
#print-choice .pc-cancel:hover { color: var(--paper-ink); }

#report-progress {
  position: fixed; inset: 0; z-index: 3000; background: rgba(12, 26, 35, .45);
  display: flex; align-items: center; justify-content: center;
}
#report-progress .rpg-card {
  background: var(--paper); border-radius: 12px; box-shadow: var(--shadow);
  padding: 18px 26px; font: 600 14px var(--sans); color: var(--paper-ink);
  display: flex; align-items: center; gap: 16px;
}
#report-progress #rpg-cancel {
  background: none; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  font: 600 12px var(--sans); color: var(--paper-mut); padding: 6px 12px;
}
#report-progress #rpg-cancel:hover { color: var(--paper-ink); border-color: var(--paper-mut); }

#print-choice .pc-sections {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin: -4px 2px 10px; padding-left: 12px;
}
#print-choice .pc-sections label {
  font: 500 12.5px var(--sans); color: var(--paper-ink);
  display: flex; align-items: center; gap: 5px; cursor: pointer;
}
#print-choice .pc-option:disabled { opacity: .45; cursor: default; }
#print-choice .pc-option:disabled:hover { background: #fff; border-color: var(--line); }

/* The report document: never on screen, the only thing on paper. The swap
   lives in print media so the live app can return to the screen while a
   non-blocking print sheet (iOS) is still rendering pages from #report. */
#report { display: none; }
@media print {
  /* On paper the on-screen frame heights mean nothing, and a fixed root
     height can clip WebKit's print output to a single page. */
  html, body, #app { height: auto !important; }
  body.printing-report > :not(#report) { display: none !important; }
  body.printing-report #report { display: block; background: #fff; }
}
#report .rp { break-after: page; }
#report .rp:last-child { break-after: auto; }
#report .rp-eyebrow { font-size: 11px; letter-spacing: .04em; color: var(--paper-mut); }

#report .rp-cover {
  height: 182mm; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  background: linear-gradient(168deg, var(--ink) 0%, var(--ink-2) 100%);
}
#report .rp-cover img { width: 240px; margin-bottom: 26px; }
#report .rp-cover .rp-eyebrow { color: var(--mist); }
#report .rp-cover h1 { font-family: var(--heading); font-size: 44px; color: #fff; margin: 8px 0 12px; }
#report .rp-cover-sub { font-size: 15px; color: var(--chalk); }
#report .rp-cover-date { font-size: 12px; color: var(--mist); margin-top: 30px; }

#report .rp-contents { padding: 14mm 18mm; max-width: 210mm; margin: 0 auto; }
#report .rp-contents-note { font-size: 11px; color: var(--paper-mut); margin-top: 6mm; }
#report .rp-divider {
  height: 182mm; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; background: #eef3f6;
}
#report .rp-divider h2 { font-family: var(--heading); font-size: 36px; margin-top: 6px; }
#report .rp-divider-tip { font-size: 14px; color: var(--paper-mut); margin-top: 8px; }
#report .rp-contents h2, #report .rp-map h2 { font-family: var(--heading); font-size: 24px; margin-bottom: 8px; }
#report .rp-contents > ol { margin: 6mm 0 0 5mm; font-size: 14px; line-height: 2; }
#report .rp-contents ol ol { margin-left: 7mm; font-size: 12.5px; line-height: 1.9; color: var(--paper-body); }

#report .rp-about { padding: 14mm 18mm; max-width: 185mm; margin: 0 auto; }
#report .rp-about h2 { font-family: var(--heading); font-size: 26px; margin-bottom: 12px; }
#report .rp-about h3 { font-family: var(--heading); font-size: 18px; margin: 18px 0 6px; break-after: avoid; }
#report .rp-about p, #report .rp-about li { font-size: 12.5px; line-height: 1.6; color: var(--paper-body); margin-bottom: 6px; break-inside: avoid; }
#report .rp-about ul { margin-left: 5mm; }

#report .rp-map { padding: 6mm 8mm; }
#report .rp-map header { border-bottom: 2px solid var(--ink); padding-bottom: 3mm; margin-bottom: 4mm; }
#report .rp-map-when { font-size: 13px; font-weight: 700; color: var(--ink); }
#report .rp-map-sub { font-size: 11px; color: var(--paper-body); }
#report .rp-mapbox { position: relative; }
#report .rp-mapbox > img { display: block; width: 100%; border: 1px solid var(--line); }
#report .rp-legend {
  position: absolute; right: 5mm; bottom: 5mm; width: 85mm;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px;
}

@media print {
  #print-choice, #report-progress { display: none !important; }
}
body.printing #sidebar, body.printing #topbar,
body.printing #timeline, body.printing #tooltip,
body.printing .esri-ui, body.printing #drawer-close {
  display: none !important;
}
/* print the compact detail card only: the expand control and everything
   below it are screen-only, so the card always fits its print box */
body.printing #drawer-toggle, body.printing #drawer-more { display: none !important; }
body.printing #welcome { display: none !important; }
body.printing #app { display: block; }
/* Fixed mm box matching the landscape content area of letter (~259×196mm) and A4
   (~277×190mm) pages, so the map is re-fit at exactly the size the paper renders. */
body.printing #stage { position: relative; height: 185mm; width: 258mm; }
body.printing #print-header {
  display: block; position: absolute; top: 0; left: 0; right: 0; z-index: 2000;
  background: #fff; padding: 12px 18px; border-bottom: 2px solid var(--ink);
}
body.printing #print-header .ph-eyebrow {
  font-size: 10px; letter-spacing: .03em; color: var(--paper-mut);
}
body.printing #print-header h2 { font-family: var(--heading); font-size: 20px; margin: 2px 0; }
body.printing #print-header p { font-size: 11px; color: var(--paper-body); }
body.printing #print-header #print-when { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 1px; }
body.printing #map { top: 76px; }
/* high-density capture printed in place of the live canvas (see enterPrintLayout) */
body.printing #print-shot {
  position: absolute; top: 76px; left: 0; right: 0; bottom: 0;
  width: 100%; height: calc(100% - 76px); object-fit: cover; z-index: 900;
}
body.printing #legend, body.printing #drawer { box-shadow: none; }
/* selected-watershed print: tuck the detail card bottom-right so the WRIA shows */
body.printing #drawer {
  top: auto; left: auto; right: 8px; bottom: 8px;
  width: 250px; max-height: 45%; overflow: hidden; font-size: 11px;
}
body.printing #legend { bottom: 28px; left: 8px; right: auto; }  /* clears the credit line */

/* About prints as a flowing document: the panel leaves its fixed scroll box
   so every section lays out in normal flow and paginates naturally. */
body.printing-about #sidebar,
body.printing-about #stage > :not(#about-panel) { display: none !important; }
body.printing-about #app { display: block; }
body.printing-about #stage { position: static; height: auto; width: auto; container-type: normal; }
body.printing-about #about-panel {
  position: static; overflow: visible; background: #fff; padding: 10mm 0;
}
body.printing-about #about-panel .inner { max-width: 170mm; margin: 0 auto; }
body.printing-about #about-panel h3 { break-after: avoid; }
body.printing-about #about-panel ul, body.printing-about #about-panel p { break-inside: avoid; }

@media (prefers-reduced-motion: no-preference) {
  .step.current button::after { animation: pulse 2.4s ease-in-out infinite; }
  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(110, 203, 232, .22); }
    50% { box-shadow: 0 0 0 7px rgba(110, 203, 232, .10); }
  }
}

/* boundary-source failure notice (service AND bundled fallback unavailable) */
#geo-notice {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 1200; background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 18px 24px;
  font: 600 14px var(--sans); color: var(--paper-ink); max-width: 340px; text-align: center;
}
