.viz-card {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	overflow: hidden;
}

/* Toolbar: mode switch + legend */
.toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px 20px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--line);
}

.mode-switch {
	display: inline-flex;
	padding: 3px;
	border-radius: 999px;
	background: var(--surface-2);
}

.mode-switch button {
	min-width: 76px;
	padding: 6px 14px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--ink-2);
	font-weight: 500;
	cursor: pointer;
}

.mode-switch button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 15%); }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; color: var(--ink-2); font-size: 0.8rem; }

.legend-item { display: inline-flex; align-items: center; gap: 8px; }

.legend-ramp { display: grid; gap: 2px; }

.legend-ramp svg { display: block; overflow: visible; }

.legend-ramp text { fill: var(--ink-3); font: 400 10px var(--font-mono); }

.legend-label { color: var(--ink-2); font-size: 0.75rem; }

/* Stage + side summary */
.viz-body { --stage-h: min(74vh, 700px); display: grid; grid-template-columns: minmax(0, 1fr) 280px; }

.stage {
	position: relative;
	height: var(--stage-h);
	min-height: 440px;
	overflow: hidden;
	touch-action: none;
	background: radial-gradient(ellipse at 50% 40%, var(--surface) 0%, var(--surface-2) 100%);
}

.view { position: absolute; inset: 0; }

.view svg, .view canvas { display: block; width: 100%; height: 100%; }

.stage-btn {
	position: absolute;
	right: 12px;
	bottom: 12px;
	padding: 6px 12px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	color: var(--ink-2);
	font-size: 0.8rem;
	cursor: pointer;
	z-index: 3;
}

.stage-btn:hover { color: var(--ink); border-color: var(--ink-3); }

.stage-hint {
	position: absolute;
	left: 12px;
	bottom: 12px;
	margin: 0;
	max-width: calc(100% - 140px);
	color: var(--ink-3);
	font-size: 0.75rem;
	pointer-events: none;
	z-index: 2;
}

.loading {
	position: absolute;
	inset: 0;
	z-index: 8;
	display: grid;
	place-items: center;
	background: radial-gradient(ellipse at 50% 45%, var(--surface) 0%, var(--surface-2) 100%);
	transition: opacity 0.5s ease, visibility 0s;
}

/* Hidden once faded, so screen readers no longer find a stale "Loading data…" status. */
.loading.done { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity 0.5s ease, visibility 0s 0.5s; }

.loading-inner { display: grid; justify-items: center; gap: 14px; width: min(260px, 70%); }

.loading-inner img { animation: bob 2.4s ease-in-out infinite; }

@keyframes bob { 50% { transform: translateY(-5px); } }

.loading-bar { width: 100%; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }

.loading-bar span { display: block; width: 4%; height: 100%; border-radius: 2px; background: var(--accent); transition: width 0.35s ease; }

.loading-text { margin: 0; color: var(--ink-3); font: 400 0.8rem var(--font-mono); text-align: center; }

.summary {
	display: flex;
	flex-direction: column;
	gap: 16px;
	padding: 18px 16px;
	border-left: 1px solid var(--line);
	font-size: 0.875rem;
	color: var(--ink-2);
}

.summary h3 { margin: 0 0 2px; color: var(--ink-3); font: 500 0.7rem/1.3 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; }

.summary .big { color: var(--ink); font: 650 2rem/1.1 var(--font-display); }

.summary .state-big { display: flex; align-items: flex-end; gap: 10px; }
/* Statewide water-level gauge: the fill eases to each month's % full; dashed tick = monthly average. */
.fill-gauge { position: relative; flex: none; width: 12px; height: 2.1rem; margin-bottom: 3px; border: 1px solid var(--ink-3); border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.fill-gauge-water { position: absolute; inset: 0; background: var(--accent); opacity: 0.85; transform-origin: 50% 100%; transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.3, 1); }
.fill-gauge-avg { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--ink); transition: bottom 0.7s cubic-bezier(0.3, 0.7, 0.3, 1); }
.fill-gauge-avg[hidden] { display: none; }
.summary .sub { color: var(--ink-3); font-size: 0.8rem; }

.summary-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.summary-list button {
	display: grid;
	grid-template-columns: 10px minmax(0, 1fr) auto;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding: 4px 6px;
	border: 0;
	border-radius: 6px;
	background: transparent;
	text-align: left;
	cursor: pointer;
}

.summary-list button:hover, .summary-list button[aria-current="true"] { background: var(--surface-2); }

.summary-list .swatch { width: 10px; height: 10px; border-radius: 50%; }

.summary-list .swatch.no-data, .lbl-dot.no-data {
	background: repeating-linear-gradient(45deg, #8a8d92 0 1.4px, transparent 1.4px 3.5px) !important;
	box-shadow: inset 0 0 0 1.4px #8a8d92, 0 0 0 1.5px rgb(255 255 255 / 85%);
}

.summary-list .swatch.flood, .lbl-dot.flood {
	background: repeating-linear-gradient(0deg, #5b7c99 0 1.6px, rgb(91 124 153 / 25%) 1.6px 3.6px) !important;
	box-shadow: inset 0 0 0 1.4px #5b7c99, 0 0 0 1.5px rgb(255 255 255 / 85%);
}

/* A flood-control basin with no data: hatched, with the flood-control ring. */
.summary-list .swatch.flood.no-data, .lbl-dot.flood.no-data {
	background: repeating-linear-gradient(45deg, #8a8d92 0 1.4px, transparent 1.4px 3.5px) !important;
	box-shadow: inset 0 0 0 1.6px #5b7c99, 0 0 0 1.5px rgb(255 255 255 / 85%);
}

.summary-note { margin: 0; color: var(--ink-3); font-size: 0.72rem; line-height: 1.4; }

.summary-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }

/* Tooltip */
.tooltip {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 6;
	width: max-content;
	max-width: 250px;
	padding: 10px 12px;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--surface);
	color: var(--ink-2);
	box-shadow: var(--shadow);
	font-size: 0.8rem;
	line-height: 1.4;
	pointer-events: none;
}

.tooltip .tt-title { margin-bottom: 4px; color: var(--ink); font-weight: 600; font-size: 0.875rem; }

.tooltip dl { display: grid; grid-template-columns: auto auto; gap: 1px 12px; margin: 0; }

.tooltip dt { color: var(--ink-3); }

.tooltip dd { margin: 0; text-align: right; font-family: var(--font-mono); color: var(--ink); }

.tooltip .tt-bar { height: 6px; margin: 6px 0 2px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }

.tooltip .tt-bar span { display: block; height: 100%; border-radius: 3px; }

.tooltip .tt-note { margin-top: 4px; color: var(--ink-3); font-size: 0.72rem; }

/* Timeline */
.timeline {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto auto;
	align-items: center;
	gap: 14px;
	padding: 12px 16px 14px;
	border-top: 1px solid var(--line);
}

.play-btn {
	display: grid;
	place-items: center;
	width: 42px;
	height: 42px;
	border: 0;
	border-radius: 50%;
	background: var(--accent);
	color: var(--accent-ink);
	cursor: pointer;
}

.speed-btn { min-width: 44px; height: 32px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2); font: 500 0.8rem var(--font-mono); cursor: pointer; }
.speed-btn:hover { color: var(--ink); border-color: var(--ink-3); }

.play-btn svg { width: 18px; height: 18px; fill: currentColor; }

.track { position: relative; height: 54px; }

.track svg { position: absolute; inset: 0 0 18px; width: 100%; height: calc(100% - 18px); overflow: visible; }

.track svg { pointer-events: none; z-index: 2; }
.track .extreme { pointer-events: all; cursor: pointer; }
.track .extreme circle { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.5; }
.track .extreme:hover circle { stroke: var(--accent); fill: var(--accent); }
.track .extreme-label { fill: var(--ink-2); font: 500 9px var(--font-mono); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.track .playhead { pointer-events: none; }
.track .playhead line { stroke: var(--ink); stroke-width: 1; opacity: 0.55; }
.track .playhead circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.track .spark-area { fill: var(--accent); opacity: 0.14; }

.track .spark-avg { fill: none; stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.8; }
.track .spark-cap { font-size: 9px; fill: var(--ink-2); }
.track .spark-line { fill: none; stroke: var(--accent); stroke-width: 1.5; }

.track .drought-band { fill: var(--warm); opacity: 0.06; }

.track .drought-cap { fill: var(--warm); opacity: 0.7; }

.track .band-label { fill: var(--warm); font: 500 10px var(--font-mono); }

.track .year-tick text { fill: var(--ink-3); font: 400 10px var(--font-mono); }

.track .year-tick line { stroke: var(--line); }

.track .year-tick.minor line { opacity: 0.6; }

.track .provisional-band { fill: url(#hatch-prov); opacity: 0.6; }

.timeline.is-provisional .date-readout .meta { font-style: italic; }

.track input[type="range"] {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	height: 36px;
	margin: 0;
	background: transparent;
	-webkit-appearance: none;
	appearance: none;
	cursor: pointer;
	top: 0;
}

.track input[type="range"]::-webkit-slider-runnable-track { height: 36px; background: transparent; }
.track input[type="range"]::-moz-range-track { height: 36px; background: transparent; }

.track input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 4px;
	height: 40px;
	margin-top: -2px;
	border-radius: 2px;
	background: var(--ink);
	box-shadow: 0 0 0 3px var(--surface);
}

.track input[type="range"]::-moz-range-thumb { width: 4px; height: 40px; border: 0; border-radius: 2px; background: var(--ink); }

.date-readout { min-width: 92px; text-align: right; }

.date-readout .month { display: block; color: var(--ink); font: 650 1.15rem/1.2 var(--font-display); }

.date-readout .meta { display: block; color: var(--ink-3); font-size: 0.75rem; }

/* 2D map */
.map-2d .county { fill: var(--land); stroke: var(--county); stroke-width: 0.6; vector-effect: non-scaling-stroke; }

.map-2d .outline { fill: none; stroke: var(--land-edge); stroke-width: 1.2; vector-effect: non-scaling-stroke; }

.map-2d .stream-base { fill: none; stroke: var(--stream); stroke-opacity: 0.18; stroke-linecap: round; vector-effect: non-scaling-stroke; }

.map-2d .stream-flow {
	fill: none;
	stroke: var(--stream);
	stroke-opacity: 0.85;
	stroke-linecap: round;
	stroke-dasharray: 2 10;
	vector-effect: non-scaling-stroke;
	animation: flow 1.6s linear infinite;
}

.map-2d .stream-flow.no-flow { stroke-opacity: 0.35; animation-duration: 3.2s; }

@keyframes flow { to { stroke-dashoffset: -24; } }

.map-2d .gauge { fill: var(--surface); stroke: var(--stream); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

.map-2d .res { cursor: pointer; outline: none; }

/* Basin = dry earth up to the capacity rim; disc = water; arc on the south rim = dam wall. */
.map-2d .res > :not(.res-hit) { pointer-events: none; }
.map-2d .res-hit { fill: transparent; cursor: pointer; }
.map-2d .res-cap { fill: #d8c4a0; fill-opacity: 0.75; stroke: #9a7f5c; stroke-width: 1; vector-effect: non-scaling-stroke; }
.map-2d .res.low .res-cap { fill: #e6d8bd; }
.map-2d .res-fill { stroke: none; transition: r 0.45s cubic-bezier(0.22, 1, 0.36, 1), fill 0.45s ease; }
/* Shoreline: a pale "bathtub ring" edge just outside the water. */
.map-2d .res-shore { fill: none; stroke: #fbf7ee; stroke-width: 1; stroke-opacity: 0.85; transition: r 0.45s cubic-bezier(0.22, 1, 0.36, 1); vector-effect: non-scaling-stroke; }
@media (prefers-reduced-motion: reduce) { .map-2d .res-fill, .map-2d .res-shore { transition: none; } }

/* No data: hollow, hatched ring, never a grey fill that could pass for a % full colour. */
.map-2d .res.no-data .res-cap,
.map-2d .res.missing .res-cap { fill: url(#hatch-nodata); fill-opacity: 1; stroke: var(--ink-3); stroke-dasharray: 2 2; }

/* Flood-control basins: steel ring, striped disc, no drought colour. */
.map-2d .res.flood .res-cap { stroke: #5b7c99; stroke-width: 1.6; }

.map-2d .res:hover .res-cap, .map-2d .res:focus-visible .res-cap, .map-2d .res.active .res-cap { stroke: var(--ink); stroke-width: 2; }

.map-2d .label { fill: var(--ink); font: 500 11px var(--font-body); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }

/* 3D labels */
.labels-3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.label-3d {
	position: absolute;
	top: 0;
	left: 0;
	padding: 1px 6px;
	border-radius: 4px;
	background: color-mix(in srgb, var(--surface) 80%, transparent);
	color: var(--ink);
	font: 500 11px var(--font-body);
	white-space: nowrap;
	will-change: transform;
}

.webgl-fallback { display: grid; place-items: center; height: 100%; padding: 24px; text-align: center; color: var(--ink-3); }

/* Desktop: size the stage so map, summary and timeline share the first screen. */
@media (min-width: 901px) {
	.viz-body { --stage-h: clamp(420px, calc(100vh - 426px), 700px); }
	/* The 3D legend needs a second row; take that height from the stage so the timeline stays on screen. */
	body[data-mode="3d"] .viz-body { --stage-h: clamp(380px, calc(100vh - 480px), 700px); }
	.stage { min-height: 0; }
	/* Scrollable summary: a soft fade at the bottom says there is more below. */
	.summary { max-height: var(--stage-h); overflow-y: auto; scrollbar-width: thin; -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent); mask-image: linear-gradient(#000 calc(100% - 28px), transparent); padding-bottom: 24px; }
}

@media (max-width: 900px) {
	.viz-body { grid-template-columns: 1fr; }
	.summary { border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
	.summary .span-all { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
	.speed-btn { display: none; }
	.stage { height: 470px; min-height: 0; }
	.toolbar { padding: 10px 12px; }
	.legend { gap: 6px 14px; }
	.timeline { grid-template-columns: auto minmax(0, 1fr); gap: 10px 12px; padding: 10px 12px 12px; }
	.date-readout { grid-column: 1 / -1; grid-row: 1; display: flex; align-items: baseline; justify-content: space-between; text-align: left; }
	.summary { padding: 14px 12px; gap: 12px; }
	.summary .big { font-size: 1.6rem; }
	.stage-hint { display: none; }
}

/* % of average for this calendar month: below 80% reads as a shortfall, above 110% as a surplus. */
.js-state-avg { margin-top: 2px; }
.js-state-avg strong { font-weight: 700; }
.js-state-avg .below-avg { color: #c2410c; }
.js-state-avg .above-avg { color: #1d6fa5; }
.tt-avg-note { opacity: 0.7; font-size: 0.92em; }

/* The legend's fold: a plain "Legend" toggle on phones, invisible on wider screens. */
.legend-wrap > summary { display: none; }
@media (max-width: 700px) {
	.legend-wrap > summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; font-size: 0.85rem; color: var(--ink-2); padding: 6px 12px; border: 1px solid var(--line, rgba(0,0,0,0.15)); border-radius: 999px; list-style: none; }
	.legend-wrap > summary::-webkit-details-marker { display: none; }
	.legend-wrap > summary::after { content: "▾"; font-size: 0.8em; }
	.legend-wrap[open] > summary::after { content: "▴"; }
	.legend-wrap[open] > .legend { margin-top: 10px; }
}

.js-state-delta { margin-top: 2px; }

/* Snowpack wash on the 2D map's mountain counties (opacity set per month in map2d.js). */
.snow-2d .snow-area { fill: #ffffff; fill-opacity: 0; stroke: none; pointer-events: none; transition: fill-opacity 0.4s ease; }
:root[data-theme="dark"] .snow-2d .snow-area { fill: #dfe9f2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .snow-2d .snow-area { fill: #dfe9f2; } }
@media (prefers-reduced-motion: reduce) { .snow-2d .snow-area { transition: none; } }
.summary .snow-stat .big.no-data { font-size: 1.1rem; color: var(--ink-3); }

/* Drought front and path on the 2D map (map2d.js). */
.drought-2d { pointer-events: none; }
.drought-2d .front-dry { fill: #d9a54a; fill-opacity: calc(0.1 + 0.18 * var(--v, 0.5)); stroke: #d99a3a; stroke-width: 1.5; stroke-opacity: 0.75; animation: front-shimmer 2.4s ease-in-out infinite alternate; }
.drought-2d .front-wet { fill: #2a8f96; fill-opacity: calc(0.08 + 0.14 * var(--v, 0.5)); stroke: #2a8f96; stroke-width: 1.5; stroke-opacity: 0.7; animation: front-shimmer 2.4s ease-in-out infinite alternate; }
@keyframes front-shimmer { from { stroke-opacity: 0.35; } to { stroke-opacity: 0.9; } }
.drought-2d .dpath-line { fill: none; stroke: #1d3a5c; stroke-width: 2; stroke-linecap: round; transition: stroke-dasharray 0.6s ease; }
.drought-2d .dpath-stop2 circle { fill: #d99a3a; stroke: #1d3a5c; stroke-width: 1.5; }
.drought-2d .dpath-stop2 text { font: 500 10px var(--font-mono); fill: #1d3a5c; paint-order: stroke; stroke: #f4f7fa; stroke-width: 3px; }
@media (prefers-reduced-motion: reduce) { .drought-2d .front-dry, .drought-2d .front-wet { animation: none; } .drought-2d .dpath-line { transition: none; } }
