:root {
  --bg0: #121316;
  --bg1: #191b1f;
  --bg2: #212328;
  --bg3: #2a2d33;
  --border: #33363d;
  --border2: #3e424a;
  --text: #e7e9ec;
  --muted: #9aa1ab;
  --accent: #4f9cf9;
  --accent-soft: rgba(79, 156, 249, 0.16);
  --danger: #e5534b;
  --v1: #2f6db1;
  --v2: #7a5bb0;
  --au: #2f9e63;
  --mono: 'JetBrains Mono', monospace;
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg0);
  color: var(--text);
  display: grid;
  grid-template-rows: 52px 1fr 292px;
  height: 100vh;
  overflow: hidden;
}

button { font: inherit; }

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

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg1); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 6px; border: 2px solid var(--bg1); }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand em { font-style: normal; color: var(--accent); }
.logo { font-size: 18px; }

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

.icon-btn {
  min-width: 44px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--bg3); border-color: var(--border2); }
.icon-btn.play {
  min-width: 52px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 15px;
}
.icon-btn.play:hover { background: #63a9fb; }

.speed-group { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.speed-group .spd {
  padding: 0 10px;
  height: 32px;
  border: none;
  background: var(--bg2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.speed-group .spd:hover { color: var(--text); }
.speed-group .spd.active { background: var(--accent-soft); color: var(--accent); }

.btn {
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--bg3); }
.btn.small { padding: 5px 12px; font-size: 12px; }
.btn.export {
  background: linear-gradient(90deg, #4f9cf9, #7a5bb0);
  border: none;
  color: #fff;
  padding: 9px 18px;
}
.btn.export:hover { filter: brightness(1.1); }
.btn.danger { background: rgba(229, 83, 75, 0.14); border-color: rgba(229, 83, 75, 0.5); color: #f08a84; }
.btn.danger:hover { background: rgba(229, 83, 75, 0.24); }

/* ---------- workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 0;
}

/* media bin */
.mediabin {
  display: flex;
  flex-direction: column;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.bin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.bin-head h2 { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.bin-count { padding: 8px 14px 0; font-size: 11px; color: var(--muted); }
.bin-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.bin-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  cursor: grab;
}
.bin-item:hover { border-color: var(--border2); }
.bin-thumb {
  width: 64px;
  height: 36px;
  border-radius: 6px;
  background: var(--bg3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 14px;
}
.bin-thumb img { width: 100%; height: 100%; object-fit: cover; }
.bin-info { flex: 1; min-width: 0; }
.bin-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bin-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bin-add {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.bin-add:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.bin-hint {
  padding: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  border-top: 1px dashed var(--border);
  margin: 0 10px 10px;
  border-radius: 8px;
}
.mediabin.dragover .bin-list { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 8px; }

/* stage */
.stage {
  display: grid;
  grid-template-rows: 1fr auto auto;
  min-height: 0;
  background: var(--bg0);
}

.viewport {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, #17191d 0%, #0d0e11 100%);
  overflow: hidden;
  padding: 12px;
}
.viewport canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  background: #000;
}
.timecode {
  position: absolute;
  bottom: 18px;
  right: 20px;
  font-family: var(--mono);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.55);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

/* toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg1);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.tool {
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.tool:hover:not(:disabled) { background: var(--bg3); border-color: var(--border2); }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }
.tool.danger:disabled { opacity: 0.45; }
.sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }
.group-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.vol {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.vol output { font-family: var(--mono); font-size: 12px; min-width: 38px; text-align: right; color: var(--text); }
.vol input[type="range"]:disabled { opacity: 0.4; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 999px;
  background: var(--bg3);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg0);
}

/* transitions popover */
.trans-wrap { position: relative; }
.popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 60;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  min-width: 230px;
}
.pop-title { font-size: 11px; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.trans-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.trans-grid button {
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.trans-grid button:hover { border-color: var(--accent); background: var(--accent-soft); }
.trans-grid button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}
.pop-row select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
}

/* statusbar */
.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg1);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
}
.tc-current { color: var(--accent); font-weight: 600; }
.tc-slash { color: var(--muted); }
.tc-total { color: var(--muted); }
.status-hint { margin-left: auto; color: var(--muted); font-family: 'Inter', sans-serif; font-size: 11px; }

/* ---------- timeline ---------- */
.timeline {
  display: flex;
  flex-direction: column;
  background: var(--bg1);
  border-top: 1px solid var(--border);
  min-height: 0;
}

.tl-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.tl-legend { display: flex; gap: 6px; }
.lg { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 5px; }
.lg.v1 { background: var(--v1); color: #dbeafe; }
.lg.v2 { background: var(--v2); color: #ede9fe; }
.lg.au { background: var(--au); color: #d1fae5; }

.zoom { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.zoom input[type="range"] { width: 140px; }

.tl-scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
  position: relative;
}
.tl-content {
  position: relative;
  min-height: 100%;
  background: var(--bg1);
}

.tl-ruler {
  position: relative;
  height: 26px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  cursor: ew-resize;
  user-select: none;
}
.tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border2);
}
.tick span {
  position: absolute;
  top: 5px;
  left: 5px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}
.tick.minor { background: rgba(62, 66, 74, 0.5); }

.tl-track {
  display: grid;
  grid-template-columns: 76px 1fr;
  height: 58px;
  border-bottom: 1px solid var(--border);
  background: var(--bg1);
}
.track-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  text-align: center;
}
.track-body {
  position: relative;
  background:
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(255, 255, 255, 0.025) 79px 80px);
  cursor: crosshair;
}

.clip {
  position: absolute;
  top: 7px;
  height: 44px;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 12px;
  cursor: grab;
  user-select: none;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
.clip.video { background: linear-gradient(180deg, #3578c2, #2a5f9e); }
.clip.image { background: linear-gradient(180deg, #8a68c4, #6b4f9e); }
.clip.audio { background: linear-gradient(180deg, #34ab6c, #27824f); }
.clip.selected {
  outline: 2px solid #7fb8ff;
  box-shadow: 0 0 0 4px rgba(79, 156, 249, 0.18), 0 3px 8px rgba(0, 0, 0, 0.35);
}
.clip.dragging { opacity: 0.85; }

.clip-name {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.clip-meta {
  font-size: 10px;
  font-family: var(--mono);
  color: rgba(255, 255, 255, 0.75);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-h {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9px;
  cursor: ew-resize;
  z-index: 2;
}
.clip-h.left { left: 0; border-left: 3px solid rgba(255, 255, 255, 0.45); border-radius: 7px 0 0 7px; }
.clip-h.right { right: 0; border-right: 3px solid rgba(255, 255, 255, 0.45); border-radius: 0 7px 7px 0; }
.clip-h:hover { background: rgba(255, 255, 255, 0.18); }

.tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 2px solid #ff5c5c;
  z-index: 30;
  pointer-events: none;
}
.ph-handle {
  position: absolute;
  top: 0;
  left: -7px;
  width: 14px;
  height: 12px;
  background: #ff5c5c;
  border-radius: 3px;
  clip-path: polygon(0 0, 100% 0, 100% 55%, 50% 100%, 0 55%);
}

/* ---------- export modal ---------- */
.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 11, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 26px;
  width: min(440px, 90vw);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { font-size: 17px; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.55; }
.progress-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg3);
  overflow: hidden;
  margin-top: 18px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4f9cf9, #7a5bb0);
  border-radius: 999px;
  transition: width 0.25s;
}
.export-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
.modal-actions { display: flex; justify-content: flex-end; margin-top: 18px; }