/* 3D overlays: controls, labels, compare split, detail card. */
.controls-3d {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 4;
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 6px;
	max-width: calc(100% - 24px);
}

.chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 32px;
	padding: 0 12px;
	border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
	border-radius: 999px;
	background: color-mix(in srgb, var(--surface) 82%, transparent);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	color: var(--ink);
	font-size: 0.8rem;
	font-weight: 500;
	cursor: pointer;
}

.chip svg { width: 14px; height: 14px; fill: currentColor; }

.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.select-chip { padding: 0 4px 0 10px; }

.select-chip select { height: 30px; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }

.select-chip select option { color: #1f2328; }

.labels-3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }

.lbl {
	position: absolute;
	top: 0;
	left: 0;
	display: flex;
	align-items: center;
	gap: 5px;
	white-space: nowrap;
	will-change: transform;
}

.lbl-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; box-shadow: 0 0 0 1.5px rgb(255 255 255 / 85%), 0 1px 3px rgb(0 0 0 / 35%); }

.lbl-text {
	padding: 1px 6px;
	border-radius: 4px;
	/* --plate fades with distance; the text stays fully opaque for AA contrast. */
	background: rgb(16 22 30 / calc(var(--plate, 0.88) * 100%));
	color: #f4f1ea;
	font: 500 11px/1.4 var(--font-body);
}

.lbl-text.far { visibility: hidden; }

.lbl.left { flex-direction: row-reverse; }

.lbl-pct { font-family: var(--font-mono); color: #cfd8e3; }

.lbl.active .lbl-text { background: rgb(16 22 30 / 88%); outline: 1px solid rgb(255 255 255 / 60%); }

.lbl.active .lbl-dot { transform: scale(1.3); }

.compare-split { position: absolute; inset: 0; z-index: 3; pointer-events: none; --split: 50%; }

.compare-handle {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--split);
	width: 28px;
	margin-left: -14px;
	pointer-events: auto;
	cursor: ew-resize;
	touch-action: none;
}

.compare-handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: 13px; width: 2px; background: rgb(255 255 255 / 90%); box-shadow: 0 0 6px rgb(0 0 0 / 40%); }

.compare-handle span {
	position: absolute;
	top: 50%;
	left: 2px;
	width: 24px;
	height: 24px;
	margin-top: -12px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 6px rgb(0 0 0 / 35%);
}

.compare-tag { position: absolute; top: 56px; display: flex; flex-direction: column; gap: 4px; max-width: calc(50% - 24px); pointer-events: auto; }

.compare-left { right: calc(100% - var(--split) + 14px); align-items: flex-end; text-align: right; }

.compare-right { left: calc(var(--split) + 14px); align-items: flex-start; }

/* Per-half summary under the month: statewide % full and the four largest lakes. */
.compare-stat {
	margin: 0;
	padding: 3px 8px;
	border-radius: 6px;
	background: rgb(16 22 30 / 70%);
	color: #e8edf2;
	font: 500 0.72rem/1.35 var(--font-body);
}

.compare-stat strong { color: #fff; font-family: var(--font-mono); }

.compare-tag .compare-stat span { display: inline; padding: 0; background: none; font: inherit; color: inherit; }

.compare-tag .compare-stat .compare-keys { display: block; color: #cfd8e3; font-size: 0.68rem; }

.compare-keys span { white-space: nowrap; }

.compare-tag select, .compare-tag span {
	display: inline-block;
	padding: 4px 10px;
	border: 0;
	border-radius: 6px;
	background: rgb(16 22 30 / 75%);
	color: #fff;
	font: 600 0.8rem var(--font-body);
}

.detail-card {
	position: absolute;
	top: 12px;
	left: 12px;
	z-index: 5;
	width: 280px;
	max-width: calc(100% - 24px);
	padding: 14px 16px 12px;
	border: 1px solid var(--line);
	border-radius: 12px;
	background: color-mix(in srgb, var(--surface) 94%, transparent);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	box-shadow: var(--shadow);
	color: var(--ink-2);
	font-size: 0.8rem;
}

.detail-close {
	position: absolute;
	top: 8px;
	right: 8px;
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--ink-3);
	cursor: pointer;
}

.detail-close:hover { background: var(--surface-2); color: var(--ink); }

.detail-close svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.detail-kicker { margin: 0 28px 2px 0; color: var(--ink-3); font: 500 0.68rem/1.3 var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; }

.detail-title { margin: 0 24px 8px 0; color: var(--ink); font: 650 1.15rem/1.2 var(--font-display); }

/* Dam-and-lake scene: hills, a lake filled to % of capacity, bathtub ring and dam wall. */
.detail-dam {
	--scene-sky-1: #e9f0f2; --scene-sky-2: #f8f4ea;
	--scene-far-1: #a9b7c3; --scene-far-2: #c9cfc9;
	--scene-near-1: #9aa47e; --scene-near-2: #b9b08a;
	--scene-earth: #b8956a; --scene-ring: #f3ead6; --scene-bank: #8a6b48;
	--scene-embank-1: #a99f86; --scene-embank-2: #857a62;
	display: block; width: 100%; height: auto; margin: 2px 0 10px; border-radius: 8px;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .detail-dam {
		--scene-sky-1: #1b2836; --scene-sky-2: #233140; --scene-far-1: #3e4d5e; --scene-far-2: #34404b;
		--scene-near-1: #4a5340; --scene-near-2: #3d4234; --scene-earth: #7a6246; --scene-ring: #cfc0a3; --scene-bank: #5d4a35;
	}
}
:root[data-theme="dark"] .detail-dam {
	--scene-sky-1: #1b2836; --scene-sky-2: #233140; --scene-far-1: #3e4d5e; --scene-far-2: #34404b;
	--scene-near-1: #4a5340; --scene-near-2: #3d4234; --scene-earth: #7a6246; --scene-ring: #cfc0a3; --scene-bank: #5d4a35;
}
.detail-dam .scene-snow { fill: #f6f8fa; opacity: 0.85; }
.detail-dam .dam-bed { fill: var(--scene-earth); }
.detail-dam .dam-bed { stroke: var(--scene-bank); stroke-width: 1; }
.detail-dam .dam-ring-band { fill: none; stroke: var(--scene-ring); stroke-width: 11; stroke-linecap: round; filter: drop-shadow(0 1px 0 rgb(0 0 0 / 18%)); }
.detail-dam .dam-surface { stroke: #ffffff; stroke-width: 1.2; opacity: 0.55; }
.detail-dam .dam-shimmer line { stroke: #ffffff; stroke-width: 1; stroke-linecap: round; opacity: 0.35; animation: dam-shimmer 4s ease-in-out infinite alternate; }
.detail-dam .dam-shimmer line:nth-child(2) { animation-delay: -1.5s; }
.detail-dam .dam-shimmer line:nth-child(3) { animation-delay: -3s; }
@keyframes dam-shimmer { from { opacity: 0.1; } to { opacity: 0.45; } }
.detail-dam .dam-ground { fill: var(--scene-near-2); }
.detail-dam .dam-river { fill: none; stroke: #5d97be; stroke-width: 2; stroke-linecap: round; opacity: 0.7; }
.detail-dam .dam-wall { stroke: #6f6b64; stroke-width: 0.8; stroke-linejoin: round; }
.detail-dam .dam-crest { stroke: #5f5b55; stroke-width: 2; stroke-linecap: round; }
.detail-dam .dam-wall.embankment { stroke: #6d644f; }
.detail-dam .dam-joint { stroke: #7d7970; stroke-width: 0.5; opacity: 0.6; }
.detail-dam .dam-fullmark { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
.detail-dam .dam-fulltext { fill: var(--ink); font: 600 8px var(--font-mono); letter-spacing: 0.02em; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.detail-dam .dam-level { fill: #ffffff; font: 600 11px var(--font-mono); paint-order: stroke; stroke: rgb(0 0 0 / 25%); stroke-width: 2px; }
.detail-dam.low .dam-level, .detail-dam.no-data .dam-level { fill: var(--ink); stroke: none; }
@media (prefers-reduced-motion: reduce) { .detail-dam .dam-shimmer line { animation: none; } }

.detail-spark .spark-avg { fill: none; stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
.detail-spark .spark-cap { font: 400 9px var(--font-mono); fill: var(--ink-3); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 0 0 8px; }

.detail-grid dt { color: var(--ink-3); font-size: 0.7rem; }

.detail-grid dd { margin: 0; color: var(--ink); font-size: 0.85rem; }

.detail-spark { display: block; width: 100%; overflow: visible; }

.detail-spark .spark-area { fill: var(--accent); opacity: 0.12; }

.detail-spark .spark-line { fill: none; stroke: var(--accent); stroke-width: 1.6; }

.detail-spark .spark-full { stroke: var(--ink-3); stroke-dasharray: 3 3; stroke-width: 1; opacity: 0.6; }

.detail-spark .spark-now { stroke: var(--ink); stroke-width: 1; opacity: 0.5; }

.detail-spark .spark-year { fill: var(--ink-3); font: 400 9px var(--font-mono); }

.detail-note { margin: 6px 0 0; color: var(--ink-3); font-size: 0.7rem; }

@media (max-width: 560px) {
	.controls-3d { top: 8px; right: 8px; gap: 4px; }
	.chip.js-compare span, .chip.js-links span { display: none; }
	.chip { height: 30px; padding: 0 10px; font-size: 0.75rem; }
	.detail-card { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; max-width: none; padding: 10px 12px 8px; }
	.detail-title { font-size: 1rem; margin-bottom: 6px; }
	.detail-dam { margin-bottom: 6px; }
	.detail-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px 8px; margin-bottom: 4px; }
	.detail-grid dd { font-size: 0.72rem; }
	.detail-spark, .detail-note { display: none; }
	.compare-tag { top: 84px; }
	.compare-tag .compare-stat .compare-keys { display: none; }
}

/* In 2D the north of the state sits top-left, so the card goes over the ocean instead. */
body[data-mode="2d"] .detail-card { top: auto; bottom: 12px; }
body:has(.detail-card:not([hidden])) .stage-hint { display: none; }

.detail-sound { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 8px; margin-top: 8px; }

.detail-sound-label { color: var(--ink-3); font-size: 0.7rem; }

.detail-meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }

.detail-meter span { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #7fb6d9, #1d5fa3); transition: width 0.4s ease; }

.detail-meter.spill span { background: linear-gradient(90deg, #7fb6d9, #1d5fa3 70%, #e8f6ff); }

.detail-sound-val { color: var(--ink); font-size: 0.72rem; white-space: nowrap; }

.detail-listen {
	padding: 3px 10px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	color: var(--ink);
	font-size: 0.72rem;
	cursor: pointer;
}

.detail-listen[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

@media (max-width: 560px) {
	.detail-sound { margin-top: 4px; }
}

/* North arrow, bottom right above Reset view; turns with the camera. */
.compass {
	position: absolute;
	right: 14px;
	bottom: 54px;
	z-index: 3;
	width: 32px;
	height: 32px;
	display: grid;
	place-items: center;
	border-radius: 50%;
	background: rgb(16 22 30 / 55%);
	pointer-events: none;
}

.compass svg { overflow: visible; }

.compass path { fill: #f4f1ea; }

.compass text { fill: #f4f1ea; font: 700 8px var(--font-body); }

/* Keyboard focus on the 3D view: an inset ring, since the stage clips anything outside it. */
.view-3d canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

/* Portrait: the split runs across the screen; the picked month is on top. */
.compare-split.stacked .compare-handle { top: var(--split); bottom: auto; left: 0; right: 0; width: auto; height: 28px; margin: -14px 0 0; cursor: ns-resize; }

.compare-split.stacked .compare-handle::before { top: 13px; bottom: auto; left: 0; right: 0; width: auto; height: 2px; }

.compare-split.stacked .compare-handle span { top: 2px; left: 50%; margin: 0 0 0 -12px; }

.compare-split.stacked .compare-tag { max-width: calc(100% - 24px); left: 10px; right: auto; align-items: flex-start; text-align: left; }

/* Top tag over Nevada (right), bottom tag over the ocean (left): neither hides the lakes. */
.compare-split.stacked .compare-left { top: 84px; left: auto; right: 10px; align-items: flex-end; text-align: right; }

.compare-split.stacked .compare-right { top: calc(var(--split) + 14px); }

/* Record-low marker: a quiet ring that settles on a lake in its lowest month, then fades. */
.record-low { position: absolute; left: 0; top: 0; pointer-events: none; opacity: 0; transition: opacity 0.9s ease; z-index: 2; }
.record-low.on { opacity: 1; transition-duration: 0.2s; }
.record-ring { position: absolute; left: -26px; top: -26px; width: 52px; height: 52px; border-radius: 50%; border: 1.5px solid var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.record-low.on .record-ring { animation: record-settle 1.4s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
@keyframes record-settle { from { transform: scale(1.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.record-text { position: absolute; left: 20px; top: 28px; white-space: nowrap; padding: 2px 7px; border-radius: 4px; background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--ink); font: 500 0.72rem/1.4 var(--font-mono); box-shadow: 0 1px 3px rgb(0 0 0 / 0.15); }
/* A lake name under the record-low label steps back while the label shows. */
.lbl-text.under-record, .lbl-text.under-path, .lbl-text.under-flare { opacity: 0.18; transition: opacity 0.3s ease; }
@media (prefers-reduced-motion: reduce) { .record-low.on .record-ring { animation: none; } .lbl-text.under-record { transition: none; } }

/* Drought flares and the dated drought path (three/droughtFx.js). */
.flares-3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; --amber: #d99a3a; --refill: #2a8f96; }
.flare { position: absolute; left: 0; top: 0; opacity: 0; }
.flare.on { opacity: 1; }
.flare-core { position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle, #fff8e6 0 30%, var(--amber) 60%, transparent 72%); }
.flare-ring { position: absolute; left: -10px; top: -10px; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--amber); opacity: 0; }
.flare-record .flare-core { background: radial-gradient(circle, #effcfc 0 30%, var(--refill) 62%, transparent 74%); }
.flare-record .flare-ring { border-color: var(--refill); }
.flare.on .flare-core { animation: flare-core 2.2s ease-out both; }
.flare.on .flare-ring { animation: flare-ring 1.6s cubic-bezier(0.2, 0.6, 0.3, 1) both; }
.flare.on .flare-ring:nth-of-type(3) { animation-delay: 0.3s; }
.flare.on .flare-ring:nth-of-type(4) { animation-delay: 0.6s; }
.flare-text { position: absolute; left: 14px; top: -22px; white-space: nowrap; font: 600 0.7rem/1.2 var(--font-body); color: #6b3f06; background: color-mix(in srgb, #fff6e3 88%, transparent); border: 1px solid color-mix(in srgb, var(--amber) 60%, transparent); border-radius: 4px; padding: 1px 5px; }
.flare-text:empty { display: none; }
.flare.on .flare-text { animation: flare-text 2.2s ease both; }
@keyframes flare-core { 0% { transform: scale(0.3); opacity: 0; } 12% { transform: scale(1.8); opacity: 1; } 60% { opacity: 0.9; } 100% { transform: scale(0.8); opacity: 0; } }
@keyframes flare-ring { 0% { transform: scale(0.4); opacity: 0.95; } 100% { transform: scale(3.6); opacity: 0; } }
@keyframes flare-text { 0%, 8% { opacity: 0; } 18%, 75% { opacity: 1; } 100% { opacity: 0; } }
.dpath-stop { position: absolute; left: 0; top: 0; opacity: 0; transition: opacity 0.4s ease; }
.dpath-stop:not(.on) { visibility: hidden; }
.path-off .dpath-stop { display: none; }
.dpath-dot { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); border: 1.5px solid #1d3a5c; }
.dpath-text { position: absolute; white-space: nowrap; font: 500 0.68rem/1.2 var(--font-mono); color: #1d3a5c; background: color-mix(in srgb, #f4f7fa 90%, transparent); border: 1px solid color-mix(in srgb, #1d3a5c 35%, transparent); border-radius: 3px; padding: 1px 4px; }
.labels-off .dpath-text { display: none; }
@media (prefers-reduced-motion: reduce) { .flare.on * { animation: none !important; } .dpath-stop { transition: none; } }
