/* ============================================================================
   Variables
   ========================================================================== */
:root {
  --bg: #fafaf7;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #666;
  --line: #d8d8d4;
  --accent: #1f6feb;
  --gt: #777;
  --pred: #1f6feb;
  --ok: #138a36;
  --warn: #b54708;
}

/* ============================================================================
   Reset / base
   ========================================================================== */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================================================
   Header
   ========================================================================== */
header {
  border-bottom: 1px solid var(--line);
  padding: 14px 28px;
  background: var(--panel);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
}
header .brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  font-family: "SF Mono", Menlo, monospace;
  letter-spacing: -0.5px;
}
header .brand .sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
header .center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
header .center .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: 600;
}
header .right { justify-self: end; }

/* ============================================================================
   Dataset picker (custom dropdown)
   ========================================================================== */
.dataset-picker {
  position: relative;
  display: inline-block;
  min-width: 320px;
}
.dataset-picker .trigger {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 38px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.dataset-picker .trigger:hover { border-color: #b8b8b3; }
.dataset-picker.open .trigger,
.dataset-picker .trigger:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}
.dataset-picker .chev {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 10px;
  pointer-events: none;
}
.dataset-picker .menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  z-index: 10;
  display: none;
  max-height: 320px;
  overflow-y: auto;
}
.dataset-picker.open .menu { display: block; }
.dataset-picker .menu .item {
  padding: 9px 14px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--ink);
}
.dataset-picker .menu .item:hover { background: #f5f3ee; }
.dataset-picker .menu .item.selected {
  background: #eef3fb;
  color: var(--accent);
  font-weight: 600;
}
.dataset-picker .menu .item.disabled {
  color: #aaa;
  cursor: not-allowed;
}
.dataset-picker .menu .item.disabled:hover { background: var(--panel); }
.dataset-picker .menu .item .soon {
  font-size: 11px;
  color: #aaa;
  font-style: italic;
  margin-left: 4px;
}
.dataset-picker .menu .group-label {
  padding: 6px 14px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  background: #fafaf7;
  text-align: center;
  border-top: 1px solid var(--line);
}
.dataset-picker .menu .group-label:first-child { border-top: none; }

/* ============================================================================
   Pose toggle
   ========================================================================== */
.pose-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.pose-toggle button {
  background: var(--panel);
  border: none;
  padding: 11px 22px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.2px;
}
.pose-toggle button.active { background: var(--ink); color: white; }
.pose-toggle button:hover:not(.active) { background: #f5f3ee; color: var(--ink); }

/* ============================================================================
   Main layout
   ========================================================================== */
main { padding: 24px 28px; max-width: 1400px; margin: 0 auto; }

/* ============================================================================
   Summary banner
   ========================================================================== */
.summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 18px;
  margin-bottom: 16px;
}
.summary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}
.summary-head .title-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.summary-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.summary-head .meta {
  color: var(--muted);
  font-size: 12px;
  font-family: "SF Mono", Menlo, monospace;
}
.summary-stats {
  display: flex;
  gap: 24px;
  color: var(--muted);
  font-size: 12px;
  font-family: "SF Mono", Menlo, monospace;
  margin-bottom: 14px;
}
.summary-stats .stat .l {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.summary-stats .stat .v {
  color: var(--ink);
  font-weight: 500;
  font-size: 13px;
  margin-top: 2px;
}

/* ============================================================================
   Metrics row
   ========================================================================== */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
}
.metric {
  border-left: 2px solid var(--line);
  padding-left: 12px;
}
.metric .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.metric .value {
  font-size: 22px;
  font-family: "SF Mono", Menlo, monospace;
  font-weight: 500;
  line-height: 1.1;
  margin-top: 2px;
}
.metric .unit { font-size: 12px; color: var(--muted); margin-left: 3px; }
.metric .desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}

/* ============================================================================
   CDF charts
   ========================================================================== */
.cdf-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.cdf-card .cdf-title {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 4px;
}
.cdf-card .cdf-sub { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.cdf-svg-wrap { position: relative; }
.cdf-svg {
  display: block;
  width: 100%;
  height: 110px;
  background: #f5f3ee;
  border-radius: 4px;
}
.cdf-label {
  position: absolute;
  font-size: 9px;
  color: #999;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.cdf-label.tl { top: 4px;    left: 6px;  }
.cdf-label.br { bottom: 4px; right: 8px; }
.cdf-tick {
  position: absolute;
  bottom: 4px;
  transform: translateX(-50%);
  font-size: 9px;
  color: #999;
  font-family: "SF Mono", Menlo, monospace;
  pointer-events: none;
}
.cdf-tick.first { transform: none; }
.cdf-tick.last  { transform: translateX(-100%); }
.cdf-ytick {
  position: absolute;
  left: 6px;
  font-size: 9px;
  color: #999;
  font-family: "SF Mono", Menlo, monospace;
  pointer-events: none;
  transform: translateY(50%);
}
.cdf-ytick.top { top: 4px;    bottom: auto; transform: none; }
.cdf-ytick.bot { bottom: 4px;               transform: none; }
.cdf-yaxis {
  position: absolute;
  top: 4px;
  left: 28px;
  font-size: 9px;
  color: #999;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  pointer-events: none;
}
.cdf-xaxis {
  text-align: center;
  margin-top: 18px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.cdf-legend {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}
.cdf-legend .swatch {
  display: inline-block;
  width: 14px;
  height: 2px;
  vertical-align: middle;
  margin-right: 4px;
}

/* ============================================================================
   Body-pose: combo metrics table
   ========================================================================== */
.combo-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 13px;
  table-layout: fixed;
}
/* Metric column gets a comfortable share (~28%); the N combo columns share the rest equally. */
.combo-table th:first-child,
.combo-table td:first-child { width: 28%; }
.combo-table th,
.combo-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  font-family: "SF Mono", Menlo, monospace;
}
.combo-table th {
  text-align: right;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  border-bottom: 1.5px solid var(--ink);
}
.combo-table th:first-child,
.combo-table td:first-child {
  text-align: left;
}
.combo-table .metric-name { font-weight: 600; }
.combo-table .metric-desc {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}
.combo-table .best-col { background: #eef3fb; font-weight: 600; }
.combo-table th.best-col { color: var(--accent); }

/* ============================================================================
   Body-pose: video matrix
   ========================================================================== */
.matrix-grid {
  display: grid;
  grid-template-columns: 140px repeat(4, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.matrix-col-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  text-align: center;
  padding: 6px 4px;
  font-size: 12px;
}
.matrix-col-header .seq-id {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
}
.matrix-col-header .seq-label {
  font-weight: 600;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
  color: var(--muted);
}
.matrix-row-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 13px;
  padding: 8px 8px 8px 0;
  border-right: 1px solid var(--line);
  min-width: 0;
}
.matrix-row-header .row-label {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.matrix-row-header .row-id {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.matrix-cell {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.matrix-cell .video-frame {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  overflow: hidden;
  background: #1a1a1a;
}
.matrix-cell .video-slot {
  width: 100%;
  height: 100%;
  background: #1a1a1a;
  color: #777;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-family: "SF Mono", Menlo, monospace;
  object-fit: cover;
  object-position: center;
  transform: scale(1.2);
  transform-origin: center;
}
.matrix-cell video.video-slot {
  display: block;
  opacity: 0;
  transition: opacity 0.45s ease;
}
.matrix-cell video.video-slot.loaded { opacity: 1; }

/* Custom controls — stay at native size regardless of the video's 1.2× zoom. */
.matrix-cell .video-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), rgba(0,0,0,0.0));
  font-family: "SF Mono", Menlo, monospace;
  font-size: 10px;
  color: white;
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}
.matrix-cell:hover .video-controls { opacity: 1; pointer-events: auto; }
.matrix-cell .vc-play {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  width: 14px;
  flex-shrink: 0;
}
.matrix-cell .vc-scrub {
  flex: 1;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
  margin: 0;
}
.matrix-cell .vc-scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.matrix-cell .vc-scrub::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.matrix-cell .vc-time {
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 50px;
  text-align: right;
}
.matrix-cell .video-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid #444;
  border-top-color: #aaa;
  border-radius: 50%;
  animation: cell-spin 0.7s linear infinite;
  pointer-events: none;
}
.matrix-cell.loaded .video-spinner { display: none; }
.matrix-cell .cell-metrics {
  padding: 6px 8px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px 8px;
  color: var(--muted);
}
.matrix-cell .cell-metrics b { color: var(--ink); font-weight: 500; }

@keyframes cell-spin { to { transform: rotate(360deg); } }

/* ============================================================================
   Sequence grid (head pose)
   ========================================================================== */
.grid-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 18px 4px 10px;
}
.grid-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.grid-head .hint { color: var(--muted); font-size: 12px; }

.seq-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.seq-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.seq-card .seq-name {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.seq-card .seq-name > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.seq-card .seq-name .dur {
  flex-shrink: 0;
  color: #999;
}
.seq-card .seq-name .difficulty {
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.difficulty.easy { background: #e7f5ec; color: var(--ok); }
.difficulty.med  { background: #fff4e5; color: var(--warn); }
.difficulty.hard { background: #fde8e8; color: #a61b1b; }

.seq-plot {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #f5f3ee;
  border-radius: 4px;
  box-sizing: border-box;
}
.seq-plot.body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
  color: #aaa;
  font-size: 12px;
}
.seq-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  margin-top: 10px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 11px;
}
.seq-metrics .cell { display: flex; flex-direction: column; min-width: 0; }
.seq-metrics .cell .l { color: var(--muted); font-size: 9px; }
.seq-metrics .cell .v {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================================
   Legend (shared)
   ========================================================================== */
.legend {
  display: flex;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
.legend .swatch {
  display: inline-block;
  width: 18px;
  height: 2px;
  vertical-align: middle;
  margin-right: 5px;
}
.legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 5px;
}

/* ============================================================================
   Password gate
   ========================================================================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 32px 36px;
  max-width: 360px;
  width: calc(100% - 48px);
  text-align: center;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 18px;
  letter-spacing: -0.3px;
}
.auth-card .auth-sub {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 22px;
}
.auth-card input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: "SF Mono", Menlo, monospace;
  text-align: center;
  box-sizing: border-box;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}
.auth-card button {
  margin-top: 12px;
  width: 100%;
  padding: 11px;
  border: none;
  background: var(--ink);
  color: white;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.auth-card .auth-error {
  color: #b54708;
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
}

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .seq-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .cdf-row { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .seq-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
