:root {
  --bg: #121416;
  --bg-elev: #1a1d21;
  --bg-panel: #16191d;
  --border: #2a3038;
  --text: #e8eaed;
  --muted: #8b939e;
  --teal: #2dd4bf;
  --teal-dim: #134e4a;
  --amber: #fbbf24;
  --amber-dim: #78350f;
  --playhead: #facc15;
  --danger: #f87171;
  --radius: 8px;
  --font: Inter, system-ui, -apple-system, sans-serif;
  --sidebar: 280px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
}
.skip-link {
  position: absolute; left: -999px; top: 0;
}
.skip-link:focus { left: 8px; top: 8px; z-index: 99; background: var(--teal); color: #042; padding: 6px 10px; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 12px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.02em; }
.logo-mark {
  width: 18px; height: 18px; border-radius: 4px;
  background: linear-gradient(135deg, var(--teal), var(--amber));
}
.header-actions { display: flex; align-items: center; gap: 10px; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--bg-panel);
  color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit;
}
.btn:hover { border-color: #3d4652; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: #115e59; border-color: #14b8a6; color: #ecfdf5; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--text);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 15px;
}
.icon-btn:hover, .tool:hover { background: #22272e; }
.icon-btn.play { width: 40px; font-size: 16px; color: var(--teal); }

.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.toggle.sm { font-size: 12px; }
.toggle input { accent-color: var(--teal); }

.banner {
  background: #3f1d1d; color: #fecaca; padding: 8px 14px; border-bottom: 1px solid #7f1d1d;
}
.banner.hidden, .hidden, .toast.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 50;
  background: #1f2937; border: 1px solid var(--border); padding: 10px 14px;
  border-radius: var(--radius); max-width: 360px; box-shadow: 0 8px 24px #0008;
}

.workspace { display: flex; height: calc(100vh - 48px); }
.sidebar {
  width: var(--sidebar); flex-shrink: 0;
  background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
}
.sidebar.collapsed { display: none; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.pane-head h2 { margin: 0; flex: 1; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.drop-zone {
  margin: 0 12px 10px; padding: 16px 10px; text-align: center; color: var(--muted);
  border: 1px dashed #3d4652; border-radius: var(--radius); font-size: 12px;
}
.drop-zone.over { border-color: var(--teal); color: var(--teal); background: #134e4a33; }
.asset-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow: auto; flex: 1; }
.asset-card {
  display: grid; grid-template-columns: 72px 1fr; gap: 8px;
  padding: 8px; margin-bottom: 8px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 6px;
}
.asset-card img, .asset-card .thumb-ph {
  width: 72px; height: 40px; object-fit: cover; border-radius: 4px; background: #0b0d10;
}
.asset-meta { min-width: 0; }
.asset-meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.asset-meta span { color: var(--muted); font-size: 11px; }
.asset-actions { grid-column: 1 / -1; display: flex; gap: 6px; }
.warn { color: var(--danger); font-size: 11px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.preview-wrap { flex: 1; min-height: 200px; display: flex; flex-direction: column; background: #0b0d10; }
.canvas-frame {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px; min-height: 0;
}
#preview-canvas {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  aspect-ratio: 16 / 9; background: #000; border-radius: 4px;
  box-shadow: 0 0 0 1px #222;
}
.transport {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 12px 10px; border-top: 1px solid var(--border); background: var(--bg-elev);
}
.timecode { font-variant-numeric: tabular-nums; color: var(--muted); margin-left: 12px; min-width: 180px; }

.ai-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-top: 1px solid var(--border); background: var(--bg-panel);
}
.ai-bar input[type="text"] {
  flex: 1; background: #0f1216; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 7px 10px; font: inherit;
}
.token-est { color: var(--muted); font-size: 11px; white-space: nowrap; }

.timeline-wrap { height: 240px; display: flex; flex-direction: column; min-width: 0; border-top: 1px solid var(--border); background: #101318; }
#timeline-root { flex: 1; min-height: 0; min-width: 0; overflow: hidden; display: flex; flex-direction: column; }
.tl-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 10px; }
.tool-group { display: flex; gap: 4px; }
.tool {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 5px; padding: 3px 8px; cursor: pointer; font: inherit;
}
.tool.active { background: var(--teal-dim); border-color: var(--teal); color: #ccfbf1; }

.tl-scroll { overflow-x: scroll; overflow-y: auto; flex: 1; min-width: 0; position: relative; scrollbar-gutter: stable; }
.tl-scroll::-webkit-scrollbar { height: 10px; }
.tl-scroll::-webkit-scrollbar-thumb { background: #3d4652; border-radius: 99px; }
.tl-inner { position: relative; min-height: 100%; min-width: 100%; }
.ruler {
  height: 22px; position: sticky; top: 0; z-index: 3;
  background: #15181d; border-bottom: 1px solid var(--border); color: var(--muted);
  font-size: 10px;
}
.track-row {
  display: flex; height: 44px; border-bottom: 1px solid #1e242c; position: relative;
}
.track-label {
  position: sticky; left: 0; z-index: 2; width: 48px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #15181d; border-right: 1px solid var(--border);
  font-weight: 600; font-size: 11px; color: var(--muted);
}
.track-lane { position: relative; flex: 1; height: 100%; min-width: 0; }
.clip {
  position: absolute; top: 6px; height: 32px; border-radius: 4px;
  overflow: hidden; cursor: grab; user-select: none;
  border: 1px solid #0006; display: flex; align-items: center; padding: 0 8px;
  font-size: 11px; white-space: nowrap;
}
.clip.video { background: #0f766e; }
.clip.audio { background: #b45309; }
.clip.selected { outline: 2px solid #fff; outline-offset: 0; z-index: 1; }
.clip .handle {
  position: absolute; top: 0; width: 6px; height: 100%; cursor: ew-resize;
}
.clip .handle.l { left: 0; } .clip .handle.r { right: 0; }
.playhead {
  position: absolute; top: 0; bottom: 0; width: 2px; background: var(--playhead);
  z-index: 4; pointer-events: none;
}
.playhead::before {
  content: ""; position: absolute; top: 0; left: -5px;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 8px solid var(--playhead);
}

.modal { border: 0; padding: 0; background: transparent; }
.modal::backdrop { background: #0008; }
.modal-card {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px; width: min(420px, 92vw);
  display: flex; flex-direction: column; gap: 10px;
}
.modal-card h2 { margin: 0 0 4px; font-size: 16px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.modal-card input, .modal-card select {
  background: #0f1216; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 7px 8px; font: inherit;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.hint { color: var(--muted); margin: 0; font-size: 12px; }
.progress { height: 8px; background: #0b0d10; border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--teal); transition: width 80ms linear; }

@media (max-width: 800px) {
  .sidebar { position: absolute; z-index: 8; height: calc(100vh - 48px); box-shadow: 8px 0 24px #0006; }
  .sidebar.collapsed { display: none; }
  .timeline-wrap { height: 200px; }
  .brand h1 { font-size: 13px; }
}

.preset-bar {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 12px 0; border-top: 1px solid var(--border); background: var(--bg-panel);
}
.preset-cats { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-cat {
  appearance: none; border: 1px solid var(--border); background: #0f1216;
  color: var(--muted); border-radius: 999px; padding: 3px 10px; font: inherit; cursor: pointer;
}
.preset-cat.active { color: #ccfbf1; border-color: var(--teal); background: var(--teal-dim); }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 2px; }
.preset-chip {
  appearance: none; border: 1px solid var(--border); background: #11161c;
  color: var(--text); border-radius: 6px; padding: 4px 9px; font: inherit; cursor: pointer;
  font-size: 12px;
}
.preset-chip:hover { border-color: #3d4652; }
.preset-chip.selected { border-color: var(--amber); background: var(--amber-dim); color: #fde68a; }

.ai-status { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 0; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.ai-status.busy { color: var(--amber); }
.ai-status.ok { color: var(--teal); }
.ai-status.err { color: var(--danger); }
.btn.busy { opacity: 0.85; }
.toast.busy { border-color: var(--amber); }
.toast.ok { border-color: var(--teal); }
.toast.err { border-color: var(--danger); }

.btn.danger-ghost { color: #fecaca; border-color: #7f1d1d; background: transparent; }
.btn.danger-ghost:hover { background: #3f1d1d; }
.zoom-group { display: flex; align-items: center; gap: 6px; }
