:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --filled: #b45309;
  --filled-soft: #fff7e6;
  --active: #fff3c4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --line: #2a2f3a;
    --accent: #6b9bff;
    --accent-soft: #1d2a45;
    --filled: #f0b45a;
    --filled-soft: #2b2416;
    --active: #3a3418;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.url-form { flex: 1; display: flex; gap: 10px; align-items: center; }
.url-form input[type=text] {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 15px;
}
.url-form input[type=text]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn, .controls button {
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text);
  padding: 8px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; color: var(--muted); white-space: nowrap; cursor: pointer; }

.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr);
  gap: 20px; padding: 20px;
}

.video-col { min-width: 0; overflow-y: auto; }
.player-wrap {
  position: relative; aspect-ratio: 16 / 9;
  background: #000; border-radius: 12px; overflow: hidden;
}
.player-wrap iframe, #player, #html5Video { position: absolute; inset: 0; width: 100%; height: 100%; }
#html5Video { background: #000; }
.player-wrap.mode-html #player { display: none; }
.player-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #9aa1ad; font-size: 15px;
}
.video-meta h1 { font-size: 18px; margin: 14px 0 2px; }
.video-meta p { margin: 0; color: var(--muted); font-size: 14px; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 24px; margin-top: 14px; }
.ctrl-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ctrl-label { color: var(--muted); font-size: 14px; margin-right: 4px; }
.controls button { padding: 6px 11px; }
.controls button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.script-col {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden;
}
.script-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.toolbar-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.select-label { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.select-label select {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 14px;
}
.script-sub {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.sub-opts { display: inline-flex; gap: 14px; }
.sub-opts .chk { font-size: 13px; }

.status { padding: 18px; color: var(--muted); }
.status:empty { display: none; }
.status .hint { margin: 0; line-height: 1.8; }
.status .error { color: #dc2626; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.script { list-style: none; margin: 0; padding: 6px 0 40vh; overflow-y: auto; flex: 1; position: relative; }

/* 화자별 묶음 */
.script .turn {
  --spk: var(--line);
  margin: 6px 12px 12px;
  padding: 4px 0 4px 10px;
  border-left: 3px solid var(--spk);
}
.turn-head { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px 4px; }
.spk {
  border: 0; border-radius: 999px; padding: 1px 10px;
  background: var(--spk); color: #fff;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.spk:hover { filter: brightness(1.1); }
.script .time { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; cursor: pointer; }
.script .time:hover { color: var(--accent); }

/* 문장 */
.sent { padding: 5px 8px; border-radius: 6px; cursor: pointer; border-left: 2px solid transparent; }
.sent:hover { background: var(--bg); }
.sent.active { background: var(--active); }
.sent.filled { border-left-color: var(--filled); }
.script .orig { font-size: 15.5px; }
.script .trans { color: var(--muted); font-size: 14px; margin-top: 2px; }
.sent.active .orig { font-weight: 600; }
.script.hide-orig .orig { display: none; }
.script.hide-orig .trans { color: var(--text); font-size: 15.5px; margin-top: 0; }
.script.hide-trans .trans { display: none; }
.badge {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  font-size: 11px; font-weight: 600; line-height: 18px; vertical-align: 1px;
  color: var(--filled); background: var(--filled-soft); border-radius: 4px;
}

.badge.mine { color: var(--accent); background: var(--accent-soft); }

/* 문장 고치기 · 받아쓰기 빈칸 */
.sent .edit {
  margin-left: 6px; padding: 0 5px; border: 0; border-radius: 4px;
  background: none; color: var(--muted); font-size: 13px; cursor: pointer;
  opacity: 0;
}
.sent:hover .edit, .sent.active .edit, .sent .edit:focus-visible { opacity: 1; }
.sent .edit:hover { color: var(--accent); background: var(--accent-soft); }
@media (hover: none) { .sent .edit { opacity: .6; } }
.sent.gap { border: 1px dashed var(--line); border-left: 2px dashed var(--accent); margin: 4px 0; }
.gap-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.gap-none {
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px;
  background: var(--panel); color: var(--muted); font-size: 12px; cursor: pointer; white-space: nowrap;
}
.gap-none:hover { color: var(--text); }
.edit-input {
  width: 100%; margin-top: 4px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); font: inherit; font-size: 15px;
}
.edit-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.link-btn { border: 0; padding: 0; background: none; color: var(--accent); font-size: 13px; cursor: pointer; }

/* 유튜브 대본 붙여넣기 */
.paste textarea {
  width: 100%; margin-top: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font: 13.5px/1.5 ui-monospace, Consolas, monospace; resize: vertical;
}
.paste textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.paste-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.paste a { color: var(--accent); }
a.bookmarklet {
  display: inline-block; padding: 2px 12px; border-radius: 999px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13.5px;
  text-decoration: none; cursor: grab; white-space: nowrap;
}
a.bookmarklet:active { cursor: grabbing; }
.sub-hint { display: inline-block; margin-top: 6px; font-size: 13px; }
.paste .link-btn { font-size: 13px; text-decoration: underline; }
.status .error + .paste { margin-top: 10px; }

.site-footer {
  padding: 0 20px 12px; font-size: 12.5px; color: var(--muted); text-align: center;
}
.site-footer a, .doc a { color: var(--accent); }
.doc { max-width: 720px; margin: 0 auto; padding: 32px 20px 60px; line-height: 1.75; }
.doc h1 { font-size: 24px; }
.doc h2 { font-size: 17px; margin-top: 28px; }

@media (max-width: 900px) {
  html, body { height: auto; }
  body { display: block; }
  .script-toolbar { flex-wrap: wrap; }
  .select-label select { max-width: 52vw; }
  .site-footer { padding: 4px 16px 20px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 16px; }
  .url-form { flex-wrap: wrap; }
  .url-form input[type=text] { flex-basis: 100%; }
  .layout { grid-template-columns: 1fr; padding: 12px 16px; gap: 12px; }
  .video-col { overflow: visible; }
  .script-col { height: 75vh; }
}
