:root {
  --bg: #0b0b0e;
  --panel: #131317;
  --panel-alt: #191920;
  --border: #232329;
  --border-strong: #34343e;
  --text: #eceef2;
  --muted: #86868f;
  --muted-dim: #57575f;
  --accent: #c24bb3;
  --accent-dim: #7b3fd4;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 7px;
  --rail-w: 68px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

a { color: #a9c7ff; text-decoration: none; }
a:hover { text-decoration: underline; }
.hint a { color: var(--muted); }

/* rail */
.rail {
  width: var(--rail-w); flex-shrink: 0; height: 100vh; position: sticky; top: 0;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: .9rem 0; gap: .3rem;
}
.rail .mark { width: 34px; height: 34px; border-radius: 8px; overflow: hidden; margin-bottom: .8rem; }
.rail .mark img { width: 100%; height: 100%; object-fit: cover; }
.rail-btn {
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; color: var(--muted); border-left: 2px solid transparent;
  transition: color .12s ease, background .12s ease;
}
.rail-btn:hover { color: var(--text); background: var(--panel-alt); text-decoration: none; }
.rail-btn.active { color: var(--accent); background: rgba(194, 75, 179, .1); }
.rail-spacer { flex: 1; }

main { flex: 1; min-width: 0; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.wrap.wide { max-width: 1320px; }

h1, h2, h3 { font-weight: 700; letter-spacing: -.01em; margin: 0 0 .9rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--border-strong); background: var(--panel-alt); color: var(--text);
  padding: .5rem .85rem; border-radius: var(--radius); font-size: .87rem; font-weight: 600;
  cursor: pointer; transition: border-color .12s ease, background .12s ease;
  font-family: inherit;
}
.btn:hover { border-color: #454550; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #17070f; }
.btn-primary:hover { background: #d05cc0; border-color: #d05cc0; }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: rgba(248, 113, 113, .08); border-color: var(--err); }
.btn-ghost { background: transparent; border-color: transparent; padding: .4rem; border-radius: var(--radius); }
.btn-ghost:hover { background: var(--panel-alt); border-color: var(--border); }
.btn-sm { padding: .35rem .6rem; font-size: .78rem; }
.btn[disabled] { opacity: .35; cursor: not-allowed; pointer-events: none; }
.icon-row { display: flex; gap: .3rem; }
.icon { flex-shrink: 0; display: block; }
form.inline { display: inline; }

/* panels / cards */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem; margin-bottom: 2rem; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-left: 2px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem;
  display: flex; flex-direction: column; gap: .55rem;
  transition: border-color .12s ease;
}
.card:hover { border-left-color: var(--accent); border-color: var(--border-strong); border-left-width: 2px; }
.card .card-title { font-weight: 700; font-size: .96rem; }
.card .card-title a { color: var(--text); }
.card .meta { color: var(--muted); font-size: .76rem; display: flex; gap: .6rem; flex-wrap: wrap; font-family: var(--mono); }
.card .meta span { display: inline-flex; align-items: center; gap: .25rem; }
.card .card-actions { display: flex; gap: .2rem; margin-top: auto; padding-top: .5rem; border-top: 1px solid var(--border); }
.new-project-card {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted-dim);
  min-height: 88px; font-weight: 600; font-size: .88rem;
}
.new-project-card:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }

/* forms */
label { display: block; margin: .85rem 0 .3rem; font-weight: 600; font-size: .82rem; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: .55rem .65rem; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: #08080a; color: var(--text); font-size: .92rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: .82rem; }
input[type=file] { padding: .45rem; font-size: .82rem; }
input[type=checkbox] { width: auto; }
.hint { color: var(--muted); font-size: .8rem; margin-top: .35rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: 1.3rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.actions-spacer { flex: 1; }

/* status pills */
.status-pill { display: inline-flex; align-items: center; gap: .4rem; padding: .18rem .55rem; border-radius: 4px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-family: var(--mono); }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-done { color: var(--ok); background: rgba(74, 222, 128, .1); }
.status-error { color: var(--err); background: rgba(248, 113, 113, .1); }
.status-review { color: var(--warn); background: rgba(251, 191, 36, .1); }
.status-queued, .status-planning, .status-generating, .status-assembling, .status-continue_requested {
  color: #7fb2ff; background: rgba(127, 178, 255, .1);
}

/* table */
table { width: 100%; border-collapse: collapse; }
td, th { padding: .55rem .5rem; border-bottom: 1px solid var(--border); text-align: left; font-size: .87rem; }
th { color: var(--muted-dim); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
td.mono, th.mono { font-family: var(--mono); }
tr:hover td { background: rgba(255, 255, 255, .012); }

.empty { color: var(--muted); padding: 2.5rem 0; text-align: center; font-size: .9rem; }
video.preview { width: 100%; max-width: 480px; border-radius: var(--radius); display: block; margin: 1rem 0; background: #000; border: 1px solid var(--border); }
.trim-box { display: flex; align-items: end; gap: .6rem; flex-wrap: wrap; }
.trim-box label { margin: 0 0 .25rem; }
.trim-box input { width: 90px; }

/* ---------- editor: preview canvas ---------- */
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }
.editor-toolbar .hint { margin: 0; }

.preview-panel { display: flex; flex-direction: column; align-items: flex-start; }
.preview-canvas {
  position: relative; width: 100%; max-width: 560px; aspect-ratio: 16/9; background: #000;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
}
.preview-canvas video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.preview-canvas .empty-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted-dim); font-size: .85rem;
}
.overlay-layer { position: absolute; inset: 0; pointer-events: none; }
.overlay-text {
  position: absolute; left: 50%; transform: translateX(-50%); max-width: 92%;
  color: #fff; font-weight: 800; font-size: clamp(.85rem, 3.2vw, 1.3rem); text-align: center;
  text-shadow: 0 2px 1px #000, 0 0 8px rgba(0,0,0,.85), 0 0 2px #000; line-height: 1.25;
}
.overlay-text.pos-top { top: 7%; }
.overlay-text.pos-center { top: 50%; transform: translate(-50%, -50%); }
.overlay-text.pos-bottom { bottom: 9%; }

.preview-controls { display: flex; align-items: center; gap: .75rem; margin-top: .65rem; }
.play-btn {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--accent); border: 0; color: #17070f; cursor: pointer; flex-shrink: 0;
}
.play-btn:hover { background: #d05cc0; }
.time-display { font-family: var(--mono); font-size: .82rem; color: var(--muted); }

/* ---------- editor: tracks ---------- */
.zoom-controls { display: flex; align-items: center; gap: .2rem; }
.zoom-controls .zoom-pct { font-family: var(--mono); font-size: .76rem; color: var(--muted-dim); width: 3.2rem; text-align: center; }

.tracks-wrap { border: 1px solid var(--border); border-radius: var(--radius); margin-top: 1rem; overflow: hidden; }
.tracks-scroll { overflow-x: auto; position: relative; }
.tracks-grid { position: relative; display: flex; flex-direction: column; align-items: flex-start; }

.track-row { display: flex; border-bottom: 1px solid var(--border); }
.track-row:last-child { border-bottom: 0; }
.track-label {
  position: sticky; left: 0; z-index: 6; width: 78px; flex-shrink: 0; background: var(--panel-alt);
  border-right: 1px solid var(--border); display: flex; align-items: center; padding: 0 .6rem;
  font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-dim);
}
.track-content { position: relative; flex-shrink: 0; }

.ruler-row .track-content { height: 22px; }
.ruler-row .tick {
  position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); padding-left: 3px;
  display: flex; align-items: center; color: var(--muted-dim); font-size: .68rem; font-family: var(--mono);
}

.video-row .track-content { height: 76px; padding: 3px 0; display: flex; align-items: stretch; }
.text-row .track-content { height: 44px; }
.music-row .track-content { height: 34px; }

.playhead-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 10; pointer-events: none; }
.playhead-grip {
  position: absolute; top: -1px; width: 13px; height: 13px; margin-left: -6px; background: var(--accent);
  border-radius: 3px 3px 3px 0; transform: rotate(45deg); z-index: 11; cursor: ew-resize; pointer-events: auto;
}

.clip {
  position: relative; flex-shrink: 0; height: 100%; overflow: hidden;
  background: #000 center/cover no-repeat; border: 1px solid var(--border-strong);
  cursor: grab; transition: box-shadow .1s ease, border-color .1s ease; box-sizing: border-box;
}
.clip:active { cursor: grabbing; }
.clip.dragging { opacity: .35; }
.clip.selected { border-color: var(--accent); }

.clip .clip-shade {
  position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(to top, rgba(0,0,0,.85) 0%, transparent 80%);
  padding: .2rem .35rem;
}
.clip .clip-dur { font-size: .64rem; color: #e4e4ea; font-family: var(--mono); }
.clip .talking-badge { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); border-radius: 3px; padding: 1px 4px; font-size: .58rem; z-index: 4; }

.clip .trim-shade { position: absolute; top: 0; bottom: 0; background: rgba(0,0,0,.72); z-index: 2; }
.clip .trim-shade.left { left: 0; }
.clip .trim-shade.right { right: 0; }

.clip .handle { position: absolute; top: 0; bottom: 0; width: 8px; z-index: 3; cursor: ew-resize; display: flex; align-items: center; justify-content: center; }
.clip .handle::after { content: ""; width: 3px; height: 60%; background: var(--accent); border-radius: 2px; opacity: 0; transition: opacity .1s ease; }
.clip:hover .handle::after, .clip .handle.active::after { opacity: 1; }
.clip .handle.left { left: 0; }
.clip .handle.right { right: 0; }

.clip .clip-tools { position: absolute; top: 2px; left: 2px; z-index: 4; display: flex; gap: 2px; opacity: 0; transition: opacity .1s ease; }
.clip:hover .clip-tools { opacity: 1; }
.clip .clip-tools button {
  width: 17px; height: 17px; border-radius: 3px; border: 0; background: rgba(0,0,0,.65); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.clip .clip-tools button:hover { background: rgba(0,0,0,.9); }
.clip.regenerating { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

.overlay-block {
  position: absolute; top: 4px; bottom: 4px; border-radius: 4px; cursor: grab;
  background: rgba(194, 75, 179, .22); border: 1px solid rgba(194, 75, 179, .55);
  color: #f0d6ec; font-size: .7rem; padding: .2rem .4rem; overflow: hidden; white-space: nowrap;
}
.overlay-block:active { cursor: grabbing; }
.overlay-block.selected { border-color: var(--accent); background: rgba(194, 75, 179, .35); }
.overlay-block.dragging { opacity: .5; }
.add-overlay-btn {
  position: absolute; top: 4px; right: 6px; z-index: 5;
}

.music-bar {
  position: absolute; top: 6px; bottom: 6px; border-radius: 4px; background: rgba(74, 222, 128, .14);
  border: 1px solid rgba(74, 222, 128, .4); color: #bdf3cf; font-size: .72rem; display: flex; align-items: center;
  padding: 0 .5rem; overflow: hidden; white-space: nowrap;
}

.removed-tray { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.removed-chip {
  display: flex; align-items: center; gap: .4rem; background: var(--panel-alt); border: 1px solid var(--border);
  border-radius: 6px; padding: .3rem .3rem .3rem .5rem; font-size: .78rem; color: var(--muted);
}
.removed-chip button { background: none; border: 0; color: var(--muted); cursor: pointer; display: flex; }
.removed-chip button:hover { color: var(--text); }

.overlay-editor {
  display: none; margin-top: 1rem; gap: .75rem; align-items: end; flex-wrap: wrap;
}
.overlay-editor.open { display: flex; }
.overlay-editor .field { display: flex; flex-direction: column; }
.overlay-editor label { margin: 0 0 .25rem; }
.overlay-editor input[type=number] { width: 80px; }
.overlay-editor input[type=text] { width: 260px; }
.overlay-editor select { width: 110px; }

.continue-bar { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 60%, transparent); padding: 1.25rem 0 .5rem; margin-top: 1rem; display: flex; justify-content: flex-end; gap: .6rem; }
