:root {
  --bg: #f7f7f5; --fg: #1d1d1b; --muted: #6b6b66; --line: #d9d9d4; --accent: #0b5cad; --proj: #b4410c;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); }
body { display: grid; grid-template-rows: auto 1fr auto; }

header { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); }
h1 { font-size: 16px; margin: 0; line-height: 0; }
h1 img { display: block; height: 40px; width: auto; }  /* lockup is 320x64: 200x40 on screen */
fieldset { border: 0; margin: 0; padding: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
legend { float: left; color: var(--muted); margin-right: 6px; }
#search { display: flex; gap: 4px; align-items: center; }
#q { width: 260px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; }
button { padding: 5px 10px; border: 1px solid var(--line); border-radius: 4px; background: #fff; cursor: pointer; }
.badge { font-size: 11px; color: var(--muted); }

main { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
#detail { position: absolute; top: 10px; right: 10px; bottom: 10px; width: min(380px, calc(100% - 20px));
  overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; box-shadow: 0 2px 10px #0002; }
#detail-close { position: absolute; top: 6px; right: 6px; border: 0; font-size: 18px; }
#detail h2 { font-size: 15px; margin: 0 24px 6px 0; }
#detail h3 { font-size: 13px; margin: 14px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
#detail ul { list-style: none; padding: 0; margin: 0; }
#detail li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.gap { color: var(--muted); font-style: italic; }
/* same 0.75 opacity as the flood layer, so the swatch matches what's drawn */
.legend-swatch { flex: none; width: 14px; height: 10px; border-radius: 3px; opacity: 0.75; margin: 0 1px; }

/* map key (bottom left of the map) */
#key { position: absolute; left: 10px; bottom: 30px; z-index: 5; width: 220px; max-width: calc(100% - 20px);
  background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 10px #0002; font-size: 12px; }
#key summary { display: flex; align-items: center; gap: 6px; padding: 5px 10px; font-weight: 600; cursor: pointer; list-style: none; }
#key summary::-webkit-details-marker { display: none; }
#key .key-body { padding: 0 10px 8px; }
#key .key-title { margin: 8px 0 3px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
#key .key-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
#key .key-row svg { flex: none; }
/* matches the gauge colour ramp in app.js: -10, 0, +20, +50, +100 cm */
#key .key-ramp { display: block; height: 10px; border-radius: 2px;
  background: linear-gradient(to right, #2c7bb6 0%, #f7f7f7 9.1%, #fdae61 27.3%, #d7191c 54.5%, #67000d 100%); }
#key .key-scale { position: relative; height: 14px; margin: 1px 8px 0 4px; color: var(--muted); font-size: 10px; }
#key .key-scale span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.legend-swatch.now { background: #08306b; }
.legend-swatch.future { background: #2b8cbe; }
.live { color: var(--proj); font-weight: 600; }

footer { border-top: 1px solid var(--line); padding: 6px 16px; }
#timebar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
#year { flex: 1 1 100%; }  /* own row: the evidence label changes width with the year and must not move the slider */
#year-label { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; width: 3.2em; }
/* one line always, so the footer height (and the map above it) never changes as the year moves */
#mode-badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: calc(100% - 150px); }  /* 150px: year, two (i), gaps */
#mode-badge.observed { background: #e3eefa; color: var(--accent); }
#mode-badge.projection { background: #fbe9df; color: var(--proj); }
#mode-badge.exploratory, #mode-badge.extrapolated { background: #fde2e2; color: #9b1c1c; }
#mode-badge.extrapolated { outline: 1px dashed #9b1c1c; }
#attribution { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
#quote { margin: 10px 0 0; padding: 4px 10px; border-left: 3px solid #9b1c1c; font-size: 13px; }

/* privacy pop-up */
.linkish { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
#privacy { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 18px 22px; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 30px #0004; font-size: 14px; line-height: 1.5; }
#privacy::backdrop { background: #0006; }
#privacy h2 { margin: 0 28px 8px 0; font-size: 18px; }
#privacy h3 { margin: 14px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
#privacy ul { margin: 0; padding-left: 18px; }
#privacy li { margin: 4px 0; }
.privacy-summary { font-weight: 600; }
.dialog-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 22px; cursor: pointer; }

/* (i) help buttons and their popover */
.info { flex: none; width: 16px; height: 16px; padding: 0; margin-left: 2px; border: 1px solid var(--muted); border-radius: 50%;
  background: transparent; color: var(--muted); font: italic 600 11px/14px Georgia, serif; cursor: pointer; vertical-align: middle; }
.info:hover, .info:focus-visible { color: #fff; background: var(--accent); border-color: var(--accent); }
#info-pop { position: absolute; z-index: 30; max-width: min(320px, calc(100vw - 32px)); padding: 10px 12px; background: #fff;
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px #0003; font-size: 13px; }
#info-pop h4 { margin: 0 0 4px; font-size: 13px; }
#info-pop p { margin: 4px 0 0; }

/* "Who made this site?" - top right of the header */
header { position: relative; padding-right: 190px; }
#about { position: absolute; top: 8px; right: 16px; z-index: 25; font-size: 13px; }
#about summary { cursor: pointer; color: var(--accent); list-style: none; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
#about summary::-webkit-details-marker { display: none; }
#about[open] #about-body { position: absolute; right: 0; margin-top: 6px; width: min(340px, calc(100vw - 32px)); padding: 10px 14px;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px #0003; }
#about-body p { margin: 0 0 6px; }
#controls { display: contents; }  /* desktop: the fieldsets flow in the header row */
#controls-toggle { display: none; }
#quote p { margin: 0; font-style: italic; }
#quote cite { font-size: 11px; color: var(--muted); font-style: normal; }

.maplibregl-popup-content { font-size: 13px; max-width: 340px; }
.popup h4 { margin: 0 0 4px; font-size: 14px; }
.popup .cite { font-size: 11px; color: var(--muted); margin-top: 6px; }
.popup svg { display: block; margin-top: 6px; }

#key { max-height: calc(100% - 40px); overflow: hidden auto; }  /* never taller than the map it sits on */
#credits > summary { cursor: pointer; }
@supports (height: 100dvh) { html, body { height: 100dvh; } }  /* phones: exclude the browser toolbars */

/* ---- narrow screens (phones, small tablets): the map gets the space ---- */
@media (min-width: 901px) {
  #credits > summary { display: none; }
}
@media (max-width: 900px) {
  header { gap: 6px 10px; padding: 6px 10px; }
  h1 img { height: 32px; }
  #controls-toggle { display: inline-block; order: 1; margin-left: auto; }
  #about { position: static; order: 2; }
  #search { order: 3; flex: 1 1 100%; }
  #q { flex: 1; width: auto; min-width: 0; }
  /* settings open as a panel over the map, so the map never changes size */
  #controls { display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 40; flex-direction: column;
    align-items: flex-start; gap: 12px; padding: 10px 14px 14px; background: #fff; border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 16px #0003; max-height: calc(100dvh - 140px); overflow: auto; }
  body.controls-open #controls { display: flex; }
  body.controls-open #controls-toggle { background: var(--accent); border-color: var(--accent); color: #fff; }
  #controls fieldset { gap: 4px 14px; }
  #controls legend { float: none; width: 100%; margin: 0 0 2px; }
  #controls label { padding: 4px 0; }
  #key { left: 8px; bottom: 8px; width: 200px; font-size: 11px; }
  #detail { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55%; border-radius: 12px 12px 0 0; }
  footer { padding: 6px 10px; }
  #year-label { font-size: 18px; }
  .maplibregl-popup-content { max-width: min(340px, calc(100vw - 40px)); }
  #key:not([open]) { width: auto; }
}
@media (max-width: 440px) {  /* phones: logo, Map settings and Who made this site? on one row */
  h1 img { height: 26px; }
  header { gap: 6px 8px; }
  #controls-toggle, #about summary { padding: 4px 7px; font-size: 12px; }
}
#info-pop { z-index: 50; }  /* above the narrow-screen settings panel */
#detail { z-index: 20; }     /* above the map key and map controls (the phone bottom sheet covers them) */
