:root {
  --bg: #08080c;
  --surface: #111117;
  --surface-2: #191922;
  --surface-3: #22222e;
  --border: #272736;
  --text: #f4f4f6;
  --muted: #9ca3af;
  --accent: #7c3aed;
  --accent-2: #ec4899;
  --accent-hover: #6d28d9;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px; user-select: none;
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2e2e3e; border-radius: 999px; }

.app-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Topbar */
.topbar {
  height: 56px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: #111117;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.brand-group { display: flex; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; letter-spacing: -0.02em; }
.brand-logo-img {
  width: 28px; height: 28px; border-radius: 7px; object-fit: cover; display: block;
}
.empty-logo-img {
  width: 60px; height: 60px; border-radius: 15px; object-fit: cover;
  margin: 0 auto 14px; display: block; box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35);
}
.project-title-input {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  font-size: 12px; padding: 4px 8px; border-radius: 6px; width: 150px; outline: none;
}
.project-title-input:hover, .project-title-input:focus {
  border-color: var(--border); background: var(--surface-2); color: var(--text);
}

.divider-v { width: 1px; height: 20px; background: var(--border); }

.hud-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 4px 8px; border-radius: 12px;
}

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon { padding: 6px 9px; min-width: 30px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border-color: transparent; color: #fff; font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-record { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.45); color: #fecaca; }
.btn-record:hover:not(:disabled) { background: rgba(239, 68, 68, 0.25); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-accent-soft { background: rgba(124, 58, 237, 0.18); border-color: rgba(124, 58, 237, 0.45); color: #ddd6fe; }
.btn-caption-soft { background: rgba(14, 165, 233, 0.16); border-color: rgba(14, 165, 233, 0.45); color: #bae6fd; }
.btn-speed-soft { background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.45); color: #fde68a; }
.btn-danger-soft { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.45); color: #fecaca; }
.btn-toggle { background: var(--surface-2); color: var(--muted); font-size: 11px; padding: 5px 9px; }
.btn-toggle.active { background: rgba(52, 211, 153, 0.16); border-color: rgba(52, 211, 153, 0.5); color: #6ee7b7; }
.btn-play { background: var(--surface-3); min-width: 72px; }
.full-btn { width: 100%; margin-top: 10px; padding: 9px; }

.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.rec-pulse { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border-radius: 8px; cursor: pointer; font-size: 12px; color: var(--muted);
  background: transparent; border: 1px solid transparent; transition: all 0.15s ease;
}
.chip-toggle:hover { background: var(--surface-3); color: var(--text); }
.chip-toggle.active {
  background: rgba(124, 58, 237, 0.22); border-color: rgba(139, 92, 246, 0.55); color: #ede9fe;
}
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #18181f; border: 1px solid var(--border); color: #fff;
  padding: 9px 16px; border-radius: 10px; font-size: 12px; z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.mic-meter { width: 22px; height: 5px; background: #09090d; border-radius: 99px; overflow: hidden; }
.mic-level { display: block; height: 100%; width: 0%; background: #22c55e; transition: width 0.08s; }

.hud-select, .mini-select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 6px; font-size: 11px; outline: none;
}
.mini-select.full { width: 100%; }
.speed-slider-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  font-size: 11px; color: var(--muted);
}
.speed-slider-chip input[type="range"] { width: 68px; accent-color: var(--accent); cursor: pointer; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

/* Main Workspace */
.workspace { flex: 1; display: grid; grid-template-columns: 1fr 330px; min-height: 0; }

.stage-column { display: flex; flex-direction: column; padding: 14px; gap: 12px; min-width: 0; min-height: 0; }

.stage-wrapper {
  flex: 1; position: relative; background: #040406;
  border: 1px solid var(--border); border-radius: 14px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 0;
}

#previewCanvas { max-width: 100%; max-height: 100%; object-fit: contain; cursor: crosshair; }

.empty-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.empty-card {
  text-align: center; max-width: 420px; padding: 28px;
  background: rgba(17, 17, 23, 0.92); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.empty-card h2 { margin: 0 0 8px; font-size: 18px; }
.empty-card p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.empty-actions { display: flex; justify-content: center; gap: 10px; }

.countdown-overlay {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.countdown-ring {
  width: 130px; height: 130px; border-radius: 50%;
  border: 4px solid var(--accent-2); display: flex; align-items: center; justify-content: center;
  font-size: 64px; font-weight: 800; background: rgba(124, 58, 237, 0.2);
}

.zoom-target-badge {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(236, 72, 153, 0.9); color: #fff; font-size: 11px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px; pointer-events: none;
}

/* Multi-Track Timeline */
.timeline-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}

.transport-bar { display: flex; align-items: center; justify-content: space-between; }
.transport-left, .transport-right { display: flex; align-items: center; gap: 8px; }
.time-readout { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 115px; }

.timeline-body { position: relative; display: flex; flex-direction: column; gap: 4px; }
.ruler-canvas { width: 100%; height: 22px; display: block; margin-left: 90px; width: calc(100% - 90px); }

.tracks-container { position: relative; display: flex; flex-direction: column; gap: 6px; }
.track-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 0; }
.tabular { font-variant-numeric: tabular-nums; }
.empty-icon-box {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.25), rgba(236, 72, 153, 0.2));
  border: 1px solid rgba(167, 139, 250, 0.3); color: #ddd6fe;
  display: flex; align-items: center; justify-content: center;
}

.track-label {
  font-size: 11px; color: var(--muted); padding-right: 8px;
  display: flex; align-items: center; gap: 6px;
}

.tab-btn {
  padding: 11px 6px; background: transparent; border: none; color: var(--muted);
  font-size: 12px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}

.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.preset-btn {
  padding: 6px 4px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 500;
}
.preset-btn:hover { background: var(--surface-3); color: #fff; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; font-size: 12px; cursor: pointer; color: var(--text);
}
input.switch {
  appearance: none; -webkit-appearance: none;
  width: 34px; height: 19px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border); position: relative; cursor: pointer; transition: background 0.15s;
}
input.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
  border-radius: 50%; background: #a1a1aa; transition: transform 0.15s, background 0.15s;
}
input.switch:checked { background: var(--accent); border-color: var(--accent); }
input.switch:checked::after { transform: translateX(15px); background: #fff; }
.track-lane {
  position: relative; height: 42px; background: #09090e;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer;
}
.zoom-lane { height: 28px; }
.speed-lane { height: 24px; }
.voice-lane { height: 24px; }
.caption-lane { height: 28px; }

.waveform-canvas { width: 100%; height: 100%; display: block; }

.trim-shade-left, .trim-shade-right {
  position: absolute; top: 0; bottom: 0; background: rgba(0, 0, 0, 0.65); pointer-events: none;
}
.trim-shade-left { left: 0; }
.trim-shade-right { right: 0; }

.trim-box {
  position: absolute; top: 0; bottom: 0;
  border-top: 2px solid #8b5cf6; border-bottom: 2px solid #8b5cf6;
  pointer-events: none;
}
.trim-handle {
  position: absolute; top: 0; bottom: 0; width: 10px;
  background: #8b5cf6; cursor: ew-resize; pointer-events: auto;
}
.trim-handle.left { left: 0; border-radius: 4px 0 0 4px; }
.trim-handle.right { right: 0; border-radius: 0 4px 4px 0; }

.tl-block {
  position: absolute; top: 3px; bottom: 3px;
  border-radius: 5px; cursor: grab; display: flex; align-items: center; justify-content: center;
  padding: 0 10px; font-size: 10px; font-weight: 600; overflow: hidden; white-space: nowrap;
  user-select: none;
}
.tl-block:active { cursor: grabbing; }
.tl-block.zoom-seg {
  background: rgba(236, 72, 153, 0.35); border: 1px solid #f472b6; color: #fce7f3;
}
.tl-block.zoom-seg.auto-seg {
  background: rgba(52, 211, 153, 0.25); border-color: #34d399; color: #d1fae5;
}
.tl-block.speed-seg {
  background: rgba(245, 158, 11, 0.28); border: 1px solid #fbbf24; color: #fef3c7;
}
.tl-block.voice-seg {
  background: rgba(16, 185, 129, 0.28); border: 1px solid #34d399; color: #d1fae5;
}
.tl-block.caption-seg {
  background: rgba(14, 165, 233, 0.28); border: 1px solid #38bdf8; color: #e0f2fe;
  font-weight: 500; justify-content: flex-start;
}
.tab-bar-4 { grid-template-columns: repeat(4, 1fr); }
.text-area {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); margin-bottom: 8px; outline: none;
  font-family: inherit; font-size: 12px; resize: vertical;
}
.text-area:focus { border-color: var(--accent); }
.tl-block.selected { box-shadow: 0 0 0 2px #fff; z-index: 3; }

.tl-resize {
  position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize;
  background: rgba(255, 255, 255, 0.15); opacity: 0; transition: opacity 0.12s;
}
.tl-block:hover .tl-resize, .tl-block.selected .tl-resize { opacity: 1; }
.tl-resize.left { left: 0; border-radius: 4px 0 0 4px; }
.tl-resize.right { right: 0; border-radius: 0 4px 4px 0; }

.playhead {
  position: absolute; top: -4px; bottom: 0; left: 90px; width: 2px;
  background: #fff; pointer-events: none; z-index: 5;
}
.playhead-cap {
  width: 10px; height: 10px; background: #fff; border-radius: 2px;
  transform: translate(-4px, -2px) rotate(45deg);
}

/* Right Inspector */
.inspector {
  border-left: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}

.tab-bar {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.tab-btn.active { color: #fff; border-bottom-color: var(--accent-2); background: var(--surface); }

.tab-pane { display: none; padding: 14px; overflow-y: auto; flex: 1; flex-direction: column; gap: 18px; }
.tab-pane.active { display: flex; }

.panel-section h3 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.subhead { margin: 10px 0 8px; font-size: 11px; color: var(--muted); font-weight: 500; }
.hint { margin: 6px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }

.pill-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pill {
  padding: 6px 0; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 12px;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.slider-row {
  display: grid; grid-template-columns: 96px 1fr 44px;
  align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px;
}
.slider-row input[type="range"] { width: 100%; accent-color: var(--accent-2); }
.val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }

.check-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  font-size: 12px; cursor: pointer; color: var(--text);
}

.custom-color-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px;
  font-size: 11px; color: var(--muted);
}
.custom-color-row label { display: flex; align-items: center; gap: 5px; }
.custom-color-row input[type="color"] { width: 26px; height: 22px; border: none; background: none; cursor: pointer; }

.swatch-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.swatch { height: 28px; border-radius: 7px; cursor: pointer; border: 2px solid transparent; }
.swatch.active { border-color: #fff; }

.wallpaper-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.wallpaper-thumb {
  height: 48px; border-radius: 7px; overflow: hidden; cursor: pointer;
  border: 2px solid transparent; background: #18181b;
}
.wallpaper-thumb.active { border-color: #fff; }
.wallpaper-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.cursor-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cursor-item {
  padding: 8px 4px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; color: var(--muted);
}
.cursor-item.active { border-color: var(--accent-2); color: #fff; background: rgba(236, 72, 153, 0.14); }
.cursor-item img { width: 24px; height: 24px; object-fit: contain; }

.text-input {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); margin-bottom: 10px; outline: none;
}
.text-input:focus { border-color: var(--accent); }

/* Modals */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.8);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px 20px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 15px; }

.progress-bar { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.1s; }

.shortcut-list { display: flex; flex-direction: column; gap: 8px; }
.shortcut-list div { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
kbd {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 5px;
  padding: 2px 7px; font-size: 11px; color: var(--text); font-family: monospace;
}

/* Capture Source Picker */
.source-modal-card { width: 680px; max-width: 92vw; max-height: 82vh; display: flex; flex-direction: column; }
.source-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.source-tab {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
}
.source-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.source-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 10px; overflow-y: auto; max-height: 46vh; padding: 2px;
}
.source-item {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  transition: border-color 0.12s, background 0.12s;
}
.source-item:hover { border-color: var(--accent); background: rgba(139, 92, 246, 0.12); }
.source-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #000; }
.source-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text); }
.source-icon { width: 15px; height: 15px; border-radius: 3px; flex-shrink: 0; }
.source-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
