/* ========================================
   Content Factory - Video Editor
   Mobile-first, CapCut-style dark theme
   ======================================== */

:root {
  --bg-primary: #0a0a0a;
  --bg-card: rgba(30, 30, 30, 0.9);
  --bg-surface: #1a1a1a;
  --bg-elevated: #242424;
  --text-primary: #ffffff;
  --text-secondary: #999999;
  --text-muted: #666666;
  --accent: #ffffff;
  --accent-blue: #3b82f6;
  --accent-green: #22c55e;
  --accent-purple: #a855f7;
  --accent-orange: #f97316;
  --track-main: #2563eb;
  --track-audio: #22c55e;
  --track-text: #eab308;
  --track-broll: #a855f7;
  --border: rgba(255, 255, 255, 0.08);
  --touch-min: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ========================================
   Layout
   ======================================== */

.editor-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ========================================
   Top Bar
   ======================================== */

.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  height: 48px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.editor-topbar .back-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
}

.editor-topbar .back-btn:active {
  background: var(--bg-elevated);
}

.editor-topbar .project-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.editor-topbar .undo-redo {
  display: flex;
  gap: 4px;
}

.editor-topbar .undo-redo button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
}

.editor-topbar .undo-redo button:active {
  background: var(--bg-elevated);
}

/* ========================================
   Video Preview (top 55%)
   ======================================== */

.preview-section {
  flex: 0 0 55%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000000;
  position: relative;
  overflow: hidden;
}

.video-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrapper video {
  max-height: 100%;
  max-width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: contain;
  border-radius: 4px;
}

.video-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.play-overlay-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  color: white;
}

.play-overlay-btn:active {
  transform: scale(0.92);
}

.play-overlay-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

.video-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  align-items: center;
  gap: 12px;
}

.timecode {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.8);
  font-variant-numeric: tabular-nums;
  min-width: 90px;
}

.video-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========================================
   Timeline (middle ~22%)
   ======================================== */

.timeline-section {
  flex: 0 0 22%;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  flex-shrink: 0;
}

.timeline-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timeline-zoom button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timeline-zoom button:active {
  background: var(--bg-card);
}

.timeline-scale {
  font-size: 11px;
  color: var(--text-muted);
}

.timeline-tracks {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.timeline-tracks::-webkit-scrollbar {
  display: none;
}

.timeline-inner {
  position: relative;
  min-width: 100%;
  height: 100%;
  padding: 0 50%;
}

/* Playhead */
.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #ffffff;
  z-index: 20;
  pointer-events: none;
}

.playhead::before {
  content: '';
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: #ffffff;
  clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
}

/* Time ruler */
.time-ruler {
  height: 20px;
  position: relative;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.time-ruler .tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  background: rgba(255,255,255,0.15);
}

.time-ruler .tick.major {
  height: 10px;
  background: rgba(255,255,255,0.3);
}

.time-ruler .tick.minor {
  height: 5px;
}

.time-ruler .tick-label {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Track rows */
.track-row {
  height: 40px;
  position: relative;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.track-row.video-track {
  height: 52px;
}

.track-label {
  position: sticky;
  left: 0;
  z-index: 10;
  width: 0;
  overflow: visible;
}

.track-label span {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  background: var(--bg-primary);
  padding: 2px 4px;
  border-radius: 2px;
  z-index: 10;
}

/* Clips on tracks */
.clip {
  position: absolute;
  height: 80%;
  top: 10%;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s;
  min-width: 20px;
}

.clip:active {
  box-shadow: 0 0 0 2px rgba(255,255,255,0.5);
}

.clip.video-clip {
  background: var(--track-main);
  display: flex;
  align-items: stretch;
}

.clip.video-clip .frame-strip {
  display: flex;
  height: 100%;
  width: 100%;
}

.clip.video-clip .frame-strip canvas {
  height: 100%;
  flex-shrink: 0;
}

.clip.audio-clip {
  background: var(--track-audio);
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.clip.audio-clip .clip-name {
  font-size: 10px;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip.audio-clip .waveform-mini {
  flex: 1;
  height: 70%;
  margin-left: 4px;
}

.clip.broll-clip {
  background: var(--track-broll);
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.clip.broll-clip .clip-name {
  font-size: 10px;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip.text-clip {
  background: var(--track-text);
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.clip.text-clip .clip-name {
  font-size: 10px;
  color: rgba(0,0,0,0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip.transition-clip {
  background: var(--accent-orange);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clip.transition-clip svg {
  width: 14px;
  height: 14px;
  color: rgba(255,255,255,0.9);
}

/* ========================================
   Toolbar (bottom ~23%)
   ======================================== */

.toolbar-section {
  flex-shrink: 0;
  background: var(--bg-primary);
  padding-bottom: var(--safe-bottom);
}

.toolbar-scroll {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 0;
  padding: 8px 12px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.toolbar-scroll::-webkit-scrollbar {
  display: none;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 64px;
  height: 60px;
  padding: 8px 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 12px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.tool-btn:active {
  background: var(--bg-elevated);
}

.tool-btn.active {
  color: var(--accent);
  background: rgba(255,255,255,0.06);
}

.tool-btn svg {
  width: 24px;
  height: 24px;
}

.tool-btn .tool-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ========================================
   Bottom Sheet
   ======================================== */

.bottom-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.bottom-sheet-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  background: var(--bg-surface);
  border-radius: 16px 16px 0 0;
  z-index: 101;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

.bottom-sheet.visible {
  transform: translateY(0);
}

.sheet-drag-handle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 8px auto;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 12px;
  flex-shrink: 0;
}

.sheet-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.sheet-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sheet-close-btn:active {
  background: var(--bg-card);
}

.sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-overflow-scrolling: touch;
}

/* ========================================
   Music List (Audio sheet)
   ======================================== */

.music-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.music-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.music-item:active {
  background: var(--bg-card);
}

.music-item .music-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--track-audio);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.music-item .music-info {
  flex: 1;
  min-width: 0;
}

.music-item .music-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-item .music-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.music-item .music-add-btn {
  min-width: var(--touch-min);
  height: 32px;
  border-radius: 8px;
  background: var(--track-audio);
  border: none;
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 14px;
  flex-shrink: 0;
}

.music-item .music-add-btn:active {
  opacity: 0.8;
}

/* ========================================
   B-Roll Grid
   ======================================== */

.broll-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.broll-card {
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  background: var(--bg-elevated);
  cursor: pointer;
}

.broll-card:active {
  opacity: 0.8;
}

.broll-card img,
.broll-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.broll-card .broll-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 6px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  font-size: 10px;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.broll-card .broll-duration {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0,0,0,0.6);
  font-size: 10px;
  color: rgba(255,255,255,0.8);
}

/* ========================================
   Transitions Grid
   ======================================== */

.transitions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.transition-card {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.transition-card:active {
  background: var(--bg-card);
}

.transition-card.selected {
  border-color: var(--accent-orange);
}

.transition-card img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
}

.transition-card .transition-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-orange);
}

.transition-card .transition-name {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ========================================
   Text Tool
   ======================================== */

.text-tool-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.text-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.text-input-group label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.text-input-group input,
.text-input-group textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.text-input-group textarea {
  resize: none;
  height: 80px;
}

.text-input-group input:focus,
.text-input-group textarea:focus {
  border-color: var(--accent-blue);
}

.text-style-row {
  display: flex;
  gap: 8px;
}

.text-style-btn {
  flex: 1;
  height: var(--touch-min);
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.text-style-btn.active {
  border-color: var(--accent-blue);
  color: var(--text-primary);
}

.text-style-btn:active {
  background: var(--bg-card);
}

.add-text-btn {
  height: var(--touch-min);
  border-radius: 12px;
  background: var(--accent-blue);
  border: none;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.add-text-btn:active {
  opacity: 0.85;
}

/* ========================================
   Effects List
   ======================================== */

.effects-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.effect-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: 10px;
  cursor: pointer;
}

.effect-item:active {
  background: var(--bg-card);
}

.effect-item .effect-name {
  font-size: 14px;
  font-weight: 500;
}

.effect-item .effect-toggle {
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: rgba(255,255,255,0.15);
  border: none;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.effect-item .effect-toggle.on {
  background: var(--accent-blue);
}

.effect-item .effect-toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.effect-item .effect-toggle.on::after {
  transform: translateX(18px);
}

/* ========================================
   Export Panel
   ======================================== */

.export-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.export-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: 10px;
}

.export-info-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.export-info-row .label {
  color: var(--text-muted);
}

.export-info-row .value {
  color: var(--text-primary);
  font-weight: 500;
}

.export-btn {
  height: 52px;
  border-radius: 14px;
  background: var(--accent-blue);
  border: none;
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.export-btn:active {
  opacity: 0.85;
}

.export-btn.exporting {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  pointer-events: none;
}

.export-progress {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: 10px;
}

.export-progress.visible {
  display: flex;
}

.export-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.export-progress-bar .fill {
  height: 100%;
  background: var(--accent-blue);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

.export-progress-text {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ========================================
   Edit Tool (Trim/Split)
   ======================================== */

.edit-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.edit-action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  background: var(--bg-elevated);
  border-radius: 10px;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.edit-action-btn:active {
  background: var(--bg-card);
}

.edit-action-btn svg {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.edit-action-btn .action-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ========================================
   Empty state
   ======================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 13px;
  line-height: 1.5;
}

/* ========================================
   Toast notifications
   ======================================== */

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
