/* ============================================================================
   mco-web-style · theme/mco-theme.css
   The Montana Climate Office shared web house style.

   Consumed via pinned CDN tag + SRI (see README.md). Rules for using and
   extending this file live in HOUSE-STYLE.md; guardrails in AGENTS.md.

   Layers, top to bottom:
     Fonts                   — the kit-hosted faces and their fallbacks
     1. Design tokens        — dark (:root), light, high-contrast themes
     2. Stacking ladder      — z-index tiers for every floating surface
     2b. Type & spacing scale
     3. Reset & accessibility utilities
     4. MapLibre control polish
     5. Component shells     — navbar, toast, tooltip, modal, panel, scrim
     6. Responsive & touch

   Fonts ARE loaded here: Outfit + Space Mono are kit-hosted in fonts/ and
   declared in the Fonts block, resolved relative to this file so they
   version with it. Consumers preload the two latin files from
   snippets/head.html; the tokens carry system fallbacks.
   ========================================================================== */

/* ── Fonts ────────────────────────────────────────────────────────────────
   Kit-hosted latin + latin-ext subsets of the Google Fonts builds (SIL OFL;
   license texts in fonts/). url() resolves against THIS stylesheet, so a page
   pinned to @X.Y.Z gets that tag's fonts. The latin files should be preloaded
   (snippets/head.html); latin-ext is fetched only when a page actually uses
   a character in its unicode-range.

   font-display: block, not swap. With display=swap a page paints its text
   in the system font and re-sets it in Outfit a beat later, and the title
   visibly jumps. Preloaded from the same origin as this
   render-blocking stylesheet, the fonts normally arrive before first paint;
   when they don't, block costs a few ms of invisible text rather than a
   re-set of every line, and the browser still falls back after ~3s if a file
   never arrives. Outfit is a variable font: one file per subset covers every
   weight in use (400–700). */
@font-face {
  font-family: 'Outfit'; font-style: normal; font-weight: 400 700; font-display: block;
  src: url(../fonts/outfit-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Outfit'; font-style: normal; font-weight: 400 700; font-display: block;
  src: url(../fonts/outfit-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Mono'; font-style: normal; font-weight: 400; font-display: block;
  src: url(../fonts/space-mono-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Space Mono'; font-style: normal; font-weight: 400; font-display: block;
  src: url(../fonts/space-mono-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Metric-matched fallbacks. During the block period text is invisible
   but still LAID OUT — in the next family in the stack. Plain Arial sets the
   navbar title ~6% wider and its line box 3px shorter than Outfit, so items
   beside the title shift when the webfont lands. These faces rescale a
   local metric-stable font (Arial; Helvetica and Liberation Sans share its
   metrics) to Outfit's
   proportions, so the layout reserved during the block period is the one
   Outfit then fills.
   - size-adjust: Outfit/Arial advance-width ratio over a corpus of real MCO UI
     strings, measured in Chrome per weight, because Outfit's advances move
     with its weight axis and Arial only has 400 and 700.
   - ascent/descent/line-gap-override: Outfit's own metrics (1.000 / 0.260 /
     0, Space Mono 1.120 / 0.361 / 0) divided by size-adjust, which scales the
     overrides too. Line boxes then match exactly (verified: 15px vs 15px,
     where plain Arial gives 12px).
   - The ITALIC face is fitted to the one italic string in the house style,
     the lockup subtitle ("A service of the Montana Climate Office", §1 —
     every public MCO app carries it),
     which sets the lockup's width in most apps: 169.3px vs Outfit's 169.4px
     (letter-spacing excluded from the fit, since size-adjust doesn't scale
     it). Outfit has no italic, so the real face is a synthesized oblique of
     the upright — same advances as upright.
   Line boxes match exactly in every face. Widths: upright text lands within a
   few percent either way, since no single scale turns Arial's letterforms
   into Outfit's — uppercase Outfit is ~6% narrower than Arial capitals, so an
   uppercase title (weight 500) still reserves ~3–5% too much. Measured
   under a throttled connection (150 ms, 200 KB/s), the navbar item beside
   the lockup moves 16.6px when Outfit lands with plain Arial and 0.1px
   with these faces. A bar whose uppercase title is wider than the subtitle
   moves 11.9px with Arial and 5.2px with these faces. Space Mono vs Courier
   New is exact (both monospaced: 0.612em vs 0.600em advance). */
@font-face {
  font-family: 'Outfit Fallback'; font-style: normal; font-weight: 400 500;
  src: local('Arial'), local('ArialMT'), local('Helvetica'), local('Liberation Sans');
  size-adjust: 98.80%; ascent-override: 101.21%; descent-override: 26.32%; line-gap-override: 0.00%;
}
@font-face {
  font-family: 'Outfit Fallback'; font-style: normal; font-weight: 600;
  src: local('Arial Bold'), local('Arial-BoldMT'), local('Helvetica Bold'), local('Liberation Sans Bold');
  size-adjust: 95.06%; ascent-override: 105.20%; descent-override: 27.35%; line-gap-override: 0.00%;
}
@font-face {
  font-family: 'Outfit Fallback'; font-style: normal; font-weight: 700;
  src: local('Arial Bold'), local('Arial-BoldMT'), local('Helvetica Bold'), local('Liberation Sans Bold');
  size-adjust: 96.64%; ascent-override: 103.48%; descent-override: 26.90%; line-gap-override: 0.00%;
}
@font-face {
  font-family: 'Outfit Fallback'; font-style: italic; font-weight: 400 500;
  src: local('Arial Italic'), local('Arial-ItalicMT'), local('Helvetica Oblique'), local('Liberation Sans Italic');
  size-adjust: 100.58%; ascent-override: 99.42%; descent-override: 25.85%; line-gap-override: 0.00%;
}
@font-face {
  font-family: 'Space Mono Fallback'; font-style: normal; font-weight: 400;
  src: local('Courier New'), local('CourierNewPSMT'), local('Liberation Mono');
  size-adjust: 101.98%; ascent-override: 109.83%; descent-override: 35.40%; line-gap-override: 0.00%;
}

/* ── 1. Design tokens ─────────────────────────────────────────────────────
   Dark is the default theme. `data-theme` on <html> switches; the anti-flash
   snippet (snippets/anti-flash.html) sets it before first paint. On any
   other element it makes a theme island (below the theme blocks).

   Contrast contract (enforced by tools/check-contrast.mjs in CI):
     --text-primary, --text-secondary  ≥ 4.5:1 on deep, surface, AND raised
     --text-muted,  --text-dim         ≥ 4.5:1 on deep and surface ONLY —
                                         never use them on --bg-raised
     --accent-line                     ≥ 3:1 on all three surfaces (1.4.11)
                                         and on every --band-*
     --text-* on --band-sky/-prairie/-sage ≥ 4.5:1 (muted/dim too)
     --prairie-line, --sage-line,
     --rust-line                       ≥ 4.5:1 on deep, surface, raised and
                                         every band
     --text-on-prairie                 ≥ 4.5:1 on --prairie
     --text-on-accent                  ≥ 4.5:1 on --accent
     --danger, --warning, --success    ≥ 4.5:1 on deep, surface, raised, and
                                          on their own --*-fill
     --text-on-danger/-warning/-success ≥ 4.5:1 on the matching --*-fill

   --accent is the MCO brand blue. On dark surfaces it only clears ~2.3–2.9:1,
   so it is a FILL color: use it behind --text-on-accent. For borders, icons,
   or text that must read against a surface, use --accent-line. */
:root {
  --font-ui:        'Outfit', 'Outfit Fallback', system-ui, -apple-system, sans-serif;
  --font-mono:      'Space Mono', 'Space Mono Fallback', ui-monospace, monospace;
  /* Display-size readings (≥ 1.75rem hero and tile values): Outfit,
     with tabular figures from .mco-num-display. Space Mono stays for every
     other numeral (tables, IDs, timestamps, axes, scale labels, <kbd>). */
  --font-display-num: 'Outfit', 'Outfit Fallback', system-ui, -apple-system, sans-serif;
  --transition:     0.2s cubic-bezier(0.4,0,0.2,1);
  --radius-sm:      4px;
  --radius-md:      8px;
  --radius-lg:      12px;
}

/* Dark values, on the root and on any element marked data-theme="dark".
   Every theme block is a plain attribute selector, so a
   data-theme on ANY element re-declares that theme's tokens there and its
   subtree inherits them: a "theme island" (HOUSE-STYLE §4). On <html>,
   :root, [data-theme="dark"], light and high-contrast are all (0,1,0), so
   the later light/high-contrast block wins on the root by source order.
   Theme-invariant tokens (fonts, radii, transition) stay in the :root
   block above, so an island never
   resets an app's override of them. */
:root,
[data-theme="dark"] {
  --bg-deep:        #161b22;
  --bg-surface:     #1e2530;
  --bg-raised:      #2c3545;
  --border:         #3a4558;
  --border-glass:   rgba(255,255,255,0.08);
  --text-primary:   #e8ecf0;
  --text-secondary: #c0cad6;
  --text-muted:     #8a99b0;
  --text-dim:       #8494ab;
  --ctrl-border:    #6a7996;
  --accent:         #1a6faf;
  --accent-light:   #5aaee8;
  --accent-dk:      #114f80;
  --accent-line:    #5aaee8;
  --accent-hover:   rgba(26,111,175,0.10);
  --text-on-accent: #ffffff;
  --accent-fill-hover: #114f80;   /* .nav-btn.is-primary hover; --text-on-accent ≥ 4.5:1 on it */
  --selection-ring: #5aaee8;
  --brand-gradient: linear-gradient(90deg, var(--accent-dk), var(--accent), var(--accent-light), var(--accent));
  --glass:          rgba(30,37,48,0.92);   /* legible WITHOUT the blur */
  --shadow:         0 4px 24px rgba(0,0,0,0.4);
  --dot-stroke:     #ffffff;
  --input-bg:       #232a35;
  --scrim:          rgba(0,0,0,0.55);
  --ctrl-icon-filter: invert(1);
  /* Status tones — CHROME, not data (HOUSE-STYLE §2): form errors,
     notices, the basemap-failure banner. Never the only channel: pair with
     a tone word or icon. Each tone is ≥ 4.5:1 on deep/surface/raised and on
     its own -fill; --text-on-* is ≥ 4.5:1 on that fill (check-contrast). */
  --danger:         #ed8780;
  --danger-fill:    #37313a;
  --text-on-danger: #e8ecf0;
  --warning:        #df9412;
  --warning-fill:   #35322c;
  --text-on-warning: #e8ecf0;
  --success:        #36ba6d;
  --success-fill:   #213737;
  --text-on-success: #e8ecf0;
  /* Landscape tones: CHROME, not data (HOUSE-STYLE §2), sampled
     from the station cameras. --band-* are section grounds that mark a
     real boundary on a content page; --prairie is a fill behind
     --text-on-prairie (a primary call to action); the -line tones are
     eyebrows, ticks and icons. Never a legend: data takes MCO.palette.
     Every text token and -line tone is ≥ 4.5:1 on deep, surface, raised
     and every band (--text-muted/-dim: not raised); check-contrast. */
  --band-sky:        #13263a;
  --band-prairie:    #252117;
  --band-sage:       #18231c;
  --prairie:         #d9a43a;
  --text-on-prairie: #161b22;
  --prairie-line:    #e3b55a;
  --sage-line:       #9cc08a;
  --rust-line:       #ec9a74;
}

[data-theme="light"] {
  --bg-deep:        #f0f2f5;
  --bg-surface:     #ffffff;
  --bg-raised:      #e8ecf0;
  --border:         #c8cdd5;
  --border-glass:   rgba(0,0,0,0.08);
  --text-primary:   #1a1a2e;
  --text-secondary: #3a3f4b;
  --text-muted:     #5a6070;
  --text-dim:       #5f6675;
  --ctrl-border:    #7e8694;
  --accent:         #1a6faf;
  --accent-light:   #1563a0;
  --accent-dk:      #0d4f7a;
  --accent-line:    #1563a0;
  --accent-hover:   rgba(26,111,175,0.08);
  --text-on-accent: #ffffff;
  --accent-fill-hover: #0d4f7a;
  --selection-ring: #1563a0;
  --brand-gradient: linear-gradient(90deg, #0a4a7a, #1266a8, #0d7fd4, #1266a8, #0a4a7a);
  --glass:          rgba(255,255,255,0.94);
  --shadow:         0 4px 24px rgba(0,0,0,0.1);
  --dot-stroke:     #2a2a3a;
  --input-bg:       #f4f5f7;
  --scrim:          rgba(0,0,0,0.45);
  --ctrl-icon-filter: none;
  --danger:         #c2271c;
  --danger-fill:    #f8e5e4;
  --text-on-danger: #1a1a2e;
  --warning:        #8a5b0b;
  --warning-fill:   #f1ebe2;
  --text-on-warning: #1a1a2e;
  --success:        #217343;
  --success-fill:   #e4eee8;
  --text-on-success: #1a1a2e;
  --band-sky:        #e5eff7;
  --band-prairie:    #f6eedb;
  --band-sage:       #e7ede3;
  --prairie:         #d9a43a;
  --text-on-prairie: #1a1a2e;
  --prairie-line:    #85570a;
  --sage-line:       #476a3c;
  --rust-line:       #a3441d;
}

/* High-contrast: pure-black surfaces, brightened accent, near-white text.
   Adapted from mco-drought-dashboard. The accent tints are derived from
   THIS theme's accent (#5bb4ff = rgb(91,180,255)).
   --text-on-accent flips to black: white fails on the brightened accent. */
[data-theme="high-contrast"] {
  --bg-deep:        #000000;
  --bg-surface:     #000000;
  --bg-raised:      #121212;
  --border:         #8a8a8a;
  --border-glass:   rgba(255,255,255,0.28);
  --text-primary:   #ffffff;
  --text-secondary: #f5f5f5;
  --text-muted:     #dcdcdc;
  --text-dim:       #bcbcbc;
  --ctrl-border:    #8a8a8a;
  --accent:         #5bb4ff;
  --accent-light:   #93d0ff;
  --accent-dk:      #2070a8;
  --accent-line:    #93d0ff;
  --accent-hover:   rgba(91,180,255,0.15);
  --text-on-accent: #000000;
  --accent-fill-hover: #93d0ff;   /* lighter, not darker: black text fails on --accent-dk (3.9:1) */
  --selection-ring: #93d0ff;
  --brand-gradient: linear-gradient(90deg, #2a9aff, #6ec0ff, #a0d8ff, #6ec0ff, #2a9aff);
  --glass:          rgba(0,0,0,0.96);
  --shadow:         0 4px 24px rgba(0,0,0,0.7);
  --dot-stroke:     #ffffff;
  --input-bg:       #121212;
  --scrim:          rgba(0,0,0,0.8);
  --ctrl-icon-filter: invert(1);
  --danger:         #f47a71;
  --danger-fill:    #1d0f0e;
  --text-on-danger: #ffffff;
  --warning:        #dc8d06;
  --warning-fill:   #1a1101;
  --text-on-warning: #ffffff;
  --success:        #26b562;
  --success-fill:   #05160c;
  --text-on-success: #ffffff;
  --band-sky:        #000000;
  --band-prairie:    #000000;
  --band-sage:       #000000;
  --prairie:         #ffc95c;
  --text-on-prairie: #000000;
  --prairie-line:    #ffc95c;
  --sage-line:       #b5e0a0;
  --rust-line:       #ffad85;
}

/* Theme islands. Tokens alone don't re-colour an island's text:
   `color` inherits as a computed value from body, so it would keep the
   page theme's --text-primary. An island takes its own, and tells the UA
   which native controls and scrollbars to draw. The root is excluded, and
   :where() keeps this at zero specificity, so any app or kit rule that
   sets color wins. An island
   paints no background of its own: give it one (or a photo, or a map),
   because its contrast is its theme's contrast against its own surfaces. */
:where([data-theme="dark"], [data-theme="high-contrast"]):where(:not(:root)) {
  color: var(--text-primary); color-scheme: dark;
}
:where([data-theme="light"]):where(:not(:root)) {
  color: var(--text-primary); color-scheme: light;
}

/* ── 2. Stacking ladder ───────────────────────────────────────────────────
   One ladder for every floating surface. Add to a tier — don't invent a
   number. MapLibre's own .maplibregl-ctrl-* containers ship with z-index 2
   from the vendor stylesheet, so anything meant to sit over the map controls
   (notably map popups, which ship with NO z-index) has to be above that.
   The detail tier stays BELOW the chrome so a docked detail surface can never
   cover the navbar; <dialog> lives in the browser's top layer and outranks
   all of these regardless. */
:root {
  --z-map-ctrl:      2;   /* vendor .maplibregl-ctrl-* containers          */
  --z-map-notice:   20;   /* empty-state / error callouts over the map     */
  --z-map-progress: 30;   /* loading bars and notes                        */
  --z-map-panel:    40;   /* docked panels (legend, sidebar) + scrim       */
  --z-detail:       60;   /* docked detail surface (station sheet etc.)    */
  --z-drawer:       70;   /* off-canvas drawer, over the detail surface    */
  --z-chrome:       90;   /* secondary chrome bars                         */
  --z-chrome-top:  100;   /* navbar                                        */
  --z-flyout:      150;   /* dropdowns / search results                    */
  --z-cursor:      200;   /* pointer-following tooltip                     */
  --z-toast:       400;   /* toast — above everything                      */
}

/* ── 2b. Type & spacing scale ─────────────────────────────────────────────
   Theme-invariant, so :root only (tools/check-tokens.mjs knows them as the
   `scale` group, like the z-index ladder). Each step names a cluster the kit
   uses, so adopting one is near-invisible. Moving a rule onto a step can be
   a visible snap (0.72→0.75rem, 0.78→0.8125rem), which makes it a major
   change. --nav-gap defaults to --space-4. */
:root {
  --fs-2xs:     0.55rem;   /* unused by the kit (the lockup subtitle is 11px) */
  --fs-xs:      0.65rem;   /* mono meta, tooltip sub */
  --fs-sm:      0.75rem;   /* brand title, panel titles, seg/tooltip, captions */
  --fs-md:      0.8125rem;   /* buttons, toast, eyebrow h3 */
  --fs-base:    0.875rem;   /* prose, table cells */
  --fs-lg:      1.0625rem;   /* modal and card titles */
  --fs-xl:      1.375rem;   /* stat readouts */
  --fs-2xl:     2rem;   /* hero numbers */
  --lh-tight:   1.2;
  --lh-body:    1.6;
  --fw-regular: 400;
  --fw-medium:  500;
  --fw-semibold:600;
  --fw-bold:    700;
  --space-1:    0.25rem;
  --space-2:    0.4rem;   /* the house rhythm (lockup, edge margins) */
  --space-3:    0.5rem;
  --space-4:    0.75rem;
  --space-5:    1rem;
  --space-6:    1.5rem;
  --space-7:    2rem;
  /* One control height: every .nav-btn, .seg-btn, .mco-chip and
     .mco-search-input in the navbar and its drawer. 40px on touch, set
     below on html:root (which outranks :root without matching it here). */
  --control-h:  34px;
}
@media (hover: none) { html:root { --control-h: 40px; } }

/* ── 3. Reset & accessibility utilities ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg-deep);
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition);
}

/* Reduced motion: blanket CSS clamp. Map camera animations are a JS concern —
   gate them with MCO.reducedMotion() (live-reactive), never a boot snapshot. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration:  0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* The UA's [hidden] { display: none } loses to any rule that sets display
   explicitly, so flex/grid elements stay visible as empty strips when hidden
   from JS. Restate it with priority. */
[hidden] { display: none !important; }

/* Visually-hidden text for screen-reader announcements + skip-link targets. */
.sr-only {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important; border: 0 !important;
}

/* ONE universal keyboard focus ring. Never enumerate per-selector rules —
   a new control added later would ship without one. */
:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }
/* WebKit focuses a date/time input's sub-fields, so the input itself never
   matches :focus-visible and would show no ring. Keyboard and pointer
   both open the field for typing, so :focus is the right trigger here. */
input:is([type="date"], [type="time"], [type="datetime-local"], [type="month"], [type="week"]):focus {
  outline: 2px solid var(--accent-line); outline-offset: 2px;
}

/* Phone text fields at 16px. iOS Safari zooms the page into any
   field whose text is under 16px when it takes focus, and the family's bar
   and drawer fields run 0.78–0.85rem. Phones only: touch AND compact, the
   COMPACT_MQ rule (≤ 640px wide or ≤ 560px tall). On a touch tablet or
   laptop the wider fields would widen a full bar enough to fold it, so
   above compact nothing changes. Checkboxes, radios and ranges have no
   text and are left alone. Specificity (0,2,2): html:root plus the :is()
   list's strongest argument outranks app rules up to two classes, such as
   input[type="date"], select.time-select or .mode-select, which load later
   inline. Don't shrink a field back under 16px on a phone. */
@media (hover: none) and (max-width: 640px), (hover: none) and (max-height: 560px) {
  html:root :is(input:not([type]), input[type="text"], input[type="search"], input[type="email"],
    input[type="url"], input[type="tel"], input[type="password"], input[type="number"],
    input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"],
    input[type="week"], select, textarea) { font-size: 16px; }
}

/* Skip link (WCAG 2.4.1): first focusable element on the page, jumps past the
   chrome. Markup in snippets/skip-link.html. */
.mco-skip-link {
  position: fixed; left: 0.5rem; top: -100px;
  z-index: calc(var(--z-toast) + 10);
  padding: 0.5rem 0.9rem;
  background: var(--accent); color: var(--text-on-accent);
  border-radius: var(--radius-md);
  font-weight: 600; font-size: 0.85rem; text-decoration: none;
}
.mco-skip-link:focus { top: 0.5rem; }

/* Display numerals: a hero reading in Outfit with tabular
   figures, so digits keep their column as values tick (the hosted subset
   carries tnum) without Space Mono's terminal spacing at 2–4rem. Size is
   the app's (≥ 1.75rem; --fs-2xl is 2rem). Below that, numerals stay mono. */
.mco-num-display {
  font-family: var(--font-display-num);
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  line-height: var(--lh-tight);
}

/* ── 4. MapLibre control polish ───────────────────────────────────────────
   Glass treatment for the vendor controls so they read as part of the app
   chrome. --ctrl-icon-filter inverts the vendor's dark icon glyphs on dark
   themes. */
.maplibregl-ctrl-group {
  background: var(--glass) !important;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--ctrl-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow) !important;
  transition: background var(--transition), border-color var(--transition);
}
.maplibregl-ctrl-group button {
  background: transparent !important;
  border-color: var(--ctrl-border) !important;
  transition: background var(--transition);
}
.maplibregl-ctrl-group button:hover { background: var(--accent-hover) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: var(--ctrl-icon-filter, none); }
/* Icon for MCO.map.addFitControl()'s "zoom to full extent" button. The
   stroke is dark like the vendor icons so --ctrl-icon-filter flips it too. */
.maplibregl-ctrl-fit .maplibregl-ctrl-icon {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23202020' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='4 8 4 4 8 4'/><polyline points='20 8 20 4 16 4'/><polyline points='4 16 4 20 8 20'/><polyline points='20 16 20 20 16 20'/></svg>");
  background-size: 60% 60%;
  background-position: center;
  background-repeat: no-repeat;
}
.maplibregl-ctrl-attrib { background: var(--glass) !important; color: var(--text-muted) !important; }
.maplibregl-ctrl-attrib a { color: var(--text-secondary) !important; text-decoration: underline; text-underline-offset: 2px; }
.maplibregl-ctrl-attrib button.maplibregl-ctrl-attrib-button { filter: var(--ctrl-icon-filter, none); }
/* Attribution links are underlined: against the surrounding credit
   text they differ by color alone, 1.74:1 on dark and 1.25:1 on
   high-contrast, and WCAG 1.4.1 wants 3:1 or a non-color cue. axe flags it
   once hillshade's "Terrain: Mapzen/AWS Open Data" credit turns the bar into
   a text block. Same remedy as prose links in .info-section. */

/* Popups: MapLibre's popup is white with a black tip in every theme.
   Repainted from tokens, and put on the --z-detail tier: the vendor sheet
   gives popups NO z-index, so the map controls (z 2) would draw over them.
   Close button 44px on touch. Content comes from MCO.map.popupContent()
   (.mco-popup / .mco-facts below), never setHTML of API strings (§7). */
.maplibregl-popup { z-index: var(--z-detail); }
.maplibregl-popup-content {
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 0.55rem 0.75rem; font-family: var(--font-ui); font-size: 0.8rem;
}
.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(--bg-surface); }
.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(--bg-surface); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--bg-surface); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--bg-surface); }
.maplibregl-popup-close-button {
  width: 28px; height: 28px; top: 2px; right: 2px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 1.1rem; line-height: 1;
}
.maplibregl-popup-close-button:hover { background: var(--accent-hover); color: var(--text-primary); }
.mco-popup { min-width: 10rem; }
.maplibregl-popup-content:has(.maplibregl-popup-close-button) .mco-popup { padding-right: 1.4rem; }
.mco-popup-title { margin: 0; font-size: 0.85rem; font-weight: 600; line-height: 1.25; color: var(--text-primary); }
.mco-popup-sub { margin: 0.1rem 0 0; font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); }
.mco-popup-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.55rem; }
.mco-popup-actions a.nav-btn { text-decoration: none; }
/* Label/value facts: a two-column <dl>, also used by detail sheets and
   cards so a popup and a sheet render a station the same way. Labels are
   --text-muted, which is allowed on deep and surface only (never --bg-raised). */
.mco-facts { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.75rem; margin: 0.45rem 0 0; font-size: 0.78rem; }
.mco-facts > div { display: contents; }
.mco-facts dt { color: var(--text-muted); }
.mco-facts dd { margin: 0; color: var(--text-primary); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Vendor default is 2; restated so the whole stacking ladder is greppable.
   With viewport-fit=cover the corner containers need the safe-area insets
   themselves, or the attribution lands under the home indicator. NOTE:
   env() is inert unless the page sets viewport-fit=cover in its viewport
   meta — see snippets/head.html. */
.maplibregl-ctrl-top-left, .maplibregl-ctrl-top-right,
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right {
  z-index: var(--z-map-ctrl);
}
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right {
  padding-bottom: env(safe-area-inset-bottom);
}
.maplibregl-ctrl-top-left, .maplibregl-ctrl-bottom-left { padding-left: var(--safe-l); }
.maplibregl-ctrl-top-right, .maplibregl-ctrl-bottom-right { padding-right: var(--safe-r); }

/* ── 5. Component shells ──────────────────────────────────────────────────── */

/* Navbar. Glass bar with the brand-gradient underline. Structure:
   .mco-navbar > .logo-link + .nav-divider + .brand + .controls + .nav-meta */
.mco-navbar {
  flex-shrink: 0;
  position: relative;
  /* --nav-gap drives BOTH the flex gap and the lockup divider's negative
     margin, so the brand rhythm survives any change to the gap (§6 tightens it
     at ≤1060px). Overriding the gap directly would desynchronise them. */
  --nav-gap: var(--space-4);
  display: flex; align-items: center; gap: var(--nav-gap);
  /* Left padding matches the vertical padding so the 40px logo badge sits
     with square margins in the 52px bar (≈6px on all three sides). */
  padding: 0.4rem max(1rem, var(--safe-r)) 0.4rem max(0.4rem, var(--safe-l));
  min-height: 52px;
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; row-gap: 0.4rem;
  z-index: var(--z-chrome-top);
}
/* Sticky, opt-in for long-scrolling pages; full-viewport map
   apps keep the in-flow bar. It stays on --z-chrome-top, clears the notch,
   and core publishes its height as --chrome-h, which html's
   scroll-padding-top reads. Needs the DOCUMENT to scroll: a body with
   overflow: hidden or a fixed height defeats position: sticky. */
.mco-navbar.is-sticky {
  position: sticky; top: 0;
  padding-top: max(0.4rem, env(safe-area-inset-top));
}
.mco-navbar::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0;
  height: 2px; background: var(--brand-gradient); pointer-events: none;
}
.logo-link { display: flex; flex-shrink: 0; }
.logo-img  { width: 40px; height: 40px; border-radius: 6px; display: block; }
.nav-divider { width: 1px; height: 28px; background: var(--border); flex-shrink: 0; }
/* The brand lockup reads as one unit: pull the divider in so logo ↔ divider ↔
   title sit at 0.4rem — the same rhythm as the squared 0.4rem edge margins —
   while the full navbar gap resumes after the lockup. Derived from --nav-gap
   rather than hard-coded, so tightening the gap can't squeeze the lockup: at
   the 0.75rem default this is −0.35rem, and at the ≤1060px 0.5rem gap it
   becomes −0.1rem, holding the 0.4rem rhythm either way. */
.mco-navbar > .nav-divider { margin-inline: calc(0.4rem - var(--nav-gap)); }
.brand { display: flex; flex-direction: column; justify-content: center; flex-shrink: 0; line-height: 1.2; }
/* 12px title, 11px subtitle. Anything smaller is below a legible floor. */
.brand-title    { font-size: var(--fs-sm); font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; margin: 0; }
.brand-subtitle { font-size: 0.6875rem; font-weight: 400; letter-spacing: 0.04em; font-style: italic; color: var(--text-dim); white-space: nowrap; }
.controls { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; row-gap: 0.3rem; }
.nav-meta { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; margin-left: auto; }
/* Bar tools (opt-in): the page's single buttons (theme, share, export,
   help) in one group, the bar's last child, after .mco-nav-drawer. Icon-only
   in the bar at every width; core moves them into .mco-drawer-tools as the
   bar runs out of room (§6, MCO.initNavRail). The group follows .nav-meta,
   which holds the right edge. Its margin is 0 or auto in every layout,
   never a length: after the fold class changes WebKit restyles this group
   a frame late, and a margin that changed the bar's width would fold it at
   one width going down and another going up. */
.mco-bar-tools { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.mco-bar-tools .btn-label { display: none; }
.mco-bar-tools .nav-btn:not(.mco-btn-info):has(> .btn-label) { padding: 0.4rem; min-width: var(--control-h); justify-content: center; }

/* Buttons. Pressed/hover borders use --accent-line, NOT --accent: the brand
   blue only clears ~2.3–2.9:1 against dark surfaces (WCAG 1.4.11 needs 3:1). */
.nav-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; min-height: 34px;
  border: 1px solid var(--ctrl-border); border-radius: var(--radius-md);
  background: none; color: var(--text-secondary);
  cursor: pointer; font-size: 0.78rem; font-weight: 500;
  font-family: inherit; white-space: nowrap; flex-shrink: 0;
  transition: var(--transition);
}
.nav-btn:hover { background: var(--accent-hover); border-color: var(--accent-line); color: var(--text-primary); }
.nav-btn svg { flex-shrink: 0; stroke: currentColor; }
.nav-btn.icon-only { padding: 0.4rem; min-width: 34px; justify-content: center; }
.nav-btn[aria-pressed="true"] { background: var(--accent-hover); border-color: var(--accent-line); color: var(--text-primary); }
/* Navigation state: a tab that is a LINK to a view carries
   aria-current="page", not aria-pressed (a toggle). Same look either way. */
.nav-btn[aria-current="page"] { background: var(--accent-hover); border-color: var(--accent-line); color: var(--text-primary); }
a.nav-btn { text-decoration: none; }
.nav-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
/* Primary action: the one button per view that does the thing — Apply,
   Download, Retry. A filled --accent with --text-on-accent, the pairing the
   contrast contract guarantees in all three themes. Never color: #fff on
   --accent: it is 2.2:1 in high contrast, where the accent brightens and
   --text-on-accent flips to black. */
.nav-btn.is-primary { background: var(--accent); border-color: var(--accent-line); color: var(--text-on-accent); }
.nav-btn.is-primary:hover { background: var(--accent-fill-hover); border-color: var(--accent-line); color: var(--text-on-accent); }
.nav-btn.is-primary[disabled]:hover { background: var(--accent); }
.nav-btn[disabled]:hover { background: none; border-color: var(--ctrl-border); color: var(--text-secondary); }

.mco-btn-info {
  border-radius: 50%; border-color: var(--accent-line);
  color: var(--accent-line); font-size: 1rem; font-weight: 600;
  padding: 0; width: 34px; height: 34px; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}
.mco-btn-info:hover { background: var(--accent); color: var(--text-on-accent); }

/* Segmented buttons: a .nav-btn group with fused borders. Deliberately a
   step shorter than the 34px nav buttons — a same-height fused group reads
   as heavy in the bar; flex centering keeps the baselines aligned. */
.seg-btns { display: flex; gap: 0; }
.seg-btn {
  padding: 4px 10px; min-height: 30px; height: 30px;
  border-radius: 0; border-right-width: 0;
  font-size: 0.74rem; font-weight: 600;
}
.seg-btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.seg-btn:last-child  { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-right-width: 1px; }
.seg-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent-line); color: var(--text-on-accent); }

/* Radio segmented: a single-choice group as a native radio fieldset —
   free arrow keys, one Tab stop. Styled exactly like the aria-pressed
   segmented group:
     <fieldset class="seg-btns is-radio"><legend class="sr-only">Units</legend>
       <label class="nav-btn seg-btn"><input type="radio" name="u" value="us" checked>US</label> …
   The input is unstyled but covers its label, so the universal focus ring
   lands on it and a click anywhere on the label selects. Corners use
   :first-of-type / :last-of-type, so the <legend> doesn't throw them off. */
.seg-btns.is-radio { border: 0; padding: 0; margin: 0; min-width: 0; }
.seg-btns.is-radio > label.seg-btn { position: relative; display: flex; align-items: center; cursor: pointer; }
.seg-btns.is-radio > label.seg-btn > input {
  position: absolute; inset: 0; margin: 0;
  appearance: none; -webkit-appearance: none;
  background: none; border: 0; border-radius: inherit; cursor: pointer;
}
.seg-btns.is-radio > .seg-btn:first-of-type { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.seg-btns.is-radio > .seg-btn:last-of-type { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-right-width: 1px; }
.seg-btns.is-radio > label.seg-btn:has(> input:checked) { background: var(--accent); border-color: var(--accent-line); color: var(--text-on-accent); }

/* Stepper buttons — MCO.initStepper. Square .nav-btn, 34px (40 on touch). */
.nav-btn.mco-step { padding: 0.4rem; min-width: 34px; justify-content: center; }

/* Chips: pill toggles in a labelled group; apps own the selection.
     <div class="mco-chips" role="group" aria-labelledby="net-label">
       <button class="mco-chip" aria-pressed="true">HydroMet <span class="mco-chip-count">142</span></button>
   Pressed adds a ✓ (alt text empty), so the state isn't color alone.
   aria-busy="true" while its count loads. 28px, 40px on touch. */
.mco-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.mco-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  min-height: 28px; padding: 2px 10px;
  background: none; border: 1px solid var(--ctrl-border); border-radius: 999px;
  color: var(--text-secondary); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium);
  white-space: nowrap; cursor: pointer; transition: var(--transition);
}
.mco-chip:hover { background: var(--accent-hover); border-color: var(--accent-line); color: var(--text-primary); }
.mco-chip[aria-pressed="true"] { background: var(--accent-hover); border-color: var(--accent-line); color: var(--text-primary); }
.mco-chip[aria-pressed="true"]::before { content: "\2713"; content: "\2713" / ""; font-size: 0.9em; }
.mco-chip-count { font-family: var(--font-mono); font-size: 0.9em; font-variant-numeric: tabular-nums; }
.mco-chip[aria-busy="true"] { cursor: progress; }
.mco-chip[aria-busy="true"] .mco-chip-count { visibility: hidden; }
/* A chip with no count still shows it is loading. */
.mco-chip[aria-busy="true"]:not(:has(.mco-chip-count))::after { content: "\2026"; content: "\2026" / ""; }

/* One control height in the bar. Inside .mco-navbar (its nav
   drawer included) buttons, segmented groups, chips, steppers and the
   search field all stand --control-h: 34px, 40px on touch, so a bar mixing
   them reads as one size. Outside the bar the seg-btn, chip and legend-row
   sizes above apply. */
.mco-navbar :is(.nav-btn, .mco-chip) { min-height: var(--control-h); }
.mco-navbar .seg-btn { height: var(--control-h); min-height: var(--control-h); }
.mco-navbar .nav-btn.mco-step { min-width: var(--control-h); }
.mco-navbar .mco-search-input { height: var(--control-h); }

/* Refresh/liveness status: read-only, deliberately subordinated. Add .static
   when the view isn't live (historical modes) to stop the pulse. The text is
   MCO.formatUpdatedMT, one wording family-wide:
     <span class="refresh-status"><span class="dot" aria-hidden="true"></span>
       <span><span class="refresh-word">Updated</span> 2:45 PM MST</span></span>
   ≤1400px the bar sheds "Updated" visually (still read); the time stays. */
.refresh-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono);
  font-size: 0.65rem; color: var(--text-muted);
  white-space: nowrap;
  padding: 0 4px;
}
.refresh-status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-line);
  box-shadow: 0 0 0 2px var(--accent-hover);
  animation: mco-refresh-pulse 2.4s ease-in-out infinite;
}
@keyframes mco-refresh-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .refresh-status .dot { animation: none; }
}
.refresh-status.static .dot { animation: none; box-shadow: none; opacity: 0.55; }

/* Toast. One per page; created for you by MCO.showToast() if absent. */
.mco-toast {
  position: fixed; bottom: 1.5rem; left: calc(50% - var(--rail-inset, 0px) / 2);
  transform: translateX(-50%) translateY(0.75rem);
  background: var(--bg-surface);
  border: 1px solid var(--accent-line);
  border-radius: 6px; padding: 0.5rem 1rem;
  font-size: 0.82rem; color: var(--text-primary);
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: var(--z-toast);
  box-shadow: var(--shadow);
}
.mco-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Footer: data-source credit, then the MCO credit (MCO.credit()),
   then an optional mono version / "last updated" line. Full-viewport map
   apps carry no footer — it costs map height — and put MCO.credit() in the
   info modal's Data section and their exports instead. --text-muted on
   --bg-deep; links underlined (1.4.1). */
.mco-footer {
  padding: var(--space-4) max(var(--space-5), var(--safe-r)) max(var(--space-4), env(safe-area-inset-bottom)) max(var(--space-5), var(--safe-l));
  border-top: 1px solid var(--border);
  background: var(--bg-deep);
  font-size: var(--fs-sm); line-height: 1.5; color: var(--text-muted); text-align: center;
}
.mco-footer p + p { margin-top: var(--space-1); }
.mco-footer a { color: var(--text-secondary); text-decoration: underline; text-underline-offset: 2px; }
/* Wordmark: the pair of fixed-color images, one per surface,
   so the theme picks. Both carry alt; the hidden one is display:none, out of
   the accessibility tree. Inline assets/mco-wordmark.svg instead to inherit
   currentColor. Keep it ≥ 40px tall.
     <img class="mco-wordmark is-on-dark"  src="…/assets/mco-wordmark-on-dark.svg"  alt="Montana Climate Office" height="48">
     <img class="mco-wordmark is-on-light" src="…/assets/mco-wordmark-on-light.svg" alt="Montana Climate Office" height="48">
   The pair follows the PAGE theme, not a theme island: these are
   descendant selectors, so <html data-theme="light"> matches through an
   island. Inside an island, inline assets/mco-wordmark.svg (currentColor). */
.mco-wordmark { display: block; width: auto; }
.mco-footer .mco-wordmark { margin: 0 auto var(--space-3); }
:root:not([data-theme="light"]) .mco-wordmark.is-on-light,
[data-theme="light"] .mco-wordmark.is-on-dark { display: none; }
.mco-footer-meta { font-family: var(--font-mono); font-size: var(--fs-xs); }

/* Card: the IN-FLOW section shell — chart and table cards, sidebar
   blocks, sheet sections. .mco-panel is the over-map glass; this sits in the
   page. Surface background, so the text contract holds (muted/dim are
   allowed on surface, never raised). Collapsible with MCO.initCollapsible.
     .mco-card > .mco-card-head (.mco-card-title + .mco-card-actions) + .mco-card-body
   .is-flush: a body that runs to the edge (tables, charts). .is-glass: panel
   visuals without the absolute positioning. */
.mco-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-width: 0; }
.mco-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border);
}
.mco-card-title {
  margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary);
}
.mco-card-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.mco-card-body { padding: var(--space-4); }
.mco-card.is-flush > .mco-card-body { padding: 0; }
.mco-card.is-glass { background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: var(--shadow); }
/* On glass the surface guarantee is gone: facts labels step up to secondary. */
.mco-card.is-glass .mco-facts dt, .mco-panel .mco-facts dt { color: var(--text-secondary); }

/* Loading — MCO.loading. A 3px bar pinned to the top of its
   (positioned) container on the --z-map-progress tier: an indeterminate
   sweep, or determinate with aria-valuenow + --progress (0–100). Static
   under reduced motion. .mco-skeleton blocks are aria-hidden placeholders
   (.is-block, .is-chart, or --skeleton-h); flat under reduced motion. */
.mco-progress {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  overflow: hidden; z-index: var(--z-map-progress); pointer-events: none;
}
.mco-progress::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 35%;
  background: var(--accent-line);
  animation: mco-progress-sweep 1.2s ease-in-out infinite;
}
.mco-progress[aria-valuenow]::before { animation: none; width: calc(var(--progress, 0) * 1%); transition: width var(--transition); }
@keyframes mco-progress-sweep { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.mco-skeleton {
  display: block; height: var(--skeleton-h, 0.9em); border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-raised) 0%, var(--border) 50%, var(--bg-raised) 100%) 0 0 / 200% 100%;
  animation: mco-skeleton-shimmer 1.4s linear infinite;
}
.mco-skeleton.is-block { --skeleton-h: 4rem; }
.mco-skeleton.is-chart { --skeleton-h: 12rem; border-radius: var(--radius-md); }
@keyframes mco-skeleton-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) {
  .mco-progress::before { animation: none; width: 100%; opacity: 0.6; }
  .mco-skeleton { animation: none; background: var(--bg-raised); }
}

/* Notice: the persistent, actionable twin of the toast — a load
   failure with Retry, a data caveat, an outage. The toast is text-only and
   pointer-events: none, so it can't hold a button. Built by MCO.notice() or
   written in markup:
     <div class="mco-notice" data-tone="warning">
       <svg class="mco-notice-icon" aria-hidden="true">…</svg>
       <p class="mco-notice-text"><strong class="mco-notice-tone">Warning</strong> …</p>
       <div class="mco-notice-actions"><button class="nav-btn">Retry</button></div>
       <button class="modal-close" aria-label="Dismiss">×</button>
     </div>
   data-tone: info (default) | warning | danger | success. The tone WORD is
   always present (.mco-notice-tone), so color is never the only channel.
   In flow by default; data-place="over" floats it at the top of the nearest
   positioned ancestor (a map container) on the --z-map-notice tier.
   .mco-empty is the same shell with no tone: the empty-state callout. */
.mco-notice, .mco-empty {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.6rem 0.55rem 0.85rem;
  background: var(--bg-surface); color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.82rem; line-height: 1.5;
}
.mco-notice { border-left: 3px solid var(--notice-edge, var(--accent-line)); }
.mco-notice-icon { flex-shrink: 0; width: 16px; height: 16px; color: var(--notice-edge, var(--accent-line)); }
.mco-notice-text { flex: 1; min-width: 0; margin: 0; }
.mco-notice-tone { font-weight: 600; color: var(--notice-tone, var(--text-primary)); }
.mco-notice-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.mco-notice-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.mco-notice[data-tone="danger"]  { --notice-edge: var(--danger);  --notice-tone: var(--danger);  background: var(--danger-fill);  color: var(--text-on-danger); }
.mco-notice[data-tone="warning"] { --notice-edge: var(--warning); --notice-tone: var(--warning); background: var(--warning-fill); color: var(--text-on-warning); }
.mco-notice[data-tone="success"] { --notice-edge: var(--success); --notice-tone: var(--success); background: var(--success-fill); color: var(--text-on-success); }
/* Over the map it keeps clear of both top corners' control columns (zoom,
   top left by default, or top right where an app puts it): 7.5rem is
   two ~44px groups and their margins. A narrow map's notice wraps instead
   of covering the zoom buttons. */
.mco-notice[data-place="over"], .mco-empty[data-place="over"] {
  position: absolute; top: 0.75rem; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: min(34rem, calc(100% - 7.5rem));
  box-shadow: var(--shadow);
  z-index: var(--z-map-notice);
}
.mco-empty { justify-content: center; text-align: center; padding: 0.9rem 1.1rem; }

/* Pointer-following tooltip. Decorative for AT: keep it aria-hidden and route
   the same content through a live region (see HOUSE-STYLE.md §5). */
.mco-tooltip {
  position: fixed;
  background: var(--glass);
  border: 1px solid var(--accent-line);
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem; font-weight: 500;
  color: var(--text-primary);
  pointer-events: none;
  z-index: var(--z-cursor);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s;
  backdrop-filter: blur(8px);
}
.mco-tooltip.visible { opacity: 1; }
.mco-tooltip .tooltip-name { font-size: 0.78rem; font-weight: 600; color: var(--text-primary); line-height: 1.2; }
.mco-tooltip .tooltip-sub {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 1px;
}
.mco-tooltip .tooltip-val {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--accent-line);
  font-weight: 600;
  margin-top: 3px;
}

/* Modal: native <dialog class="mco-modal"> wired by MCO.initInfoModal()
   (backdrop click closes, focus restores to the opener). */
.mco-modal { background: transparent; border: none; padding: 1rem; position: fixed; inset: 0; margin: auto; width: fit-content; height: fit-content; max-width: calc(100vw - 2rem); max-height: calc(100dvh - 2rem); }
.mco-modal::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
/* Long modals: the header sticks so the title and close button stay reachable
   while the body scrolls, scrolling never chains to the page behind, and a
   soft shade at the bottom edge says "there's more". The shade is two
   layers: a --bg-surface cover attached to the END of the content (local)
   over a shade pinned to the box's bottom edge (scroll). Mid-scroll the
   cover is out of view and the shade shows; at the end it slides over the
   shade and hides it. A modal that doesn't overflow never shows it. */
.info-modal-box {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 10px; width: min(540px, calc(100vw - 4rem));
  max-height: calc(100dvh - 4rem); overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.5rem; box-shadow: var(--shadow);
  background-image:
    linear-gradient(var(--bg-surface), var(--bg-surface)),
    linear-gradient(to top, rgba(0,0,0,0.42), rgba(0,0,0,0));
  background-repeat: no-repeat;
  background-size: 100% 32px, 100% 22px;
  background-position: 0 100%, 0 100%;
  background-attachment: local, scroll;
}
.info-modal-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  position: sticky; top: -1.5rem; z-index: 1;
  margin: -1.5rem -1.5rem 1.25rem; padding: 1.5rem 1.5rem 0.75rem;
  background: var(--bg-surface);
  border-radius: 10px 10px 0 0;
}
.info-modal-title    { font-size: 1.05rem; font-weight: 700; color: var(--accent-line); margin: 0; }
.info-modal-subtitle { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }
.modal-close { display: flex; align-items: center; justify-content: center; background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font: inherit; font-size: 1.2rem; cursor: pointer; line-height: 1; flex-shrink: 0; min-width: 34px; min-height: 34px; transition: var(--transition); }
.modal-close:hover { color: var(--text-primary); border-color: var(--accent-line); }
.info-section { margin-bottom: 1.25rem; }
.info-section:last-child { margin-bottom: 0; }
.info-section h3 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 0.5rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); }
.info-section p, .info-section ul { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }
.info-section ul { padding-left: 1.1rem; }
.info-section li { margin-bottom: 0.2rem; }
/* Links inside prose are underlined, not color-only (WCAG 1.4.1 —
   link-in-text-block). Color alone fails for CVD users; hover-only
   underlines don't count. */
.info-section a { color: var(--accent-line); text-decoration: underline; text-underline-offset: 2px; }
.info-section a:hover { text-decoration-thickness: 2px; }
/* A "more" line: a <details> in the help. Its summary is a 40px target in
   body-size text. A key or a code sample never breaks across lines. */
.info-section summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); padding: 0.6rem 0; min-height: 40px; box-sizing: border-box; }
.info-section code, .info-section kbd { white-space: nowrap; }
.info-section kbd {
  font-family: var(--font-mono);
  font-size: 0.75em;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text-primary);
}
.info-section code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-raised);
  border-radius: 3px;
  padding: 1px 4px;
}

/* Floating glass panel (legend, filter dock, …). Collapse behavior comes from
   MCO.initCollapsible(); the toggle carries aria-expanded, the body gets
   [hidden]. Structure:
     .mco-panel > .mco-panel-head (> .mco-panel-title + .mco-panel-toggle)
                + .mco-panel-body */
.mco-panel {
  position: absolute;
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: var(--z-map-panel);
  max-width: min(320px, calc(100vw - 2rem));
}
.mco-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem;
}
.mco-panel-title {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-secondary);
}
.mco-panel-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex-shrink: 0;
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; font-family: inherit;
  transition: var(--transition);
}
.mco-panel-toggle:hover { color: var(--text-primary); border-color: var(--accent-line); }
/* The caret shows the ACTION, not the state (markup glyph is an up-chevron):
   expanded → points down ("collapse toward the bottom dock"); collapsed →
   points up ("expand upward"). */
.mco-panel-toggle svg { transition: transform var(--transition); transform: rotate(180deg); }
.mco-panel-toggle[aria-expanded="false"] svg { transform: none; }
/* Collapse is animated (slide + fade), then
   MCO.initCollapsible sets [hidden] so collapsed content leaves the tab
   order. The max-height cap comfortably fits house panels; raise it locally
   for an unusually tall one. Reduced motion clamps the transition. */
.mco-panel-body {
  padding: 0 0.75rem 0.75rem;
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
  transition: max-height var(--transition), opacity var(--transition);
}
.mco-panel-body.is-collapsing { max-height: 0; opacity: 0; }
/* Height cap. Core caps a bottom-anchored panel that would rise past the
   room over its map, so its head, with the
   collapse toggle, can always be reached: the panel scrolls inside and the
   head stays pinned on an opaque surface. Set only when it doesn't fit, so
   a panel that fits is untouched. */
.mco-panel.is-capped {
  max-height: var(--panel-max-h);
  overflow-y: auto; overscroll-behavior: contain;
}
.mco-panel.is-capped > .mco-panel-head {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-surface);
}

/* Legend rows — click to show/hide a category, wired by
   MCO.initLegendToggles. aria-pressed is the styling source of truth (§5.7):
     <button class="mco-legend-row" aria-pressed="true" data-key="fresh">
       <span class="mco-legend-swatch" style="--swatch: #2a8a86" aria-hidden="true"></span>
       <span class="mco-legend-label">Fresh</span><span class="mco-legend-count">42</span>
     </button>
   The ROW never gets opacity: parent opacity composites the whole subtree,
   so no child rule can restore the label's contrast (`opacity: .4` on the
   row makes a 2.7:1 label). Off dims the swatch
   only and strikes the label through, a non-color cue. The label stays
   --text-secondary: the panel is glass over an arbitrary basemap, where
   --text-muted's surface-only guarantee doesn't hold.
   Swatches always carry a --border edge, so a white "near normal" bin can't
   vanish on light glass. data-shape matches the map mark: circle | hollow |
   ring | line | dash (default: rounded square, a fill). */
.mco-legend-row {
  display: flex; align-items: center; gap: 0.5rem;
  width: 100%; min-height: 28px; padding: 2px 4px;
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--text-secondary); font: inherit; font-size: 0.78rem; text-align: left;
  cursor: pointer; transition: background var(--transition);
}
.mco-legend-row:hover { background: var(--accent-hover); color: var(--text-primary); }
.mco-legend-swatch {
  width: 14px; height: 14px; flex-shrink: 0;
  background: var(--swatch, transparent);
  border: 1px solid var(--border); border-radius: 3px;
  transition: opacity var(--transition);
}
.mco-legend-swatch[data-shape="circle"] { border-radius: 50%; }
.mco-legend-swatch[data-shape="hollow"] { border-radius: 50%; background: transparent; border: 2px solid var(--swatch); }
.mco-legend-swatch[data-shape="ring"]   { border-radius: 50%; background: transparent; border: 3.5px solid var(--swatch); }
.mco-legend-swatch[data-shape="line"]   { height: 3px; width: 16px; border: 0; border-radius: 2px; }
.mco-legend-swatch[data-shape="dash"]   { height: 3px; width: 16px; border: 0; border-radius: 0;
  background: repeating-linear-gradient(90deg, var(--swatch) 0 4px, transparent 4px 7px); }
.mco-legend-label { flex: 1; min-width: 0; }
.mco-legend-count { margin-left: auto; padding-left: 0.5rem; font-family: var(--font-mono); font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.mco-legend-row[aria-pressed="false"] .mco-legend-swatch { opacity: 0.35; }
.mco-legend-row[aria-pressed="false"] .mco-legend-label { text-decoration: line-through; text-decoration-thickness: 1px; }
@media (hover: none) { .mco-legend-row { min-height: 40px; } }

/* Search combobox — MCO.initSearchBox. Field, icon and listbox are the
   kit's. The icon is a CSS mask, so it takes currentColor (--text-dim) in
   every theme.
     .mco-search > .mco-search-icon + input.mco-search-input + .mco-search-list
   The active option is marked by an inset --accent-line bar as well as the
   tint, the current one by ✓ (alt text empty, so it isn't read), so neither
   is color alone. The list sits on the --z-flyout tier. */
.mco-search { position: relative; display: inline-flex; align-items: center; }
.mco-search-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; pointer-events: none;
  color: var(--text-dim); background: currentColor;
  -webkit-mask: var(--mco-search-glyph) center / contain no-repeat;
          mask: var(--mco-search-glyph) center / contain no-repeat;
  --mco-search-glyph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.6-3.6'/></svg>");
}
.mco-search-input {
  background-color: var(--input-bg); color: var(--text-primary);
  border: 1px solid var(--ctrl-border); border-radius: var(--radius-md);
  height: 32px; width: 220px; max-width: 100%;
  padding: 0 10px 0 29px;
  font: inherit; font-size: 0.82rem;
  transition: border-color var(--transition);
}
.mco-search-input:hover { border-color: var(--accent-line); }
.mco-search-input::placeholder { color: var(--text-dim); opacity: 1; }
.mco-search-list {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 100%; width: max-content; max-width: min(360px, calc(100vw - 1.5rem));
  max-height: min(340px, 60vh); overflow-y: auto; overscroll-behavior: contain;
  padding: 4px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow);
  z-index: var(--z-flyout);
}
.mco-search-group {
  padding: 6px 8px 2px;
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-secondary);
}
.mco-search-option {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem;
  min-height: 32px; padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem; color: var(--text-primary); cursor: pointer;
}
.mco-search-option:hover { background: var(--accent-hover); }
.mco-search-option[aria-selected="true"] { background: var(--accent-hover); box-shadow: inset 3px 0 0 var(--accent-line); }
.mco-search-option.is-current { font-weight: 600; }
.mco-search-option.is-current > :first-child::before { content: "\2713\00a0"; content: "\2713\00a0" / ""; }
/* The native clear (×) glyph is dark on every theme; flip it like the map
   control icons. */
.mco-search-input::-webkit-search-cancel-button { filter: var(--ctrl-icon-filter, none); }
.mco-search-meta { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; }
.mco-search-note { padding: 6px 8px; font-size: 0.75rem; color: var(--text-secondary); cursor: default; }
@media (hover: none) {
  .mco-search-input { min-height: 40px; }
  .mco-search-option { min-height: 40px; align-items: center; }
}

/* Collapsible search (MCO.initSearchCollapse) ───────────────────────────────
   At compact widths a navbar search field costs more width than it earns, but
   hiding it strands the only keyboard route to a named feature. Instead it
   collapses into a disclosure button grouped with the other nav buttons and
   expands as a full-width overlay bar under the navbar.

   The breakpoint is the ladder's 640px compact edge rather than a
   fifth number: compact is exactly where an inline field stops paying for
   itself. Deliberately width-only — unlike MCO.viewport.COMPACT_MQ it has no
   max-height clause, because a short landscape window is still wide enough for
   an inline field. A lower edge is not enough: at 460px a control-dense bar
   wraps to a third row between 461 and 527px, and the wrap point drifts
   with live data in the labels.

   This is the COLLAPSE mechanics only; the field is .mco-search +
   MCO.initSearchBox above, or an app's own. Add
   .mco-search-collapse to the search wrapper and .mco-search-toggle to the
   button:
     <div class="mco-search mco-search-collapse" id="search-wrap"> … </div>
     <button class="nav-btn icon-only mco-search-toggle"
             aria-expanded="false" aria-controls="search-wrap"> … </button>
   Inner selectors are generic on purpose (input[type=search], kbd), so this
   works whatever the app calls its own parts. */
.mco-search-toggle { display: none; }
@media (max-width: 640px) {
  .mco-search-toggle { display: flex; }
  .mco-navbar .mco-search-collapse { display: none; }
  .mco-navbar .mco-search-collapse.is-open {
    display: flex;
    /* .mco-navbar is the positioned ancestor, so top:100% lands the bar
       directly beneath the whole (possibly wrapped) navbar. */
    position: absolute;
    top: 100%; left: 0; right: 0;
    z-index: var(--z-flyout);
    padding: 0.5rem max(0.75rem, var(--safe-r))
             0.5rem max(0.75rem, var(--safe-l));
    background: var(--glass);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  /* Fill the bar — flex-basis beats the field's own fixed and :focus widths. */
  .mco-navbar .mco-search-collapse.is-open input[type="search"],
  .mco-navbar .mco-search-collapse.is-open input[type="search"]:focus {
    flex: 1 1 0; width: auto;
  }
  /* A "press /" hint is a physical-keyboard affordance; in the overlay it would
     sit on top of the text being typed. */
  .mco-navbar .mco-search-collapse.is-open kbd { display: none; }
  /* The overlay's padding moves the field in; the kit icon follows it. */
  .mco-navbar .mco-search-collapse.is-open .mco-search-icon { left: calc(max(0.75rem, var(--safe-l)) + 9px); }
}

/* Scrim behind off-canvas drawers on compact viewports. Pair with a panel at
   --z-drawer; the scrim sits one tier below it. Always aria-hidden="true"
   (it is a click target, not content); clicking it closes its owner.
   data-scope="container" fills its nearest positioned ancestor
   instead of the viewport, so a drawer inside the map frame can dim the map
   without dimming the navbar above it. */
.mco-scrim {
  position: fixed; inset: 0;
  background: var(--scrim);
  z-index: var(--z-map-panel);
}
.mco-scrim[data-scope="container"] { position: absolute; }

/* Off-canvas drawer — MCO.initDrawer. A labelled <aside> on the
   --z-drawer tier, sliding in from data-side (start | end). [hidden] after the
   slide-out, so nothing off-screen stays tabbable. data-scope="container"
   keeps it inside a positioned frame (with a scoped scrim) so the navbar
   stays live; data-docked (set by modal: 'compact' above compact) turns it
   into a plain column in flow. */
.mco-drawer {
  position: fixed; top: 0; bottom: 0; left: 0;
  width: min(var(--drawer-w, 320px), 88vw);
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: var(--z-drawer);
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  transform: translateX(-100%);
  transition: transform var(--transition);
}
/* An end-side drawer stops at the right-hand rail: --rail-inset is
   what the rail covers, unset (0) outside rail mode. */
.mco-drawer[data-side="end"] { left: auto; right: var(--rail-inset, 0px); border-right: 0; border-left: 1px solid var(--border); transform: translateX(100%); }
.mco-drawer[data-scope="container"] { position: absolute; }
/* Inside its frame, which the rail's body padding already clears. */
.mco-drawer[data-scope="container"][data-side="end"] { right: 0; }
/* Over an on-screen keyboard (MCO.keyboard). */
.kb-open .mco-drawer:not([data-docked]) { bottom: var(--kb-inset, 0px); }
.mco-drawer.is-open { transform: none; }
.mco-drawer[data-docked] {
  position: static; transform: none; box-shadow: none;
  width: var(--drawer-w, 320px); flex-shrink: 0; z-index: auto;
  padding-top: 0; transition: none;
}
.mco-drawer[data-docked] [data-close-drawer] { display: none; }
.mco-drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) max(var(--space-4), var(--safe-l));
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.mco-drawer-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-4) var(--space-4) var(--space-4) max(var(--space-4), var(--safe-l));
}
.mco-drawer[data-side="end"] .mco-drawer-head,
.mco-drawer[data-side="end"] .mco-drawer-body { padding-right: max(var(--space-4), var(--safe-r)); }

/* Station panel — MCO.initSheet. Above compact it docks at the end edge,
   full height under the bar, with the map live beside it. On compact it
   is a full-height panel under the bar: --sheet-top (the bar's bottom, 0
   beside a rail, measured by core) to the top of the bottom control bar
   (--tabbar-h), full width left of the rail (--rail-inset). One state: no
   peek, no drag, no grip. --z-detail: under the drawer and the chrome, over
   the map controls. */
.mco-sheet {
  position: fixed; z-index: var(--z-detail);
  /* Above the bottom control bar wherever it is docked: a folded
     tablet bar docks it under an end-docked panel too. */
  top: var(--sheet-top, var(--chrome-h, 0px)); bottom: var(--tabbar-h, 0px); right: 0;
  width: min(var(--sheet-w, 360px), 40vw);
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  /* The control bar under it already clears the home indicator. */
  padding-bottom: max(0px, env(safe-area-inset-bottom) - var(--tabbar-h, 0px));
  transform: none;
  transition: transform 0.22s cubic-bezier(0.4,0,0.2,1);
}
.mco-sheet.is-entering, .mco-sheet.is-leaving { transform: translateX(100%); }
.mco-sheet-head {
  position: relative; flex-shrink: 0;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 48px; padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.mco-sheet-title { flex: 1; min-width: 0; margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text-primary); }
.mco-sheet-title:focus { outline: none; }          /* programmatic focus target; never reached by Tab */
/* The close button: required, top right, 44px at every width, so the
   panel's header is identical on a phone, a tablet and a desktop. */
.mco-sheet-head [data-close-sheet] { min-width: 44px; min-height: 44px; flex-shrink: 0; }
/* No grip at any width. Old markup's grip stays out of sight and
   out of the tab order. */
.mco-sheet-grip { display: none !important; }
.mco-sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-4) max(var(--space-4), var(--safe-r)) var(--space-4) var(--space-4);
}
.is-compact .mco-sheet {
  top: var(--sheet-top, var(--chrome-h, 0px)); bottom: var(--tabbar-h, 0px);
  left: 0; right: var(--rail-inset, 0px); width: auto;
  border-left: 0; border-top: 1px solid var(--border);
}
.is-compact .mco-sheet.is-entering, .is-compact .mco-sheet.is-leaving { transform: translateY(100%); }
.is-compact .mco-sheet-head { padding-left: max(var(--space-4), var(--safe-l)); }
.is-compact .mco-sheet-body { padding-left: max(var(--space-4), var(--safe-l)); }
/* A field in the panel stays reachable over an on-screen keyboard. */
.kb-open .mco-sheet-body { padding-bottom: calc(var(--space-4) + var(--kb-inset, 0px)); }

/* First-paint hold: see MCO.ready(). visibility, never display, so
   the reserved layout doesn't shift when the hold lifts. */
html.mco-booting [data-hold] { visibility: hidden; }
html:not(.mco-booting) [data-skeleton] { display: none; }

/* Overlay metrics + auto-lift. --chrome-h / --sheet-h / --tabbar-h
   are written on <html> by MCO.metrics (the sheet and the control bar
   publish their own, --controlbar-h included; MCO.keyboard writes
   --kb-inset and --vv-h).
   Lifting the toast and MapLibre's bottom corners is opt-in via
   html.mco-autolift, which a page with a kit control bar turns on. It is
   opt-in because the toast's position is an observable default. */
/* Side safe areas. iOS reports the same left and right inset in landscape,
   whichever side the camera is on, so padding for both leaves an empty
   strip on the side away from it. MCO.viewport finds the camera's side and
   sets html.mco-cam-left or .mco-cam-right; the other side's inset is then
   0. Without either class (core not loaded yet, no side insets, an Android
   phone that reports only the real side) these are the plain insets. Use
   them, not env(safe-area-inset-left/right), for side padding. */
:root { --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); }
html.mco-cam-left { --safe-r: 0px; }
html.mco-cam-right { --safe-l: 0px; }
:root { --chrome-h: 0px; --sheet-h: 0px; --sheet-end: 0px; --tabbar-h: 0px; --controlbar-h: 0px; --kb-inset: 0px; --vv-h: 100dvh; --overlay-bottom: calc(var(--sheet-h) + var(--tabbar-h)); }
html { scroll-padding-top: var(--chrome-h); }
/* An end-docked sheet covers the map's right edge: MapLibre's right
   corners (the attribution; zoom and fit too where an app puts them top
   right) step clear by --sheet-end, which the open sheet publishes. Not
   opt-in: they would be unreachable under it. A map that
   stops short of the viewport's right edge opts out with
   .maplibregl-map { --sheet-end: 0px; }. */
html .maplibregl-ctrl-top-right,
html .maplibregl-ctrl-bottom-right { right: var(--sheet-end); transition: right 0.22s cubic-bezier(0.4,0,0.2,1); }
html.mco-autolift .mco-toast { bottom: calc(1.5rem + var(--overlay-bottom) + env(safe-area-inset-bottom)); }
html.mco-autolift .maplibregl-ctrl-bottom-left,
html.mco-autolift .maplibregl-ctrl-bottom-right { transform: translateY(calc(-1 * var(--lift, var(--overlay-bottom)))); transition: transform var(--transition); }
/* An app's own bottom-corner panel (a legend, a scale) joins the lift with
   [data-autolift], so MapLibre's corner never rides up over it.
   It uses `translate`, not `transform`, so it composes with any transform
   the panel already has (a collapse, a slide-in). MCO.metrics caps each
   element's lift at the room above it as --lift, so a tall panel
   stops at the top of its container instead of riding off it. */
html.mco-autolift [data-autolift] { translate: 0 calc(-1 * var(--lift, var(--overlay-bottom))); transition: translate var(--transition); }

/* ── 6. Responsive & touch ────────────────────────────────────────────────
   Breakpoint ladder (HOUSE-STYLE.md §3): 1400 shed button labels · 1060
   tighten chrome · 750 collapse the brand to the badge · 640 compact. "Compact" also has
   a height variant — KEEP IN SYNC with MCO.viewport.COMPACT_MQ in
   core/mco-core.js and the copy in snippets/anti-flash.html:
   (max-width: 640px), (max-height: 560px). Layout lives in
   real @media rules (no flash before deferred JS runs); behavior decisions
   (sheet vs popup, auto-collapse) key off MCO.viewport. */
@media (max-width: 1400px) {
  /* .btn-label lives INSIDE its button, so removing it is safe: the house rule
     is that such a button carries a permanent aria-label (§3). */
  .mco-navbar .btn-label { display: none; }
  /* .control-label is usually a <label for> naming a real control, so hide it
     VISUALLY rather than removing it — display:none takes it out of the
     accessibility tree and the input it names is left with NO accessible name
     from 1400px down (axe: label / select-name). Same reasoning as the brand
     lockup collapse. */
  .mco-navbar .control-label {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
  }
  /* Once the label is gone, the icon is left sitting in label-sized padding
     (6px 12px) — visibly wider than the .icon-only buttons next to it in the
     same bar. Square it up so a mixed row of labelled and icon-only buttons
     reads as one set. .mco-btn-info is untouched: its circle is a deliberate
     distinction, and it never carries a .btn-label. */
  .mco-navbar .nav-btn:has(> .btn-label) {
    padding: 0.4rem; min-width: 34px; justify-content: center;
  }
  /* The freshness stamp keeps its time and sheds the word, the
     .control-label way: visually, so "Updated" is still read. */
  .mco-navbar .refresh-status .refresh-word {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
  }
}
@media (max-width: 1060px) {
  /* Tighten via the custom property, never `gap` directly — the lockup
     divider's margin is derived from it. */
  .mco-navbar { padding-right: 0.6rem; --nav-gap: 0.5rem; }
  .nav-meta { gap: 0.3rem; }
  .mco-bar-tools { gap: 0.3rem; }
}
/* Mobile brand collapse: the logo badge alone carries the identity, because at
   phone widths the controls need every pixel. Both the title and the subtitle
   go, along with the lockup divider that would otherwise dangle beside nothing.

   The lockup is VISUALLY hidden rather than display:none'd on purpose:
   .brand-title is often the page's <h1> (HOUSE-STYLE §3), and a document
   outline shouldn't disappear at a breakpoint. Screen readers still get the
   app name; sighted users get the badge.

   Consumers that keep branding at every width must restore BOTH the lockup's
   static position and the divider — see mesonet-status.

   Scoped to the navbar: a lockup an app moves elsewhere (the top of a
   compact drawer, say) has room and must stay visible. :where() keeps the
   specificity at a bare `.brand`, so a consumer override wins. */
@media (max-width: 750px) {
  :where(.mco-navbar) .brand {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
  }
  .mco-navbar > .nav-divider { display: none; }
}
/* Core's fold measure (.is-fold-probe, set and cleared in one task, never
   painted): the lockup as it stands above 750px. A bar that folds at 751px
   stays folded below it. KEEP IN SYNC with BRAND_W in mco-core.js. */
@media (max-width: 750px) {
  .mco-navbar.is-fold-probe .brand {
    position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto;
  }
  .mco-navbar.is-fold-probe > .nav-divider { display: block; }
}
@media (max-width: 640px) {
  .refresh-status { display: none; }   /* reclaim space on phones */
}

/* WCAG 2.5.5 — comfortable touch targets on touch-only devices. */
@media (hover: none) {
  .nav-btn, .seg-btn { min-height: 40px; }
  .nav-btn.mco-step { min-width: 40px; }
  .mco-chip { min-height: 40px; padding: 4px 14px; }
  /* The :has() arm covers label-shed buttons squared by §6; above 1400px the
     label makes them wider than 40px anyway, so it's a no-op there. */
  .nav-btn.icon-only, .mco-navbar .nav-btn:has(> .btn-label) { min-width: 40px; }
  .mco-btn-info { width: 40px; height: 40px; }
  .modal-close { min-width: 44px; min-height: 44px; }
  .maplibregl-popup-close-button { width: 44px; height: 44px; top: 0; right: 0; }
  .maplibregl-popup-content:has(.maplibregl-popup-close-button) .mco-popup { padding-right: 2.4rem; }
  /* 40px, not 36: the house floor on touch. */
  .mco-panel-toggle { width: 40px; height: 40px; }
  /* MapLibre's own controls are 29px (zoom/fit) and 24px (the compact
     attribution ⓘ) — under the 40px floor on touch. */
  .maplibregl-ctrl-group button { width: 40px; height: 40px; }
  .maplibregl-ctrl-attrib.maplibregl-compact { min-height: 40px; padding-right: 40px; }
  .maplibregl-ctrl-attrib-button { width: 40px; height: 40px; border-radius: 20px; background-position: center; background-repeat: no-repeat; }
}

/* Short-landscape rail, at the RIGHT edge —
   opt-in: .mco-navbar[data-rail] + MCO.initNavRail. On a landscape phone
   the bar wraps to two rows and eats ~30% of the height, while width sits
   unused. In rail mode the bar is turned on its side: a 56px column at the
   right edge (fixed, so it works whether the body is a flex column or
   scrolls), clear of the right safe area, and the page is padded clear of
   it, so the map's right-hand controls (the attribution; zoom is top left
   by default) sit just left of it. Top to bottom: the logo badge, ☰, the
   search button, then the app's time controls (.mco-rail's hot controls,
   then a .mco-controlbar at
   the foot of the column). Everything else is in .mco-nav-drawer, which
   opens from the right, beside the rail.

     <header class="mco-navbar" data-rail>
       <a class="logo-link" …>…</a>
       <div class="mco-rail">        <!-- display:none outside rail mode -->
         <button class="nav-btn icon-only" aria-label="Menu" aria-expanded="false"
                 aria-controls="nav-drawer">☰</button>
         <button class="nav-btn icon-only mco-search-toggle" aria-label="Search" …>…</button>
       </div>
       <div class="nav-divider" aria-hidden="true"></div>
       <div class="mco-nav-drawer" id="nav-drawer">
         <!-- display:contents outside rail mode: the bar lays out as before -->
         <div class="brand">…</div> <div class="controls">…</div> <div class="nav-meta">…</div>
       </div>
     </header>
     <div class="mco-scrim" aria-hidden="true" hidden></div>

   KEEP IN SYNC with MCO.viewport.RAIL_MQ: the landscape half of the compact
   query, not a new number. Every rule is scoped to
   :where(html:not(.mco-bar-hold)) (no added specificity): while someone
   types, core holds the folded bar rather than flip into the rail.
   --rail-inset (what the rail covers, unset so 0 outside rail mode) is a
   RIGHT-hand inset: the end-side drawer, the compact sheet and the toast's
   centre read it. Pitfalls this encodes: the closed drawer is display:none,
   not visibility:hidden (a transitioned child flips a frame late and
   focus() fails); the navbar's backdrop-filter makes it the containing
   block, so the drawer sits at right:100% of the rail; the plain .mco-scrim
   (--z-map-panel) dims the page beside the rail (--z-chrome-top). */
.mco-rail { display: none; }
.mco-nav-drawer { display: contents; }
/* ☰ focuses the open drawer itself; it hugs the viewport edge, so
   the ring goes inside. */
.mco-nav-drawer:focus-visible { outline-offset: -2px; }
@media (max-height: 560px) and (orientation: landscape) {
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) {
    --rail-w: 56px;
    --rail-inset: calc(var(--rail-w) + var(--safe-r));
    padding-right: var(--rail-inset);
  }
  /* The rail isn't above anything: nothing needs scroll padding for it. */
  html:not(.mco-bar-hold):has(> body > .mco-navbar[data-rail]) { --chrome-h: 0px !important; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] {
    position: fixed; top: 0; bottom: var(--controlbar-h, 0px); left: auto; right: 0;
    width: calc(var(--rail-w, 56px) + var(--safe-r));
    min-height: 0;
    flex-direction: column; flex-wrap: nowrap; justify-content: flex-start;
    padding: max(0.4rem, env(safe-area-inset-top)) max(6px, var(--safe-r))
             0.4rem 6px;
    border-bottom: 0; border-left: 1px solid var(--border);
  }
  /* The brand underline runs down the inner (map) edge. */
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail]::after { top: 0; bottom: 0; left: 0; right: auto; width: 2px; height: auto; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] > .nav-divider { display: none; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-rail {
    display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
    min-height: 0; overflow-y: auto; scrollbar-width: none;
  }
  /* ☰, then search, then the hot controls. */
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-rail > :first-child { order: -2; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-rail > .mco-search-toggle { display: flex; order: -1; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-rail .nav-btn { width: 40px; min-height: 40px; padding: 0; justify-content: center; }
  /* Bar tools: help joins the column under .mco-rail, at its spacing. Core
     puts the other tools in the drawer; they are hidden until it has. */
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] > .mco-bar-tools {
    flex-direction: column; gap: 0.35rem; margin-left: 0; margin-top: calc(0.35rem - var(--nav-gap));
  }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] > .mco-bar-tools .nav-btn { width: 40px; height: 40px; min-height: 40px; padding: 0; justify-content: center; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail="compact"]:not([data-tools]) > .mco-bar-tools > :not(.mco-btn-info) { display: none; }

  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer {
    display: none; flex-direction: column; align-items: stretch; gap: 0.9rem;
    position: absolute; top: 0; bottom: calc(-1 * var(--controlbar-h, 0px)); left: auto; right: 100%;
    width: min(var(--drawer-w, 300px), calc(100vw - var(--rail-inset, 56px)));
    padding: max(0.75rem, env(safe-area-inset-top)) 0.9rem max(0.75rem, env(safe-area-inset-bottom)) max(0.9rem, var(--safe-l));
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--bg-surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
    transition: transform 0.18s ease-out, opacity 0.18s ease-out;
  }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer.is-open { display: flex; }
  /* Over an on-screen keyboard (MCO.keyboard). */
  :where(html.kb-open:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer { bottom: calc(var(--kb-inset, 0px) - var(--controlbar-h, 0px)); }
  /* Undo the bar-only collapses: the drawer has the room. */
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .brand,
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .control-label,
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .refresh-word {
    position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto;
  }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .brand-title,
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .brand-subtitle { white-space: normal; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .btn-label { display: inline; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .nav-btn:has(> .btn-label) { padding: 6px 12px; justify-content: flex-start; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .controls { flex-direction: column; align-items: stretch; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .nav-meta { margin-left: 0; flex-wrap: wrap; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .mco-search-collapse { display: flex; position: relative; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .mco-search > input { flex: 1; min-width: 0; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .mco-search-toggle { display: none; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-nav-drawer .refresh-status { display: inline-flex; }

  /* The map's right-hand corners: the rail already sits over the right
     safe area, so they don't pad for it again. Padding twice leaves a
     thumb-width gap on iPhone Safari in landscape. The body padding puts
     them just left of the rail. */
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) :is(.maplibregl-ctrl-top-right, .maplibregl-ctrl-bottom-right) { padding-right: 0; }
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) .mco-sheet-body { padding-right: var(--space-4); }

  /* The bottom control bar (below) joins the rail at its foot. */
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 0.35rem;
    position: fixed; left: auto; right: 0; bottom: 0; top: auto;
    width: calc(var(--rail-w, 56px) + var(--safe-r));
    /* Never over the rail's top group (badge, ☰, search): core measures it
       into --rail-top-h. 100%, not 100dvh: the box the rail is fixed to,
       which iOS Safari can size differently. What doesn't fit scrolls
       here (.is-scroll). */
    max-height: calc(100% - var(--rail-top-h, 9.5rem)); overflow-y: auto; scrollbar-width: none;
    justify-content: safe flex-end;
    padding: 0.35rem max(6px, var(--safe-r)) max(0.4rem, env(safe-area-inset-bottom)) 6px;
    border-top: 0; border-left: 1px solid var(--border); box-shadow: none;
  }
  /* Short of room the readouts go first (visually: still read), then the
     column scrolls, with shadows at the scrolled edges as the affordance. */
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar.is-tight .mco-controlbar-readout {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar.is-scroll {
    justify-content: flex-start;
    background:
      linear-gradient(var(--bg-surface) 40%, transparent) top / 100% 20px no-repeat local,
      linear-gradient(transparent, var(--bg-surface) 60%) bottom / 100% 20px no-repeat local,
      radial-gradient(farthest-side at 50% 0, color-mix(in srgb, var(--text-primary) 45%, transparent), transparent) top / 100% 10px no-repeat scroll,
      radial-gradient(farthest-side at 50% 100%, color-mix(in srgb, var(--text-primary) 45%, transparent), transparent) bottom / 100% 10px no-repeat scroll,
      var(--bg-surface);
  }
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar .nav-btn { width: 40px; min-height: 40px; padding: 0; justify-content: center; }
  /* In the 44px column a readout stacks its parts (spans), each whole, in
     the UI face (mono splits "12:00 PM"). */
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar .mco-controlbar-readout {
    max-width: 100%; text-align: center; white-space: normal; overflow-wrap: normal;
    font: var(--fw-medium) 0.66rem/1.25 var(--font-ui); color: var(--text-secondary);
  }
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar .mco-controlbar-readout > span { display: block; }
}
/* The drawer slides in from the right in both modes. */
@starting-style {
  .mco-navbar[data-rail] .mco-nav-drawer.is-open { transform: translateX(12px); opacity: 0; }
}
/* 44px rail buttons on a touch screen: the rail has the width. */
@media (max-height: 560px) and (orientation: landscape) and (hover: none) {
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] .mco-rail .nav-btn,
  :where(html:not(.mco-bar-hold)) body:has(> .mco-navbar[data-rail]) > .mco-controlbar .nav-btn { width: 44px; min-width: 44px; min-height: 44px; }
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] > .mco-bar-tools .nav-btn { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
  /* The badge matches: one 44px column. */
  :where(html:not(.mco-bar-hold)) .mco-navbar[data-rail] > .logo-link .logo-img { width: 44px; height: 44px; }
}

/* Compact nav drawer — opt-in: .mco-navbar[data-rail="compact"] +
   MCO.initNavRail. The rail above still takes short landscape; this takes
   the rest of compact (portrait phones, narrow windows), where the bar
   would otherwise wrap. One row, ≤ 64px, in this order:
     logo · hot controls · search toggle · ☰ (.mco-rail's first child)
   The badge always holds the left edge and ☰ the right,
   with .mco-rail flattened into the bar (display: contents) and
   .mco-search-toggle last in .mco-rail. .mco-nav-drawer becomes a fixed
   RIGHT drawer under the bar, opening from its button (core measures the
   bar into --nav-drawer-top), down to the bottom control bar or an
   on-screen keyboard, whichever is higher. The plain .mco-scrim dims the
   page below the bar.
     <header class="mco-navbar" data-rail="compact">
       <a class="logo-link" …>…</a>
       <div class="mco-rail">
         <button class="nav-btn icon-only" aria-label="Menu" aria-controls="nav-drawer">☰</button>
         …1–2 hot controls…
         <button class="nav-btn icon-only mco-search-toggle" aria-label="Search" aria-controls="nav-drawer">…</button>
       </div>
       <div class="nav-divider" aria-hidden="true"></div>
       <div class="mco-nav-drawer" id="nav-drawer">brand · .controls (search field) · .nav-meta</div>
       <div class="mco-bar-tools" role="group" aria-label="Page tools">…optional: theme, share, export, help…</div>
     </header>
   With .mco-bar-tools the row is logo · hot controls · search · tools · ☰.
   The query is compact ∧ ¬rail, written out: COMPACT_MQ minus RAIL_MQ.
   KEEP IN SYNC with MCO.viewport.COMPACT_MQ and RAIL_MQ. The bar drops its
   backdrop blur here: a backdrop-filter would make the bar the containing
   block of the fixed drawer (--glass is legible without it, §3). */
@media (max-width: 640px) and (orientation: portrait), (max-width: 640px) and (height > 560px) {
  .mco-navbar[data-rail="compact"] {
    flex-wrap: nowrap;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .mco-navbar[data-rail="compact"] > .nav-divider { display: none; }
  .mco-navbar[data-rail="compact"] .mco-rail { display: contents; }
  .mco-navbar[data-rail="compact"] .mco-rail > :first-child { order: 1; }
  .mco-navbar[data-rail="compact"] .mco-rail > .mco-search-toggle { margin-left: auto; }
  /* Bar tools sit between the search button and ☰. */
  .mco-navbar[data-rail="compact"] > .mco-bar-tools { margin-left: 0; }
  .mco-navbar[data-rail="compact"] > .mco-rail:not(:has(> .mco-search-toggle)) ~ .mco-bar-tools { margin-left: auto; }

  .mco-navbar[data-rail="compact"] .mco-nav-drawer {
    display: none; flex-direction: column; align-items: stretch; gap: 0.9rem;
    position: fixed; top: var(--nav-drawer-top, 0px); bottom: max(var(--tabbar-h, 0px), var(--kb-inset, 0px)); right: 0;
    width: min(var(--drawer-w, 300px), 88vw);
    padding: 0.75rem max(0.9rem, var(--safe-r)) max(0.75rem, env(safe-area-inset-bottom)) 0.9rem;
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--bg-surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
    transition: transform 0.18s ease-out, opacity 0.18s ease-out;
  }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer.is-open { display: flex; }
  /* Undo the bar-only collapses, as the rail's drawer does. */
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .brand,
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .control-label,
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .refresh-word {
    position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto;
  }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .brand-title,
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .brand-subtitle { white-space: normal; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .btn-label { display: inline; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .nav-btn:has(> .btn-label) { padding: 6px 12px; justify-content: flex-start; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .controls { flex-direction: column; align-items: stretch; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .nav-meta { margin-left: 0; flex-wrap: wrap; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .mco-search-collapse { display: flex; position: relative; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .mco-search > input { flex: 1; min-width: 0; }
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .mco-search-toggle { display: none; }
  /* The bar hides the stamp ≤640px; the drawer has the room. */
  .mco-navbar[data-rail="compact"] .mco-nav-drawer .refresh-status { display: inline-flex; }
}

/* Fold-to-fit: the compact bar at ANY width. One row is the family
   rule at every width, so MCO.initNavRail — and core on
   load, for every .mco-navbar[data-rail="compact"] — sets .is-folded
   whenever the full bar would not fit one row (taller than 64px unfolded),
   and on portrait compact, where the @media block above already holds first
   paint. The rules are the block above, generated from it: KEEP IN SYNC. */
.mco-navbar[data-rail="compact"].is-folded {
  flex-wrap: nowrap;
  backdrop-filter: none; -webkit-backdrop-filter: none;
}
.mco-navbar[data-rail="compact"].is-folded > .nav-divider { display: none; }
.mco-navbar[data-rail="compact"].is-folded .mco-rail { display: contents; }
.mco-navbar[data-rail="compact"].is-folded .mco-rail > :first-child { order: 1; }
/* The search button shows wherever the bar folds, not only ≤640px: above
   640px the plain .mco-search-toggle rule hides it, and then nothing takes
   the auto margin and ☰ sits mid-bar. Its field is in the closed drawer,
   and the button opens the drawer on it (MCO.initNavRail's search option). */
.mco-navbar[data-rail="compact"].is-folded .mco-rail > .mco-search-toggle { display: flex; margin-left: auto; }
/* Bar tools sit between the search button and ☰. */
.mco-navbar[data-rail="compact"].is-folded > .mco-bar-tools { margin-left: 0; }
.mco-navbar[data-rail="compact"].is-folded > .mco-rail:not(:has(> .mco-search-toggle)) ~ .mco-bar-tools { margin-left: auto; }

.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer {
  display: none; flex-direction: column; align-items: stretch; gap: 0.9rem;
  position: fixed; top: var(--nav-drawer-top, 0px); bottom: max(var(--tabbar-h, 0px), var(--kb-inset, 0px)); right: 0;
  width: min(var(--drawer-w, 300px), 88vw);
  padding: 0.75rem max(0.9rem, var(--safe-r)) max(0.75rem, env(safe-area-inset-bottom)) 0.9rem;
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform 0.18s ease-out, opacity 0.18s ease-out;
}
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer.is-open { display: flex; }
/* Undo the bar-only collapses, as the rail's drawer does. */
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .brand,
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .control-label,
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .refresh-word {
  position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto;
}
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .brand-title,
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .brand-subtitle { white-space: normal; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .btn-label { display: inline; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .nav-btn:has(> .btn-label) { padding: 6px 12px; justify-content: flex-start; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .controls { flex-direction: column; align-items: stretch; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .nav-meta { margin-left: 0; flex-wrap: wrap; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .mco-search-collapse { display: flex; position: relative; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .mco-search > input { flex: 1; min-width: 0; }
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .mco-search-toggle { display: none; }
/* The stamp lives in the drawer here too. */
.mco-navbar[data-rail="compact"].is-folded .mco-nav-drawer .refresh-status { display: inline-flex; }
@starting-style {
  .mco-navbar[data-rail="compact"] .mco-nav-drawer.is-open { transform: translateX(12px); opacity: 0; }
}

/* Page tools in the drawer: the bar tools that did not fit, as one centred
   row at the top of .mco-nav-drawer. Core makes the row and moves the
   buttons. Each is its icon over its word, so four fit a 320px phone; the
   help button drops its circle to match the rest. */
.mco-drawer-tools { display: flex; justify-content: center; gap: 0.4rem; }
.mco-navbar[data-rail="compact"] .mco-nav-drawer > .mco-drawer-tools > .nav-btn,
.mco-navbar[data-rail="compact"] .mco-nav-drawer > .mco-drawer-tools > .nav-btn:has(> .btn-label) {
  flex: 0 1 4.75rem; min-width: 0; width: auto; height: auto; min-height: 48px;
  flex-direction: column; justify-content: center; gap: 3px; padding: 5px 4px;
  border-radius: var(--radius-md); border-color: var(--ctrl-border); color: var(--text-secondary);
  line-height: 1;
}
.mco-navbar[data-rail="compact"] .mco-nav-drawer > .mco-drawer-tools > .nav-btn:hover {
  background: var(--accent-hover); border-color: var(--accent-line); color: var(--text-primary);
}
.mco-navbar[data-rail="compact"] .mco-nav-drawer > .mco-drawer-tools > .nav-btn > .btn-label {
  display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  font-size: 0.6875rem; font-weight: var(--fw-medium); line-height: 1.2;
}

/* Bottom control bar — .mco-controlbar, a direct child of <body>,
   wired by core (MCO.initControlBar). The phone's time controls: a date
   stepper, a direction. Hidden by default; docked at the bottom wherever
   the compact bar is folded (a CSS query on portrait compact for first
   paint, .is-folded at any other width, so a tablet gets the same folded
   layout), and at the foot of the rail in short landscape (the rail block
   above). It publishes --tabbar-h, which the toast, MapLibre's bottom
   corners, [data-autolift] panels, the ☰ drawer and the station panel
   clear. Hidden while a keyboard is up. On --z-chrome, under the top bar,
   over the panel and the scrim, so it stays live. */
.mco-controlbar {
  display: none; align-items: center; justify-content: center; gap: var(--space-3);
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-chrome);
  min-height: 52px;
  padding: var(--space-2) max(var(--space-4), var(--safe-r)) max(var(--space-2), env(safe-area-inset-bottom)) max(var(--space-4), var(--safe-l));
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  font-family: var(--font-ui); color: var(--text-primary);
}
body:has(> .mco-navbar[data-rail="compact"].is-folded) > .mco-controlbar { display: flex; }
@media (max-width: 640px) and (orientation: portrait), (max-width: 640px) and (height > 560px) {
  body:has(> .mco-navbar[data-rail="compact"]) > .mco-controlbar { display: flex; }
}
.mco-controlbar :is(.nav-btn, .mco-chip) { min-height: var(--control-h); }
.mco-controlbar .nav-btn.mco-step { min-width: var(--control-h); }
.mco-controlbar-readout {
  font-family: var(--font-mono); font-size: var(--fs-md); font-variant-numeric: tabular-nums;
  color: var(--text-primary); text-align: center; white-space: nowrap; min-width: 0;
}
/* A readout in parts ("Nov 12," "2026," "12:00 PM" as spans) may break
   between them, never inside one, so a long one fits beside four buttons
   at 320px. */
.mco-controlbar-readout:has(> span) { white-space: normal; }
.mco-controlbar-readout > span { white-space: nowrap; }
@media (hover: none) {
  .mco-controlbar .nav-btn, .mco-controlbar .mco-chip { min-height: 44px; }
  .mco-controlbar .nav-btn.mco-step, .mco-controlbar .nav-btn.icon-only { min-width: 44px; }
}
.kb-open .mco-controlbar { display: none !important; }
@media (prefers-reduced-transparency: reduce) {
  .mco-controlbar { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* Keyboard (MCO.keyboard): a search list open over an on-screen
   keyboard keeps to the room above it (--list-room, measured by core; the
   visible height as a fallback), so every option can be reached. */
.kb-open .mco-search-list { max-height: min(340px, var(--list-room, calc(var(--vv-h, 100dvh) / 2))); }
/* Too little room under the field and more over it: the list opens upward. */
.kb-open .mco-search-list.is-above { top: auto; bottom: calc(100% + 4px); }

/* Legend in the drawer — MCO.initLegendDrawer. On compact the
   floating legend moves into a "Legend" group in the ☰ drawer and loses its
   glass; a small "Legend" button holds its corner on the map. */
.mco-legend-btn {
  position: absolute; z-index: var(--z-map-panel);
  /* Core places it (it steps over the map's bottom-corner controls): its
     insets never animate, or a measure reads it mid-move. */
  transition-property: background-color, border-color, color, translate;
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.mco-legend-btn[hidden] { display: none; }
.mco-legend-slot { display: flex; flex-direction: column; }
html .mco-panel.is-in-drawer {
  position: static; inset: auto; max-width: none; max-height: none;
  background: none; border: 0; border-top: 1px solid var(--border); border-radius: 0; box-shadow: none;
  backdrop-filter: none; -webkit-backdrop-filter: none;
  translate: none; transform: none; overflow: visible;
}
.mco-panel.is-in-drawer > .mco-panel-head { padding-left: 0; padding-right: 0; position: static; background: none; }
.mco-panel.is-in-drawer > .mco-panel-body { padding-left: 0; padding-right: 0; max-height: none; }

/* Glass is legible on its own: --glass is near-opaque and the
   backdrop blur is an enhancement on top, because an engine that drops it
   (headless WebKit, low-power modes) or a visitor who asks for Reduce
   Transparency gets the bare fill. Under that preference every glass surface
   goes solid: --glass becomes --bg-surface, and the blur is dropped.
   html:root outranks the [data-theme] blocks without matching their selector;
   `html [data-theme]` (0,1,1) does the same inside a theme island,
   which re-declares --glass and would otherwise keep its translucent one. */
@media (prefers-reduced-transparency: reduce) {
  html:root, html [data-theme] { --glass: var(--bg-surface); }
  .mco-navbar, .mco-panel, .mco-card.is-glass, .mco-tooltip, .maplibregl-ctrl-group,
  .mco-navbar .mco-search-collapse.is-open, .mco-modal::backdrop {
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
}
