:root {
  --bg: #12161c;
  --panel: #1a2029;
  --line: #29313d;
  --text: #e6eaf0;
  --muted: #8b97a6;
  --orange: #e8622a;
  --ok: #3fb27f;
  --warn: #d9a441;
  --name: #4f9bc4;
  --question: #e8933f;
  --answer: #5b7fd4;
  --notice: #57b89b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 "Pretendard", -apple-system, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

/* 높이 사슬.
   페이지 자체는 창 높이에 딱 맞추고, 넘치는 것은 각 칸이 안에서 스크롤한다.
   중간에 min-height:0 이 하나라도 빠지면 flex 항목이 내용 높이만큼 부풀어
   화면을 밀어내고, 그러면 아래쪽(영상·목록)이 보이지 않게 된다. */
/* (실제 배치는 아래 main / #stage / #right 규칙에 있다) */

header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: none;
}
header h1 { margin: 0; font-size: 15px; letter-spacing: .02em; font-weight: 700; }
header h1 b { color: var(--orange); font-weight: 700; }
.spacer { flex: 1; }
.path { color: var(--muted); font-size: 12px; }
.conn { font-size: 12px; color: var(--muted); }
.conn.on { color: var(--ok); }
.conn.off { color: var(--orange); }

button {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: #222a35; color: var(--text); cursor: pointer; font: inherit;
}
button:hover { border-color: #3b4655; }
button.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
button:disabled { opacity: .45; cursor: default; }

/* 왼쪽 = 영상, 오른쪽 = 편집창. Vrew 처럼 자막을 오른쪽에서 표로 다룬다. */
main {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(380px, 34vw, 520px);
}
#stage {
  min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; padding: 12px; gap: 10px;
}
#right {
  min-height: 0; overflow: hidden;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--line); background: var(--panel);
}

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 11px; margin: 6px 0 2px; line-height: 1.45; }
.chk { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; white-space: nowrap; }

input[type=number], input[type=text], input[type=search], select, textarea {
  background: #12181f; color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; font: inherit;
}
input[type=range] { accent-color: var(--orange); }

/* ── 영상 + 오버레이 ───────────────────────────────────────── */
.player {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: flex-start; justify-content: center;
  background: #05070a; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
#video { max-width: 100%; max-height: 100%; display: block; }
#overlay { position: absolute; pointer-events: none; display: none; }
#overlay.on { display: block; }
#overlay.grab { pointer-events: auto; cursor: grab; }
.player.dragging { cursor: grabbing; }
.novideo { position: absolute; color: var(--muted); }

.controls { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: wrap; }
.controls button { padding: 5px 9px; }
button.play { width: 42px; font-size: 14px; }
.controls .sep { width: 1px; height: 20px; background: var(--line); }
.tc { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
#tcNow { color: var(--text); }
#loopInfo { font-size: 11px; }

/* ── 타임라인 ──────────────────────────────────────────────── */
.timeline-wrap {
  flex: none; border: 1px solid var(--line); border-radius: 8px;
  background: #151a21; overflow: hidden;
}
.ruler {
  height: 20px; position: relative; border-bottom: 1px solid var(--line);
  overflow: hidden; background: #11151b;
}
.ruler span {
  position: absolute; top: 2px; font-size: 10px; color: var(--muted);
  padding-left: 3px; border-left: 1px solid #333c49; height: 16px;
}
.tracks { position: relative; overflow-x: auto; overflow-y: auto; max-height: 132px; }
.track { display: flex; align-items: center; height: 28px; border-bottom: 1px solid #1d232c; }
.track:last-of-type { border-bottom: 0; }
.track-label {
  width: 44px; flex: none; font-size: 11px; color: var(--muted);
  padding-left: 8px; position: sticky; left: 0; background: #151a21; z-index: 2;
}
.lane { position: relative; height: 100%; flex: 1; }

.blk {
  position: absolute; top: 3px; height: 22px;
  border-radius: 4px; overflow: hidden; cursor: pointer;
  font-size: 11px; line-height: 22px; white-space: nowrap; text-overflow: ellipsis;
  padding: 0 6px; color: #0d1117; opacity: .85;
}
.blk:hover { opacity: 1; }
.blk.sel { outline: 2px solid var(--orange); outline-offset: -2px; opacity: 1; }
.blk.name { background: var(--name); }
.blk.question { background: var(--question); }
.blk.answer { background: var(--answer); color: #eaf0ff; }
.blk.notice { background: var(--notice); }
.blk.accent { background: var(--orange); color: #fff; }
.blk .h { position: absolute; top: 0; width: 6px; height: 100%; cursor: ew-resize; background: rgba(0,0,0,.28); }
.blk .h.l { left: 0; } .blk .h.r { right: 0; }

/* 오렌지 바 = 재생 헤드. 잡아 끌어 시간을 옮긴다.
   막대 자체는 2px 이라 잡기 어려우므로 좌우로 투명한 손잡이를 덧댄다. */
.playhead {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--orange); z-index: 3; cursor: ew-resize;
  box-shadow: 0 0 6px rgba(232,98,42,.7);
}
.playhead::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: -7px; right: -7px;
}
.playhead::after {
  content: ""; position: absolute; top: -1px; left: -5px;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 7px solid var(--orange);
}
.ruler { cursor: ew-resize; }
.lane { cursor: ew-resize; }
.blk { cursor: pointer; }
.loopband {
  position: absolute; top: 0; bottom: 0;
  background: rgba(232,98,42,.14);
  border-left: 1px solid var(--orange); border-right: 1px solid var(--orange);
  pointer-events: none; z-index: 1;
}
.zoom {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.zoom label { display: flex; align-items: center; gap: 8px; }
.zoom input[type=range] { width: 180px; }

#warnings { display: flex; flex-direction: column; gap: 4px; flex: none; }
.warn {
  padding: 5px 10px; border-radius: 5px; font-size: 12px;
  background: #2e2618; color: var(--warn); border: 1px solid #4a3c22;
}

/* ── 오른쪽 편집창 ─────────────────────────────────────────── */
.tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px 0; border-bottom: 1px solid var(--line); flex: none;
}
.tab {
  border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0;
  background: transparent; color: var(--muted); padding: 6px 14px; margin-bottom: -1px;
}
.tab.on {
  background: var(--bg); color: var(--text);
  border-color: var(--line); border-bottom-color: var(--bg);
}

.tabpane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tabpane.on { display: flex; }
#pane-design { overflow-y: auto; display: none; }
#pane-design.on { display: block; }

.grid-tools {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); flex: none;
}
.grid-tools input[type=search] { flex: 1; min-width: 60px; }

/* 데이터 그리드 — 행마다 썸네일 · 시각 · 자막 · 길이 */
.grid-head, .row {
  display: grid;
  grid-template-columns: 20px 80px 66px 1fr 46px;
  gap: 8px; align-items: start;
}
.c-pick { display: flex; justify-content: center; padding-top: 2px; }
.c-pick input { cursor: pointer; accent-color: var(--orange); }
.row.picked { background: #2a2620; box-shadow: inset 3px 0 0 var(--orange); }

/* 선택했을 때만 뜨는 합치기 막대 */
.sel-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; background: #23201b;
  border-bottom: 1px solid var(--line); flex: none;
  font-size: 12px; color: var(--warn);
}
.sel-bar button { padding: 4px 10px; font-size: 12px; }
.grid-head {
  padding: 6px 12px; font-size: 11px; color: var(--muted);
  border-bottom: 1px solid var(--line); flex: none; background: #161c24;
}
.grid-head span:last-child, .row .c-len { text-align: right; }

.grid { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.row {
  padding: 6px 10px; border-bottom: 1px solid #202733; cursor: pointer;
  border-left: 3px solid transparent;
}
.row:hover { background: #1f2731; }
.row.sel { background: #232f3d; border-left-color: var(--orange); }
.row.live { background: #1d2b25; border-left-color: var(--ok); }
.row.sel.live { border-left-color: var(--orange); }

.c-thumb {
  width: 80px; height: 45px; border-radius: 4px; overflow: hidden;
  background: #0b0e12; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.c-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.c-thumb .kindtag {
  position: absolute; left: 0; bottom: 0; font-size: 9px; padding: 0 4px;
  background: rgba(0,0,0,.6); color: #dbe3ec; border-radius: 0 4px 0 0;
}
.no-thumbs .c-thumb { display: none; }
.no-thumbs .grid-head, .no-thumbs .row { grid-template-columns: 20px 66px 1fr 46px; }

.c-time { font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted); line-height: 1.35; }
.c-time b, .c-time span { display: block; cursor: pointer; border-radius: 3px; padding: 0 2px; }
.c-time b { color: var(--text); font-weight: 600; }
.c-time b:hover, .c-time span:hover { background: #2b3441; color: var(--orange); }
.c-thumb { cursor: pointer; }
.c-len { font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted); }

.c-text { min-width: 0; }
.c-text .txt {
  white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.row.sel .c-text .txt { -webkit-line-clamp: unset; }
.c-text textarea {
  width: 100%; min-height: 50px; resize: vertical;
  background: #12181f; color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; padding: 6px; font: inherit;
}
.c-text input[type=text] { width: 100%; margin-top: 6px; }
.tags { display: flex; gap: 5px; align-items: center; margin-bottom: 3px; flex-wrap: wrap; }
.badge { padding: 1px 6px; border-radius: 4px; font-size: 10px; background: #2b3441; color: #b9c4d1; }
.badge.name { background: #1e3240; color: #7bb6d6; }
.badge.question { background: #3a2a1e; color: #e39a6a; }
.badge.answer { background: #232c41; color: #96acdd; }
.badge.notice { background: #1d3730; color: #7fcfb6; }
.badge.accent { background: var(--orange); color: #fff; }
.badge.over { background: #4a3c22; color: var(--warn); }

.rowedit { margin-top: 6px; }
.rowedit .times { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.rowedit .times input { width: 68px; }
.rowedit .acts { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.rowedit button { padding: 3px 8px; font-size: 11px; }

.grid-foot {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 12px; border-top: 1px solid var(--line); flex: none;
}

/* ── 디자인 패널 ───────────────────────────────────────────── */
#pane-design details { border-bottom: 1px solid var(--line); padding: 8px 12px; }
#pane-design summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
#pane-design label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 6px 0; color: var(--muted);
}
#pane-design label input[type=number],
#pane-design label input[type=text],
#pane-design label select,
#pane-design label input[type=range] { width: 130px; }
#pane-design label.row { justify-content: flex-start; }
#pane-design label.col { flex-direction: column; align-items: stretch; }
#pane-design label.col input { width: 100%; }
#tplList { width: 100%; }
.tpl-note { font-size: 11px; min-height: 30px; margin: 4px 0; line-height: 1.4; }
.tpl-actions { display: flex; gap: 6px; }
.tpl-actions button { flex: 1; padding: 4px 6px; font-size: 12px; }
.pos-presets { display: flex; gap: 6px; margin-bottom: 6px; }
.pos-presets button { flex: 1; padding: 4px 6px; font-size: 12px; }

footer {
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 7px 14px; min-height: 38px; flex: none;
}
#progressWrap { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 6px; background: #222a35; border-radius: 3px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: var(--orange); transition: width .2s; }
#progressMsg { font-size: 12px; color: var(--muted); min-width: 260px; }
#toast { font-size: 12px; color: var(--muted); }
#toast.err { color: var(--orange); }

/* 썸네일을 못 받았을 때 빈 칸이 무엇인지 알려준다 */
.c-thumb.nothumb::after {
  content: "썸네일 없음";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--muted);
}

/* ── 자막 나누기 대화상자 ─────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6,9,13,.66);
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none !important; }
.sheet {
  width: min(760px, 92vw); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.sheet-foot { display: flex; align-items: center; gap: 8px; margin-top: 14px; }

/* 어절 사이를 눌러 나눈다 */
.split-text {
  background: #12181f; border: 1px solid var(--line); border-radius: 7px;
  padding: 12px 10px; margin: 8px 0 12px; line-height: 2.2; font-size: 15px;
}
.split-text .w { padding: 2px 1px; }
.split-text .gap {
  display: inline-block; width: 14px; text-align: center; cursor: pointer;
  border-radius: 4px; color: #3d4956; user-select: none;
}
.split-text .gap::before { content: "|"; }
.split-text .gap:hover { background: var(--orange); color: #fff; }
.split-text .gap.on { background: var(--orange); color: #fff; }

.split-when { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.split-when label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.split-when input { width: 96px; }
.split-when button { padding: 4px 10px; font-size: 12px; }

.split-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.half { border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.half-head {
  padding: 6px 10px; background: #202832; font-size: 12px;
  border-bottom: 1px solid var(--line);
}
.half-body { padding: 10px; min-height: 52px; white-space: pre-wrap; word-break: break-word; }
.half-body:empty::after { content: "(비어 있음)"; color: var(--orange); }
.warn-inline { color: var(--warn); font-size: 12px; }

/* 안내 카드 행: 썸네일 자리에 무엇인지 적는다 */
.c-thumb.notice-slot {
  background: #1d3730; color: #7fcfb6;
  font-size: 11px; letter-spacing: .02em;
  border: 1px solid #2a4d43;
}

/* 편집칸 라벨 */
.field-label {
  font-size: 11px; color: var(--muted);
  margin: 6px 0 3px; letter-spacing: .02em;
}
.rowedit input[type=text] { width: 100%; }
.grid-foot select { padding: 4px 6px; }

/* 안내 카드별 배치 설정 */
.notice-set {
  margin-top: 10px; padding: 10px;
  background: #17211d; border: 1px solid #2a4d43; border-radius: 7px;
}
.notice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-bottom: 8px; }
.notice-grid label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; color: var(--muted); font-size: 11px;
}
.notice-grid input, .notice-grid select { width: 82px; }
.grid-foot { flex-wrap: wrap; }

/* 이름 로워서드 행: 썸네일 자리 표시 */
.c-thumb.slot-name {
  background: #16262e; color: #7bb6d6; border-color: #274554;
}

/* 좁은 창에서는 편집창을 아래로 내린다. 가로로 밀어 넣으면 둘 다 못 쓴다. */
@media (max-width: 1180px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  #right { border-left: 0; border-top: 1px solid var(--line); }
}

/* 창이 낮으면 타임라인을 접어 영상과 목록에 자리를 준다 */
@media (max-height: 760px) {
  .tracks { max-height: 92px; }
  .track { height: 24px; }
  #stage { padding: 8px; gap: 7px; }
}

/* 프로젝트 */
.proj { color: var(--ok); font-size: 12px; font-weight: 600; }
.proj-list {
  max-height: 46vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 7px; margin-bottom: 14px;
}
.proj-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 10px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid #202733; cursor: pointer;
}
.proj-row:last-child { border-bottom: 0; }
.proj-row:hover { background: #1f2731; }
.proj-row.cur { background: #1d2b25; box-shadow: inset 3px 0 0 var(--ok); }
.proj-name { font-weight: 600; }
.proj-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.proj-row button { padding: 4px 10px; font-size: 12px; }
.proj-empty { padding: 18px; text-align: center; color: var(--muted); }
.proj-new { border-top: 1px solid var(--line); padding-top: 10px; }
.proj-new-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.proj-new-row input[type=text] { flex: 1; }
#projNewVideo { width: 100%; }
