:root {
  --bg: #070c16;
  --panel: rgba(10, 18, 32, 0.86);
  --line: rgba(140, 185, 225, 0.18);
  --text: #dce8f6;
  --dim: #8ba3bd;
  --accent: #ffe27a;
  --bottom-h: 168px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.dim { color: var(--dim); }
.small { font-size: 11px; }

#stage {
  position: absolute; inset: 0 0 var(--bottom-h) 0;
  display: grid;
  grid-template-columns: 1fr;
}
#stage > * { min-width: 0; min-height: 0; }

#stage[data-mode="map"]   { grid-template-columns: 1fr; }
#stage[data-mode="3d"]    { grid-template-columns: 1fr; }
#stage[data-mode="split"] { grid-template-columns: 1fr 1fr; }

#stage[data-mode="map"] #orreryPane { display: none; }
#stage[data-mode="3d"]  #mapPane    { display: none; }
#stage[data-mode="split"] #orreryPane { border-left: 1px solid var(--line); }

#mapPane, #orreryPane { position: relative; overflow: hidden; }

#map, #orrery { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active, #orrery:active { cursor: grabbing; }

#orreryHud {
  position: absolute; left: 12px; top: 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px;
  font: 11px/1.6 ui-monospace, Consolas, monospace;
  pointer-events: none; white-space: pre;
}
#orreryTip {
  position: absolute; right: 12px; bottom: 12px;
  font-size: 11px; pointer-events: none; text-align: right;
}

#loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--dim); font-size: 15px; letter-spacing: .02em;
  background: var(--bg);
}

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 28px rgba(0, 0, 0, .45);
}

#info { top: 14px; left: 14px; width: 296px; }

#info .head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
  border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
#ecDate { font-size: 17px; font-weight: 620; letter-spacing: .01em; }
#ecType { font-size: 11px; font-weight: 700; letter-spacing: .12em; }

.stats {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px;
  font-size: 12px;
}
.stats .k { color: var(--dim); }
.stats .v { text-align: right; font-family: ui-monospace, Consolas, monospace; }

#controls {
  top: 14px; right: 14px; width: 262px;
  max-height: calc(100% - 28px); overflow-y: auto;
}

#controls fieldset {
  border: 1px solid var(--line); border-radius: 8px;
  margin: 12px 0 0; padding: 8px 10px 10px;
}
#controls legend { color: var(--dim); font-size: 11px; padding: 0 4px; }

.field { display: block; margin-bottom: 8px; }
.field > span { display: block; color: var(--dim); font-size: 11px; margin-bottom: 3px; }

select, input[type="number"] {
  width: 100%; padding: 5px 7px;
  background: #0d1728; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit;
}

.checks { display: grid; gap: 3px; }
#controls label { display: flex; align-items: center; gap: 7px; font-size: 12px; cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.row { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }

.note {
  margin: 8px 0 0; font-size: 11px; line-height: 1.5;
  color: var(--dim);
}

#eventPanel {
  left: 326px; top: 14px;
  width: min(430px, calc(100% - 620px));
  max-height: calc(100% - 28px); overflow-y: auto;
  padding: 0;
}
#eventPanel[hidden] { display: none; }
#eventClose {
  position: absolute; right: 8px; top: 6px; z-index: 2;
  width: 26px; height: 26px; line-height: 1;
  background: rgba(10,20,34,.85); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 16px; cursor: pointer;
}
#eventClose:hover { background: #1a2d4d; }
#eventBody { padding: 14px 16px 16px; }
#eventBody figure { margin: 0 0 12px; }
#eventBody img {
  width: 100%; max-height: 240px; object-fit: contain; display: block;
  border-radius: 8px; border: 1px solid var(--line);
  background: #0b1524;
}
#eventBody figcaption { margin-top: 5px; font-size: 10.5px; color: var(--dim); }
#eventBody h2 { margin: 0 0 4px; font-size: 16px; line-height: 1.3; }
#eventBody .where { color: var(--dim); font-size: 12px; margin-bottom: 10px; }
#eventBody p { margin: 0 0 10px; font-size: 12.5px; line-height: 1.6; }
#eventBody .note {
  border-left: 2px solid var(--accent); padding-left: 10px;
  color: #e6d9a8; font-size: 12px;
}
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid var(--line); margin-left: 6px; vertical-align: middle;
}
.badge.disputed { color: #ffb45c; border-color: #7a5320; }
.badge.established { color: #7fd6a0; border-color: #2c5b3f; }
.seen {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 12px;
  font-size: 12px; margin: 10px 0;
  border-top: 1px solid var(--line); padding-top: 10px;
}
.seen .k { color: var(--dim); }
.seen .v { font-family: ui-monospace, Consolas, monospace; }
.spread { display: flex; align-items: center; gap: 6px; }
.spread .bar {
  position: relative; flex: 1; height: 7px; border-radius: 4px;
  background: #16253c; overflow: hidden; min-width: 90px;
}
.spread .bar i {
  position: absolute; top: 0; bottom: 0;
  background: linear-gradient(90deg, #3f6ea8, #ffe27a);
}

#hud {
  position: absolute; left: 14px; bottom: 14px; right: 292px;
  display: grid; gap: 5px;
  pointer-events: none;
}
#readout, #site {
  display: inline-block;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 11px; font-size: 12px;
  width: fit-content; max-width: 100%;
}
#readout .warn { color: var(--accent); }
#site .tot { color: #ff6b6b; }
#site .ann { color: #ffab4d; }

#cursor {
  position: absolute; right: 292px; bottom: 14px;
  font-size: 11px; color: var(--dim);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 8px;
}

#bottom {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--bottom-h);
  border-top: 1px solid var(--line);
  background: #080e1a;
  display: grid; grid-template-rows: 34px 1fr 22px;
  overflow: hidden;
}
/* A canvas has an intrinsic 300x150 size; without this the middle row
   refuses to shrink and pushes the legend off the bottom of the page. */
#bottom > * { min-height: 0; min-width: 0; }

#transport {
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
}
#transport button {
  width: 30px; height: 22px;
  background: #12203a; color: var(--text);
  border: 1px solid var(--line); border-radius: 5px;
  cursor: pointer; font-size: 12px; line-height: 1;
}
#transport button:hover { background: #1a2d4d; }
#scrub { flex: 1 1 auto; }
#speed { width: 110px; flex: none; }

#timeline { width: 100%; height: 100%; display: block; cursor: crosshair; }

#legend {
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px; font-size: 11px; color: var(--dim);
}
#legend span { display: flex; align-items: center; gap: 5px; }
#legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

@media (max-width: 900px) {
  #controls, #info { position: static; width: auto; margin: 8px; }
  #hud, #cursor { right: 14px; }
}
