:root {
  --bg: #111317;
  --panel: #1a1d23;
  --panel2: #22262e;
  --border: #2e333d;
  --text: #e6e8eb;
  --muted: #8b929e;
  --accent: #4c9aff;
  --danger: #e5534b;
  --warn: #d29922;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; overflow: hidden; }

header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-size: 14px; margin-right: 6px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

button, select, input {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--border); border-radius: 5px; padding: 4px 8px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger:hover:not(:disabled) { border-color: var(--danger); color: #ff8a84; }
button.active { border-color: var(--accent); outline: 1px solid var(--accent); }
#propStatus { margin-top: 4px; display: flex; align-items: center; gap: 6px; color: var(--accent); }
#propStatus[hidden], #propBusy[hidden], #kpPropStatus[hidden] { display: none; }
#kpPropStatus { margin-top: 4px; display: flex; align-items: center; gap: 6px; color: var(--accent); }
/* propagation-in-progress badge over the video (stage is position: relative) */
#propBusy {
  position: absolute; top: 10px; right: 10px; z-index: 5; pointer-events: none;
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: rgba(17, 19, 23, .85); border: 1px solid var(--accent); border-radius: 6px;
  color: #fff; font-size: 12px; font-weight: 600;
}
.spinner {
  width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 2px solid rgba(76, 154, 255, .3); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.actions button.busy, .actions button.busy:disabled { justify-content: flex-start; gap: 6px; opacity: 1; color: var(--accent); }
input[type=number] { width: 70px; }
label.chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
kbd {
  font: 11px ui-monospace, monospace; padding: 0 4px; border-radius: 3px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted); margin-left: 4px;
}

main { flex: 1; display: flex; min-height: 0; }
#left { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 8px; gap: 8px; }
#right {
  width: 360px; flex-shrink: 0; overflow-y: auto; padding: 8px 8px 8px 0;
  display: flex; flex-direction: column; gap: 8px;
}

#stage {
  position: relative; flex: 1 1 auto; min-height: 200px; background: #000;
  border-radius: 6px; overflow: hidden;
}
#stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
#emptyMsg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; pointer-events: none;
}
#emptyMsg[hidden] { display: none; }
#endInfo { display: inline-flex; align-items: center; gap: 4px; color: var(--danger); }
#endInfo[hidden] { display: none; }
#endInfo a { color: var(--danger); }
#endInfo button { min-width: 0; padding: 0 6px; }
.list li.after-end { opacity: .45; text-decoration: line-through; }
#trackStatus {
  color: var(--warn); max-width: 520px; overflow: hidden; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
#trackStatus button { flex: none; }
#trackStatus[hidden] { display: none; }
#trackStatus.err { color: var(--danger); }
#clipInfo { min-width: 0; flex: 1 1 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#transport {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
#transport button { min-width: 38px; }
#playBtn { min-width: 48px; }
.zoomctl { display: inline-flex; gap: 2px; }
#transport .zoomctl button { min-width: 28px; }
#transport #zoomResetBtn { min-width: 52px; font-variant-numeric: tabular-nums; }
#stage video { transform-origin: 50% 50%; }

#timelineWrap {
  flex: 0 0 auto; max-height: 34vh; min-height: 90px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
}
#timeline { display: block; width: 100%; cursor: pointer; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
}
.panel.grow { flex: 1 0 180px; display: flex; flex-direction: column; min-height: 180px; }
.panel.grow .list { flex: 1; max-height: none; }
.panel h3 {
  margin: 0 0 6px; font-size: 13px; display: flex; align-items: center; gap: 6px;
}
.panel h3 select { margin-left: auto; padding: 1px 4px; }
.badge {
  font-size: 11px; font-weight: normal; padding: 0 6px; border-radius: 9px;
  background: var(--panel2); color: var(--muted);
}
.badge.warn { background: var(--warn); color: #000; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 8px 0 6px; }
.actions button { text-align: left; font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.opts { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; color: var(--muted); }
.opts input { padding: 1px 4px; }
.opts.kpgroup { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 6px; }
#selInfo .sel { display: flex; align-items: center; gap: 6px; }
#rangeInfo { margin-top: 4px; color: var(--warn); }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 220px; }
ol.list { list-style: decimal inside; }
.list li {
  padding: 3px 6px; border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
ol.list li { display: list-item; cursor: default; }
ol.list li.redo { color: var(--muted); text-decoration: line-through; }
.list li:hover { background: var(--panel2); }
.list li.selected { background: #263449; }
.list li.primary { outline: 1px solid var(--accent); }
.list li .grow { flex: 1; }
.list li button { padding: 0 6px; font-size: 11px; }
.list li.hidden-track { opacity: .45; }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.tid { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 34px; }
.warnmark { color: var(--warn); }

table.keys { border-collapse: collapse; margin-top: 6px; width: 100%; }
table.keys td { padding: 2px 4px; border-top: 1px solid var(--border); }
table.keys td:first-child { white-space: nowrap; color: var(--muted); font-family: ui-monospace, monospace; }
summary { cursor: pointer; font-weight: 600; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #2b3340; border: 1px solid var(--border); padding: 8px 14px; border-radius: 6px;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 70vw;
}
#toast.show { opacity: 1; }
#toast.err { border-color: var(--danger); }

/* field keypoints panel */
#kpMissing { margin-bottom: 4px; }
#kpDetect { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
#kpDetect select { padding: 1px 4px; }
#kpMissing[hidden], #kpEditor[hidden], #kpDetect[hidden], #fieldStatus:empty { display: none; }
#fieldStatus { color: var(--warn); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fieldStatus.err { color: var(--danger); }
#kpGrid { display: grid; grid-template-columns: repeat(23, 1fr); gap: 2px; margin: 4px 0; }
#kpGrid .kc {
  aspect-ratio: 1; border-radius: 3px; border: 1px solid var(--border); background: var(--bg);
  cursor: pointer; position: relative;
}
#kpGrid .kc.empty { visibility: hidden; }
#kpGrid .kc.vis { background: var(--c); border-color: transparent; }
#kpGrid .kc.hid { background: var(--bg); border-color: var(--c); opacity: .55; }
#kpGrid .kc.edited::after {
  content: ''; position: absolute; inset: 25%; border-radius: 50%; background: #fff;
}
#kpGrid .kc.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
#kpGrid .kc.arm { outline: 2px dashed var(--warn); outline-offset: 1px; opacity: 1; }
#kpGrid .kc:hover { border-color: var(--accent); }
#kpInfo { min-height: 18px; }
#kpGrid .kc.prop::after {
  content: ''; position: absolute; inset: 25%; border-radius: 50%; background: #3fd0e0;
}
.proprange { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.proprange input.frameto { width: 62px; padding: 1px 4px; font-variant-numeric: tabular-nums; }
.proprange input.frameto::placeholder { color: var(--muted); opacity: .8; }
button.mini { padding: 0 5px; font-size: 11px; line-height: 16px; }

/* bird's-eye view drawer, beside the video (never over it) */
#stageRow { position: relative; flex: 1 1 auto; min-height: 200px; display: flex; min-width: 0; }
#stageRow > #stage { flex: 1 1 auto; min-width: 0; }
#bevTab {
  flex: 0 0 22px; margin-left: 4px; padding: 0; border-radius: 6px; writing-mode: vertical-rl;
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted);
}
#bevTab:hover { color: var(--text); }
#bevTab[hidden], #bevDrawer[hidden] { display: none; }
#bevDrawer {
  flex: 0 0 var(--bev-w, 480px); display: flex; min-width: 0; margin-left: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
}
#bevSplit { flex: 0 0 6px; cursor: col-resize; background: var(--panel2); }
#bevSplit:hover, #bevSplit.drag { background: var(--accent); }
#bevBody { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
#bevHeader {
  display: flex; gap: 8px; align-items: baseline; padding: 5px 8px; font-size: 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
#bevTitle { font-weight: 600; }
#bevInfo { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#bevInfo.err { color: var(--warn); }
#bev { display: block; width: 100%; cursor: pointer; flex: none; }
#bevDetails { padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
#bevDetails .row { display: flex; gap: 6px; align-items: center; }
#bevDetails .tid { min-width: 30px; }
#bevDetails .warn { color: var(--warn); }

/* overall job progress (tracking, field detection, upload) */
.pbar {
  flex: 0 0 120px; height: 7px; border-radius: 4px; background: var(--panel2);
  border: 1px solid var(--border); overflow: hidden; position: relative;
}
.pbar i { display: block; height: 100%; background: var(--accent); transition: width .4s ease; }
.pbar.indet i { width: 35% !important; position: absolute; animation: pbar-slide 1.2s ease-in-out infinite; }
@keyframes pbar-slide { from { left: -35%; } to { left: 100%; } }
.ptext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pname { flex: none; }
#fieldStatus:not(.err) { display: flex; align-items: center; gap: 6px; color: var(--warn); }
#fieldStatus:empty { display: none; }
