:root {
  --bg: #0f1420;
  --panel: #171d2b;
  --panel-2: #1f2637;
  --line: #2b3346;
  --text: #e6ebf5;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --green: #22c55e;
  --blue: #3b82f6;
  --danger: #ef4444;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: auto;
}

#annotation-page {
  display: grid;
  grid-template-columns: 1fr 290px;
  height: 100vh;
  overflow: hidden;
}

h1 { font-size: 16px; margin: 0 0 12px; }
h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* 项目库 */
#project-library { max-width: 1220px; margin: 0 auto; padding: 28px; min-height: 100vh; }
.library-header h1 { font-size: 24px; margin-bottom: 6px; }
.library-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 22px 0 14px; }
.action-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.action-box label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.inline-row { display: flex; gap: 8px; }
.inline-row input { flex: 1; min-width: 0; }
.inline-row button { flex: 0 0 auto; width: auto; margin: 0; }
#import-preview { max-height: 220px; overflow-y: auto; margin-top: 8px; }
.episode-preview {
  display: flex; align-items: flex-start; gap: 8px; padding: 7px 4px;
  border-top: 1px solid var(--line); font-size: 12px;
}
.episode-preview:first-child { border-top: 0; }
.episode-preview label { flex: 1; margin: 0; color: var(--text); cursor: pointer; }
.episode-preview .missing { display: block; margin-top: 3px; color: #fca5a5; font-size: 11px; }
.episode-preview .ready { color: #86efac; font-size: 11px; }
.library-toolbar { display: flex; align-items: center; gap: 14px; margin: 12px 2px; }
#project-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.project-card {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; cursor: pointer; transition: .12s;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.project-card.selected { box-shadow: 0 0 0 2px var(--accent); }
.project-check { position: absolute; top: 14px; right: 14px; }
.project-name { font-size: 14px; font-weight: 650; padding-right: 26px; overflow-wrap: anywhere; }
.project-meta { color: var(--muted); font-size: 12px; margin: 12px 0; }
.project-progress { height: 5px; border-radius: 4px; overflow: hidden; background: var(--panel-2); }
.project-progress > span { display: block; height: 100%; background: var(--green); }
.status-tag { display: inline-block; font-size: 11px; padding: 3px 8px; border-radius: 10px; border: 1px solid var(--line); }
.status-tag.unstarted { color: var(--muted); }
.status-tag.working { color: #fde68a; border-color: var(--warn); background: #3a2e0e; }
.status-tag.ready { color: #fdba74; border-color: #f97316; background: #40230c; }
.status-tag.completed { color: #86efac; border-color: var(--green); background: #143d24; }

/* 主区 */
#main { display: flex; flex-direction: column; min-width: 0; padding: 12px; gap: 6px; overflow: hidden; }
.annotation-topbar { display: flex; align-items: center; gap: 12px; min-height: 36px; }
.annotation-topbar button { width: auto; margin: 0; }
#stage-row { display: flex; gap: 0; min-height: 0; flex: 1; }
.stage-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
/* 主标注面板初始比参考面板宽 */
#col-main { flex: 1.7 1 0; }
#col-ref { flex: 1 1 0; }
.stage-label { font-size: 12px; color: var(--muted); }
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #000; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); transition: box-shadow .12s; }
.stage.active { box-shadow: 0 0 0 3px var(--accent); }
#canvas-main, #canvas-ref { max-width: 100%; max-height: 100%; display: block; }
#canvas-main { cursor: crosshair; }
#canvas-ref { cursor: copy; }
.viewport-controls {
  position: absolute; z-index: 2; top: 8px; left: 8px;
  display: flex; gap: 4px; padding: 4px;
  border-radius: 7px; background: #111827cc; backdrop-filter: blur(4px);
}
.viewport-controls button {
  width: auto; min-width: 28px; margin: 0; padding: 4px 7px;
  background: #1f2937dd;
}

/* 可拖拽分隔条 */
.divider-h { flex: 0 0 8px; cursor: row-resize; background: var(--line); border-radius: 4px; }
.divider-h:hover, .divider-h.active { background: var(--accent); }
.divider-v { flex: 0 0 8px; cursor: col-resize; background: var(--line); border-radius: 4px; margin: 18px 6px 0; }
.divider-v:hover, .divider-v.active { background: var(--accent); }

/* 控制条 */
#controls { display: flex; align-items: center; gap: 10px; background: var(--panel); padding: 10px 14px; border-radius: 10px; }
#frame-info { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 84px; text-align: center; }
#frame-slider { flex: 1; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.badge.done { background: #143d24; border-color: var(--green); color: #86efac; }
.badge.modified { background: #3a2e0e; border-color: #f59e0b; color: #fde68a; }
.badge.rejected { background: #3d1414; border-color: var(--danger); color: #fca5a5; }
.badge.pending { color: var(--muted); }

/* 逐帧状态色带 */
#status-strip { width: 100%; height: 16px; border-radius: 6px; display: block; background: var(--panel-2); cursor: pointer; }
#shortcut-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 26px; padding: 4px 10px; border-radius: 7px;
  color: var(--muted); background: var(--panel); font-size: 11px;
}
#shortcut-bar strong { color: #fff; white-space: nowrap; }
#shortcut-bar span { text-align: right; }

/* 工具面板 */
#tools { background: var(--panel); border-left: 1px solid var(--line); padding: 16px 14px; overflow-y: auto; display: flex; flex-direction: column; }
#tools section { margin-bottom: 20px; }
.seg-btns { display: flex; gap: 8px; margin-bottom: 8px; }
.slot-status { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.7; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 6px; }
.swatch { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }
.swatch.left { background: #3b82f6; }
.swatch.right { background: #22c55e; }
.opacity-control { display: flex; align-items: center; gap: 10px; }
.opacity-control input { flex: 1; }
.opacity-control span { min-width: 38px; font-variant-numeric: tabular-nums; color: var(--muted); }
.pending-warning {
  margin-bottom: 10px; padding: 8px 10px; border-radius: 7px;
  color: #fde68a; background: #3a2e0e; border: 1px solid #f59e0b;
  font-size: 12px; line-height: 1.5;
}
.frame-toast {
  position: fixed; z-index: 20; left: 50%; bottom: 34px;
  transform: translateX(-50%); padding: 10px 16px; border-radius: 8px;
  color: #fde68a; background: #111827ee; border: 1px solid #f59e0b;
  box-shadow: 0 8px 24px #0008; pointer-events: none;
}
dialog {
  width: min(420px, calc(100vw - 40px)); padding: 20px;
  color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 20px 60px #000a;
}
dialog::backdrop { background: #0009; }
dialog h3 { margin: 0 0 12px; font-size: 16px; }
dialog p { line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.dialog-actions button { width: auto; margin: 0; }
.hint { font-size: 11px; color: var(--muted); margin: 4px 0 10px; line-height: 1.5; }

/* 选中手的可勾选属性 */
.prop-group { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop-label { font-size: 12px; color: var(--muted); flex: 0 0 34px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { width: auto; margin-bottom: 0; padding: 5px 14px; font-size: 12px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chips.disabled .chip { opacity: .35; cursor: not-allowed; }
.chips.disabled .chip:hover { border-color: var(--line); }

/* 底部提交/导出并排，钉在最下方 */
#submit-section { margin-top: auto; margin-bottom: 0; }
.submit-row { display: flex; gap: 10px; }
.submit-row button { flex: 1; width: auto; margin-bottom: 0; }
.progress { font-size: 13px; margin-bottom: 10px; }
.warn { font-size: 12px; color: #fde68a; background: #3a2e0e; border: 1px solid var(--warn); border-radius: 6px; padding: 6px 8px; margin-bottom: 10px; }

/* 通用控件 */
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; width: 100%;
  margin-bottom: 8px; transition: .12s;
}
#controls button, .seg-btns button { width: auto; margin-bottom: 0; }
.seg-btns button { flex: 1; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { border-color: #5b2b2b; color: #ffb4b4; }
button.danger:hover { border-color: var(--danger); }
button:disabled { opacity: .4; cursor: not-allowed; }
input[type=text], input[type=number], input[type=range] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font-family: inherit; font-size: 12px;
}
.hidden { display: none !important; }

@media (max-width: 800px) {
  .library-actions { grid-template-columns: 1fr; }
  #annotation-page { grid-template-columns: 1fr; overflow: auto; }
  #tools { border-left: 0; border-top: 1px solid var(--line); }
}
