:root {
  --bg: #0b0d11;
  --bg-2: #0f1218;
  --panel: #14171d;
  --card: #191d25;
  --card-2: #1f242e;
  --line: #262c36;
  --line-2: #333b48;
  --txt: #e8ecf2;
  --muted: #8b93a2;
  --muted-2: #6b7383;
  --accent: #f2b651;
  --accent-ink: #241a06;
  --mint: #6ee7b7;
  --red: #f2705a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic",
    system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(242, 182, 81, .08), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(110, 231, 183, .06), transparent 55%),
    var(--bg);
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── 상단 바 ─────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(11, 13, 17, .86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 auto; overflow: hidden; }

.logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(150deg, var(--accent), #c98a2c);
  color: var(--accent-ink);
  font-size: 13px;
  padding-left: 2px;
  box-shadow: 0 4px 14px rgba(242, 182, 81, .25);
  flex: none;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; flex: 0 1 auto; }
.brand-text strong { font-size: 16px; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: var(--muted); font-size: 11.5px; white-space: nowrap; }

.proj-meta {
  margin-left: auto;
  flex: none;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── 버튼 ────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--card-2);
  color: var(--txt);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #262c38; border-color: #3d4657; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, #f7c266, var(--accent));
  color: var(--accent-ink);
  border-color: #d99f38;
}
.btn.primary:hover { background: linear-gradient(180deg, #ffd07a, #f5bd58); }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, .06); }
.btn.ghost.on { border-color: var(--accent); color: var(--accent); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: var(--red); border-color: rgba(242, 112, 90, .4); }
.btn.danger:hover { background: rgba(242, 112, 90, .12); }
.btn.wide { width: 100%; padding: 13px; font-size: 15px; margin-top: 6px; }

.btn.icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #f7c266, var(--accent));
  color: var(--accent-ink);
  border: none;
  flex: none;
}

/* ── 레이아웃 ────────────────────────────── */
.studio {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(380px, 460px);
  gap: 18px;
  align-items: start;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 18px 40px;
}

.stage { min-width: 0; }

/* ── 프리뷰 ──────────────────────────────── */
.preview-shell {
  display: flex;
  justify-content: center;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(0, 0, 0, .25)), var(--bg-2);
  border: 1px solid var(--line);
}

.preview-frame {
  position: relative;
  aspect-ratio: 9 / 16;
  height: min(62vh, 620px);
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
}

#preview { display: block; width: 100%; height: 100%; }

.preview-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
  background: repeating-linear-gradient(45deg, #0c0e12 0 12px, #0e1015 12px 24px);
}
.preview-hint b { color: var(--txt); font-size: 15px; display: block; }
.preview-hint.hide { display: none; }

.preview-tag {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  color: #cfd6e2;
  font-size: 11px;
  letter-spacing: .3px;
  pointer-events: none;
}

/* ── 재생 컨트롤 ─────────────────────────── */
.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.timecode {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  display: flex;
  gap: 5px;
}
.timecode b { color: var(--txt); font-weight: 700; }
.timecode i { font-style: normal; opacity: .5; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  min-width: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #2c333f;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a1d24;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: #2c333f; }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 2px solid #1a1d24;
}

/* ── 타임라인 ────────────────────────────── */
.timeline {
  position: relative;
  margin-top: 12px;
  padding: 6px 10px 10px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.tl-ruler {
  position: relative;
  height: 16px;
  color: var(--muted-2);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.tl-ruler span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}
.tl-ruler span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 13px;
  width: 1px;
  height: 4px;
  background: var(--line-2);
}

.tl-lane {
  position: relative;
  height: 26px;
  margin-top: 5px;
  border-radius: 7px;
  background: #101319;
  overflow: hidden;
}
.tl-lane.subs { height: 16px; }
.tl-lane.bgm { height: 9px; }

.seg {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 6px;
  background: linear-gradient(180deg, #2f3a4c, #263040);
  border: 1px solid #3a465a;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 10.5px;
  color: #cfd6e2;
  white-space: nowrap;
}
.seg + .seg { margin-left: 0; }
.seg.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(242, 182, 81, .35); }
.seg.drop { opacity: .55; }
.seg .name { overflow: hidden; text-overflow: ellipsis; }

.subbar {
  position: absolute;
  top: 2px;
  bottom: 2px;
  border-radius: 4px;
  background: rgba(110, 231, 183, .55);
  border: 1px solid rgba(110, 231, 183, .8);
  overflow: hidden;
  font-size: 9px;
  color: #04241a;
  padding: 0 3px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.subbar.active { background: rgba(110, 231, 183, .9); }

.bgmbar {
  position: absolute;
  top: 1px;
  bottom: 1px;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, rgba(242, 182, 81, .45) 0 6px, rgba(242, 182, 81, .28) 6px 12px);
  border: 1px solid rgba(242, 182, 81, .55);
}

.tl-playhead {
  position: absolute;
  top: 6px;
  bottom: 8px;
  width: 2px;
  background: var(--red);
  border-radius: 2px;
  pointer-events: none;
  transform: translateX(-1px);
}
.tl-playhead::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
}

.tl-note {
  margin: 8px 2px 0;
  color: var(--muted-2);
  font-size: 11.5px;
}

/* ── 우측 패널 ───────────────────────────── */
.panel {
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  background: #101319;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 53px;
  z-index: 5;
}
.tab {
  flex: 1;
  appearance: none;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 6px 11px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.on { color: var(--txt); border-bottom-color: var(--accent); }
.tab .cnt {
  display: inline-block;
  min-width: 17px;
  padding: 1px 5px;
  margin-left: 2px;
  border-radius: 9px;
  background: #262c38;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  vertical-align: 1px;
}
.tab.on .cnt { background: rgba(242, 182, 81, .18); color: var(--accent); }

.pane { display: none; padding: 14px; }
.pane.on { display: block; }

.pane-head, .clip-card, .sub-card, .bgm-card, .empty { scroll-margin-top: 66px; }

/* 데스크톱: 패널은 화면에 고정, 내용만 스크롤 */
@media (min-width: 1081px) {
  .panel {
    position: sticky;
    top: 70px;
    max-height: calc(100vh - 88px);
    display: flex;
    flex-direction: column;
  }
  .tabs { position: static; flex: none; }
  .pane {
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1 1 auto;
  }
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.pane-head h2 { margin: 0; font-size: 14.5px; letter-spacing: -.2px; }

.hint { margin: 4px 0 12px; color: var(--muted-2); font-size: 12px; line-height: 1.5; }

.empty {
  display: grid;
  gap: 4px;
  padding: 18px 14px;
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}
.empty b { color: var(--txt); font-size: 13px; }
.empty.hide { display: none; }

/* ── 클립 카드 ───────────────────────────── */
.clip-list { display: grid; gap: 10px; }

.clip-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
}
.clip-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(242, 182, 81, .25); }

.clip-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--card-2);
}
.clip-idx {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #2b3342;
  color: #cfd6e2;
  font-size: 11px;
  font-weight: 700;
  flex: none;
}
.thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: #0c0e12;
  flex: none;
  border: 1px solid var(--line-2);
}
.clip-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-name small { display: block; color: var(--muted-2); font-size: 10.5px; }

.icon-row { display: flex; gap: 3px; flex: none; }
.icon-btn {
  width: 27px;
  height: 27px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: #232936;
  color: #c3cbd8;
  cursor: pointer;
  font-size: 12px;
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn:hover { background: #2d3543; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.danger { color: var(--red); border-color: rgba(242, 112, 90, .35); }

.clip-body { padding: 10px; display: grid; gap: 9px; }

.field { display: grid; gap: 3px; }
.field > span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11.5px;
}
.field output { color: var(--txt); font-variant-numeric: tabular-nums; font-size: 11.5px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

.segmented {
  display: flex;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  overflow: hidden;
  background: #12151b;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 4px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button.on { background: rgba(242, 182, 81, .16); color: var(--accent); }

select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: #12151b;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--txt);
  outline: none;
}
select:focus, input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 54px; line-height: 1.4; }

input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  background: #12151b;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  cursor: pointer;
}

.check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }

/* ── 자막 카드 ───────────────────────────── */
.card-list { display: grid; gap: 10px; }

.sub-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 10px;
  display: grid;
  gap: 9px;
}
.sub-card.active { border-color: rgba(110, 231, 183, .7); }

.sub-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.sub-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); flex: none; }
.sub-head .time { font-variant-numeric: tabular-nums; color: var(--txt); }
.sub-head .spacer { flex: 1; }

/* ── BGM ─────────────────────────────────── */
.bgm-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 12px;
  display: grid;
  gap: 10px;
}
.bgm-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bgm-title b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 내보내기 ────────────────────────────── */
.field-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}
.field-row label { color: var(--muted); font-size: 12.5px; }

.progress {
  height: 7px;
  margin-top: 12px;
  border-radius: 4px;
  background: #1b1f27;
  overflow: hidden;
}
.progress .bar {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), #ffd98a);
  transition: width .2s;
}
.progress.busy .bar {
  width: 35% !important;
  animation: slide 1.1s ease-in-out infinite alternate;
}
@keyframes slide { from { margin-left: 0; } to { margin-left: 65%; } }

.exp-status { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 17px; }
.exp-status.ok { color: var(--mint); }
.exp-status.err { color: var(--red); }

.log {
  display: none;
  margin: 10px 0 0;
  max-height: 150px;
  overflow: auto;
  padding: 8px 10px;
  border-radius: 9px;
  background: #0c0e12;
  border: 1px solid var(--line);
  color: var(--muted-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.log.show { display: block; }

.exp-result { margin-top: 10px; }
.exp-result .ok-card {
  border: 1px solid rgba(110, 231, 183, .45);
  background: rgba(110, 231, 183, .07);
  border-radius: 11px;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.exp-result video { width: 100%; border-radius: 9px; background: #000; max-height: 260px; }
.exp-result .meta { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.exp-result a.btn { display: inline-block; text-align: center; text-decoration: none; }

/* ── 미디어 호스트·오버레이 ───────────────── */
.media-host {
  position: fixed;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  opacity: .01;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}
.media-host video, .media-host audio { width: 2px; height: 2px; }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  place-items: center;
  background: rgba(11, 13, 17, .82);
  border: 3px dashed var(--accent);
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
}
.drop-overlay.on { display: grid; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  z-index: 99;
  padding: 10px 16px;
  border-radius: 10px;
  background: #232a35;
  color: var(--txt);
  border: 1px solid var(--line-2);
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(90vw, 460px);
  text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ── 반응형 ──────────────────────────────── */
@media (max-width: 1080px) {
  .studio {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px 12px 32px;
    gap: 12px;
  }
  .preview-frame { height: min(52vh, 520px); }
  .tabs { position: static; }
  .panel { border-radius: var(--radius); }
}

@media (max-width: 760px) {
  html, body { font-size: 14.5px; }
  #btnExportTop { margin-left: auto; }
  .topbar { gap: 8px; padding: 9px 12px; }
  .brand-text small { display: none; }
  .brand-text strong { font-size: 15px; }
  .proj-meta { font-size: 11.5px; }
  .btn { padding: 8px 11px; font-size: 12.5px; }
  #btnExportTop { padding: 8px 11px; font-size: 12.5px; flex: none; }
  .topbar { flex-wrap: nowrap; }

  .preview-shell { padding: 8px; }
  .preview-frame { height: min(52vh, 520px); }
  .transport { gap: 8px; padding: 8px; }
  .btn.icon { width: 40px; height: 40px; }
  .timecode { font-size: 12px; }
  .tl-note { display: none; }
  .timeline { padding: 5px 8px 8px; }
  .tl-lane { height: 22px; }

  .pane { padding: 12px; }
  .tabs { padding: 6px 6px 0; }
  .tab { padding: 9px 4px 10px; font-size: 12.5px; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .studio { padding: 8px 10px 28px; }
}

@media (max-width: 430px) {
  .proj-meta { display: none; }
  .brand-text strong { font-size: 14.5px; }
  .preview-frame { height: min(52vh, 460px); }
  .field-row { grid-template-columns: 66px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
