:root {
  --navy: #102A56;
  --navy-dark: #010917;
  --primary: #1265FF;
  --primary-hover: #0F55E0;
  --primary-light: #4D8BFF;
  --primary-mid: #1F5ACA;
  --primary-tint: #E0EAFA;
  --muted: #576782;
  --meta: #78849B;
  --surface: #F5FAFF;
  --border: #D1E9FF;
  --border-strong: #B7D6F5;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #F5FAFF;
  --track: #F5FAFF;
  --text: #102A56;
  --success: #0F7B4F;
  --success-tint: #E6F6EE;
  --danger: #C23B3B;
  --danger-tint: #FDECEC;
  --font: "Geist", "Geist Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sidebar-w: 240px;
  --summary-w: 300px;
  --video-h: 300px;
  --radius: 10px;
  --scroll-thumb: rgba(16, 42, 86, 0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--scroll-thumb);
  border-radius: 9999px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: rgba(16, 42, 86, 0.32);
}
*::-webkit-scrollbar-corner { background: transparent; }

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex: 0 0 auto;
  min-width: 0;
}
.brand-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 0 1 auto;
}
#task-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
  line-height: 1.2;
  min-width: 0;
}
#topbar .toggle {
  flex: 0 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
#topbar .toggle::-webkit-scrollbar { display: none; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-left: auto;
}
.topbar-actions a {
  color: var(--primary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
}
.topbar-actions a:hover { color: var(--primary-hover); }

.api-key-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.api-key-field input {
  width: 140px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 5px 8px;
  font: inherit;
  font-size: 11px;
}
.api-host {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--primary);
}

button, select {
  font: inherit;
  color: var(--navy);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
button:hover { background: var(--primary-tint); border-color: var(--border-strong); }
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:disabled { opacity: 0.5; cursor: wait; }

.toggle {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  gap: 2px;
}
.toggle button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 8px;
  color: var(--muted);
}
.toggle button:hover { background: rgba(18, 101, 255, 0.06); color: var(--primary); }
.toggle button.has-labels:not(.active) { color: var(--navy); }
.toggle button.active {
  background: var(--primary);
  color: #fff;
}

.shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--summary-w);
}

#sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head,
.steps-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 18px 18px 8px;
  flex: 0 0 auto;
}
.sidebar-head h3,
.steps-head h3,
.ob-title,
.stats-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--navy);
  font-family: var(--font);
  text-transform: none;
}
.sidebar-head .muted,
.steps-head .muted {
  font-size: 13px;
  font-family: var(--font);
}
#overall-board {
  padding: 4px 18px 14px;
  display: grid;
  gap: 8px;
}
#overall-board .ob-title {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
#overall-board .ob-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
}
#overall-board .ob-row .name { color: var(--muted); font-weight: 500; }
#overall-board .ob-row .sum {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
}
#overall-board .ob-row.best .name,
#overall-board .ob-row.best .sum { color: var(--primary); }
#overall-board .ob-row .avg {
  font-size: 12px;
  color: var(--meta);
  grid-column: 1 / -1;
  margin-top: -4px;
}
#episode-list { overflow-y: auto; padding: 4px 10px 16px; flex: 1; }
.episode-more {
  width: auto;
  margin: 4px 8px 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}
.episode-more:hover {
  background: transparent;
  border: 0;
  color: var(--primary);
}
.episode-row {
  width: 100%;
  text-align: left;
  margin-bottom: 0;
  padding: 10px 8px;
  border-radius: 0;
  border: 0;
  background: transparent;
  display: grid;
  gap: 2px;
}
.episode-row:hover { background: transparent; border: 0; color: var(--primary); }
.episode-row.active {
  border: 0;
  background: transparent;
  box-shadow: none;
}
.episode-row.active .name { color: var(--primary); }
.episode-row .name {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  word-break: break-all;
  line-height: 1.3;
  color: var(--navy);
}
.episode-row .sub {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

#workspace {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 16px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}
.stage {
  flex: 0 0 auto;
  display: grid;
  gap: 12px;
  min-width: 0;
}
.episode-header h2 {
  margin: 0;
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 500;
  word-break: break-all;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
#episode-name {
  min-width: 0;
}
.scene-tip {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--meta);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: help;
}
.scene-tip:hover,
.scene-tip:focus-visible {
  background: var(--primary-tint);
  color: var(--primary);
  border: 0;
}
a.scene-tip {
  cursor: pointer;
}
#float-tip {
  position: fixed;
  z-index: 200;
  max-width: min(320px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
  box-shadow: 0 10px 28px rgba(16, 42, 86, 0.16);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  pointer-events: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 0;
  padding: 1px 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: transparent;
}
.chip.pass { color: var(--primary-mid); background: transparent; }
.chip.fail { color: var(--success); background: transparent; }
.chip.orion, .chip.gt { color: var(--primary); background: transparent; }
#status-chip.chip {
  padding: 2px 8px;
  background: var(--primary-tint);
  color: var(--primary-mid);
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.video-cell {
  position: relative;
  background: #0B1220;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  height: min(var(--video-h), 28vh);
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-cell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #0B1220;
}
.cam-label {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--navy);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
  z-index: 1;
}

.playbar {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  position: static;
  overflow: visible;
  min-width: 0;
}
.playbar-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#seek { flex: 1; min-width: 0; accent-color: var(--primary); }
.speed { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }

.multi-timeline {
  display: block;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0 0 18px;
  position: relative;
  min-width: 0;
  overflow: visible;
}
.tl-stack {
  display: grid;
  gap: 8px;
  position: relative;
}
.tl-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 32px;
}
.tl-row.focus .tl-name { color: var(--primary); }
.tl-row.focus .tl-track {
  outline: none;
}
.tl-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
  padding-right: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-track {
  position: relative;
  height: 28px;
  background: var(--surface);
  border-radius: 6px;
  overflow: visible;
  border: 0;
}
.seg {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 4px;
  opacity: 0.92;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  overflow: hidden;
  min-width: 2px;
}
.seg-label {
  font-size: 9px;
  font-weight: 650;
  line-height: 1.1;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  pointer-events: none;
}
.seg.narrow .seg-label { display: none; }
.seg:hover, .seg.active {
  opacity: 1;
  outline: 1px solid var(--navy);
  z-index: 2;
  overflow: visible;
}
.seg:hover .seg-label,
.seg.active .seg-label {
  display: block;
  position: absolute;
  left: 50%;
  top: calc(100% + 4px);
  transform: translateX(-50%);
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 10px;
  white-space: nowrap;
  max-width: none;
  z-index: 8;
  box-shadow: 0 6px 16px rgba(16, 42, 86, 0.12);
}
.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--primary);
  transform: translateX(-1px);
  pointer-events: none;
  z-index: 3;
}

.stats-panel {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  overflow-x: hidden;
  overflow-y: auto;
}
.stats-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
  padding-bottom: 4px;
}
.stats-head .muted { font-size: 12px; }
.stats-table { display: grid; gap: 0; min-width: 0; }
.stats-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) repeat(5, minmax(0, 0.7fr)) minmax(0, 1.1fr);
  gap: 6px;
  align-items: center;
  font-size: 13px;
  padding: 8px 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.stats-row.head {
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  padding-bottom: 6px;
  font-family: var(--font);
  border-bottom: 1px solid var(--border);
}
.stats-row.focus { border-color: var(--border); background: transparent; }
.stats-row.focus span:first-child { color: var(--primary); font-weight: 600; }
.stats-row .mono { font-size: 13px; }
.stats-row .score { font-weight: 700; color: var(--primary); }
.stars {
  display: inline-flex;
  gap: 1px;
}
.stars button,
.stars span {
  border: 0;
  background: transparent;
  color: #C5D4E8;
  padding: 0 1px;
  font-size: 14px;
  line-height: 1;
}
.stars .on { color: var(--primary); }
.stars button:hover {
  background: transparent;
  border: 0;
}
.stars:hover button { color: var(--primary); }
.stars:hover button:hover ~ button { color: #C5D4E8; }

.ratings-block {
  padding: 4px 18px 12px;
  border: 0;
  display: grid;
  gap: 8px;
  flex: 0 0 auto;
}
.segment-views {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 14px 10px;
  flex: 0 0 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.segment-views::-webkit-scrollbar { display: none; }
.seg-view {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.seg-view svg { display: block; flex: 0 0 auto; }
.seg-view:hover {
  background: rgba(16, 42, 86, 0.05);
  border: 0;
  color: var(--navy);
}
.seg-view.labeled.active {
  background: rgba(16, 42, 86, 0.07);
  color: var(--navy);
  padding: 0 8px 0 6px;
}
.rating-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.rating-row .name { color: var(--muted); font-weight: 500; }
.episode-row .model-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.mini-score {
  font-family: var(--font);
  font-size: 11px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
}
.mini-score.best { color: var(--primary); background: transparent; border: 0; }
.mini-stars { color: var(--primary); letter-spacing: -1px; }

.model-group {
  margin-bottom: 16px;
  border: 0;
  border-radius: 0;
  overflow: visible;
  background: transparent;
}
.model-group.focus { border: 0; }
.model-group.focus summary { color: var(--primary); }
.model-group summary {
  cursor: pointer;
  list-style: none;
  padding: 4px 0 8px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--navy);
  background: transparent;
}
.model-group summary::-webkit-details-marker { display: none; }
.model-group[open] summary { border: 0; }
.model-group .group-meta { color: var(--muted); font-family: var(--font); font-weight: 500; }
.model-group .step { margin: 0; border-radius: 0; border: 0; }
.model-group .step:last-child { border: 0; }

#summary-panel {
  border-left: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
#steps-list {
  list-style: none;
  margin: 0;
  padding: 0 18px 18px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.step {
  display: grid;
  grid-template-columns: 8px 52px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-radius: 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  border: 0;
  margin-bottom: 0;
  background: transparent;
}
.step:hover { background: transparent; border: 0; }
.step.active {
  background: transparent;
  border: 0;
  color: var(--primary);
}
.step.active .step-body b { color: var(--primary); }
.step-dot { width: 8px; height: 8px; border-radius: 2px; margin-top: 5px; }
.step-time { font-family: var(--mono); font-size: 11px; color: var(--primary); }
.step-body { min-width: 0; }
.step-body b {
  display: block;
  color: var(--navy);
  font-weight: 600;
  margin-bottom: 2px;
  font-size: 13px;
}
.step-body span {
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  border: 1px solid var(--navy);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
  max-width: min(640px, 90vw);
}

@media (max-width: 1100px) {
  :root {
    --sidebar-w: 200px;
    --summary-w: 260px;
    --video-h: 240px;
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 120px minmax(0, 1fr) minmax(180px, 32vh);
  }
  #sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  #summary-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}
