/* ============================================================
   V-JEPA 2 PCA Explorer · stylesheet
============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:           #f7f7f5;
  --bg-tint:      #fafaf8;
  --surface:      #ffffff;
  --surface-2:    #f4f5f7;
  --border:       #e5e7eb;
  --border-soft:  #eef0f2;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;

  --primary:      #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;

  --accent:       #0ea5e9;
  --warn:         #f97316;
  --danger:       #dc2626;
  --danger-soft:  #fef2f2;
  --success:      #059669;

  --steer-linear:  #e05c5c;
  --steer-tangent: #27ae60;

  --grad-paper: radial-gradient(120% 80% at 50% -10%, #ffffff 0%, #f7f7f5 60%, #f1f1ee 100%);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 1px rgba(15,23,42,.03);
  --shadow:    0 1px 2px rgba(15,23,42,.05), 0 4px 14px rgba(15,23,42,.06);
  --shadow-lg: 0 8px 28px rgba(15,23,42,.10);

  --font:       "Inter", system-ui, -apple-system, sans-serif;
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-mono:  "JetBrains Mono", "Fira Code", monospace;

  --nav-h:       50px;
  --sidebar-w:   256px;
  --panel-h:     320px;
}

html, body { height: 100%; background: var(--grad-paper); color: var(--text); font-family: var(--font); font-size: 13px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================ TOP NAV */
#topnav {
  position: fixed; inset: 0 0 auto 0;
  height: var(--nav-h);
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 18px;
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.brand-mark { width: 13px; height: 13px; border-radius: 4px; background: conic-gradient(from 220deg, #4f46e5, #0ea5e9, #f97316, #4f46e5); box-shadow: 0 0 0 1px rgba(15,23,42,.08), 0 4px 10px rgba(79,70,229,.25); }
.brand-title { font-size: 14.5px; }
.brand-title .brand-sub { font-family: var(--font-mono); font-size: 11px; color: var(--primary); margin-left: 1px; vertical-align: 2px; }
.brand-tag { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }

.nav-tabs { display: flex; gap: 2px; margin-left: auto; background: var(--surface-2); padding: 3px; border-radius: 999px; border: 1px solid var(--border-soft); }
.nav-tab { padding: 5px 13px; border: none; background: transparent; border-radius: 999px; color: var(--text-muted); font-size: 12.5px; font-weight: 500; font-family: inherit; cursor: pointer; }
.nav-tab:hover { color: var(--text); }
.nav-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }

.nav-meta { display: flex; gap: 6px; align-items: center; }
.meta-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 11px; font-family: var(--font-mono); color: var(--text); }
.meta-pill .meta-key { color: var(--text-muted); }
.meta-pill .meta-val { font-weight: 500; }
button.meta-pill { cursor: pointer; font-family: var(--font); transition: background .12s, border-color .12s; }
button.meta-pill:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
button.meta-pill.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.explain-btn .meta-key { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-serif); font-style: italic; font-size: 9px; line-height: 1; font-weight: 700; }

/* ============================================================ PAGE */
.page { position: fixed; top: var(--nav-h); left: 0; right: 0; bottom: 0; display: flex; min-height: 0; }

/* ============================================================ SIDEBAR — must scroll */
aside.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}
aside.sidebar::-webkit-scrollbar { width: 8px; }
aside.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.card { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.picker-card { display: flex; flex-direction: column; min-height: 0; }
.card-header { display: flex; align-items: baseline; gap: 8px; padding: 9px 11px 7px; border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, rgba(248,249,251,.8), transparent); flex-shrink: 0; }
.card-eyebrow { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-faint); font-weight: 600; }
.card-title { font-size: 12px; font-weight: 600; color: var(--text); }
.card .badge { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); padding: 2px 7px; border: 1px solid var(--border); border-radius: 999px; }
.card-body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.card-body.tight { gap: 6px; }
.mute-seg { margin-top: 2px; line-height: 1.4; }

/* Form controls */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.field.tight { gap: 3px; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; flex-wrap: wrap; }
.field.inline .field-label { margin-bottom: 0; }
.field-label { font-size: 11px; font-weight: 600; color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.kbd { display: inline-block; padding: 1px 5px; font-family: var(--font-mono); font-size: 10px; border-radius: 4px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

select, input[type="number"], input[type="text"], textarea {
  width: 100%; padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  font-size: 12px; font-family: var(--font);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select { padding-right: 26px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2364748b' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 8px;
}
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.16); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); }
.toggle { position: relative; width: 32px; height: 18px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: #d1d5db; border-radius: 999px; cursor: pointer; transition: background .2s; }
.toggle-slider::before { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(14px); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--border); border-radius: 999px; outline: none; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--primary); box-shadow: var(--shadow-sm); cursor: pointer; }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--primary); cursor: pointer; }

.btn { padding: 6px 12px; border: 1px solid transparent; border-radius: var(--r-sm); font-size: 12px; font-weight: 600; font-family: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px; transition: background .15s, border-color .15s, transform .08s, box-shadow .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.25); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 6px 18px rgba(79,70,229,.35); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-icon { width: 28px; height: 28px; padding: 0; font-size: 18px; line-height: 1; }
.btn-block { width: 100%; }

.link-btn { background: none; border: none; color: var(--primary); font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.select-row { display: flex; align-items: center; gap: 6px; padding: 0 1px 4px; flex-wrap: wrap; }
.dot-sep { color: var(--text-faint); }
.ml-auto { margin-left: auto; }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-sm); padding: 3px; border: 1px solid var(--border-soft); width: 100%; }
.seg button { flex: 1; border: none; background: transparent; border-radius: calc(var(--r-sm) - 2px); padding: 5px 8px; font-size: 11.5px; font-weight: 500; font-family: inherit; color: var(--text-muted); cursor: pointer; transition: background .15s, color .15s; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }
.seg-tight { width: auto; }
.seg-tight button { padding: 4px 10px; }

/* Chips */
.chip-list { display: flex; flex-wrap: wrap; gap: 4px; min-height: 20px; }
.waypoint-chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 4px 1px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 10.5px; font-weight: 600; font-family: var(--font-mono); }
.waypoint-chip button { background: none; border: none; cursor: pointer; color: var(--primary); font-size: 13px; width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.waypoint-chip button:hover { background: rgba(79,70,229,.15); }
.chip-input { display: flex; gap: 5px; margin-top: 3px; }
.chip-input input { flex: 1; max-width: 60px; }

/* ============================================================ SCROLL LISTS (sidebar) */
.scroll-list { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-right: 2px; }
.scroll-list::-webkit-scrollbar { width: 6px; }
.scroll-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* clip grid: bounded height, scrolls inside picker-card */
.clip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;   /* rows size to card content, no collapse */
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.clip-grid.compact { max-height: 240px; }

.clip-card { position: relative; border-radius: var(--r-sm); overflow: hidden; background: #0f172a; cursor: pointer; border: 1.5px solid var(--border); aspect-ratio: 16/11; transition: border-color .15s, transform .15s, box-shadow .15s; }
.clip-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.clip-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.18); }
.clip-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.clip-card .clip-overlay { position: absolute; inset: auto 0 0 0; padding: 3px 5px; background: linear-gradient(180deg, transparent, rgba(15,23,42,.85)); display: flex; align-items: center; justify-content: space-between; font-family: var(--font-mono); font-size: 9.5px; color: rgba(255,255,255,.92); }
.clip-card .clip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); margin-right: 4px; box-shadow: 0 0 0 1px rgba(255,255,255,.7); }
.clip-card .clip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-card .clip-check { position: absolute; top: 4px; right: 4px; width: 15px; height: 15px; border-radius: 50%; background: rgba(15,23,42,.6); color: #fff; font-size: 9px; display: flex; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.45); opacity: 0; transition: opacity .15s, background .15s; }
.clip-card.selected .clip-check { opacity: 1; background: var(--primary); border-color: #fff; }

/* Layer list */
.layer-list { display: flex; flex-direction: column; gap: 3px; max-height: 340px; }
.layer-row { display: flex; align-items: center; gap: 7px; padding: 4px 6px; border-radius: var(--r-sm); border: 1px solid transparent; cursor: pointer; font-family: var(--font-mono); font-size: 11px; color: var(--text); transition: background .12s, border-color .12s; }
.layer-row:hover { background: var(--surface-2); }
.layer-row.selected { background: var(--primary-soft); border-color: rgba(79,70,229,.35); color: var(--primary-dark); }
.layer-row input { accent-color: var(--primary); cursor: pointer; }
.layer-row .layer-num { color: var(--text-faint); width: 22px; text-align: right; }

/* ============================================================ CANVAS */
main.canvas {
  flex: 1; min-width: 0; min-height: 0;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex; flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(80% 60% at 100% 0%, rgba(79,70,229,.05), transparent 60%),
    radial-gradient(60% 50% at 0% 100%, rgba(14,165,233,.04), transparent 60%);
}
main.canvas::-webkit-scrollbar { width: 8px; }
main.canvas::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.canvas-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.canvas-title-wrap { min-width: 0; }
.canvas-title { font-size: 18px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.canvas-sub { font-size: 12.5px; color: var(--text-muted); max-width: 70ch; margin-top: 2px; }
.canvas-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.variance-row { display: flex; gap: 5px; flex-wrap: wrap; }
.var-badge { padding: 2px 8px; font-family: var(--font-mono); font-size: 10.5px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.var-badge .var-pc { color: var(--primary); font-weight: 600; }

.explain-pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-family: var(--font); font-size: 12px; font-weight: 500; cursor: pointer; transition: background .12s, border-color .12s, color .12s, transform .08s; }
.explain-pill:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }
.explain-pill.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.dot.dot-grad { width: 8px; height: 8px; background: conic-gradient(from 220deg, var(--primary), var(--accent), var(--warn), var(--primary)); border-radius: 50%; }

.explain-card { position: relative; background: linear-gradient(180deg, var(--surface) 0%, var(--bg-tint) 100%); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px 20px; box-shadow: var(--shadow-sm); }
.explain-card h3 { font-family: var(--font-serif); font-weight: 600; font-size: 15px; letter-spacing: -.01em; margin-bottom: 10px; }
.explain-card .explain-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; }
.explain-card h4 { font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--primary); margin-bottom: 4px; text-transform: uppercase; }
.explain-card p { font-size: 12.5px; color: var(--text); line-height: 1.55; }
.explain-card code { font-family: var(--font-mono); font-size: 11px; padding: 1px 5px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.explain-close { position: absolute; top: 7px; right: 9px; width: 22px; height: 22px; background: none; border: none; cursor: pointer; color: var(--text-faint); font-size: 18px; line-height: 1; border-radius: 50%; }
.explain-close:hover { background: var(--surface-2); color: var(--text); }

/* ============================================================ PLOT CARD (generic) */
.plot-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.plot-card-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 11px; border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, var(--surface) 0%, var(--bg-tint) 100%); flex-shrink: 0; }
.plot-card-title { font-size: 11.5px; font-weight: 600; }
.plot-card-meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); }
.plot-frame { flex: 1; min-height: 0; min-width: 0; position: relative; }
.plot-frame > div { width: 100%; height: 100%; }

/* ============================================================ PANEL GRID */
.panel-grid {
  --cols: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 10px;
  align-content: start;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  height: var(--panel-h);
  min-width: 0;
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.panel-thumb { width: 36px; height: 22px; border-radius: var(--r-sm); object-fit: cover; background: #0f172a; flex-shrink: 0; }
.panel-meta { display: flex; flex-direction: column; gap: 0; min-width: 0; flex: 1; }
.panel-clip { font-family: var(--font-mono); font-size: 11px; color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-var { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-muted); }

.panel-steer-btn {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s, box-shadow .12s;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
  box-shadow: 0 2px 8px rgba(79,70,229,.30);
  flex-shrink: 0;
}
.panel-steer-btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); box-shadow: 0 4px 14px rgba(79,70,229,.40); }
.panel-steer-btn:active { transform: translateY(1px); }
.panel-steer-btn .arrow { font-size: 10px; opacity: .9; }

/* Body: PCA plot left, sidebar right (colorbar + thumbnail) */
.panel-body {
  flex: 1; min-height: 0;
  display: flex;
  flex-direction: row;
}
.panel-plot { flex: 1; min-height: 0; min-width: 0; position: relative; }
.panel-plot > div { width: 100%; height: 100%; }

/* Right sidebar: colorbar above thumbnail */
.panel-sidebar {
  width: 112px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-left: 1px solid var(--border-soft);
  background: var(--surface);
}

/* Colorbar area fills available space above thumbnail */
.panel-colorbar {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px 4px;
  overflow: hidden;
}
.cb-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-faint);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: .04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.cb-wrap {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 3px;
  flex: 1;
  min-height: 0;
  justify-content: center;
}
.cb-ticks {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--text-faint);
  padding: 1px 0;
}
.cb-bar {
  width: 8px;
  border-radius: 3px;
  border: 1px solid var(--border-soft);
  flex-shrink: 0;
}

/* Thumbnail / playback widget */
.panel-corner-video {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0f172a;
  border-top: 1px solid var(--border-soft);
}
.panel-corner-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}
.video-progress { height: 2px; background: rgba(255,255,255,.18); flex-shrink: 0; }
.video-progress-bar { height: 100%; width: 0%; background: var(--primary); transition: width .22s linear; }
.panel-corner-controls {
  display: flex; align-items: center; justify-content: center;
  gap: 5px; padding: 3px 5px;
  background: rgba(15,23,42,.88);
  border-top: 1px solid rgba(255,255,255,.06);
}
.video-btn {
  width: 22px; height: 20px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px;
  transition: background .12s;
}
.video-btn:hover { background: rgba(255,255,255,.20); }
.video-step {
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(255,255,255,.78);
  min-width: 26px;
  text-align: center;
}

/* Empty state */
.empty-state { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--text-muted); border: 1.5px dashed var(--border); border-radius: var(--r-lg); background: var(--bg-tint); padding: 28px; font-size: 12.5px; min-height: 200px; }
.empty-mark { width: 28px; height: 28px; border-radius: 8px; background: conic-gradient(from 90deg, var(--primary-soft), #e0f2fe, var(--primary-soft)); border: 1px solid var(--border); }

/* ============================================================ ATLAS */
.atlas-canvas { padding-bottom: 16px; }
.atlas-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 10px;
  min-height: 0;
}
.atlas-plot { min-height: 0; flex: 1; }

.inspector { display: flex; flex-direction: column; min-height: 0; }
.inspector-card { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); overflow-y: auto; min-height: 0; }
.inspector-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px 18px; text-align: center; }
.inspector-content { padding: 0 0 12px; }

.insp-thumb-wrap { position: relative; background: #0f172a; aspect-ratio: 16/9; }
.insp-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.insp-thumb-overlay { position: absolute; inset: auto 0 0 0; padding: 6px 9px; background: linear-gradient(180deg, transparent, rgba(15,23,42,.85)); color: #fff; display: flex; align-items: baseline; justify-content: space-between; }
.insp-clip-name { font-family: var(--font-mono); font-size: 11px; }
.insp-tpatch { font-family: var(--font-mono); font-size: 10px; color: rgba(255,255,255,.8); }

.insp-section { padding: 10px 12px; border-top: 1px solid var(--border-soft); }
.insp-section h4 { font-size: 10px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px; display: flex; gap: 6px; align-items: baseline; }

.insp-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-family: var(--font-mono); font-size: 10.5px; }
.insp-meta dt { color: var(--text-muted); }
.insp-meta dd { color: var(--text); text-align: right; }

.insp-neighbours { display: flex; flex-direction: column; gap: 5px; }
.neighbour { display: flex; align-items: center; gap: 7px; padding: 4px; border-radius: var(--r-sm); border: 1px solid var(--border-soft); background: var(--bg-tint); cursor: pointer; }
.neighbour:hover { border-color: var(--primary); background: var(--primary-soft); }
.neighbour img { width: 48px; height: 30px; border-radius: 4px; object-fit: cover; background: #0f172a; flex-shrink: 0; }
.neighbour-meta { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.neighbour-clip { font-family: var(--font-mono); font-size: 10px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.neighbour-sim { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-muted); }
.sim-bar { width: 30px; height: 4px; background: var(--border); border-radius: 4px; position: relative; overflow: hidden; flex-shrink: 0; }
.sim-bar::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: var(--p, 0%); background: linear-gradient(90deg, var(--accent), var(--primary)); }

/* Atlas Layers grid */
.atlas-panel-grid { min-height: 0; }

/* ============================================================ STEER MODAL */
.steer-modal {
  position: fixed; inset: 0;
  z-index: 250;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.steer-modal-shell {
  width: 100%; max-width: 1280px;
  height: 100%; max-height: calc(100vh - 32px);
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.steer-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border-soft); background: linear-gradient(180deg, var(--surface) 0%, var(--bg-tint) 100%); flex-shrink: 0; }
.modal-title { font-size: 15.5px; font-weight: 700; letter-spacing: -.01em; margin-top: 1px; word-break: break-all; }
.steer-modal-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.steer-modal-body { flex: 1; min-height: 0; padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 10px; }

.steer-controls-bar {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.steer-controls-bar .field.inline input[type="number"] { width: 52px; }
.steer-controls-bar .field.inline input[type="range"] { width: 120px; }

/* Play bar — sits after the controls row */
.steer-playbar {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
  margin-top: 2px;
}
.steer-play-btn { min-width: 60px; }
.steer-scrub {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
}
.steer-scrub-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--primary);
  border-radius: 999px;
  pointer-events: none;
  transition: width .12s linear;
}
.steer-scrub-val {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  min-width: 48px;
  text-align: right;
}

/*
   STEER GRID
   Two-column: PCA on left (spans full height), 2×2 equal subgrid on right.
*/
.steer-grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  grid-template-rows: 1fr;
  gap: 10px;
}
.sg-pca {
  grid-column: 1; grid-row: 1;
  min-height: 0;
}
/* Right subgrid: 2 columns × 2 rows.
   Rows are sized so cells match 16/9 — achieved by making each plot-card
   use aspect-ratio on its content area, and rows = auto. */
.sg-right-grid {
  grid-column: 2; grid-row: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

/* Frame and camera cards: constrain preview to 16/9 */
.frame-card { display: flex; flex-direction: column; min-height: 0; }
.frame-card .frame-preview {
  flex: 1;
  min-height: 0;
  aspect-ratio: 16 / 9;
}
.frame-preview {
  background: #0f172a;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
  width: 100%;
}
.frame-preview img { width: 100%; height: 100%; object-fit: contain; }
.frame-preview .muted { color: rgba(255,255,255,.55); }

/* Camera panel in steer modal: match 16/9 like frame panels */
.sg-right-grid .plot-card:not(.frame-card) .plot-frame {
  aspect-ratio: 16 / 9;
  flex: 1;
}

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; margin-right: 4px; }
.dot-red { background: var(--steer-linear); }
.dot-green { background: var(--steer-tangent); }

/* ============================================================ BANNER */
.banner { display: none; align-items: center; gap: 8px; padding: 7px 12px; border-radius: var(--r-sm); font-size: 12px; border: 1px solid; }
.banner.active { display: flex; }
.banner.error { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.banner.info { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary-dark); }
.banner-close { margin-left: auto; background: none; border: none; cursor: pointer; color: inherit; font-size: 16px; line-height: 1; }

/* ============================================================ SPINNER */
#spinner { display: none; position: fixed; inset: 0; background: rgba(247,247,245,.65); backdrop-filter: blur(1px); z-index: 200; align-items: center; justify-content: center; }
#spinner.active { display: flex; }
.spinner-ring { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================ TOOLTIP */
.info { display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px; border-radius: 50%; background: var(--surface-2); color: var(--text-muted); font-family: var(--font-serif); font-style: italic; font-size: 9.5px; font-weight: 600; cursor: help; border: 1px solid var(--border); }
.tooltip { position: fixed; z-index: 300; max-width: 240px; padding: 8px 10px; font-size: 11.5px; line-height: 1.45; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--shadow-lg); pointer-events: none; }

/* ============================================================ MISC */
.muted { color: var(--text-muted); }
.small { font-size: 11.5px; }

/* ============================================================ RESPONSIVE */
@media (max-width: 1280px) {
  :root { --sidebar-w: 232px; --panel-h: 300px; }
  .canvas-title { font-size: 17px; }
  main.canvas { padding: 14px 16px; }
}
@media (max-width: 1100px) {
  .atlas-grid { grid-template-columns: 1fr; }
  .inspector-card { max-height: 360px; }
  /* Modal: stack PCA on top, 2×2 subgrid below */
  .steer-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 1fr) minmax(0, 1fr);
  }
  .sg-pca         { grid-column: 1; grid-row: 1; }
  .sg-right-grid  { grid-column: 1; grid-row: 2; }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 220px; --panel-h: 280px; }
  .panel-sidebar { width: 120px; }
}
@media (max-width: 720px) {
  .steer-modal { padding: 8px; }
  .steer-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 1fr) minmax(0, 1fr);
  }
  .sg-right-grid { grid-template-columns: 1fr; grid-template-rows: repeat(4, 1fr); }
}
