*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --bg2: #111111;
  --bg3: #1a1a1a;
  --bg4: #222222;
  --border: #2a2a2a;
  --text: #cccccc;
  --text-dim: #555555;
  --red: #ff3333;
  --red-dim: rgba(255, 51, 51, 0.15);
  --white: #eeeeee;
  --font-mono: 'Courier New', Courier, monospace;
  --font-ui: system-ui, -apple-system, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ---- Left panel ---- */
#video-list {
  width: 180px;
  min-width: 180px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 10px 12px;
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
}

#video-items {
  overflow-y: auto;
  flex: 1;
}

#video-items::-webkit-scrollbar { width: 4px; }
#video-items::-webkit-scrollbar-track { background: transparent; }
#video-items::-webkit-scrollbar-thumb { background: var(--bg4); }

.video-item {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  padding: 0;
  position: relative;
}

.video-item:hover { background: var(--bg3); }
.video-item.active {
  background: var(--bg3);
  border-left: 2px solid var(--red);
}

.video-item .thumb-wrap {
  width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
  background: #000;
}

.video-item .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.85;
}

.video-item .thumb-wrap .no-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 20px;
}

.video-item .item-info {
  padding: 6px 10px;
}

.video-item .item-title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--white);
}

.video-item .item-dur {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---- Center ---- */
#center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

#player-wrap {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

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

/* ---- Reels Crop Mode ---- */
#reels-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#reels-toggle:hover { background: var(--bg4); color: var(--white); }
#reels-toggle.active { border-color: var(--red); color: var(--red); }

/* Reels guide: 9:16 center frame — sized by JS to match actual video */
#reels-guide {
  display: none;
  position: absolute;
  border: 1px solid rgba(255, 51, 51, 0.5);
  pointer-events: none;
  z-index: 15;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
}

#player-wrap.reels-mode #reels-guide {
  display: block;
}

#subtitle-overlay {
  position: absolute;
  bottom: 40px;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  padding: 0 40px;
  z-index: 10;
}

#subtitle-overlay .sub-line {
  display: inline-block;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  padding: 2px 8px;
  border-radius: 2px;
  white-space: pre-wrap;
}

#no-video-msg {
  position: absolute;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.05em;
  pointer-events: none;
}

#video:not([src]) + #subtitle-overlay + #no-video-msg,
#video.empty + #subtitle-overlay + #no-video-msg {
  display: block;
}

/* ---- Controls bar ---- */
#controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

#playback-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
  border-radius: 2px;
  padding: 0;
}

.ctrl-btn:hover { background: var(--bg4); color: var(--white); }
.ctrl-btn:active { background: var(--red); color: #fff; }

#btn-play {
  width: 34px;
  height: 34px;
  font-size: 12px;
  background: var(--bg4);
}

.mono { font-family: var(--font-mono); }

#timecode-current, #timecode-duration {
  font-size: 12px;
  color: var(--text);
  min-width: 90px;
}
#timecode-current { text-align: left; }
#timecode-duration { text-align: right; color: var(--text-dim); }

/* ---- Timeline ---- */
#timeline-wrap {
  flex-shrink: 0;
  padding: 10px 14px 6px;
  background: var(--bg);
}

#timeline {
  width: 100%;
  height: 32px;
  display: block;
  cursor: pointer;
  border-radius: 2px;
}

#inout-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 8px;
  flex-wrap: wrap;
}

#inout-bar > div {
  display: flex;
  align-items: center;
  gap: 5px;
}

.label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

.tc-val {
  font-size: 11px;
  color: var(--red);
  min-width: 86px;
}

.tiny-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 7px;
  font-size: 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  border-radius: 2px;
  transition: background 0.1s;
  letter-spacing: 0.05em;
}
.tiny-btn:hover { background: var(--bg4); color: var(--white); }

#btn-add-queue {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 4px 14px;
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.12em;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s, color 0.1s;
}
#btn-add-queue:hover { background: var(--red); color: #fff; }
#btn-add-queue:disabled { opacity: 0.3; cursor: default; }

/* ---- Sequence Timeline ---- */
#sequence-wrap {
  flex-shrink: 0;
  padding: 6px 14px 4px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

#sequence-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

#seq-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

#seq-actions .tiny-btn.active {
  border-color: var(--red);
  color: var(--red);
}

#sequence-timeline {
  min-height: 80px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 2px;
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}

#seq-clips {
  display: flex;
  flex: 1;
  align-items: stretch;
}

#sequence-timeline.drop-target {
  border-color: var(--red);
  background: rgba(255, 51, 51, 0.03);
}

/* Drop target highlight */
#sequence-timeline.drop-target { border-color: var(--red); background: rgba(255, 51, 51, 0.06); }
.video-item.dragging { opacity: 0.5; }
.video-item[draggable] { cursor: grab; }
.video-item[draggable]:active { cursor: grabbing; }

/* Scrubber bar above clips */
#seq-scrubber {
  height: 16px;
  background: var(--bg3);
  cursor: pointer;
  position: relative;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 15;
}
#seq-scrubber:hover { background: var(--bg4); }
#seq-scrub-fill {
  height: 100%;
  background: var(--red);
  opacity: 0.4;
  width: 0%;
  pointer-events: none;
}

#seq-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  pointer-events: none;
}

.seq-clip {
  flex-shrink: 0;
  padding: 6px 8px;
  border-top: 3px solid var(--red);
  background: var(--bg3);
  cursor: grab;
  position: relative;
  display: flex;
  align-items: stretch;
  transition: background 0.1s;
  border-right: 1px solid var(--bg);
  min-width: 60px;
  overflow: hidden;
}

.seq-clip-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  overflow: hidden;
}

/* Trim handles */
.trim-handle {
  width: 6px;
  min-width: 6px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  flex-shrink: 0;
}
.trim-handle:hover, body.trimming .trim-handle {
  background: rgba(255, 255, 255, 0.15);
}
.trim-left { margin-left: -8px; margin-right: 4px; border-radius: 2px 0 0 2px; }
.trim-right { margin-right: -8px; margin-left: 4px; border-radius: 0 2px 2px 0; }

.seq-clip:hover { background: var(--bg4); }
.seq-clip.dragging { opacity: 0.4; }
.seq-clip.drag-over { background: var(--bg4); box-shadow: inset -2px 0 0 var(--white); }
.seq-clip.playing { background: rgba(255, 51, 51, 0.1); }

.seq-clip-title {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 16px;
}

.seq-clip-range {
  font-size: 9px;
  color: var(--text-dim);
  white-space: nowrap;
}

.seq-clip-dur {
  font-size: 9px;
  color: var(--text-dim);
}

.seq-clip-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  padding: 2px;
}
.seq-clip-remove:hover { color: var(--red); }

/* Sequence playhead */
#seq-playhead {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--white);
  z-index: 20;
  pointer-events: none;
  transition: left 0.03s linear;
}
#seq-playhead::before {
  content: '';
  position: absolute;
  top: 0;
  left: -5px;
  width: 12px;
  height: 16px;
  background: var(--white);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

/* Project name input */
#project-name {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 8px;
  width: 120px;
  border-radius: 2px;
  outline: none;
  transition: border-color 0.15s;
}
#project-name:focus { border-color: var(--text-dim); }
#project-name::placeholder { color: var(--text-dim); }

#export-status {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  min-height: 14px;
}

.export-link {
  color: var(--red);
  text-decoration: none;
  font-family: var(--font-mono);
}
.export-link:hover { text-decoration: underline; }

#shortcuts-hint {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  padding: 4px 14px 8px;
  flex-shrink: 0;
}



#export-status {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  min-height: 14px;
}

/* ---- Project Modal ---- */
#project-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pm-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}
.pm-panel {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 360px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.pm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.pm-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}
.pm-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.pm-close:hover { color: var(--white); }
.pm-list {
  overflow-y: auto;
  padding: 4px 0;
}
.pm-empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
}
.pm-row {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.pm-row:last-child { border-bottom: none; }
.pm-row:hover { background: var(--bg3); }
.pm-row.pm-current { border-left: 2px solid var(--red); }
.pm-row-info {
  flex: 1;
  cursor: pointer;
  min-width: 0;
}
.pm-row-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pm-badge {
  font-size: 9px;
  color: var(--red);
  font-weight: normal;
  margin-left: 6px;
}
.pm-row-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}
.pm-row-actions {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
}
.pm-row:hover .pm-row-actions { opacity: 1; }
.pm-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  transition: background 0.1s, color 0.1s;
  padding: 0;
}
.pm-btn:hover { background: var(--bg4); color: var(--white); }
.pm-btn-delete:hover { color: var(--red); border-color: var(--red); }

/* Scrollbar global */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
