:root {
  --ground: #0b1220;
  --surface: #121c2e;
  --surface-raised: #1b2941;
  --line: #2a3a55;
  --ink: #e8eef7;
  --ink-dim: #a9b8cd;
  --ink-faint: #7387a3;
  --accent: #38bdf8;
  --camera: #22d3ee;
  --operator: #34d399;
  --warn: #f59e0b;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--ground);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

.app {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 244px;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
}

/* ---- panels ---- */

.panel {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}
.panel-left { grid-column: 1; grid-row: 1 / 3; border-right: 1px solid var(--line); }
.panel-right { grid-column: 3; grid-row: 1; border-left: 1px solid var(--line); }

.brand { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.brand h1 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand p {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.block { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.block.grow { flex: 1; min-height: 0; overflow-y: auto; border-bottom: 0; }

.block h2 {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
}
.block h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-dim);
  margin: 14px 0 6px;
}
.block h3:first-of-type { margin-top: 0; }

/* ---- file loading ---- */

.drop {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  text-align: center;
  padding: 16px 10px;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(56, 189, 248, 0.07); }
.drop strong { font-size: 12px; font-weight: 500; }
.drop span { font-size: 11px; color: var(--ink-faint); }

.link-button {
  margin-top: 8px;
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--sans);
  font-size: 12px;
  padding: 7px;
  border-radius: 6px;
  cursor: pointer;
}
.link-button:hover { border-color: var(--accent); color: var(--ink); }

.note { font-size: 11px; color: var(--ink-faint); margin-top: 8px; line-height: 1.45; }
.note.error { color: #fca5a5; }

/* ---- readouts ---- */

.readout > div, .identity > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(42, 58, 85, 0.5);
}
.readout dt, .identity dt { font-size: 12px; color: var(--ink-dim); }
.readout dd, .identity dd {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-align: right;
}
.identity dd { color: var(--ink-dim); font-size: 11px; }
.readout dd.wrap, .identity dd.wrap { overflow-wrap: anywhere; text-align: right; }

/* ---- viewport ---- */

.viewport { grid-column: 2; grid-row: 1; position: relative; min-height: 0; }
.viewport canvas { display: block; width: 100%; height: 100%; }

.viewport-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-size: 13px;
  pointer-events: none;
}
.viewport-empty[hidden] { display: none; }

.viewport-badge {
  position: absolute;
  left: 14px;
  bottom: 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  background: rgba(11, 18, 32, 0.75);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
}

/* ---- layers ---- */

.layers { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.layers li { display: flex; }
.layers label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-dim);
}
.layers label:hover { background: var(--surface-raised); color: var(--ink); }
.layers input { accent-color: var(--accent); }
.swatch { width: 9px; height: 9px; border-radius: 2px; margin-left: auto; }

/* ---- controller ---- */

.sticks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sticks figure { display: flex; flex-direction: column; gap: 5px; }
.stick { width: 100%; background: var(--ground); border-radius: 6px; }
.stick-box { fill: none; stroke: var(--line); stroke-width: 0.03; }
.stick-axis { stroke: var(--line); stroke-width: 0.015; }
.stick-dot { fill: var(--accent); transition: cx 0.06s linear, cy 0.06s linear; }
.sticks figcaption {
  font-size: 10px;
  color: var(--ink-dim);
  text-align: center;
  line-height: 1.3;
}
.sticks figcaption span { display: block; color: var(--ink-faint); font-size: 9px; }

/* ---- events ---- */

.events { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.events li {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 11px;
  color: var(--ink-dim);
  cursor: pointer;
  line-height: 1.35;
}
.events li:hover { background: var(--surface-raised); color: var(--ink); }
.events li.warning { color: var(--warn); }
.events time { font-family: var(--mono); color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ---- timeline ---- */

.timeline {
  grid-column: 2 / 4;
  grid-row: 2;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.transport { display: flex; align-items: center; gap: 8px; }
.transport-button {
  min-width: 34px;
  height: 28px;
  padding: 0 8px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 11px;
  cursor: pointer;
}
.transport-button:hover { border-color: var(--accent); }
.transport-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.clock {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.stamp {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  margin-left: auto;
}

.plot-row { display: flex; gap: 12px; align-items: stretch; }
.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: var(--accent);
  box-shadow: 0 0 7px rgba(56, 189, 248, 0.75);
  pointer-events: none;
  left: 0;
}

@media (prefers-reduced-motion: reduce) {
  .stick-dot { transition: none; }
}

/* ---- video overlay ---- */

.drop-sm { padding: 11px 10px; }
.drop-sm strong { font-size: 11px; }
.drop-sm span { font-size: 10px; }

.nudge { display: flex; gap: 4px; margin-top: 9px; }
.nudge .transport-button { flex: 1; min-width: 0; padding: 0 2px; font-size: 10px; height: 24px; }

.video-overlay {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: min(38%, 400px);
  background: #05090f;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
.video-overlay[hidden] { display: none; }
.video-overlay video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #05090f; }

.video-overlay figcaption {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 9px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
}
#video-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#video-clock { margin-left: auto; color: var(--camera); font-variant-numeric: tabular-nums; }

.video-hide {
  background: none;
  border: 0;
  color: var(--ink-faint);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.video-hide:hover { color: var(--ink); }

/* Shown when the playhead sits outside the clip's coverage. */
.video-gap {
  position: absolute;
  inset: 0 0 26px 0;
  display: grid;
  place-items: center;
  background: rgba(5, 9, 15, 0.9);
  color: var(--ink-faint);
  font-size: 11px;
}
.video-gap[hidden] { display: none; }

.confidence-high { color: var(--operator); }
.confidence-medium { color: var(--accent); }
.confidence-low, .confidence-none { color: var(--warn); }

/* ---- case file ---- */

.fields { display: flex; flex-direction: column; gap: 7px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field span { font-size: 10px; color: var(--ink-faint); }
.field input {
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 7px;
  width: 100%;
}
.field input:focus { outline: none; border-color: var(--accent); }

.case-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.case-actions .link-button { margin-top: 0; font-size: 11px; padding: 6px 4px; }
.as-label { text-align: center; cursor: pointer; }

.integrity {
  font-size: 11px;
  line-height: 1.45;
  margin-top: 8px;
  padding: 7px 9px;
  border-radius: 5px;
  border-left: 2px solid var(--operator);
  background: rgba(52, 211, 153, 0.09);
  color: var(--ink-dim);
}
.integrity[hidden] { display: none; }
.integrity.mismatch {
  border-left-color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
}

/* ---- annotations ---- */

.annotations { list-style: none; display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.annotations:empty { display: none; }
.annotations li {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: baseline;
  gap: 7px;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.35;
  border-left: 2px solid #c084fc;
}
.annotations li:hover { background: var(--surface-raised); color: var(--ink); }
.annotations time {
  font-family: var(--mono);
  color: #c084fc;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.annotations .text { overflow-wrap: anywhere; cursor: pointer; }
.annotations .remove {
  background: none;
  border: 0;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
.annotations .remove:hover { color: #fca5a5; }

/* ---- provenance ---- */

/* A field carrying a caveat is marked, so the tooltip is discoverable. */
.readout dt.has-note { cursor: help; border-bottom: 1px dotted var(--line); }
.readout dt.has-note:hover { color: var(--ink); border-bottom-color: var(--accent); }

.readout dd.derived { color: var(--ink-dim); }
.readout dd.derived::after {
  content: 'derived';
  font-family: var(--sans);
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 3px;
  margin-left: 6px;
  vertical-align: 1px;
}

.readout dd.flag-good { color: var(--operator); }
.readout dd.flag-warn { color: var(--warn); }

/* ---- camera anchor ---- */

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.segmented button {
  background: var(--ground);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--sans);
  font-size: 11px;
  padding: 6px 2px;
  border-radius: 5px;
  cursor: pointer;
}
.segmented button:hover { color: var(--ink); border-color: var(--accent); }
.segmented button.on {
  background: rgba(56, 189, 248, 0.14);
  border-color: var(--accent);
  color: var(--ink);
}
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* A layer with nothing behind it reads as unavailable, not merely switched off. */
.layers li.empty label { color: var(--ink-faint); cursor: not-allowed; opacity: 0.5; }
.layers li.empty label:hover { background: none; color: var(--ink-faint); }
.layers li.empty .swatch { opacity: 0.35; }

/* ---- plots ---- */

.plot-canvas {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 132px;
  cursor: pointer;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.plot-canvas canvas { display: block; width: 100%; height: 100%; }

.plot-legend {
  width: 216px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 11px;
  overflow-y: auto;
  max-height: 132px;
}
.plot-legend div {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 7px;
  align-items: baseline;
  padding: 2px 4px;
  border-radius: 4px;
}
.plot-legend .key { width: 8px; height: 8px; border-radius: 2px; align-self: center; }
.plot-legend .name { color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plot-legend .val {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* ---- field picker ---- */

.field-picker { position: relative; }
.field-picker summary {
  list-style: none;
  cursor: pointer;
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  color: var(--ink-dim);
  white-space: nowrap;
}
.field-picker summary::-webkit-details-marker { display: none; }
.field-picker summary:hover { border-color: var(--accent); color: var(--ink); }
.field-picker[open] summary { border-color: var(--accent); color: var(--ink); }

.field-list {
  position: absolute;
  bottom: 34px;
  left: 0;
  z-index: 20;
  width: 232px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
}
.field-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-dim);
}
.field-list label:hover { background: var(--surface-raised); color: var(--ink); }
.field-list label.empty { opacity: 0.4; cursor: not-allowed; }
.field-list label.empty:hover { background: none; color: var(--ink-dim); }
.field-list input { accent-color: var(--accent); }
.field-list .key { width: 9px; height: 9px; border-radius: 2px; margin-left: auto; }

/* ---- collapsible panel sections ---- */

.block > h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  margin: -2px -4px 10px;
  padding: 2px 4px;
  border-radius: 4px;
}
.block > h2:hover { color: var(--ink-dim); background: var(--surface-raised); }
.block > h2:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Chevron points down when open, right when collapsed. */
.block > h2::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.14s ease;
  flex: none;
}
.block.collapsed > h2::before { transform: rotate(-90deg); }
.block.collapsed > h2 { margin-bottom: 0; }
.block.collapsed > *:not(h2) { display: none; }

/* A collapsed section must not keep claiming the panel's spare height. */
.block.grow.collapsed { flex: 0 0 auto; overflow: visible; }

@media (prefers-reduced-motion: reduce) {
  .block > h2::before { transition: none; }
}

/* ---- timeline options ---- */

.timeline-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--ink-dim);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.timeline-toggle input { accent-color: var(--warn); }
.timeline-toggle:hover { color: var(--ink); }

/* The list sections sit at the bottom of their panels, and the plot strip took
   height from them. Guarantee enough room to read a few rows; the panel
   scrolls to reach the rest. */
.block.grow:not(.collapsed) { min-height: 190px; }


/* ---- single-timeline additions ---- */

.field-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-dim);
}
.field-option:hover { background: var(--surface-raised); color: var(--ink); }
.field-option input { accent-color: var(--warn); }
.field-option .key { width: 9px; height: 9px; border-radius: 2px; margin-left: auto; }

.field-divider { height: 1px; background: var(--line); margin: 5px 2px; }

/* ---- basemap attribution ---- */

/* Required whenever Google imagery is on screen, and it has to track what is
   actually in view rather than sit as a static credit. */
.attribution {
  position: absolute;
  left: 14px;
  bottom: 44px;
  max-width: 60%;
  font-size: 11px;
  color: #f1f5f9;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  line-height: 1.4;
}
.attribution[hidden] { display: none; }
.attribution .source { color: #cbd5e1; }

/* ---- playback speed ---- */

.segmented.speed {
  grid-template-columns: repeat(3, 1fr);
  width: 108px;
  gap: 2px;
}
.segmented.speed button {
  padding: 0;
  height: 28px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ---- controller overlay ---- */

.controller-overlay {
  position: absolute;
  left: 14px;
  top: 14px;
  padding: 8px;
  background: rgba(11, 18, 32, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(3px);
}
.controller-overlay[hidden] { display: none; }
.controller-overlay .sticks { display: flex; gap: 8px; }
.controller-overlay .stick-wrap { display: flex; flex-direction: column; gap: 3px; }
.controller-overlay .stick { width: 62px; height: 62px; }
.controller-overlay figcaption {
  font-size: 9px;
  color: var(--ink-faint);
  text-align: center;
  letter-spacing: 0.02em;
}
