:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --surface-3: #e3e8ee;
  --text: #17202a;
  --muted: #607080;
  --line: #cfd8e3;
  --line-strong: #97a6b5;
  --bad: #dc2626;
  --shadow: 0 14px 34px rgba(23, 32, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.sidebar-collapsed {
  grid-template-columns: 44px minmax(0, 1fr);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.sidebar {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.sidebar-head {
  min-height: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
}

.sidebar-title {
  font-size: 19px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-toggle {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  line-height: 1;
  cursor: pointer;
}

.sidebar-toggle:hover {
  border-color: #0f766e;
  background: #d9f2ed;
}

.sidebar-rail-hint {
  display: none;
}

.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
}

.chips,
.score-chips,
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: var(--surface-2);
  cursor: pointer;
}

.chip.active,
.chip:hover {
  border-color: #0f766e;
  background: #d9f2ed;
}

.episode-list {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.app-attribution {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.app-attribution a {
  color: #0f766e;
}

body.sidebar-collapsed .sidebar {
  gap: 10px;
  align-items: center;
  padding: 8px 7px;
}

body.sidebar-collapsed .sidebar-head {
  display: flex;
  justify-content: center;
}

body.sidebar-collapsed .sidebar-title,
body.sidebar-collapsed .search,
body.sidebar-collapsed .chips,
body.sidebar-collapsed .episode-list,
body.sidebar-collapsed .app-attribution {
  display: none;
}

body.sidebar-collapsed .sidebar-rail-hint {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.episode-row {
  width: 100%;
  min-height: 55px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.episode-row.active,
.episode-row:hover {
  border-color: var(--line);
  background: var(--surface-2);
}

.episode-row strong,
.episode-row em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.episode-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.mini-bars {
  height: 34px;
  display: grid;
  grid-template-columns: repeat(5, 5px);
  gap: 3px;
  align-items: end;
}

.f1-mini {
  width: 5px;
  height: 34px;
  display: flex;
  align-items: end;
  overflow: hidden;
  border-radius: 5px;
  background: var(--line);
}

.f1-mini i {
  width: 100%;
  display: block;
}

.main {
  min-width: 0;
  padding: 14px 18px 28px;
}

.app {
  max-width: 1480px;
  margin: 0 auto;
}

.status,
.empty {
  padding: 14px;
  color: var(--muted);
}

.cockpit {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  box-shadow: var(--shadow);
}

.header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-bottom: 10px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.badge,
.hint,
.score-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 7px;
  background: var(--surface-2);
}

.hint {
  background: #fff7df;
  color: #76520a;
}

h1 {
  margin: 5px 0 0;
  max-width: 980px;
  font-size: 20px;
  line-height: 1.18;
  letter-spacing: 0;
}

.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  border-left: 5px solid var(--lane);
}

.cockpit-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.video-panel,
.timeline-panel {
  min-width: 0;
}

.video-shell {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #050608;
}

video {
  width: 100%;
  max-height: 500px;
  display: block;
  object-fit: contain;
  background: #050608;
}

.caption-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 10px;
}

.run-captions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  max-width: 94%;
}

.run-caption,
.gold-caption span {
  max-width: min(760px, 94vw);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid color-mix(in srgb, var(--lane) 80%, white);
  border-radius: 8px;
  padding: 5px 9px;
  background: rgba(5, 8, 12, 0.78);
  color: #fff;
  text-shadow: 0 1px 1px #000;
  overflow-wrap: anywhere;
}

.run-caption {
  border-left: 6px solid var(--lane);
  font-size: 12px;
}

.run-caption em {
  flex: 0 0 auto;
  font-style: normal;
  color: #f8fafc;
}

.gold-caption {
  display: flex;
  justify-content: center;
  max-width: 100%;
}

.gold-caption span {
  border-left: 6px solid var(--lane);
  font-size: 13px;
  font-weight: 700;
}

.caption-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item i,
.lane-name i {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 999px;
  background: var(--lane);
}

.timeline-panel {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.timeline-toolbar {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.threshold-control {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) 44px auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.threshold-control input {
  width: 100%;
  accent-color: #0f766e;
}

.threshold-control strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.paper-mark {
  white-space: nowrap;
}

.legend {
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-body {
  touch-action: none;
  user-select: none;
}

.timeline-grid {
  display: grid;
  grid-template-columns: 154px minmax(0, 1fr);
  gap: 8px;
}

.track-headers,
.track-area {
  position: relative;
  height: var(--timeline-h);
}

.lane-header {
  position: relative;
  width: 100%;
  margin: 0 0 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 7px;
  background: var(--surface);
  text-align: left;
  font-size: 12px;
}

.lane-header.agreement-head {
  border: 0;
  margin-bottom: 6px;
  padding: 0;
  background: transparent;
}

.lane-header.run-head {
  cursor: pointer;
}

.lane-header.focused {
  outline: 2px solid var(--lane);
  outline-offset: 2px;
}

.lane-header.is-hidden {
  opacity: 0.58;
}

.lane-name {
  min-width: 0;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.lane-score,
.eye-toggle {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.eye-toggle {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 4px;
  background: var(--surface-2);
}

.track-area {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    repeating-linear-gradient(to right, rgba(96, 112, 128, 0.11) 0 1px, transparent 1px 10%),
    var(--surface-2);
}

.band-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.match-band {
  opacity: 0.25;
  pointer-events: auto;
}

.match-band:hover {
  opacity: 0.38;
}

.timeline-lane {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
}

.timeline-lane::after {
  content: "";
  position: absolute;
  inset: 0;
  border-bottom: 1px solid rgba(96, 112, 128, 0.22);
  pointer-events: none;
}

.run-lane.focused-lane {
  box-shadow: inset 0 0 0 2px var(--lane);
}

.run-lane.is-hidden {
  background: repeating-linear-gradient(135deg, rgba(96, 112, 128, 0.12) 0 6px, rgba(96, 112, 128, 0.04) 6px 12px);
}

.hidden-lane-note {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

.agreement-strip {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  border-top: 1px solid rgba(15, 118, 110, 0.25);
  border-bottom: 1px solid rgba(15, 118, 110, 0.25);
}

.segment {
  position: absolute;
  top: 4px;
  height: 24px;
  z-index: 3;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 7px;
  padding: 0 5px;
  color: #fff;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  line-height: 22px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.65);
  cursor: pointer;
}

.segment.fp {
  border-color: var(--bad);
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.28) 0 5px, rgba(0, 0, 0, 0.12) 5px 10px) !important;
}

.segment.fn {
  border: 2px solid #8b96a3;
  background: rgba(255, 255, 255, 0.34) !important;
  color: #2b3540;
  text-shadow: none;
}

.segment.active {
  filter: brightness(1.18);
  box-shadow: 0 0 0 2px #fff, 0 0 16px rgba(255, 255, 255, 0.9);
}

.seg-index {
  position: absolute;
  right: 4px;
  top: 0;
  color: rgba(255, 255, 255, 0.82);
}

.fn .seg-index {
  color: #2b3540;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  width: 2px;
  background: #111827;
  pointer-events: none;
  will-change: transform;
}

.playhead span {
  position: absolute;
  top: -2px;
  left: 6px;
  border-radius: 7px;
  padding: 2px 5px;
  background: #111827;
  color: #fff;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.details-sections {
  margin-top: 18px;
  display: grid;
  gap: 18px;
  min-width: 0;
}

.detail-card {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(23, 32, 42, 0.08);
}

.section-head {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: #fbfcfe;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.source-chip,
.tool-pill,
.toggle-pill,
.tool-button,
.copy-button,
.run-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

.source-chip {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.section-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 16px 0;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toggle-pill input {
  margin: 0;
  accent-color: #0f766e;
}

.tool-button,
.copy-button {
  cursor: pointer;
}

.tool-button:hover,
.copy-button:hover {
  border-color: #0f766e;
  background: #d9f2ed;
  color: var(--text);
}

.prompt-panel {
  margin: 12px 16px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.prompt-panel[hidden] {
  display: none;
}

.panel-head,
.pane-head {
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  background: #fbfcfe;
}

.panel-head span {
  font-weight: 800;
}

.panel-head .copy-button,
.pane-head .copy-button {
  margin-left: auto;
}

.model-output-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 14px 16px 16px;
}

.output-pane {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.pane-head h3 {
  margin: 0;
  font-size: 14px;
}

.run-chip {
  border-left: 5px solid var(--lane);
  color: var(--text);
  font-weight: 800;
}

.gold-section .table-wrap {
  margin: 14px 16px 16px;
}

.sheet-gallery {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-behavior: smooth;
  padding: 14px 16px 8px;
}

.sheet-card {
  flex: 0 0 min(520px, 82vw);
  margin: 0;
  min-width: 0;
}

.sheet-frame {
  position: relative;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #111827;
}

.sheet-card.active .sheet-frame {
  border-color: #111827;
}

.sheet-frame img {
  width: 100%;
  height: auto;
  display: block;
  cursor: zoom-in;
}

.sheet-grid {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to right, transparent calc(20% - 1px), rgba(255, 255, 255, 0.55) calc(20% - 1px) 20%, transparent 20% calc(40% - 1px), rgba(255, 255, 255, 0.55) calc(40% - 1px) 40%, transparent 40% calc(60% - 1px), rgba(255, 255, 255, 0.55) calc(60% - 1px) 60%, transparent 60% calc(80% - 1px), rgba(255, 255, 255, 0.55) calc(80% - 1px) 80%, transparent 80%),
    linear-gradient(to bottom, transparent calc(25% - 1px), rgba(255, 255, 255, 0.55) calc(25% - 1px) 25%, transparent 25% calc(50% - 1px), rgba(255, 255, 255, 0.55) calc(50% - 1px) 50%, transparent 50% calc(75% - 1px), rgba(255, 255, 255, 0.55) calc(75% - 1px) 75%, transparent 75%);
}

.tile-marker {
  display: none;
  position: absolute;
  border: 4px solid #facc15;
  box-shadow: 0 0 0 2px #111827, 0 0 18px rgba(250, 204, 21, 0.9);
  pointer-events: none;
}

.sheet-card.active .tile-marker {
  display: block;
}

.sheet-card figcaption,
.sheet-caption {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.sheet-caption {
  padding: 0 16px 14px;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--surface-2);
}

.mono-block,
pre {
  margin: 0;
  max-height: 520px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 12px;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

.tooltip {
  position: fixed;
  z-index: 50;
  max-width: min(420px, calc(100vw - 24px));
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(17, 24, 39, 0.94);
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
  pointer-events: none;
}

.key-hints {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 60;
  width: min(320px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.key-hints h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.key-hints button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
}

.key-hints dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 12px;
  margin: 0;
}

.key-hints dt {
  font-weight: 800;
}

.key-hints dd {
  margin: 0;
  color: var(--muted);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 48px;
  background: rgba(0, 0, 0, 0.84);
}

.lightbox[hidden],
.key-hints[hidden],
.tooltip[hidden],
.caption-overlay[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.icon-button {
  position: fixed;
  right: 18px;
  top: 18px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
}

@media (max-width: 1180px) {
  body.sidebar-collapsed {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  video {
    max-height: 500px;
  }

  .model-output-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    max-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main {
    padding: 10px;
  }

  .header,
  .timeline-toolbar,
  .section-head {
    grid-template-columns: 1fr;
  }

  .source-chip {
    max-width: 100%;
  }

  .threshold-control {
    grid-template-columns: 1fr 58px;
  }

  .threshold-control label,
  .paper-mark {
    grid-column: 1 / -1;
  }

  .timeline-grid {
    grid-template-columns: 126px minmax(0, 1fr);
  }

  .lane-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    padding: 4px;
  }
}
