/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --bg-light: #22223a;
  --bg-lighter: #2d2d4a;
  --surface: #16213e;
  --surface-light: #1f3054;
  --primary: #4a9eff;
  --primary-dark: #2d7ce0;
  --success: #4caf50;
  --danger: #e74c3c;
  --warning: #f39c12;
  --text: #e0e0e0;
  --text-dim: #8899aa;
  --text-bright: #ffffff;
  --border: #333355;
  --track-height: 48px;
  --header-height: 48px;
  --controls-height: 48px;

  --timeline-header: 32px;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === Header === */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-left .logo { font-size: 20px; }

.header-left h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-bright);
}

.header-right {
  display: flex;
  gap: 8px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-lighter);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-light); color: var(--text-bright); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

.btn-primary { background: var(--primary-dark); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary); }

.btn-success { background: #2e7d32; border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success); }

.btn-danger { background: #8b1a1a; border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); }

.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-full { width: 100%; justify-content: center; margin-top: 4px; }
.btn-play { padding: 6px 20px; font-size: 16px; }

.icon { font-size: 14px; }

/* === Main Content === */
#main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* === Preview === */
#preview-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0d1a;
  position: relative;
  overflow: hidden;
}

#video-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#video-container:fullscreen {
  background: #000;
}
#video-container:fullscreen #video-player {
  width: 100%;
  height: 100%;
}
#video-container:fullscreen #crop-overlay,
#video-container:fullscreen #crop-handles {
  display: none;
}

#video-player {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

#crop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

#crop-handles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
}

.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  z-index: 5;
}

.crop-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.crop-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.crop-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.crop-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.crop-handle.n { top: -5px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle.s { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle.e { top: 50%; right: -5px; transform: translateY(-50%); cursor: e-resize; }
.crop-handle.w { top: 50%; left: -5px; transform: translateY(-50%); cursor: w-resize; }

.crop-region {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border: 2px dashed var(--primary);
  pointer-events: none;
}

#no-video-msg {
  color: var(--text-dim);
  text-align: center;
}
#no-video-msg p { margin: 4px 0; }
#no-video-msg .sub { font-size: 11px; }

/* === Properties Panel === */
#properties-panel {
  width: 240px;
  background: var(--bg-light);
  border-left: 1px solid var(--border);
  padding: 10px;
  overflow-y: auto;
  flex-shrink: 0;
}

#properties-panel h3 {
  font-size: 13px;
  color: var(--text-bright);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#properties-panel h4 {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 10px 0 6px;
}

.panel-msg {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 20px 0;
}

.prop-group {
  margin-bottom: 6px;
}

.prop-group label {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.prop-value {
  font-size: 12px;
  color: var(--text);
}

.prop-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.prop-group.small { flex: 1; }

.prop-group input[type="number"],
.prop-group input[type="range"],
#properties-panel select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
}

#properties-panel select {
  margin-bottom: 6px;
}

#properties-panel hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

#audio-volume-val {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 4px;
}

/* === Playback Controls === */
#playback-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--controls-height);
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.controls-left, .controls-center, .controls-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.controls-center { gap: 4px; }

.speed-control {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 12px;
}

.speed-control label {
  font-size: 11px;
  color: var(--text-dim);
}

.speed-control select {
  background: var(--bg-lighter);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

#time-display {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: var(--text-dim);
}

/* === Timeline === */
#timeline-area {
  height: 200px;
  background: var(--bg-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--timeline-header);
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
}

.timeline-header-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

#timeline-scroll {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  position: relative;
  min-width: 0;
}

#timeline-ruler {
  height: 20px;
  background: var(--bg-lighter);
  border-bottom: 1px solid var(--border);
  position: relative;
  min-width: 100%;
}

.ruler-mark {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid var(--border);
  font-size: 9px;
  color: var(--text-dim);
  padding: 2px 3px;
}

/* Playhead */
#playhead {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

.playhead-marker {
  width: 10px;
  height: 10px;
  background: #ff4444;
  margin-left: -4px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.playhead-line {
  width: 2px;
  height: calc(100% - 10px);
  background: #ff4444;
}

/* Tracks */
.track {
  display: flex;
  min-height: var(--track-height);
  border-bottom: 1px solid var(--border);
}

.track-label {
  width: 90px;
  min-width: 90px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 11px;
  background: var(--bg-lighter);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.track-content {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  padding: 4px 0;
  min-width: 0;
}

.empty-track-msg {
  color: var(--text-dim);
  font-size: 11px;
  padding: 0 10px;
}

/* Section blocks */
.section-block {
  position: absolute;
  height: calc(var(--track-height) - 12px);
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: 1px solid #3b82f6;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 10px;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: border-color 0.1s, box-shadow 0.1s;
  user-select: none;
  background-size: cover;
  background-position: center;
}

.section-label {
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.6);
  pointer-events: none;
}

.section-block:hover {
  border-color: var(--primary);
  box-shadow: 0 0 6px rgba(74, 158, 255, 0.3);
}

.section-block.selected {
  border-color: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
  outline: 2px solid rgba(239, 68, 68, 0.4);
  outline-offset: -1px;
}

.section-block.has-crop {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border-color: #8b5cf6;
}

/* Audio section blocks */
.audio-block {
  position: absolute;
  height: calc(var(--track-height) - 12px);
  background: linear-gradient(135deg, #059669, #047857);
  border: 1px solid #10b981;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 10px;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  user-select: none;
}

.audio-block:hover {
  border-color: #34d399;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.3);
}

.audio-block.selected {
  border-color: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

/* === Export Progress (floating) === */
#export-progress {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  z-index: 100;
  font-size: 12px;
  color: var(--text);
}

#progress-bar {
  width: 160px;
  height: 6px;
  background: var(--bg-lighter);
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar::after {
  content: '';
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

#progress-text { font-size: 10px; }

/* === Drop Overlay === */
#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.9);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-message {
  text-align: center;
  border: 3px dashed var(--primary);
  border-radius: 16px;
  padding: 40px 60px;
}

.drop-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.drop-message p { margin: 4px 0; color: var(--text); font-size: 18px; }
.drop-message .sub { font-size: 13px; color: var(--text-dim); }

/* === Utilities === */
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Export modal */
#export-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  text-align: center;
}

.modal-content h3 {
  margin-bottom: 12px;
  color: var(--text-bright);
}

.modal-progress {
  width: 100%;
  height: 8px;
  background: var(--bg-lighter);
  border-radius: 4px;
  margin: 16px 0;
  overflow: hidden;
}

.modal-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s;
}

.modal-status {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* Color variants for different video sources */
.section-block[data-color="0"] { background: linear-gradient(135deg, #2563eb, #1d4ed8); border-color: #3b82f6; }
.section-block[data-color="1"] { background: linear-gradient(135deg, #dc2626, #b91c1c); border-color: #ef4444; }
.section-block[data-color="2"] { background: linear-gradient(135deg, #d97706, #b45309); border-color: #f59e0b; }
.section-block[data-color="3"] { background: linear-gradient(135deg, #059669, #047857); border-color: #10b981; }
.section-block[data-color="4"] { background: linear-gradient(135deg, #7c3aed, #6d28d9); border-color: #8b5cf6; }
.section-block[data-color="5"] { background: linear-gradient(135deg, #db2777, #be185d); border-color: #ec4899; }

/* Active toggle button */
.btn-active { background: var(--primary-dark) !important; border-color: var(--primary) !important; color: #fff !important; }
.btn-active:hover { background: var(--primary) !important; }

/* Slice mode cursor */
#timeline-scroll.slice-active .section-block { cursor: crosshair; }
#timeline-scroll.slice-active .track-content { cursor: crosshair; }
#timeline-scroll.slice-active #timeline-ruler { cursor: crosshair; }

/* === Timeline Minimap === */
#timeline-minimap {
  display: flex;
  height: 22px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.minimap-label {
  width: 90px;
  min-width: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: var(--bg-lighter);
  border-right: 1px solid var(--border);
}

#minimap-bar {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#minimap-sections {
  position: absolute;
  inset: 2px 0;
}

#minimap-viewport {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(74, 158, 255, 0.15);
  border: 1px solid rgba(74, 158, 255, 0.6);
  border-radius: 2px;
  cursor: grab;
  min-width: 16px;
  z-index: 2;
}

#minimap-viewport:active { cursor: grabbing; }

.minimap-handle {
  position: absolute;
  top: 0;
  width: 8px;
  height: 100%;
  cursor: ew-resize;
  z-index: 3;
}

.minimap-handle-left {
  left: -4px;
  border-left: 2px solid var(--primary);
}

.minimap-handle-right {
  right: -4px;
  border-right: 2px solid var(--primary);
}
