:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --blue: #1d4ed8;
  --green: #166534;
  --rose: #b91c1c;
  --accent: #1d4ed8;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.title-block h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: .2px;
}
.subtitle { margin: 2px 0 0; color: var(--muted); }
.rule {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--faint);
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.token-readout { text-align: right; }
.token-readout .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); display: block; }
.token-readout .v { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--ink); }

/* ---------- navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 10px 24px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}
.nav-group { display: flex; align-items: center; gap: 8px; }
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color .12s, box-shadow .12s;
}
.btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.nav-btn { min-width: 74px; }
.ghost-btn { color: var(--muted); }
.index-box { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.index-box input {
  width: 64px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
}
.filter-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 24px 40px;
  max-width: 1500px;
  margin: 0 auto;
}
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

.info-col { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
}
.hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); font-size: 12px; }

.big-text { font-size: 16px; font-weight: 600; line-height: 1.35; }

/* ---------- frames ---------- */
.frame-grid { display: grid; grid-template-columns: 44px repeat(4, 1fr); gap: 8px 10px; align-items: center; }
.corner { }
.cam-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
  align-self: center;
}
.time-tag { font-size: 12px; color: var(--ink); text-align: center; font-weight: 600; }
.frame-grid > img {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: zoom-in;
  background: #eef2f7;
  aspect-ratio: 16/9;
  object-fit: cover;
}
.frame-grid > img.loading { opacity: .35; }

/* ---------- metrics ---------- */
.metric-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.tile {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px 7px;
}
.tile .k { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); display: block; }
.tile .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .v.fail { color: var(--rose); }
.tile .v.ok { color: var(--green); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
}
.validity { margin-top: 6px; font-size: 12px; color: var(--muted); }
.validity b.icon { font-weight: 600; margin-right: 3px; }

/* ---------- trajectory ---------- */
.canvas-legend { display: flex; gap: 16px; align-items: center; margin-bottom: 6px; }
.lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink); }
.lg i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.lg.pred i { background: var(--blue); }
.lg.gt i { background: var(--green); }
#trajCanvas {
  width: 100%;
  height: auto;
  background: #fbfdff;
  border: 1px solid var(--border);
  border-radius: 8px;
}
#trajMeta { margin-left: auto; font-family: ui-monospace, Menlo, monospace; }

/* ---------- cot ---------- */
.cot {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px;
}

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .86);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 32px;
}
.lightbox[hidden] { display: none; }
.lb-inner { max-width: 92%; max-height: 92%; text-align: center; cursor: zoom-out; }
.lb-inner img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.lb-inner img[data-err="1"] { outline: 2px dashed #cbd5e1; }
.lb-caption { margin-top: 10px; color: #cbd5e1; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  z-index: 5;
  font-size: 30px;
  color: #e2e8f0;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
}

.footer {
  padding: 12px 24px;
  color: var(--faint);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  border-top: 1px solid var(--border);
}