:root {
	--bg: #ffffff;
	--panel: rgba(255, 255, 255, 0.94);
	--text: #1d2330;
	--muted: #5d6677;
	--line: rgba(29, 35, 48, 0.12);
	/* Deep navy, like the app icon: --accent fills (selected tab, toggles)
	   with white text; --accent-text is for links, icons and outlines. */
	--accent: #1b2a4a;
	--accent-soft: rgba(27, 42, 74, 0.1);
	--accent-text: #27457f;
	--shadow: 0 4px 18px rgba(20, 30, 50, 0.16), 0 1px 3px rgba(20, 30, 50, 0.12);
	--surface: #ffffff; /* solid panels (settings) */
	--surface-2: #f1f3f6; /* inset areas (segmented control) */
	--on-accent: #ffffff;
	--map-bg: #eceef1; /* the base map's land (tools/basemap/style.mjs) */
	--legend-text: #111722;
	--halo: #ffffff; /* outline around legend text */
	--edge: rgba(29, 35, 48, 0.35); /* swatch outlines */
	--bar-top: #e8ecf3; /* scrub bar gradient, a faint navy tint */
	--bar-bottom: #dde3ee;
	--pill-top: #34528e; /* hour pill: navy like the selected tab */
	--pill-bottom: #1b2a4a;
	--disabled-bg: #f3f4f6;
	--tiles-filter: none; /* raster base map; vector tiles draw in theme colors */
	--arrow: rgba(20, 26, 38, 0.8); /* wind arrows (read by app.js) */
	--radius: 3px; /* legacy corners, used everywhere */
	--gap: 12px;
	--thumb: 56px; /* width of the hour pill on the scrub bar */
	--bar-h: 24px;
	--tap: 36px;
	--topbar-h: 56px;
	--panel-w: 572px; /* desktop top panel */
	--timebar-h: 0px;
	color-scheme: light;
	font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	color: var(--text);
	-webkit-text-size-adjust: 100%;
}

/* Dark theme: data-theme is set by mode.js (setting, or the system). The
   OSM tiles are turned into a dark gray map by filters; overlays keep their
   colors. */
[data-theme="dark"] {
	--bg: #14171c;
	--panel: rgba(28, 32, 39, 0.94);
	--text: #e6e9ee;
	--muted: #9aa3b2;
	--line: rgba(230, 233, 238, 0.14);
	--accent: #34518c;
	--accent-soft: rgba(163, 189, 240, 0.16);
	--accent-text: #a3bdf0;
	--shadow: 0 4px 18px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
	--surface: #1c2027;
	--surface-2: #262b33;
	--on-accent: #ffffff;
	--map-bg: #23272e;
	--legend-text: #eef1f5;
	--halo: #111317;
	--edge: rgba(230, 233, 238, 0.35);
	--bar-top: #2a303b;
	--bar-bottom: #232935;
	--pill-top: #4a67a3;
	--pill-bottom: #34518c;
	--disabled-bg: #22262d;
	--tiles-filter: invert(1) hue-rotate(180deg) brightness(1.1) contrast(0.8);
	--arrow: rgba(236, 240, 245, 0.85);
	color-scheme: dark;
}

[data-ui="mobile"] {
	--gap: 8px;
	--tap: 44px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	background: var(--bg);
}

#map {
	position: fixed;
	inset: 0;
	background: var(--map-bg);
}

.leaflet-tile-pane { filter: var(--tiles-filter); }
[data-basemap="vector"] .leaflet-tile-pane { filter: none; }
.wx-overlay { pointer-events: none; }
.wx-vector, .wx-vector canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
.wx-vector canvas:first-child { opacity: var(--overlay-opacity, 0.5); } /* bands; arrows stay solid */

button { font: inherit; color: inherit; }
a { color: var(--accent-text); }

.icon-btn {
	display: inline-grid;
	place-items: center;
	width: var(--tap);
	height: var(--tap);
	padding: 0;
	border: 0;
	border-radius: var(--radius);
	background: transparent;
	cursor: pointer;
	flex: none;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn:focus-visible, .tab:focus-visible, input:focus-visible + *, input[type="range"]:focus-visible {
	outline: 2px solid var(--accent-text);
	outline-offset: 2px;
}
.icon-btn svg {
	width: 20px;
	height: 20px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}
.icon-btn[aria-pressed="true"] { color: var(--accent-text); background: var(--accent-soft); }

/* ---- top bar ---- */

.topbar {
	position: fixed;
	z-index: 1000;
	top: calc(var(--gap) + env(safe-area-inset-top));
	left: calc(var(--gap) + env(safe-area-inset-left));
	right: calc(var(--gap) + env(safe-area-inset-right));
	pointer-events: none;
}
.toprow {
	display: flex;
	align-items: center;
	gap: 8px;
}
.toprow > *, .timebar { pointer-events: auto; }

/* Desktop: tabs row and timeline merge into one centered panel. */
[data-ui="desktop"] .topbar {
	width: min(var(--panel-w), calc(100vw - 2 * var(--gap)));
	margin-inline: auto;
	background: var(--panel);
	box-shadow: var(--shadow);
	border-radius: var(--radius);
	pointer-events: auto;
}
[data-ui="desktop"] .toprow { padding: 4px; }
[data-ui="desktop"] .tab { padding: 0 12px; } /* all tabs fit the panel width */
[data-ui="desktop"] .tabs,
[data-ui="desktop"] .tabs-wrap,
[data-ui="desktop"] .actions { background: none; box-shadow: none; padding: 0; }


.tabs-wrap {
	position: relative;
	min-width: 0;
	background: var(--panel);
	box-shadow: var(--shadow);
	border-radius: var(--radius);
}
.tabs-wrap:has(.tabs:empty) { display: none; }
.tabs {
	display: flex;
	gap: 4px;
	padding: 4px;
	overflow-x: auto;
	scrollbar-width: none;
	overscroll-behavior-x: contain;
}
.tabs::-webkit-scrollbar { display: none; }

/* When the tabs do not fit, the side with more of them fades out behind a
   chevron (app.js bindTabsOverflow toggles more-left / more-right). */
.tabs-wrap::before,
.tabs-wrap::after {
	position: absolute;
	z-index: 2;
	top: 0;
	bottom: 0;
	width: 36px;
	display: flex;
	align-items: center;
	padding: 0 7px 3px;
	box-sizing: border-box;
	pointer-events: none;
	opacity: 0;
	color: var(--muted);
	font-size: 24px;
	font-weight: 600;
	line-height: 1;
}
.tabs-wrap::before {
	content: "‹";
	left: 0;
	justify-content: flex-start;
	border-radius: var(--radius) 0 0 var(--radius);
	background: linear-gradient(to right, var(--panel) 50%, transparent);
}
.tabs-wrap::after {
	content: "›";
	right: 0;
	justify-content: flex-end;
	border-radius: 0 var(--radius) var(--radius) 0;
	background: linear-gradient(to left, var(--panel) 50%, transparent);
}
.tabs-wrap.more-left::before,
.tabs-wrap.more-right::after { opacity: 1; }

.tab {
	border: 0;
	background: transparent;
	border-radius: var(--radius);
	padding: 0 14px;
	height: 36px;
	white-space: nowrap;
	cursor: pointer;
	color: var(--muted);
	font-weight: 500;
}
.tabs { position: relative; }
.tab { position: relative; z-index: 1; }
.tab:hover { color: var(--text); background: var(--accent-soft); }
.tab[aria-selected="true"], .tab[aria-selected="true"]:hover { background: transparent; color: var(--on-accent); }

/* The selected tab's background is one element sliding between tabs
   (app.js moveTabIndicator). */
.tab-indicator {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 0;
	border-radius: var(--radius);
	background: var(--accent);
	pointer-events: none;
}

/* Layer switch: the new drawing fades in over the old one (app.js). */
.wx-vector { opacity: 1; }
.wx-vector.wx-entering, .wx-vector.wx-leaving { opacity: 0; }

@media (prefers-reduced-motion: no-preference) {
	.tab-indicator:not(.instant) { transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.2, 1), width 0.28s cubic-bezier(0.3, 0.7, 0.2, 1), height 0.28s ease; }
	.tab { transition: color 0.2s ease, background-color 0.15s; }
	.tabs-wrap::before, .tabs-wrap::after { transition: opacity 0.2s ease; }
	.wx-vector { transition: opacity 0.25s ease; }
}

.actions {
	margin-left: auto;
	display: flex;
	gap: 4px;
	padding: 4px;
	background: var(--panel);
	box-shadow: var(--shadow);
	border-radius: var(--radius);
	flex: none;
}

/* ---- legend ---- */

.legend {
	position: fixed;
	z-index: 900;
	top: calc(var(--topbar-h) + 2 * var(--gap) + env(safe-area-inset-top));
	right: calc(var(--gap) + env(safe-area-inset-right));
	/* No panel: swatches sit on the real map, so they look like the overlay. */
	padding: 8px 10px 10px 8px;
	pointer-events: none;
	/* Right-aligned: swatches keep to the window edge and long labels
	   reach inward, not out over the map. */
	text-align: right;
	color: var(--legend-text);
	font-weight: 600;
	/* A solid 1px white outline plus a soft glow keeps text readable over
	   any map or overlay color. */
	text-shadow:
		-1px -1px 0 var(--halo), 0 -1px 0 var(--halo), 1px -1px 0 var(--halo),
		-1px 0 0 var(--halo), 1px 0 0 var(--halo),
		-1px 1px 0 var(--halo), 0 1px 0 var(--halo), 1px 1px 0 var(--halo),
		0 0 4px var(--halo), 0 0 7px var(--halo);
	max-height: calc(100dvh - var(--topbar-h) - 4 * var(--gap));
	overflow: auto;
	line-height: 1.2;
	/* Bigger when the window is tall enough: the 24-band temperature bar
	   (plus title) must still fit. */
	--cell: clamp(10px, calc((100dvh - 130px) / 27), 18px); /* one color band */
	--lg-font: clamp(11px, calc(var(--cell) * 0.72), 13px);
	--swatch-w: clamp(14px, calc(var(--cell) * 1.1), 20px);
	font-size: var(--lg-font);
}
.lg-group + .lg-group { margin-top: calc(var(--cell) * 0.9); }
.lg-group h4 { margin: 0 0 calc(var(--cell) * 0.5); font-size: var(--lg-font); font-weight: 700; white-space: nowrap; }

/* Color bar: a swatch per band, values centered on the band edges. */
.lg-bar {
	display: grid;
	grid-template-columns: auto var(--swatch-w);
	column-gap: 7px;
	margin-top: calc(var(--lg-font) * 0.5); /* room for the first value */
}
.lg-bar .lg-swatch { height: var(--cell); }
.lg-bar .lg-swatch { box-shadow: 1px 0 0 var(--edge), -1px 0 0 var(--edge); }
.lg-bar .lg-swatch:first-child { box-shadow: 1px 0 0 var(--edge), -1px 0 0 var(--edge), 0 -1px 0 var(--edge); }
.lg-bar .lg-swatch:nth-last-child(3) { /* last swatch: then the last tick and a spacer */ box-shadow: 1px 0 0 var(--edge), -1px 0 0 var(--edge), 0 1px 0 var(--edge); }
.lg-tick {
	align-self: start;
	justify-self: end;
	transform: translateY(-50%);
	line-height: 1;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

/* Swatches show the overlay color at the overlay opacity over the map. */
.lg-swatch { display: block; }
.lg-swatch i { display: block; height: 100%; opacity: var(--overlay-opacity, 0.5); }
.lg-age { margin-top: calc(var(--cell) * 0.9); font-weight: 600; line-height: 1.35; white-space: nowrap; }
.lg-age[hidden] { display: none; }
.lg-item { display: flex; flex-direction: row-reverse; align-items: center; gap: 7px; margin-top: calc(var(--cell) * 0.3); white-space: nowrap; }
.lg-item .lg-swatch { width: var(--swatch-w); height: var(--cell); flex: none; box-shadow: 0 0 0 1px var(--edge); }

/* ---- about ---- */

.about {
	position: fixed;
	z-index: 1100;
	top: calc(var(--topbar-h) + 2 * var(--gap) + env(safe-area-inset-top));
	right: calc(var(--gap) + env(safe-area-inset-right));
	width: min(380px, calc(100vw - 2 * var(--gap)));
	max-height: calc(100dvh - var(--topbar-h) - 4 * var(--gap));
	overflow: auto;
	background: var(--surface);
	box-shadow: var(--shadow);
	border-radius: var(--radius);
}
.about-inner { padding: 16px 18px 18px; position: relative; }
.about h2 { margin: 0 40px 10px 0; font-size: 17px; }
.about h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.about p { margin: 0 0 10px; }
.about .close { position: absolute; top: 8px; right: 8px; }
.muted { color: var(--muted); font-size: 13px; }

.segmented {
	display: flex;
	background: var(--surface-2);
	border-radius: var(--radius);
	padding: 3px;
	gap: 2px;
}
.segmented label {
	flex: 1;
	text-align: center;
	position: relative;
	cursor: pointer;
}
.segmented input {
	position: absolute;
	opacity: 0;
	inset: 0;
	margin: 0;
	cursor: pointer;
}
.segmented label:has(input:checked) {
	background: var(--surface);
	box-shadow: 0 1px 3px rgba(20, 30, 50, 0.18);
	font-weight: 600;
}
.segmented label { padding: 7px 4px; border-radius: var(--radius); font-size: 13px; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent-text); }

.keys {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 6px 12px;
	margin: 0;
	align-items: center;
}
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
kbd {
	font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
	border: 1px solid var(--line);
	border-bottom-width: 2px;
	border-radius: var(--radius);
	padding: 3px 5px;
	background: var(--surface-2);
}

/* ---- time bar ---- */

.timebar {
	display: grid;
	grid-template-columns: auto 1fr;
	grid-template-areas: "controls track";
	align-items: end;
	gap: 10px;
	padding: 6px 12px 6px 4px;
}
/* Desktop: second row of the top panel; the panel width (--panel-w) gives the
   track the legacy 432px. */
[data-ui="desktop"] .timebar { border-top: 1px solid var(--line); }


.controls { grid-area: controls; display: flex; gap: 2px; }
.play .i-pause { display: none; }
.play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-pause { display: block; }
.play .i-play path { fill: currentColor; }

.track { grid-area: track; position: relative; min-width: 0; padding: 2px 0 4px; touch-action: none; user-select: none; }
[data-ui="desktop"] .track { cursor: ew-resize; }

.days {
	position: relative;
	z-index: 1;
	height: 18px;
	margin: 0 calc(var(--thumb) / 2); /* align with the pill's travel, see app.js */
	font-size: 11px;
	color: var(--muted);
}
.days .day {
	position: absolute;
	top: 0;
	height: 100%;
	border-left: 1px solid var(--line);
	padding-left: 4px;
	white-space: nowrap;
	overflow: hidden;
}
.days .day:first-child { border-left-color: transparent; }
.days .day.current { color: var(--text); font-weight: 600; }

/* Legacy-style scrub bar: a thick bar with an hour "pill" that follows the
   pointer smoothly (app.js, bindScrub). The real <input type=range> lies on
   top, invisible and click-through, for keyboard and screen readers only. */
.scrub {
	position: relative;
	height: var(--bar-h);
	border-radius: var(--radius);
	background: linear-gradient(var(--bar-top), var(--bar-bottom));
	box-shadow: inset 0 1px 2px rgba(20, 30, 50, 0.12);
}
.scrub:has(input:focus-visible) { outline: 2px solid var(--accent-text); outline-offset: 2px; }

.ts {
	position: absolute;
	z-index: 2;
	top: 0;
	bottom: 0;
	left: var(--x, 0px);
	width: var(--thumb);
	display: grid;
	place-items: center;
	border-radius: var(--radius);
	background: linear-gradient(var(--pill-top), var(--pill-bottom));
	color: #fff;
	text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
	font-size: 13px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	pointer-events: none;
	box-shadow: 0 1px 3px rgba(20, 30, 50, 0.3);
}

.scrub input[type="range"] {
	-webkit-appearance: none;
	appearance: none;
	position: absolute;
	z-index: 3;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	opacity: 0;
	pointer-events: none;
}
.scrub input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: var(--thumb);
	height: var(--bar-h);
}
.scrub input[type="range"]::-moz-range-thumb {
	width: var(--thumb);
	height: var(--bar-h);
	border: 0;
}

/* ---- status ---- */

.status {
	position: fixed;
	z-index: 1200;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	max-width: calc(100vw - 32px);
	background: var(--panel);
	box-shadow: var(--shadow);
	border-radius: var(--radius);
	padding: 14px 18px;
	text-align: center;
}

/* ---- Leaflet controls clear of our bars ---- */

.leaflet-top { top: calc(var(--topbar-h) + var(--gap) + env(safe-area-inset-top)); }
[data-ui="desktop"] .legend,
[data-ui="desktop"] .about { top: calc(var(--gap) + env(safe-area-inset-top)); }
[data-ui="desktop"] .legend { max-height: calc(100dvh - 2 * var(--gap)); }
[data-ui="desktop"] .about { max-height: calc(100dvh - 2 * var(--gap)); }
.leaflet-control-attribution { border-radius: var(--radius) 0 0 0; }

/* ---- mobile layout ---- */

[data-ui="mobile"] .desktop-only { display: none; }
[data-ui="mobile"] .leaflet-control-zoom { display: none; }

[data-ui="mobile"] .tabs-wrap { flex: 1; }
[data-ui="mobile"] .tab { flex: 1 0 auto; height: 40px; padding: 0 12px; }
[data-ui="mobile"] .actions { padding: 2px; }

[data-ui="mobile"] .legend {
	--cell: clamp(8px, calc((100dvh - var(--topbar-h) - var(--timebar-h) - 90px) / 27), 14px);
	max-height: calc(100dvh - var(--topbar-h) - var(--timebar-h) - 3 * var(--gap));
}

[data-ui="mobile"] .about {
	top: auto;
	left: 0;
	right: 0;
	bottom: 0;
	width: auto;
	max-height: 85dvh;
	border-radius: var(--radius) var(--radius) 0 0;
	padding-bottom: env(safe-area-inset-bottom);
}

[data-ui="mobile"] .timebar {
	position: fixed;
	z-index: 1000;
	left: 0;
	right: 0;
	bottom: 0;
	background: var(--panel);
	box-shadow: var(--shadow);
	border-radius: var(--radius) var(--radius) 0 0;
	padding: 8px 12px calc(10px + env(safe-area-inset-bottom)) 4px;
	gap: 6px;
	--thumb: 64px;
	--bar-h: 34px;
}
[data-ui="mobile"] .days { font-size: 12px; }

[data-ui="mobile"] .leaflet-bottom { bottom: var(--timebar-h); }

@media (prefers-reduced-motion: no-preference) {
	.tab, .icon-btn { transition: background-color 0.15s, color 0.15s; }
}

/* Settings sliders reuse the scrub bar look. Click/drag is handled in
   app.js (bindSettingDrag, pointer capture: the drag follows the mouse off
   the bar); the invisible input stays for the keyboard and screen readers. */
.setting-scrub { cursor: pointer; touch-action: none; user-select: none; }
.setting-scrub .ts { left: calc(var(--p, 0) * (100% - var(--thumb))); }
[data-ui="mobile"] .setting-scrub { --bar-h: 34px; --thumb: 64px; }

/* Multi-select toggles (radar countries). */
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle {
	border: 1px solid var(--line);
	background: var(--surface);
	border-radius: var(--radius);
	padding: 6px 12px;
	cursor: pointer;
	font-size: 13px;
}
.toggle:hover:not(:disabled) { border-color: var(--accent-text); }
.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.toggle:disabled { cursor: not-allowed; color: var(--muted); background: var(--disabled-bg); }
.toggle:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.about .hint { margin: 8px 0 0; }

/* Leaflet's own controls follow the theme. */
.leaflet-container { background: var(--map-bg); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--panel); color: var(--text); border-bottom-color: var(--line); }
.leaflet-bar { border: 0; box-shadow: var(--shadow); }
.leaflet-control-attribution.leaflet-control { background: var(--panel); color: var(--muted); }
.leaflet-control-attribution a { color: var(--accent-text); }

.sources { margin: 0 0 10px; padding-left: 18px; }
.sources li { margin: 3px 0; }

/* What is under the cursor (app.js showTip). */
.map-tip {
	position: fixed;
	z-index: 1300;
	pointer-events: none;
	padding: 5px 9px;
	border-radius: var(--radius);
	background: var(--panel);
	box-shadow: var(--shadow);
	color: var(--text);
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}
.lg-swatch.hl { outline: 2px solid var(--legend-text); outline-offset: 1px; position: relative; z-index: 1; }
