:root {
  --bg: #0b0d10;
  --panel: #13171c;
  --panel2: #1a1f26;
  --line: #262d36;
  --txt: #e6e9ef;
  --dim: #8a94a3;
  --accent: #4ea1ff;
  --accent2: #22d3a6;
  --sel: rgba(78,161,255,.22);
  --danger: #ff5d5d;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--txt);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .3px; font-size: 17px; }
.brand span { color: var(--accent); }
.topbar .tools { display: flex; gap: 8px; }
.topbar .right { margin-left: auto; display: flex; gap: 8px; }

.btn {
  background: var(--panel2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-size: 13px;
  transition: .15s border-color, .15s background;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.file { display: inline-flex; align-items: center; }

/* stage */
.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.preview { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 16px; }
.preview-frame {
  position: relative; flex: 1; min-height: 0;
  background:
    repeating-conic-gradient(#15181d 0% 25%, #101318 0% 50%) 50% / 28px 28px;
  border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
#player { max-width: 100%; max-height: 100%; display: block; }
.yt-wrap { position: absolute; inset: 0; display: flex; }
.yt-wrap > div { flex: 1; }
.hidden { display: none !important; }

.empty { text-align: center; color: var(--dim); }
.empty-icon { font-size: 46px; color: #2d3642; margin-bottom: 8px; }
.empty small { display: block; margin-top: 6px; color: #5c6673; }

.transport {
  display: flex; align-items: center; gap: 14px; padding: 10px 4px 0;
}
.tp {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #04121f; border: none;
  font-size: 15px; cursor: pointer;
}
.time { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 13px; }
.spacer { flex: 1; }
.scale { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12px; }
.scale input[type=range] { accent-color: var(--accent); }

/* timeline */
.timeline-panel {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 10px 16px 14px;
}
.tl-head { display: flex; gap: 10px; margin-bottom: 8px; }
.badge {
  font-size: 12px; color: var(--dim); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px;
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tl-scroll { position: relative; overflow-x: auto; overflow-y: hidden; border-radius: 8px; }
#ruler { display: block; background: #0f1216; }
#timeline { display: block; cursor: crosshair; }
.tl-foot { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.tl-foot .hint { color: #5c6673; font-size: 12px; }

/* segbar */
.segbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel2);
  border-bottom: 1px solid var(--line);
}
.segbar-label { color: var(--dim); font-size: 12px; }
.segchips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #10161d; border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; font-size: 12px; font-variant-numeric: tabular-nums;
}
.chip button {
  background: none; border: none; color: var(--danger);
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0;
}
.btn.small { padding: 4px 9px; font-size: 12px; }

/* overlay preview */
.overlay-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}

/* crop layer */
.crop-layer {
  position: absolute; inset: 0; cursor: crosshair;
  background: rgba(0,0,0,.5);
}
.crop-box {
  position: absolute;
  border: 1.5px solid #4ea1ff;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.5);
  cursor: move;
  touch-action: none;
}
.crop-handle {
  position: absolute; width: 14px; height: 14px;
  background: #4ea1ff; border: 2px solid #06121f; border-radius: 3px;
}
.crop-handle.nw { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-handle.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-handle.sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-handle.se { right: -8px; bottom: -8px; cursor: nwse-resize; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 20px; width: min(560px, 92vw);
}
.modal-box h3 { margin: 0 0 12px; font-size: 16px; }
.modal-box input[type=text] {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  font-size: 13px; margin-bottom: 12px;
}
.modal-box .row { display: flex; gap: 8px; justify-content: flex-end; }
.modal-box p { color: var(--dim); font-size: 13px; }
.modal-box video { width: 100%; border-radius: 8px; margin-top: 12px; }
.modal-box a.dl { color: var(--accent2); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 30;
  max-width: 80vw;
}
.toast.err { border-color: var(--danger); color: #ffd7d7; }
