:root {
  color-scheme: dark;
  --void: #05060a;
  --ink: #E8ECF4;
  --ink-soft: #9AA4BC;
  --ink-faint: #6B7590;
  --panel: rgba(16, 19, 30, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #6FA8FF;
  --measured: #9FD8FF;
  --model: #C79BFF;
  --label-halo: rgba(5, 6, 10, 0.85);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--void);
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

#gl {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#gl:active { cursor: grabbing; }

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.body-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  text-shadow: 0 1px 3px var(--label-halo), 0 0 8px var(--label-halo), 0 0 8px var(--label-halo);
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  padding: 3px 6px;
  letter-spacing: 0.01em;
}
.body-label::before {
  content: "";
  position: absolute;
  left: 50%; top: -1px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--dot-color, var(--measured));
  transform: translate(-50%, -50%);
  box-shadow: 0 0 5px var(--dot-color, var(--measured));
}
.body-label.model { color: var(--model); }
.body-label.model::before { background: var(--model); box-shadow: 0 0 5px var(--model); }
.body-label:hover { color: #fff; }
.body-label:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-size: 12px;
}
#hud .panel { pointer-events: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  backdrop-filter: none;
}

.top-bar {
  position: fixed;
  top: 14px; left: 14px; right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}
.wordmark {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--ink-soft);
  margin-right: 4px;
}
.chip-btn {
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.chip-btn:hover { background: rgba(255,255,255,0.12); }
.chip-btn:disabled { opacity: 0.4; cursor: default; }
.chip-btn:disabled:hover { background: rgba(255,255,255,0.06); }
.chip-btn.active { background: var(--accent); color: #06070c; border-color: var(--accent); }
#help-btn { flex: 0 0 auto; width: 30px; padding: 6px 0; text-align: center; border-radius: 50%; }

.layer-toggles { display: flex; gap: 6px; margin-left: auto; }

/* ---- zoom control: a real slider, not just scroll-to-discover ---- */
.zoom-bar {
  position: fixed;
  right: 14px; top: 64px; bottom: 90px;
  width: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px;
  gap: 8px;
}
.zoom-readout { font-size: 10px; color: var(--ink-soft); text-align: center; line-height: 1.3; }
#zoom-slider {
  flex: 1;
  writing-mode: vertical-lr;
  direction: rtl;
  width: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
.zoom-presets { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.zoom-preset-btn {
  background: rgba(255,255,255,0.06);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 2px;
  font-size: 9px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.2;
}
.zoom-preset-btn:hover { background: rgba(255,255,255,0.12); color: var(--ink); }

.time-bar {
  position: fixed;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
}
.date-readout { font-size: 12px; color: var(--ink-soft); min-width: 220px; text-align: center; }

.modal-panel {
  position: fixed;
  top: 60px; right: 14px;
  width: min(380px, calc(100vw - 28px));
  max-height: min(600px, calc(100vh - 100px));
  overflow-y: auto;
  padding: 18px 20px;
  pointer-events: auto;
}
.modal-panel h3 { margin: 0 0 10px; font-size: 14px; letter-spacing: 0.04em; }
.modal-panel p { font-size: 12.5px; line-height: 1.55; color: var(--ink-soft); margin: 0 0 10px; }
.modal-panel ul { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.9; color: var(--ink-soft); }
.layer-legend { display: flex; gap: 16px; margin: 0 0 14px; }
.layer-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.layer-swatch { width: 9px; height: 9px; border-radius: 50%; }
.layer-swatch.measured { background: var(--measured); box-shadow: 0 0 4px var(--measured); }
.layer-swatch.model { background: var(--model); box-shadow: 0 0 4px var(--model); }
.source-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; margin-bottom: 10px; }
.source-row { display: flex; flex-direction: column; gap: 2px; font-size: 11px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.source-row a { color: var(--accent); word-break: break-all; }
.source-meta { color: var(--ink-faint); }
.credit { font-size: 11px; color: var(--ink-faint); }

#info-panel {
  position: fixed;
  bottom: 70px; left: 14px;
  padding: 14px 18px;
  min-width: 200px;
  max-width: 320px;
  max-height: min(500px, calc(100vh - 170px));
  overflow-y: auto;
}
.info-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.info-layer-tag { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 8px; display: inline-block; padding: 2px 7px; border-radius: 999px; }
.info-layer-tag.measured { color: var(--measured); border: 1px solid var(--measured); }
.info-layer-tag.model { color: var(--model); border: 1px solid var(--model); }
.info-row { display: flex; justify-content: space-between; gap: 16px; font-size: 12px; color: var(--ink-soft); padding: 2px 0; }
.info-tagline { font-size: 12px; line-height: 1.5; color: var(--ink-soft); margin: 8px 0; }
.info-scale-chain { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.info-scale-caption { font-size: 11px; color: var(--ink-faint); margin: 0 0 8px; }
.info-scale-step { margin-bottom: 8px; padding-left: 10px; border-left: 2px solid var(--accent); }
.info-scale-label { font-size: 11px; color: var(--ink-soft); }
.info-scale-value { font-size: 13px; font-weight: 700; color: var(--ink); }
.info-scale-note { font-size: 10.5px; font-weight: 400; color: var(--ink-faint); }
.info-scale-source { font-size: 10px; color: var(--ink-faint); margin: 6px 0 0; }
.info-row span:last-child { color: var(--ink); font-weight: 600; text-align: right; }

@media (max-width: 640px) {
  .top-bar { flex-wrap: wrap; }
  .zoom-bar { top: auto; bottom: 90px; height: 160px; right: 10px; }
  .time-bar { flex-wrap: wrap; justify-content: center; width: min(300px, calc(100vw - 28px)); }
  .date-readout { min-width: 0; flex: 1 1 100%; order: 3; }
  #info-panel { bottom: 132px; max-width: calc(100vw - 28px); }
}
