/* Viewer styles. Tokens first; the map is the whole screen and everything else floats above it. */
:root {
  --surface: #ffffff;
  --text: #0f1b2d;
  --text-2: #4a5b70;
  --hairline: #e2e8f0;
  --hover: #f3f6fa;
  --accent: #1a6fe8;
  --accent-press: #1558bd;
  --accent-tint: #e8f1fe;
  --accent-tint-press: #d8e8fd;
  --warning: #b45309;
  --error: #b42318;
  --control-border: #98a2b3;   /* radio and checkbox outlines, marker colour for "no value" */
  --scrollbar: #c4cdd8;        /* scrollbar thumbs, sheet handle, time ticks */
  /* marker group palette: no repeats inside a dataset; the accent blue is not in it, so the selection ring stays unique */
  --group-1: #0e9384; --group-2: #c2410c; --group-3: #7a5af8; --group-4: #be185d; --group-5: #4d7c0f; --group-6: #475467;
  --group-7: #d99a00; --group-8: #7c4a1e; --group-9: #f472b6; --group-10: #16a34a; --group-11: #111827; --group-12: #0aa5c0;
  --r-panel: 12px;
  --r-ctrl: 8px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .08), 0 8px 24px rgba(15, 27, 45, .12);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --slide: 280ms;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --left-w: 320px;
  --detail-w: 440px;
  --legend-w: 280px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --edge-t: calc(var(--s4) + var(--safe-t));   /* the 16px panel margin plus the notch / home bar, for everything the desktop layout places at a screen edge */
  --edge-b: calc(var(--s4) + var(--safe-b));
  --edge-l: calc(var(--s4) + var(--safe-l));
  --edge-r: calc(var(--s4) + var(--safe-r));
  --reserve: 0px;      /* bottom space taken by legend / time bar, so the left panel never runs under them */
  --legend-base: 104px;                /* legend height without the flow line; taller where the inputs are 44px, see the touch block */
  --legend-h: var(--legend-base);      /* legend height; grows with the flow line, see body.has-flowline */
  --flow-h: 0px;       /* extra legend height taken by the flow line */
  --rside: var(--safe-r);   /* right space taken by the detail panel (just the safe area while it is closed) */
  --dock-h: 0px;       /* compact layouts: measured height of #dock, set by main.js; the map controls sit above it */
  --tr-w: 72px;        /* top-right space taken by the map controls, so the notice stays clear of them */
  --layout: desktop;   /* desktop | phone-portrait | phone-landscape; set by the media queries below, read by layout.js */
  color-scheme: light;
}
@media (max-width: 899.98px) { :root { --detail-w: 380px; } }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 400 14px/1.4 var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--hover);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  caret-color: var(--accent);
}
::selection { background: var(--accent-tint); color: var(--text); }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.keep { display: inline-block; }
.clamp2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { display: block; flex: none; }
.pad { padding: var(--s3) 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=number]:focus-visible, select:focus-visible { outline-offset: 0; }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }
@media (hover: hover) { *::-webkit-scrollbar-thumb:hover { background: var(--control-border); } }

#map { position: fixed; inset: 0; }
.maplibregl-canvas { outline: none; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; gap: var(--s2); height: 36px; padding: 0 var(--s3);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-ctrl); font-weight: 500;
}
@media (hover: hover) { .btn:hover { background: var(--hover); } }
.btn:active { background: var(--accent-tint); }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0; flex: none;
  background: transparent; border: 0; border-radius: var(--r-ctrl); color: var(--text-2);
}
@media (hover: hover) { .icon-btn:hover { background: var(--hover); color: var(--text); } }
.icon-btn:active { background: var(--accent-tint); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn:disabled, .btn:disabled { opacity: .4; cursor: default; background: transparent; }
.fab {
  position: fixed; top: var(--edge-t); left: var(--edge-l); z-index: 7; width: 44px; height: 44px; display: grid; place-items: center;
  background: var(--surface); border: 0; border-radius: var(--r-panel); box-shadow: var(--shadow); color: var(--text);
}
@media (hover: hover) { .fab:hover { background: var(--hover); } }
body.left-open .fab { display: none; }

/* sheets: left (results) and detail */
.sheet { position: fixed; z-index: 8; display: flex; flex-direction: column; transition: transform var(--slide) var(--ease); }
body.preload .sheet { transition: none; }
#left { top: var(--edge-t); left: var(--edge-l); width: var(--left-w); max-height: calc(100dvh - var(--edge-t) - var(--edge-b) - var(--reserve)); }
#left[data-state=closed] { transform: translateX(calc(-100% - var(--s5))); }
#left .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-radius: inherit; }
/* fade at the foot while the list is not scrolled to its end, so a cut row never reads as the end */
#left::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 48px; pointer-events: none; opacity: 0; border-radius: 0 0 var(--r-panel) var(--r-panel); background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--surface) 85%); }
#left[data-more]::after { opacity: 1; }
#left .scroll::-webkit-scrollbar { width: 10px; }
#left .scroll::-webkit-scrollbar-thumb { border: 2px solid var(--surface); background-clip: padding-box; }
#detail { top: var(--edge-t); right: var(--edge-r); bottom: var(--edge-b); width: var(--detail-w); z-index: 9; }
#detail[data-state=closed] { transform: translateX(calc(100% + var(--s5))); }
.handle { display: none; }

.p-head { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s4) var(--s3) var(--s3) var(--s4); }
.p-titles { flex: 1 1 auto; min-width: 0; }
#site-title { font-size: 20px; font-weight: 600; line-height: 1.25; }
/* foot of the scroller, below the last setting: the "All domains" link (portal mode) */
.p-foot { display: grid; justify-items: start; gap: var(--s1); padding: var(--s3) var(--s3) var(--s3) calc(var(--s3) + var(--s2)); border-top: 1px solid var(--hairline); }
.sec { padding: var(--s3) var(--s3) var(--s3); border-top: 1px solid var(--hairline); }
.sec-title { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 0 var(--s2) var(--s2); }
.list { display: flex; flex-direction: column; gap: 2px; }
.group { display: flex; flex-direction: column; gap: 2px; }
.group-title { font-size: 12px; font-weight: 500; color: var(--text-2); padding: var(--s3) var(--s2) var(--s1); }
.list > :first-child.group > .group-title { padding-top: 0; }
.divider { border: 0; border-top: 1px solid var(--hairline); margin: var(--s1) var(--s2); }

/* selectable rows: native inputs stay in the tab order, drawn by the row */
.row { display: flex; align-items: center; gap: var(--s2); }
.choice { position: relative; min-height: 34px; padding: 4px var(--s2); border-radius: var(--r-ctrl); cursor: pointer; font-size: 14px; }
@media (hover: hover) { .choice:hover { background: var(--hover); } }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.choice:has(input[type=radio]:checked) { background: var(--accent-tint); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.choice .check { width: 16px; height: 16px; color: var(--accent); flex: none; opacity: 0; }
.choice input:checked ~ .check { opacity: 1; }
.dot { width: 16px; height: 16px; flex: none; border: 1.5px solid var(--control-border); border-radius: 50%; display: grid; place-items: center; background: var(--surface); }
.choice input:checked ~ .dot { border-color: var(--accent); }
.choice input:checked ~ .dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.box { width: 16px; height: 16px; flex: none; border: 1.5px solid var(--control-border); border-radius: 4px; display: grid; place-items: center; background: var(--surface); color: transparent; }
.choice input:checked ~ .box { background: var(--accent); border-color: var(--accent); color: #fff; }
.tag { flex: none; font-size: 12px; color: var(--text-2); padding: 1px 6px; border: 1px solid var(--hairline); border-radius: 6px; background: var(--surface); }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px var(--hairline); }
.swatch.grad { width: 24px; height: 12px; border-radius: 6px; box-shadow: none; }
.sub-field { display: grid; gap: 4px; padding: var(--s2) var(--s2) var(--s1) 32px; }
.sub-field label { font-size: 12px; color: var(--text-2); }
.choice.disabled { cursor: default; color: var(--text-2); }
@media (hover: hover) { .choice.disabled:hover { background: transparent; } }
.sub-note { font-size: 12px; padding: 0 var(--s2) var(--s1) 32px; }
.cycle-note { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
@media (hover: hover) { .link-btn:hover { color: var(--accent-press); } }
.link-btn.back-link { display: inline-block; font-size: 13px; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.vlegend { display: grid; gap: 4px; padding: 0 var(--s2) var(--s2) 62px; font-size: 12px; color: var(--text-2); }
.vl-bar { display: flex; align-items: center; gap: var(--s2); }
.vbar { width: 96px; height: 8px; border-radius: 4px; display: block; }
.opacity { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s2) 0; font-size: 13px; color: var(--text-2); }
.opacity input { flex: 1; }
.range-bar { width: calc(100% - 16px); margin: 0 var(--s2) var(--s2); height: 12px; border-radius: 6px; display: block; }
.phone-only { display: none; }

select {
  appearance: none; height: 36px; padding: 0 32px 0 var(--s3); width: 100%;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234a5b70' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right var(--s3) center;
  border: 1px solid var(--hairline); border-radius: var(--r-ctrl); font-size: 13px;
}
@media (hover: hover) { select:hover { background-color: var(--hover); } }
select:disabled { opacity: .4; }
input[type=number] {
  width: 100%; min-width: 0; height: 32px; padding: 0 var(--s2); text-align: right; font-size: 13px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-ctrl);
}
@media (hover: hover) { input[type=number]:hover { background: var(--hover); } }

/* range sliders */
input[type=range] { appearance: none; -webkit-appearance: none; height: 24px; background: transparent; margin: 0; cursor: pointer; width: 100%; --fill: 100%; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--fill), var(--hairline) var(--fill)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--hairline); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(15, 27, 45, .35); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(15, 27, 45, .35); }
input[type=range]:disabled { cursor: default; opacity: .4; }
.opacity input[type=range] { --fill: 100%; background: transparent; }
.opacity input[type=range]::-webkit-slider-runnable-track { background: var(--hairline); }

/* about */
details summary { display: flex; align-items: center; justify-content: space-between; min-height: 32px; padding: 0 var(--s2); border-radius: var(--r-ctrl); cursor: pointer; list-style: none; font-size: 12px; font-weight: 600; color: var(--text-2); }
details summary::-webkit-details-marker { display: none; }
@media (hover: hover) { details summary:hover { background: var(--hover); } }
details[open] .chev { transform: rotate(180deg); }
.notes { font-size: 13px; line-height: 1.45; color: var(--text-2); padding: var(--s2) var(--s2) 0; }
.about-dl { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--s3); margin: var(--s3) var(--s2) var(--s1); font-size: 12px; }
.about-dl dt { color: var(--text-2); }
.about-dl dd { margin: 0; overflow-wrap: anywhere; }

/* segmented control */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px; background: var(--hover); border-radius: var(--r-ctrl); }
.segmented label, .segmented button { position: relative; display: grid; place-items: center; height: 32px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text-2); background: transparent; border: 0; padding: 0 var(--s2); }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label:has(input:checked), .segmented button[aria-checked=true], .segmented button[aria-selected=true] { background: var(--surface); color: var(--accent); box-shadow: 0 0 0 1px var(--hairline); }
.segmented button[aria-selected=true] { font-weight: 600; }   /* tabs: the selected one is also bolder, not only another colour */
.segmented label:has(input:focus-visible), .segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* a result tab with no dataset to open: still there, quieter than an unselected tab, no hover, press or focus ring */
.segmented button[aria-disabled=true] { cursor: default; opacity: .65; }
.segmented button[aria-disabled=true]:focus-visible { outline: 0; }
.group-title.disabled { opacity: .65; }
.tab-heading { font-size: 12px; font-weight: 500; color: var(--text-2); padding: var(--s3) var(--s2) var(--s1); }
.segmented.small { width: fit-content; }
.segmented.small button { height: 28px; font-size: 12px; padding: 0 var(--s3); }

/* ---------- dock: time bar and legend ---------- */
#dock { display: contents; }
#timebar {
  position: fixed; z-index: 5; bottom: var(--edge-b); left: calc(var(--edge-l) + var(--legend-w) + var(--s4)); right: calc(var(--rside) + 160px);
  max-width: 760px; margin-inline: auto; padding: var(--s2) var(--s3);
  container-type: inline-size;   /* the grid below drops the step buttons, then the speed select, as the bar narrows */
}
.tb-grid { display: grid; grid-template-columns: auto minmax(160px, 1fr) minmax(150px, max-content) 76px; align-items: center; column-gap: var(--s3); }
/* desktop only (not the sideways phone, which is wide but low): the bar's own container steps */
@media (min-width: 700px) and (min-height: 520px) {
  @container (max-width: 539.98px) { .step-btn { display: none; } }
  @container (max-width: 459.98px) { .speed { display: none; } .tb-grid { grid-template-columns: auto minmax(160px, 1fr) minmax(150px, max-content); } }
  @container (max-width: 371.98px) { .tb-grid { grid-template-columns: auto minmax(160px, 1fr); row-gap: var(--s1); } .readout { grid-column: 1 / -1; grid-row: 3; } }
}
body:not(.has-legend) #timebar { left: var(--edge-l); }
body.has-gate:not(.has-legend) { --reserve: 128px; }
.tb-btns { display: flex; gap: var(--s1); }
.tb-ticks { grid-column: 2; grid-row: 2; position: relative; height: 8px; }
.tb-ticks:empty { display: none; }
.tb-ticks[data-labels] { height: 20px; }
.tb-tick { position: absolute; top: 0; left: calc(9px + (100% - 18px) * var(--f)); width: 1px; height: 4px; background: var(--scrollbar); }
.tb-tick.day { height: 6px; background: var(--control-border); }
.tb-tl { position: absolute; top: 8px; left: calc(9px + (100% - 18px) * var(--f)); transform: translateX(-50%); font-size: 12px; line-height: 12px; color: var(--text-2); white-space: nowrap; }
.play-btn { background: var(--accent-tint); color: var(--accent); }
@media (hover: hover) { .play-btn:hover { background: var(--accent-tint-press); color: var(--accent-press); } }
.play-btn.on { background: var(--accent); color: #fff; }
@media (hover: hover) { .play-btn.on:hover { background: var(--accent-press); color: #fff; } }
.play-btn:disabled { background: transparent; color: var(--text-2); }
.progress-line { position: absolute; top: 0; left: var(--s3); right: var(--s3); height: 2px; background: var(--accent-tint); border-radius: 1px; overflow: hidden; }
.progress-line span { display: block; height: 100%; width: 0; background: var(--accent); }
.readout { min-width: 0; }
.t-main { font-size: 20px; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-main.quiet { font-size: 14px; font-weight: 500; color: var(--text-2); line-height: 1.7; }
.t-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.speed select { height: 32px; padding: 0 22px 0 var(--s2); background-position: right 4px center; font-size: 13px; }

#mesh-gate {
  position: fixed; z-index: 5; bottom: var(--edge-b); left: var(--edge-l); width: var(--legend-w); padding: var(--s3) var(--s4);
  display: grid; gap: var(--s2); justify-items: start; font-size: 13px;
}
#mesh-gate p { line-height: 1.4; }
/* the prompt card: centred in the free part of the map (right panel and dock taken off), under the panels (z 6 < 10), never blocking the map around it */
.gate-card {
  position: fixed; z-index: 6; left: calc((100% - var(--rside) + var(--gate-lw, 0px)) / 2); top: calc((100dvh - max(var(--dock-h), var(--gate-sheet, 0px)) + var(--gate-top, 0px)) / 2); transform: translate(-50%, -50%);
  width: min(320px, calc(100% - var(--rside) - 32px)); display: grid; justify-items: stretch; gap: var(--s2); padding: var(--s4);
  background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow);
}
.gate-card h2 { font-size: 15px; font-weight: 600; line-height: 1.3; }
.gate-card p { font-size: 13px; line-height: 1.4; color: var(--text-2); }
.gate-card .btn { justify-content: center; height: 44px; margin-top: var(--s1); }
.gate-card .link-btn { justify-self: center; font-size: 13px; min-height: 32px; }
@media (min-width: 700px) and (min-height: 520px) { body.left-open { --gate-lw: calc(var(--left-w) + 2 * var(--s4)); } }
#legend {
  position: fixed; z-index: 5; bottom: var(--edge-b); left: var(--edge-l); width: var(--legend-w); padding: var(--s3) var(--s4);
  display: grid; gap: var(--s2); min-height: var(--legend-base); align-content: start;
}
.lg-top { display: flex; align-items: baseline; gap: var(--s2); min-width: 0; }
.lg-label { font-size: 13px; font-weight: 600; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; }
.lg-top .muted { font-size: 12px; flex: none; }
#lg-bar { width: 100%; height: 12px; border-radius: 6px; display: block; }
.lg-ticks { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.lg-range { display: flex; align-items: center; gap: var(--s2); }
.lg-t { display: none; }
.lg-flow { font-size: 12px; line-height: 1.35; color: var(--text-2); text-wrap: pretty; }
body.has-flowline { --flow-h: 40px; --legend-h: calc(var(--legend-base) + var(--flow-h)); }
#legend.flow-only { min-height: 0; }
#legend.flow-only > :not(.lg-flow) { display: none; }
body.legend-flow-only { --legend-h: 60px; }

/* ---------- detail ---------- */
.d-head { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s4) var(--s3) var(--s2) var(--s4); flex: none; }
#d-name { font-size: 16px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
#d-sub { font-size: 13px; margin-top: var(--s1); }
#d-note { font-size: 13px; margin-top: 2px; }
#detail.scrolled:has(#d-tabs[hidden]) .d-head { box-shadow: 0 1px 0 var(--hairline); }
.tabs { display: flex; gap: var(--s4); padding: 0 var(--s4); border-bottom: 1px solid var(--hairline); flex: none; }
.tabs button { height: 40px; padding: 0 var(--s1); background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; color: var(--text-2); }
@media (hover: hover) { .tabs button:hover { color: var(--text); } }
.tabs button[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.d-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s2) var(--s4) var(--s4); }
.chart-box { width: 100%; }
.chart-legend { list-style: none; margin: var(--s2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: 12px; color: var(--text-2); }
.chart-legend li { display: flex; align-items: center; gap: var(--s2); }
.chart-legend .key { width: 18px; height: 2px; background: var(--c); flex: none; }
.chart-legend .key.dash { background: repeating-linear-gradient(90deg, var(--c) 0 6px, transparent 6px 9px); }
.chart-legend .key.dot { background: repeating-linear-gradient(90deg, var(--c) 0 2px, transparent 2px 4px); }
.chart-legend .key.marks { height: 4px; background: radial-gradient(circle at 3px 2px, var(--c) 0 1.8px, transparent 2.3px) 0 0 / 6px 4px repeat-x; }   /* three round dots at the 18px key width */
.chart-legend .key.dashdot { background: repeating-linear-gradient(90deg, var(--c) 0 6px, transparent 6px 8px, var(--c) 8px 10px, transparent 10px 12px); }
.chart-legend .key.band { height: 8px; background: var(--c); opacity: .35; border-radius: 2px; }
.chart-legend .key.fc { height: 10px; background: var(--c); border-left: 1.5px dashed var(--text-2); }
.chart-sub { margin: var(--s2) 0 0; }
.chart { width: 100%; }
.chart-wrap { position: relative; }
.chart-pick { position: absolute; right: 0; z-index: 3; height: 44px; box-shadow: var(--shadow); }   /* touch only: shown after a tap on the plot */
.chart .modebar { top: 0 !important; }
.js-plotly-plot text { font-variant-numeric: tabular-nums; }
.media { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); margin-top: var(--s4); }
.thumb { display: grid; gap: 4px; padding: 0; background: none; border: 0; text-align: left; min-width: 0; }
.thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-ctrl); border: 1px solid var(--hairline); background: var(--hover); display: block; }
@media (hover: hover) { .thumb:hover img { border-color: var(--accent); } }
.thumb span { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-body .notes { padding: var(--s4) 0 0; }
.chart-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s4); padding: var(--s2) 0 0; }
.chart-controls:empty { display: none; }
.levels-toggle { display: flex; align-items: center; gap: var(--s3); }
.levels-table { margin-top: var(--s4); }
.levels-table h3 { margin: 0; font-size: 13px; font-weight: 600; }
.data-table.levels th, .data-table.levels td { text-align: left; }
.data-table.levels th.num, .data-table.levels td.num { text-align: right; }
.data-table.levels td.src { color: var(--text-2); }
.data-table.levels td, .data-table.levels th { vertical-align: top; }
.table-wrap { overflow-x: auto; margin-top: var(--s3); }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td { padding: var(--s1) var(--s2); border-bottom: 1px solid var(--hairline); text-align: right; font-weight: 400; }
.data-table thead th { color: var(--text-2); font-weight: 500; vertical-align: bottom; }
.data-table tbody th { text-align: left; font-weight: 500; }
.data-table th:first-child { text-align: left; }
.skill { margin-top: var(--s3); font-size: 13px; }
.d-body > .tabpanel > .muted.small { margin-top: var(--s2); }
.inline-error { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; color: var(--error); font-size: 13px; }

/* ---------- states ---------- */
.loading { position: fixed; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(320px, calc(100% - 32px)); background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow); padding: var(--s4) var(--s4) var(--s4); }
.loading p { font-size: 13px; color: var(--text-2); margin-bottom: var(--s3); }
.loading .bar { height: 4px; border-radius: 2px; background: var(--hairline); overflow: hidden; }
.loading .bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.notice {
  position: fixed; z-index: 21; top: var(--edge-t); left: calc(var(--edge-l) + var(--left-w) + var(--s4)); right: var(--tr-w); margin-inline: auto; width: fit-content; max-width: 560px;
  display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s2) var(--s4);
  background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow); color: var(--error); font-size: 13px; font-weight: 500;
}
.notice.calm { color: var(--text-2); }   /* the late-forecast line is information, not a failure */
.fullpage { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: var(--s5); background: var(--surface); }
.fullpage p { max-width: 44ch; font-size: 16px; line-height: 1.5; }

dialog { border: 0; padding: 0; background: var(--surface); color: var(--text); border-radius: var(--r-panel); box-shadow: var(--shadow); max-width: min(92vw, 1000px); max-height: 92dvh; overflow: hidden; }
dialog::backdrop { background: rgba(15, 27, 45, .5); }
#lb-slot img { display: block; max-width: 100%; max-height: calc(92dvh - 52px); margin: 0 auto; }
dialog p { padding: var(--s3) var(--s4); font-size: 13px; color: var(--text-2); }
#lb-close { position: absolute; top: var(--s2); right: var(--s2); background: var(--surface); box-shadow: 0 0 0 1px var(--hairline); }

/* disclaimer gate: a modal over the dimmed map (the dimming is the lightbox backdrop colour); the card scrolls inside itself on a small screen */
.disclaimer {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; overflow: hidden; background: rgba(15, 27, 45, .5);
  padding: calc(var(--s4) + var(--safe-t)) calc(var(--s4) + var(--safe-r)) calc(var(--s4) + var(--safe-b)) calc(var(--s4) + var(--safe-l));
}
.dsc-card {
  width: min(520px, 100%); max-height: calc(100dvh - 2 * var(--s4) - var(--safe-t) - var(--safe-b)); overflow: hidden;
  display: flex; flex-direction: column; padding: 0; background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow);
}
/* the text scrolls, the button stays: the foot is always on screen; its hairline shows only while the text actually scrolls (.scrolls, set by main.js) */
.dsc-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; gap: var(--s4); padding: var(--s5) var(--s5) var(--s2); }
.dsc-scroll:focus { outline: none; }
.dsc-foot { flex: none; display: flex; justify-content: flex-end; padding: calc(var(--s2) - 1px) var(--s5) var(--s5); border-top: 1px solid transparent; }   /* the 1px line is taken out of the top padding, so the card is the height it was */
.dsc-card.scrolls .dsc-foot { border-top-color: var(--hairline); }
.dsc-card:focus { outline: none; }   /* the card takes focus so a screen reader starts at the top; the button carries the visible ring */
.dsc-logos { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3) var(--s4); }
.dsc-logos .dsc-site img { width: 56px; height: 56px; }
.dsc-logos img { display: block; max-width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.dsc-card h2 { font-size: 20px; font-weight: 600; line-height: 1.25; text-wrap: balance; }
.dsc-body { display: grid; gap: var(--s3); font-size: 14px; line-height: 1.5; max-width: 68ch; }
.dsc-body p { text-wrap: pretty; }
.dsc-foot .btn { height: 44px; padding: 0 var(--s5); font-size: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (hover: hover) { .btn.primary:hover { background: var(--accent-press); border-color: var(--accent-press); } }
.btn.primary:active { background: var(--accent-press); }
#dsc-reminder { line-height: 1.35; }
/* contact and home lines: quiet text in the panel foot and at the end of the disclaimer text */
.contact { display: grid; gap: var(--s1); font-size: 12px; line-height: 1.35; color: var(--text-2); }
.p-foot .contact { justify-items: start; }
.contact a { color: var(--accent); text-underline-offset: 2px; overflow-wrap: anywhere; }
.dsc-body .contact { margin-top: var(--s1); }

/* ---------- map furniture ---------- */
.maplibregl-ctrl-top-right { right: var(--rside); }
.maplibregl-ctrl-top-right .maplibregl-ctrl { margin: var(--edge-t) var(--s4) 0 0; }
.maplibregl-ctrl-group { border-radius: var(--r-panel) !important; box-shadow: var(--shadow) !important; background: var(--surface); overflow: hidden; }
.maplibregl-ctrl-group button { width: 36px; height: 36px; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--hairline); }
@media (hover: hover) { .maplibregl-ctrl-group button:hover { background-color: var(--hover); } }
.maplibregl-ctrl-group button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: none; }
/* zoom and info glyphs: 1.75-stroke line icons (as icons.js), drawn as masks so they take the token colours */
.maplibregl-ctrl-group button .maplibregl-ctrl-icon, .maplibregl-ctrl-attrib-button::before {
  background-color: var(--text-2); background-image: none !important;
  -webkit-mask: var(--glyph) center / 20px 20px no-repeat; mask: var(--glyph) center / 20px 20px no-repeat;
}
@media (hover: hover) { .maplibregl-ctrl-group button:hover .maplibregl-ctrl-icon, .maplibregl-ctrl-attrib-button:hover::before { background-color: var(--text); } }
.maplibregl-ctrl-zoom-in .maplibregl-ctrl-icon { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='M12 5v14'/%3E%3C/svg%3E"); }
.maplibregl-ctrl-zoom-out .maplibregl-ctrl-icon { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
.maplibregl-ctrl-attrib-button::before { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E"); content: ""; position: absolute; inset: 0; }

/* bottom-right: info button and scale bar in one row, 8px apart, with the Deltares USA card under them, all on the 16px panel margin.
   Placed by grid column and row, not by DOM order: the info control is added again whenever the basemap changes. */
.maplibregl-ctrl-bottom-right { right: var(--rside); bottom: 0; padding: 0 var(--s4) var(--edge-b) 0; display: grid; grid-template-columns: auto auto; justify-content: end; justify-items: end; align-items: center; gap: var(--s2); }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl { float: none; margin: 0; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib { grid-row: 1; grid-column: 1; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-scale { grid-row: 1; grid-column: 2; }
.maplibregl-ctrl-bottom-right .map-logo-dusa { grid-row: 2; grid-column: 1 / -1; }

/* logos: a white card like the other map controls (surface, radius, shadow, hairline), quiet, no hover state; only the link has a focus ring */
.map-logo { padding: 3px 6px; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-panel); box-shadow: var(--shadow); user-select: none; }
.map-logo-site { padding: var(--s1); }
.map-logo a { display: block; border-radius: var(--r-ctrl); text-decoration: none; color: inherit; }
.map-logo .logo-row { padding-right: var(--s2); }   /* the name is not flush against the card edge */
.logo-img { display: block; max-width: none; -webkit-user-drag: none; }
/* a logo with label lines: image, 8px gap, the text as real text (the viewer font), left-aligned, centred on the image */
.logo-row, .dsc-site { display: flex; align-items: center; gap: 8px; }
.logo-row .logo-img, .dsc-site img { flex: none; }
.logo-text { display: grid; font-family: inherit; color: var(--text); line-height: 1.25; text-align: left; white-space: nowrap; }
.logo-l1 { font-weight: 600; }
.logo-l2 { font-weight: 400; }
.map-logo .logo-l1 { font-size: 13px; }
.map-logo .logo-l2 { font-size: 12px; }
.dsc-site .logo-l1 { font-size: 15px; }
.dsc-site .logo-l2 { font-size: 14px; }
.maplibregl-ctrl-top-right .map-logo-site + .maplibregl-ctrl { margin-top: var(--s2); }   /* zoom buttons directly under the site logo */
.maplibregl-ctrl-scale { background: var(--surface); border: 1px solid var(--text-2); border-top: 0; border-radius: 0 0 4px 4px; color: var(--text-2); font: 400 11px/1.3 var(--font); padding: 1px var(--s2); margin: 0 !important; }
.maplibregl-ctrl.maplibregl-ctrl-attrib { background: var(--surface) !important; border-radius: 14px; box-shadow: var(--shadow); font: 400 11px/1.4 var(--font); color: var(--text-2); margin: 0; padding: 0; }
.maplibregl-ctrl-attrib.maplibregl-compact { min-height: 28px; padding: 0 28px 0 0; margin: 0; }
.maplibregl-ctrl-attrib.maplibregl-compact-show { padding: var(--s1) 32px var(--s1) var(--s3); }
.maplibregl-ctrl-attrib a { color: var(--text-2); }
.maplibregl-ctrl-attrib-button { width: 28px; height: 28px; border-radius: 14px; background-color: transparent; background-image: none; background-repeat: no-repeat; background-position: center; }
@media (hover: hover) { .maplibregl-ctrl-attrib-button:hover { background-color: var(--hover); } }
.maplibregl-ctrl-attrib-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: none; }
.maplibregl-popup-content { padding: var(--s3) var(--s4); border-radius: var(--r-panel); box-shadow: var(--shadow); font: inherit; color: var(--text); }
.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: #fff; }
.cp-val { font-size: 16px; font-weight: 600; }
.cp-label { font-size: 13px; color: var(--text-2); }
.cp-flow { font-size: 13px; margin-top: var(--s1); }
.cp-val + .cp-label + .cp-flow { margin-top: var(--s2); }
.cp-time { font-size: 12px; color: var(--text-2); margin-top: var(--s1); }

/* stacked layout when the window is too narrow for legend and time bar side by side */
@media (max-width: 1099.98px) {
  #timebar { left: var(--edge-l); }
  body.has-legend #timebar { bottom: calc(var(--edge-b) + var(--legend-h) + var(--s2)); right: calc(var(--rside) + var(--s4)); }   /* sits above the legend, clear of the map controls */
  body.has-legend { --reserve: calc(var(--legend-h) + 24px); }
  body.has-legend.has-timebar { --reserve: calc(var(--legend-h) + 110px); }
  body:not(.has-legend).has-timebar { --reserve: 92px; }
}
@media (min-width: 1100px) { body.has-legend, body.has-timebar { --reserve: 140px; } body.has-flowline { --reserve: calc(var(--legend-h) + 36px); } }
/* detail panel open: side by side would leave the time bar under ~400 px, so stack it above the legend up to 1330 px */
/* stacked with the detail panel open: a compact bar over the legend instead of 760 px across the map */
@media (min-width: 700px) and (max-width: 1329.98px) and (min-height: 520px) {
  body.detail-open.has-legend #timebar { max-width: 480px; margin-inline: 0 auto; }
}
@media (min-width: 1100px) and (max-width: 1329.98px) {
  body.detail-open #timebar { left: var(--edge-l); }
  body.detail-open.has-legend #timebar { bottom: calc(var(--edge-b) + var(--legend-h) + var(--s2)); right: calc(var(--rside) + var(--s4)); }
  body.detail-open.has-legend { --reserve: calc(var(--legend-h) + 24px); }
  body.detail-open.has-legend.has-timebar { --reserve: calc(var(--legend-h) + 110px); }
  body.detail-open:not(.has-legend).has-timebar { --reserve: 92px; }
}
body.has-site-logo { --tr-w: calc(var(--site-logo-w) + 48px); }   /* measured card width + 16px margin each side + 16px gap */
body.detail-open { --rside: calc(var(--detail-w) + var(--edge-r)); }
body.detail-open .maplibregl-ctrl-top-right, body.detail-open .maplibregl-ctrl-bottom-right { right: var(--rside); }
body.detail-open .notice { right: calc(var(--rside) + var(--tr-w)); }

/* ---------- touch and phone ----------
   Four blocks, each query written once. A window is one of three layouts (--layout, read by layout.js):
     phone-portrait : width under 560px, or under 700px and at least 520px high
     phone-landscape: at least 560px wide and under 520px high (a phone held sideways, or any low window)
     desktop        : the rest (700px and wider, 520px and higher)
   1. touch    : a finger is the pointer (or the window is phone-sized): target sizes, input font size, gestures
   2. compact  : both phone layouts: the dock, the compact time bar and legend row
   3. portrait : the upright phone: top bar, bottom sheets, map controls above the dock
   4. landscape: the sideways phone: one side panel on the right, no top bar, one slim dock (at the end of this block) */

/* 1. touch */
@media (pointer: coarse), (max-width: 699.98px), (max-height: 519.98px) {
  html, body { overscroll-behavior: none; }
  button, a, label, select, summary, input { touch-action: manipulation; }   /* no double-tap zoom; not on the sheet handle (touch-action: none) or the map */
  .handle, #dock, .tabs, .segmented { user-select: none; -webkit-user-select: none; }

  /* 44 px targets */
  .maplibregl-ctrl-group button { width: 44px; height: 44px; }
  .maplibregl-ctrl-attrib-button::after { content: ""; position: absolute; inset: -8px; }   /* the 28 px button keeps its look, its hit area is 44 px */
  .choice { min-height: 44px; }
  .icon-btn, .icon-btn.small { width: 44px; height: 44px; }
  select, input[type=number] { height: 44px; font-size: 16px; }   /* iOS zooms the page on focus under 16 px */
  .segmented label, .segmented button, .segmented.small button { height: 44px; }
  .tabs button { height: 44px; }
  details summary:not(.maplibregl-ctrl-attrib-button) { min-height: 44px; }   /* the map attribution is a details too: its hit area comes from ::after */
  .contact-line { display: flex; flex-wrap: wrap; align-items: center; column-gap: .3em; }
  .contact-line a { display: inline-flex; align-items: center; min-height: 44px; }   /* a 44 px target */
  .gate-card .link-btn { min-height: 44px; }
  .cycle-note .link-btn { min-height: 44px; padding: 0 var(--s2); font-size: 13px; }
  input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9px; }
  input[type=range] { height: 44px; }

  /* names that a tooltip would complete wrap instead of being cut (there is no hover on a finger) */
  .choice .truncate { overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }
  .choice .clamp2 { display: block; -webkit-line-clamp: unset; line-clamp: unset; overflow: visible; }
}
/* tablets: the 44 px number inputs make the desktop legend taller */
@media (pointer: coarse) and (min-width: 700px) { :root { --legend-base: 116px; } }

/* 2. compact: both phone layouts */
@media (max-width: 699.98px), (max-height: 519.98px) {
  body { font-size: 15px; }
  .map-logo-site { display: none; }   /* the site logo is left off the small map */
  .maplibregl-ctrl-top-right .map-logo-site + .maplibregl-ctrl { margin-top: var(--s3); }
  .phone-only { display: block; }
  .tabs { gap: var(--s5); }
  .dsc-scroll { padding: var(--s4) var(--s4) var(--s2); }
  .dsc-foot { padding: calc(var(--s2) - 1px) var(--s4) var(--s4); }
  .dsc-foot .btn { flex: 1 1 auto; justify-content: center; }

  /* dock: time bar and legend as one white strip along the bottom edge; --dock-h is its measured height */
  #dock { display: block; position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; padding-bottom: var(--safe-b); background: var(--surface); border-radius: var(--r-panel) var(--r-panel) 0 0; box-shadow: var(--shadow); }
  body:not(.has-timebar):not(.has-legend):not(.has-gate) #dock { display: none; }
  #mesh-gate { position: static; box-shadow: none; border-radius: 0; background: transparent; width: auto; grid-template-columns: 1fr auto; align-items: center; padding: var(--s2) calc(var(--s4) + var(--safe-r)) var(--s2) calc(var(--s4) + var(--safe-l)); }
  #timebar, #legend { position: static; box-shadow: none; border-radius: 0; background: transparent; width: auto; max-width: none; margin: 0; }
  #timebar { padding: 6px calc(var(--s4) + var(--safe-r)) 2px calc(var(--s2) + var(--safe-l)); }
  /* time bar: previous, play, next, slider, read-out in one row from 480 px wide; narrower, two rows: the buttons and the read-out, then the slider across the full width */
  .tb-grid { grid-template-columns: auto minmax(0, 1fr) auto; column-gap: var(--s2); }
  .speed, .tb-ticks { display: none; }
  .readout { text-align: right; min-width: 92px; }
  @container (max-width: 479.98px) {
    .tb-grid { grid-template-columns: auto minmax(0, 1fr); column-gap: var(--s2); }
    .tb-btns { grid-column: 1; grid-row: 1; }
    .readout { grid-column: 2; grid-row: 1; }
    #slider { grid-column: 1 / -1; grid-row: 2; height: 40px; }   /* the thumb stays 22 px */
  }
  .t-main { font-size: 15px; }
  .t-main.quiet { font-size: 13px; line-height: 1.5; }
  .t-sub { font-size: 12px; }
  .t-sub .step { display: none; }
  .progress-line { left: 0; right: 0; }
  #legend { display: grid; grid-template-columns: minmax(0, 1fr) 72px auto auto; align-items: center; gap: var(--s2); min-height: 0; padding: 2px calc(var(--s4) + var(--safe-r)) 8px calc(var(--s4) + var(--safe-l)); cursor: pointer; }
  #legend .lg-range, #legend .lg-ticks { display: none; }
  #legend .lg-flow { grid-column: 1 / -1; }
  #legend.flow-only { grid-template-columns: minmax(0, 1fr); padding-top: var(--s2); }
  #legend .lg-t { display: block; font-size: 12px; color: var(--text-2); }
  #legend .lg-label { display: block; white-space: nowrap; text-overflow: ellipsis; }
}

/* 3. portrait: the upright phone */
#topbar { display: none; }
@media (max-width: 559.98px), (max-width: 699.98px) and (min-height: 520px) {
  :root { --layout: phone-portrait; }
  body { --gate-top: calc(52px + var(--safe-t)); }   /* the free part of the map starts under the top bar */
  body.detail-open { --gate-sheet: 62dvh; --rside: var(--safe-r); }   /* and ends over the half-height chart sheet; the charts are a bottom sheet here and take no right space */

  #topbar {
    display: flex; align-items: center; justify-content: space-between; gap: var(--s3); position: fixed; z-index: 6; top: 0; left: 0; right: 0;
    padding: calc(var(--safe-t) + 4px) calc(var(--s3) + var(--safe-r)) 4px calc(var(--s4) + var(--safe-l));
    min-height: calc(52px + var(--safe-t)); background: var(--surface); box-shadow: 0 1px 0 var(--hairline);
  }
  #topbar-title { font-size: 16px; font-weight: 600; min-width: 0; }
  #topbar .btn { height: 44px; flex: none; }
  .fab { display: none !important; }

  /* map controls: under the top bar, above the dock (--dock-h already holds the dock's bottom safe-area padding) */
  .maplibregl-ctrl-top-right { top: calc(52px + var(--safe-t)); right: var(--safe-r); }
  .maplibregl-ctrl-top-right .maplibregl-ctrl { margin: var(--s3) var(--s3) 0 0; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: max(var(--dock-h), var(--safe-b)); right: var(--safe-r); }
  .maplibregl-ctrl-bottom-right { padding: 0 var(--s3) var(--s3) 0; }
  body.detail-open .maplibregl-ctrl-top-right, body.detail-open .maplibregl-ctrl-bottom-right { right: var(--safe-r); }
  /* Deltares USA logo shrinks to 18px and goes when the map is very short */
  .map-logo-dusa { padding: 2px 5px; }
  .map-logo-dusa .logo-img { width: 79px; height: 18px; }

  /* bottom sheets with a drag handle */
  .handle { display: flex; justify-content: center; align-items: center; height: 44px; flex: none; touch-action: none; cursor: grab; }
  .handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--scrollbar); }
  .sheet { left: 0 !important; right: 0 !important; width: auto !important; top: auto !important; bottom: 0 !important; border-radius: 16px 16px 0 0; padding-bottom: var(--safe-b); }
  #left { max-height: 78dvh; z-index: 10; }
  #left .scroll { border-radius: 0; }
  #sec-basemap { padding-bottom: var(--s3); }
  #left[data-state=closed] { transform: translateY(100%); }
  #left[data-state=open] { transform: translateY(0); }
  #detail { height: calc(100dvh - var(--safe-t) - 52px); z-index: 11; }   /* full height stops under the top bar */
  #left::after { bottom: var(--safe-b); border-radius: 0; }
  #detail[data-state=closed] { transform: translateY(100%); }
  #detail[data-state=half] { transform: translateY(calc(100% - 62dvh)); }
  #detail[data-state=full] { transform: translateY(0); }
  #detail[data-state=half] .d-body { padding-bottom: calc(38dvh + var(--safe-b)); }
  .d-head { padding-top: 0; }
  .p-head { padding-top: 0; }
  .back-link { min-height: 44px; line-height: 44px; margin: 0; }
  .p-foot { padding-top: var(--s1); padding-bottom: var(--s3); }

  /* right: clear of the zoom column (44px buttons + 12px margin + 12px gap), also while a sheet is open: the controls keep their place */
  #notice, .notice { top: calc(60px + var(--safe-t)); left: var(--s3); right: calc(var(--safe-r) + 68px); width: auto; max-width: none; margin: 0; }
  body.detail-open .notice { right: calc(var(--safe-r) + 68px); }
  .loading { top: 40%; }
}
@media (max-width: 559.98px) and (max-height: 479.98px) { .map-logo-dusa { display: none; } }

/* 4. landscape: a phone held sideways (or any window under 520px high). One panel slot on the right holds Layers or the charts, never both;
   the top bar is gone (the fab is the Layers button); one slim dock along the bottom of the map part; both logos off the map.
   Desktop rules that would still reach here and are switched off or overridden below: the --detail-w / --reserve / --legend-base tokens (unused: the panels
   take --side-w, the dock is not positioned), the stacked time bar and legend offsets (the dock items are static), the time bar container steps and the
   detail-open time bar width (given min-height: 520px above), body.detail-open .notice (beaten by #notice). */
@media (min-width: 560px) and (max-height: 519.98px) {
  :root { --layout: phone-landscape; --side-w: clamp(300px, 50vw, 480px); }
  body { --rside: var(--safe-r); --dock-r: 0px; --dock-pr: var(--safe-r); }
  body.detail-open, body.left-open { --rside: var(--side-w); --dock-r: var(--side-w); --dock-pr: 0px; }

  /* the panel slot: full height on the right; closed it slides out to the right */
  #left, #detail { top: 0; right: 0; bottom: 0; left: auto; width: var(--side-w); height: auto; max-height: none; border-radius: 16px 0 0 16px; padding-right: var(--safe-r); }
  #left { z-index: 10; }
  #detail { z-index: 11; }
  #left[data-state=closed], #detail[data-state=closed] { transform: translateX(calc(100% + var(--s5))); }
  #detail[data-state=half], #detail[data-state=full] { transform: none; }
  #left::after { bottom: 0; border-radius: 0 0 0 16px; }
  #left .scroll, .d-body { padding-bottom: calc(var(--s4) + var(--safe-b)); }
  .p-head, .d-head { padding-top: calc(var(--s3) + var(--safe-t)); }
  .d-head { padding-bottom: var(--s1); }
  #sec-basemap { padding-bottom: var(--s3); }

  /* no top bar: the fab opens Layers */
  .fab { top: calc(var(--s3) + var(--safe-t)); left: calc(var(--s3) + var(--safe-l)); }

  /* dock: the time bar and the legend in one row over the map part; two rows when the panel narrows it */
  #dock { display: flex; flex-wrap: wrap; align-items: center; left: 0; right: var(--dock-r); padding-left: var(--safe-l); padding-right: var(--dock-pr); padding-bottom: var(--safe-b); }
  body:not(.has-timebar):not(.has-legend):not(.has-gate) #dock { display: none; }
  #timebar { flex: 1 1 300px; min-width: 0; padding: 4px var(--s3) 4px var(--s2); }
  #legend { flex: 0 1 240px; min-width: 0; padding: 2px var(--s3); }
  #mesh-gate { flex: 1 1 280px; min-width: 0; padding: var(--s2) var(--s3); }
  #legend:not(.flow-only) .lg-flow { display: none; }
  /* the time bar stays one row at any width: the step buttons go first, the slider keeps at least 96px */
  .tb-grid { grid-template-columns: auto minmax(96px, 1fr) auto; }
  @container (max-width: 479.98px) {
    .tb-btns, .readout, #slider { grid-column: auto; grid-row: auto; }
    #slider { height: 44px; }
    .step-btn { display: none; }
  }

  /* map controls: zoom top right clear of the panel, scale and attribution above the dock; the names are in the gate dialog and the Layers panel */
  .map-logo-dusa { display: none; }
  .maplibregl-ctrl-top-right { top: var(--safe-t); right: var(--rside); }
  .maplibregl-ctrl-top-right .maplibregl-ctrl { margin: var(--s3) var(--s3) 0 0; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: max(var(--dock-h), var(--safe-b)); }
  .maplibregl-ctrl-bottom-right { right: var(--rside); padding: 0 var(--s3) var(--s3) 0; }

  /* charts in the narrow panel: the plot first (a 300 px high panel shows no plot under a full legend), then the legend and the levels table; the switch stays on one line above */
  .chart-box { display: flex; flex-direction: column; }
  .chart-box > .chart-wrap { order: 1; }
  .chart-box > .chart-legend { order: 2; }
  .chart-box > .levels-table { order: 3; }
  .levels-toggle { flex-wrap: nowrap; gap: var(--s2); }
  .levels-toggle > span { white-space: nowrap; }
  .levels-toggle .segmented.small button { padding: 0 var(--s2); }

  #notice, .notice { top: calc(var(--s2) + var(--safe-t)); left: calc(var(--safe-l) + 68px); right: calc(var(--rside) + 68px); width: auto; max-width: none; margin: 0; }
  .loading { left: calc((100% - var(--rside)) / 2); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { transition: none; }
}
.data-table.levels th[scope=row], .data-table.levels td:not(.src) { white-space: nowrap; }
