:root {
  --bg: rgba(255, 255, 255, 0.72);
  --bg-solid: #ffffff;
  --fg: #1d2433;
  --muted: #5b6475;
  --accent: #1f6feb;
  --border: rgba(29, 36, 51, 0.12);
  --control: rgba(255, 255, 255, 0.6);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  --buffer: rgba(29, 36, 51, 0.32);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: rgba(22, 26, 34, 0.7);
    --bg-solid: #161a22;
    --fg: #e6e9ef;
    --muted: #9aa3b2;
    --border: rgba(255, 255, 255, 0.12);
    --control: rgba(255, 255, 255, 0.06);
    --accent: #58a6ff;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --buffer: rgba(255, 255, 255, 0.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0d1117; overflow: hidden; }
#map { position: absolute; inset: 0; }

/* ---------- shared panel look ---------- */
.panel {
  position: absolute;
  z-index: 2;
  background: var(--bg);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  backdrop-filter: blur(10px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 12px;
}
select, button {
  font: inherit; color: var(--fg); background: var(--control);
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px;
}
select option { color: #1d2433; background: #fff; }
button { cursor: pointer; line-height: 1; }
button:hover, select:hover { border-color: var(--accent); }
input[type=range] { width: 100%; margin: 0; accent-color: var(--accent); }

/* ---------- left controls (collapsible) ---------- */
#controls { top: 10px; left: 10px; width: 250px; max-width: calc(100% - 70px); overflow: hidden; }
.panel-head {
  all: unset; box-sizing: border-box; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 8px 10px; gap: 10px;
  font-weight: 600; font-size: 13px; color: var(--fg);
}
.panel-head .chev { color: var(--muted); font-size: 16px; transition: transform 0.2s; }
.panel-body { display: flex; flex-direction: column; gap: 7px; padding: 0 10px 10px; }
.panel-body label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); }
.panel-body label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--fg); }
.panel-body select { width: 100%; }
.docs { color: var(--accent); text-decoration: none; font-size: 11px; }

#controls.collapsed { width: auto; }
#controls.collapsed .panel-body { display: none; }
#controls.collapsed .chev { transform: rotate(180deg); }

/* ---------- legend (bottom-right, above the scale bar) ---------- */
#legend {left: 10px;bottom: 70px;width: 250px;padding: 6px 8px;}
#legend:empty { display: none; }
#legend .title { color: var(--muted); margin-bottom: 4px; font-size: 11px; }
#legend .bar { display: flex; height: 8px; border-radius: 3px; overflow: hidden; }
#legend .bar span { flex: 1; }
#legend .labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; margin-top: 2px; }

/* ---------- timeline: full-width bar, round play button, hour ticks, time bubble ---------- */
#timeline {
  z-index: 3;  /* the time bubble may pass over the corner controls */
  left: 10px; right: 10px; bottom: 10px; height: 54px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px 0 8px;
  border-radius: 10px;
}
.play {
  flex: none; width: 40px; height: 40px; padding: 0; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); border: none; color: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}
.play:hover { filter: brightness(1.1); }
.play svg { width: 20px; height: 20px; fill: currentColor; }
.play .i-pause, .play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }

.tl { position: relative; flex: 1; min-width: 0; height: 40px; margin: 0 18px; cursor: pointer; touch-action: none; outline: none; }
.tl-track {
  position: absolute; left: 0; right: 0; top: 10px; height: 6px;
  border-radius: 3px; background: rgba(127, 127, 127, 0.28); overflow: hidden;
}
.tl-fill { height: 100%; width: 0; background: var(--accent); }
.tl-ticks { position: absolute; inset: 0; pointer-events: none; }
.tl-tick {
  position: absolute; top: 18px; transform: translateX(-50%);
  font-size: 10px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tl-tick::before {
  content: ""; position: absolute; left: 50%; top: -8px; width: 1px; height: 6px; background: var(--muted); opacity: 0.6;
}
.tl-tick.day { color: var(--fg); font-weight: 600; }
.tl-tick.minor { font-size: 0; }
.tl-tick.minor::before { top: -8px; height: 4px; opacity: 0.4; }

.tl-handle {
  position: absolute; top: 13px; left: 0; width: 0; height: 0; pointer-events: none;
}
.tl-handle::after {
  content: ""; position: absolute; left: -8px; top: -8px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-sizing: border-box;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.tl-bubble {
  position: absolute; bottom: 16px; left: 0; transform: translateX(var(--shift, -50%));
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 9px; border-radius: 6px; white-space: nowrap;
  background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.tl-bubble::after {
  content: ""; position: absolute; left: var(--arrow, 50%); bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-bottom: 0; border-top-color: var(--accent);
}
.tl-bubble strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.tl-bubble span { font-size: 10px; opacity: 0.9; }
.tl-hover {
  position: absolute; bottom: 30px; display: none; transform: translateX(-50%);
  padding: 2px 6px; border-radius: 4px; font-size: 11px; white-space: nowrap; pointer-events: none;
  background: var(--bg-solid); color: var(--fg); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.tl:hover .tl-hover.on { display: block; }

.tl-side { flex: none; position: relative; display: flex; align-items: center; }
.tl-side #speed { padding: 3px 4px; }
/* Out of the flow: the text appearing/disappearing must not resize the timeline. */
#status {
  position: absolute; top: 100%; right: 0; margin-top: 2px;
  font-size: 10px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
  pointer-events: none;
}
#status.warn { color: #d97706; }

/* ---------- MapLibre controls ---------- */
.maplibregl-ctrl-group, .maplibregl-ctrl-scale, .maplibregl-ctrl-attrib {
  background: var(--bg) !important;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.maplibregl-ctrl-bottom-right { bottom: 60px; }  /* + 10px control margin = 6px above the timeline, like the legend */

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  #timeline { left: 6px; right: 6px; bottom: 6px; gap: 10px; padding-right: 10px; }
  .tl-tick { font-size: 9px; }
  .maplibregl-ctrl-scale { display: none; }
  .maplibregl-ctrl-bottom-right { bottom: 56px; }
  #legend { left: 6px; right: auto; bottom: 66px; width: 150px; }
}
