:root {
  --bg: #0b1120;
  --panel: rgba(15, 23, 42, 0.86);
  --border: rgba(148, 163, 184, 0.18);
  --fg: #e5e7eb;
  --title: #f9fafb;
  --muted: #94a3b8;
  --faint: #64748b;
  --blue: #3b82f6;
  --orange: #f97316;
  --gap: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 13px/1.4 Inter, system-ui, sans-serif; overflow: hidden; }
#map { position: absolute; inset: 0; }
a { color: var(--blue); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.hidden { display: none !important; }

.panel { position: absolute; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }
.label { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  margin: 10px 0 6px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
label.check { flex-direction: row; align-items: center; gap: 6px; margin: 8px 0; color: var(--fg); }
label.check input { width: auto; margin: 0; }  /* not stretched as the number boxes are */

button, .button, select, input { font: inherit; color: var(--fg); border-radius: 8px; border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.8); padding: 6px 10px; }
button, .button { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s; }
button:hover, .button:hover { border-color: var(--muted); }
button svg, .button svg { width: 15px; height: 15px; }
button.ghost, .button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover, .button.ghost:hover { color: var(--fg); background: rgba(148, 163, 184, 0.12); }
button.outline { border-color: var(--blue); color: #93c5fd; background: transparent; }
button.outline.active { background: var(--blue); color: white; }
button.primary { background: var(--blue); border-color: var(--blue); color: white; font-weight: 600; }
button.accent { background: var(--orange); border-color: var(--orange); color: white; font-weight: 600; }
input { width: 100%; }
select { cursor: pointer; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { flex: 1; border: 0; border-radius: 0; background: transparent; color: var(--muted);
  justify-content: center; padding: 6px 4px; font-size: 12px; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--blue); color: white; }

#controls { top: var(--gap); left: var(--gap); padding: 12px 14px; max-width: 470px; }
.brand { display: flex; gap: 10px; align-items: center; }
.logo { color: var(--orange); font-size: 26px; font-weight: 700; line-height: 1; }
h1 { font-size: 16px; margin: 0; color: var(--title); font-weight: 600; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
#variable { font-weight: 500; }
#region-text { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.popover { width: 300px; padding: 12px 14px; z-index: 5; }
#region-menu { top: 150px; left: var(--gap); }
#display-menu { top: 150px; left: var(--gap); }

#legend { top: var(--gap); right: var(--gap); width: 270px; padding: 12px 14px; }
.legend-title { display: flex; justify-content: space-between; font-weight: 600; color: var(--title); }
#busy { color: var(--orange); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
#progress { margin: 6px 0 8px; font-size: 12px; color: var(--muted); }
#progress .progress-bar { height: 4px; border-radius: 2px; background: rgba(148,163,184,0.2); margin: 5px 0 3px; overflow: hidden; }
#progress .progress-bar i { display: block; height: 100%; width: 0; background: var(--orange); }
.spinner { width: 12px; height: 12px; border: 2px solid rgba(249, 115, 22, .3); border-top-color: var(--orange);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#colorbar { height: 12px; border-radius: 6px; margin: 8px 0 4px; }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.stats { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.stats b { color: var(--fg); font-weight: 600; }

#time { left: var(--gap); right: var(--gap); bottom: var(--gap); padding: 8px 14px 6px; }
.time-top { display: flex; justify-content: space-between; height: 18px; font-size: 12px; }
#readout { color: var(--muted); }
#selection { color: var(--orange); font-weight: 600; padding: 0; border: 0; background: none; cursor: default; }
#selection:hover { background: none; }
#pick { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
#time-buttons { display: none; }
#timeline { width: 100%; height: 46px; display: block; cursor: crosshair; touch-action: none; }
#time .hint { margin: 2px 0 0; font-size: 11px; }

#overview { position: absolute; left: var(--gap); bottom: 170px; width: 170px; height: 83px; cursor: pointer;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .5)); }
#coords { position: absolute; right: var(--gap); bottom: 128px; padding: 4px 8px; border-radius: 6px;
  background: var(--panel); color: var(--fg); font-size: 12px; font-variant-numeric: tabular-nums; }
#coords:empty { display: none; }
body.globe #overview { display: none; }
#projection { position: absolute; left: var(--gap); bottom: 128px; background: var(--panel); color: var(--fg);
  border: 1px solid var(--border); box-shadow: 0 4px 10px rgba(0, 0, 0, .4); }
.maplibregl-ctrl-bottom-right { bottom: 160px; }

/* the time series at a point: a card tied to the point by a line */
.pin { position: relative; width: 0; height: 0; }
.pin .dot { position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; border-radius: 50%;
  background: white; border: 3px solid var(--orange); }
.pin > svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.pin line { stroke: var(--orange); stroke-width: 1.5; }
.card { position: absolute; width: 440px; height: 250px; resize: both; overflow: hidden; min-width: 320px; min-height: 200px; padding: 10px 12px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0, 0, 0, .45); backdrop-filter: blur(8px); cursor: default; }
.card header { cursor: move; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card h3 { margin: 0; font-size: 13px; color: var(--title); }
.card .hint { margin: 1px 0 0; white-space: pre-line; }
.card header .tools { display: flex; align-items: center; gap: 4px; }
.card select { padding: 2px 6px; font-size: 12px; }
.card .chart { margin-top: 4px; }
.card .u-over { cursor: pointer; }
.card.compact { width: 300px; height: auto; min-height: 0; resize: none; }
.card.compact .chart { display: none; }
.card .expand { margin-top: 6px; padding: 3px 10px; font-size: 12px; font-weight: 500; background: transparent;
  color: var(--orange); border-color: rgba(249, 115, 22, 0.6); }
.card .expand:hover { background: rgba(249, 115, 22, 0.15); border-color: var(--orange); }
.card .expand svg { width: 13px; height: 13px; }
.card:not(.compact) .expand { display: none; }
.card .hint .spinner { display: inline-block; vertical-align: middle; }
.card .hint .key { cursor: pointer; margin-right: 12px; white-space: nowrap; }
.card .hint .key i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.card .hint .key.off { opacity: 0.4; text-decoration: line-through; }
.tip { position: absolute; pointer-events: none; white-space: nowrap; padding: 3px 7px; border-radius: 6px; z-index: 5;
  background: rgba(2, 6, 23, 0.9); border: 1px solid var(--orange); color: var(--fg); font-size: 11px; }
.card .loading { height: 180px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); }
.uplot { font-family: Inter, system-ui, sans-serif; }
.card.transect { position: fixed; right: var(--gap); bottom: 170px; width: 600px; height: 360px; z-index: 3; }
/* the line's card: the title on its own row, then its controls */
.card.transect header { flex-wrap: wrap; row-gap: 4px; }
.card.transect header > div:first-child { flex-basis: 100%; }
.card.transect header .tools { flex: 1; gap: 6px; }
.card.transect header .tools .close { margin-left: auto; }
.card .segmented.kind { margin-right: 4px; }
.card .segmented.kind button { padding: 2px 8px; font-size: 12px; flex: none; }
.tip.floating { position: fixed; z-index: 10; display: none; }
.tip table { border-collapse: collapse; margin-top: 2px; }
.tip th { color: var(--orange); font-weight: 500; text-align: right; padding: 0 0 1px 10px; }
.tip td { text-align: right; padding: 0 0 0 10px; font-variant-numeric: tabular-nums; }
.tip td:first-child, .tip th:first-child { padding: 0; }
.tip .picked tr:not(:first-child):not(.on) { opacity: 0.45; }
.tip tr.on td { color: #fff; font-weight: 600; background: rgba(255, 255, 255, 0.08); }
.tip tr.on i { height: 5px; }
.tip i { display: inline-block; width: 10px; height: 3px; margin-right: 5px; vertical-align: middle; }

dialog.panel { position: fixed; color: var(--fg); padding: 16px 20px; max-width: 720px; width: calc(100% - 40px); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog header { display: flex; justify-content: space-between; align-items: center; }
dialog h2 { margin: 0; font-size: 16px; color: var(--title); }
dialog h3 { font-size: 13px; color: var(--title); margin: 14px 0 4px; }
dialog pre[class*="language-"] { background: rgba(2, 6, 23, .7); margin: 8px 0; }
dialog pre { background: rgba(2, 6, 23, .7); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  overflow: auto; font-size: 12px; max-height: 50vh; }
dialog table { border-collapse: collapse; width: 100%; margin: 8px 0; }
dialog th, dialog td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
dialog td + td, dialog th + th { text-align: right; }

#toast { left: 50%; transform: translateX(-50%); top: var(--gap); padding: 10px 14px; border-color: var(--orange);
  z-index: 10; max-width: 480px; }

/* icon-only buttons (their text is in the tooltip) */
button.icon { padding: 6px 8px; }
button.icon svg { width: 17px; height: 17px; }
#sheet-close, #tools, #tool-about { display: none; }

/* while drawing a box or a line: what to do, and Undo / Done / Cancel (a touch screen has no double click) */
#drawing { top: var(--gap); left: 50%; transform: translateX(-50%); padding: 6px 8px 6px 14px; z-index: 6;
  display: flex; align-items: center; gap: 8px; white-space: nowrap; }
#drawing-text { color: var(--fg); font-size: 12px; }

/* the timeline's hint and the mouse position need a mouse; a phone has neither room nor hover */
@media (max-width: 640px), (max-height: 500px) {
  :root { --gap: 8px; --time-h: 98px; --legend-h: 64px; }
  #time-hint, #coords, #overview, #projection, #percentiles, .stats, #readout,
  .maplibregl-ctrl-attrib { display: none !important; }  /* the credits are in About */
  #time { padding: 6px 12px 4px; }
  #timeline { height: 52px; }
  /* the date (taps open the calendar) and buttons for a finger: move by the selection's length, a day less or more */
  .time-top { height: auto; align-items: center; }
  #selection { cursor: pointer; font-size: 14px; text-decoration: underline dotted; text-underline-offset: 3px; }
  #time-buttons { display: flex; gap: 6px; }
  #time-buttons button { width: 38px; height: 32px; padding: 0; justify-content: center; }
  #time-buttons svg { width: 18px; height: 18px; }

  /* top left: a small label with the name and About; the panel opens from it as a sheet (layers icon) */
  #controls { left: var(--gap); max-width: none; padding: 6px 6px 6px 12px; z-index: 6; }
  body.sheet #controls { right: var(--gap); padding: 8px 12px; }
  #controls .row, .brand p { display: none; }
  body.sheet #controls .row, body.sheet .brand p { display: flex; }
  body.sheet .brand p { display: block; }
  body.sheet #sheet-close { display: inline-flex; margin-left: auto; }
  .brand { gap: 8px; }
  .logo { font-size: 20px; }
  h1 { font-size: 15px; }
  #tool-about { display: inline-flex; padding: 6px; margin-left: 4px; }
  body.sheet #tool-about { display: none; }
  #draw, #line { display: none; }  /* they are icons on the map here */
  .popover { left: var(--gap) !important; right: var(--gap); width: auto; }

  /* bottom: the color bar, then the time bar */
  #legend { left: var(--gap); right: var(--gap); width: auto; top: auto; bottom: calc(var(--gap) * 2 + var(--time-h));
    padding: 6px 12px; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; }
  .legend-title { font-size: 11px; font-weight: 500; color: var(--muted); grid-column: 1 / -1; }
  #colorbar { margin: 4px 0 2px; grid-column: 1 / -1; }
  .ticks { grid-column: 1 / -1; }

  /* the options, as icons, bottom left */
  #tools { display: flex; flex-direction: column; gap: 6px; position: absolute; left: var(--gap); z-index: 4;
    bottom: calc(var(--gap) * 3 + var(--time-h) + var(--legend-h) + 12px); }
  #tools button { width: 40px; height: 40px; justify-content: center; padding: 0; border-radius: 10px;
    background: var(--panel); box-shadow: 0 4px 10px rgba(0, 0, 0, .4); }
  #tools button.active { background: var(--blue); color: white; border-color: var(--blue); }
  #tools svg { width: 19px; height: 19px; }
  .maplibregl-ctrl-bottom-right { bottom: calc(var(--gap) * 3 + var(--time-h) + var(--legend-h) + 8px); }

  /* the point's card and the line's card: sheets across the bottom, above the color bar */
  .card.sheet, .card.transect { position: fixed; left: var(--gap); right: var(--gap); width: auto !important;
    bottom: calc(var(--gap) * 3 + var(--time-h) + var(--legend-h) + 8px); top: auto; resize: none; min-width: 0; z-index: 5; }
  .card.sheet.compact { height: auto; }
  .card.sheet:not(.compact), .card.transect { height: 230px !important; padding-top: 4px; }
  .card.sheet.tall:not(.compact), .card.transect.tall { height: 70vh !important; }
  /* while a card is open it takes the color bar's place, and the icons go in a row above it */
  body.card-open #legend { display: none; }
  body.card-open .card.sheet, body.card-open .card.transect { bottom: calc(var(--gap) * 2 + var(--time-h)); }
  body.card-open #tools { flex-direction: row; bottom: calc(var(--gap) * 3 + var(--time-h) + 230px); }
  body.card-open:has(.tall) #tools, body.card-open:has(.sheet.compact) #tools { display: none; }
  .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--faint); margin: 2px auto 6px; cursor: ns-resize;
    touch-action: none; padding: 6px 0; background-clip: content-box; box-sizing: content-box; }
  .card.sheet.compact .grab { display: none; }
  .card.sheet:not(.compact) .hint, .card.transect .hint { display: none; }
  .card.sheet h3, .card.transect h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .card.sheet header > div, .card.transect header > div { min-width: 0; }

  #drawing { top: calc(var(--gap) + 52px); max-width: calc(100% - 2 * var(--gap)); }
}
@media (max-height: 500px) {  /* a phone held sideways: the icons in a row, the panels lower and thinner */
  :root { --time-h: 90px; --legend-h: 48px; }
  #tools { flex-direction: row; }
  #timeline { height: 44px; }
  .legend-title { display: none; }
  .card.sheet:not(.compact), .card.transect { height: calc(100vh - 220px) !important; }
}

.card .chart-buttons { display: inline-flex; gap: 0; }
.card .chart-buttons button { padding: 4px 6px; }
.card .chart-buttons svg { width: 16px; height: 16px; }

/* the colormap menu: a strip and a name for each */
#cmap { position: relative; }
#cmap button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 6px; font-size: 12px; text-align: left; }
#cmap button i { flex: 0 0 90px; height: 10px; border-radius: 2px; }
#cmap .cmap-list { max-height: 260px; overflow-y: auto; margin-top: 4px; border: 1px solid rgba(148,163,184,0.25); border-radius: 6px; }
#cmap .cmap-list button { background: none; border: 0; color: var(--text, #e5e7eb); cursor: pointer; }
#cmap .cmap-list button:hover, #cmap .cmap-list button.active { background: rgba(148,163,184,0.15); }
#cmap .cmap-list hr { border: 0; border-top: 1px solid rgba(148,163,184,0.25); margin: 2px 0; }
