:root {
  --bg: #0b1622;
  --bar: #13283d;
  --bar-2: #1b3550;
  --line: #2a4a6b;
  --text: #e8eef5;
  --muted: #9fb3c8;
  --accent: #3fa9f5;
  --accent-2: #8fd0ff;
  --buffer: rgba(143, 208, 255, .28);
  --warn: #f2b33d;
  --warn-text: #1f1400;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: var(--bar); border-bottom: 1px solid var(--line); z-index: 3;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; color: var(--accent-2); }
.brand svg circle { fill: #15324f; stroke: var(--accent); }
.spacer { flex: 1; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
select, input[type=datetime-local], input[type=time] {
  background: var(--bar-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 8px; max-width: 100%;
}
.layer select { min-width: 0; max-width: 46vw; }

button.icon {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  background: var(--bar-2); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
button.icon:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #04121f; border: 0; border-radius: var(--radius); padding: 8px 12px; font-weight: 600; cursor: pointer; }

#stage { position: relative; overflow: hidden; background: #000; touch-action: none; }
#viewport { position: absolute; inset: 0; overflow: hidden; cursor: grab; }
#viewport.dragging { cursor: grabbing; }
/* Sized and placed by fitView() in app.js so it always fills the stage; hidden until then. */
#frame { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; user-select: none; will-change: transform; visibility: hidden; }
#frame.fitted { visibility: visible; }
/* Visible's 0.5 km tiles, laid over a paused, zoomed-in frame (placeDetail() in app.js). */
.detail { position: absolute; left: 0; top: 0; pointer-events: none; will-change: transform; }
.detail img { position: absolute; max-width: none; user-select: none; }
/* Map lines and cities (placeOverlays() in app.js). They ignore the mouse, so dragging and
   zooming work exactly as before. Colours follow Satview: blue coastlines, dark borders. */
.lines { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: visible; pointer-events: none; will-change: transform; fill: none; stroke: none; }
.lines path { fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.lines .coast { stroke: #3b8ee0; stroke-width: 1.6px; }
.lines .country { stroke: #161616; stroke-width: 1.3px; }
.lines .state { stroke: #161616; stroke-width: 1px; }
.lines .halo { stroke: rgba(255, 255, 255, .35); stroke-width: 3px; }
.cities { position: absolute; inset: 0; pointer-events: none; }
.city {
  position: absolute; left: 0; top: 0; padding-left: 10px; white-space: nowrap;
  font-size: 11px; line-height: 14px; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000, 0 0 1px #000;
}
.city::before {
  content: ""; position: absolute; left: 0; top: 4px; width: 6px; height: 6px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .8);
}
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 0 0 8px; font-size: 18px; }
.zoom { position: absolute; right: 16px; top: 16px; display: grid; gap: 6px; }
.attribution {
  position: absolute; left: 16px; bottom: 8px; max-width: calc(100% - 32px); pointer-events: none;
  font-size: 11px; color: var(--muted); background: rgba(11, 22, 34, .75); padding: 2px 6px; border-radius: 4px;
}
.zoom button { font-size: 20px; background: rgba(19, 40, 61, .85); }
/* Colour scale along the bottom of the image, like Satview's (showLegend() in app.js). */
.legend {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; height: 20px;
  pointer-events: none; font-size: 11px; font-weight: 700; line-height: 20px;
}
.legend div { flex: 1 1 0; min-width: 0; padding-left: 3px; white-space: nowrap; }
.legend span { position: relative; z-index: 1; }  /* a long label may run over the next cell */
#stage.has-legend .attribution { bottom: 28px; }
@media (max-width: 640px) { .legend div.minor span { display: none; } }
.stale {
  position: absolute; top: 16px; left: 16px; right: 70px; max-width: 560px; margin: 0 auto; z-index: 2;
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--warn); color: var(--warn-text); box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.stale svg { flex: none; width: 20px; height: 20px; margin-top: 1px; }
.stale.info { background: var(--accent); color: #04121f; }
.stale .i-info, .stale.info .i-warn { display: none; }
.stale.info .i-info { display: block; }
.stale p { margin: 0; flex: 1; }
.stale button { flex: none; background: none; border: 0; padding: 0 2px; font-size: 20px; line-height: 1; cursor: pointer; color: inherit; }

.panel {
  position: absolute; top: 55px; right: 0; bottom: 92px; width: min(340px, 100vw);
  background: var(--bar); border-left: 1px solid var(--line); overflow-y: auto; z-index: 4;
  padding: 4px 16px 16px; box-shadow: -8px 0 24px rgba(0,0,0,.35);
}
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.panel select { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  background: var(--bar-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; cursor: pointer;
}
.chips button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.chips button:disabled { opacity: .4; cursor: not-allowed; }
.custom { display: grid; gap: 8px; margin-top: 10px; }
.custom label { display: grid; gap: 4px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row input[type=range] { flex: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.meta a { color: var(--accent-2); }
.credit { color: var(--muted); font-size: 12px; }

.timeline {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px 12px;
  background: var(--bar); border-top: 1px solid var(--line); z-index: 3;
}
.controls { display: flex; gap: 6px; }
.play .i-pause { display: none; }
.playing .play .i-play { display: none; }
.playing .play .i-pause { display: block; }
.play { background: var(--accent) !important; color: #04121f; border-color: var(--accent) !important; }
.track { flex: 1; min-width: 0; }
.labels { position: relative; height: 16px; font-size: 11px; color: var(--muted); }
.labels span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.labels span::after { content: ""; position: absolute; left: 50%; top: 15px; height: 6px; border-left: 1px solid var(--line); }
.bar { position: relative; height: 22px; display: flex; align-items: center; }
.buffer { position: absolute; left: 0; right: 0; top: 8px; height: 6px; border-radius: 3px; background: var(--bar-2); overflow: hidden; }
.buffer i { position: absolute; top: 0; bottom: 0; background: var(--buffer); }
#scrub { position: relative; width: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; height: 22px; }
#scrub::-webkit-slider-runnable-track { height: 6px; background: transparent; }
#scrub::-moz-range-track { height: 6px; background: transparent; }
#scrub::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 50%; background: var(--accent-2); border: 2px solid var(--bg); }
#scrub::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent-2); border: 2px solid var(--bg); }
.status { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
#frameTime { font-weight: 600; }
#frameCount { color: var(--muted); }

@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 8px; }
  .brand span, .clock { display: none; }
  .layer select { max-width: 60vw; }
  .timeline { flex-direction: column; align-items: stretch; gap: 6px; }
  .controls { justify-content: center; }
  .panel { bottom: 128px; }
  .labels span:nth-child(even) { display: none; }
}
