:root {
  --bg: #0f0f0f;
  --surface: #212121;
  --surface-2: #272727;
  --surface-3: #3f3f3f;
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --line: #3a3a3a;
  --accent: #3ea6ff;
  --chip: #2a2a2a;
  --chip-active: #4a3328;
  --progress: #e8e8e8;
  --player-h: 56.25vw;
  --side-w: 420px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.muted { color: var(--text-2); font-weight: 400; }

/* ── 레이아웃 (모바일 기본) ─────────────────────────── */
.app { max-width: 720px; margin: 0 auto; }
.main { min-width: 0; }
.desktop-only { display: none; }

/* ── 플레이어 ─────────────────────────────────────── */
.player {
  position: sticky; top: 0; z-index: 20;
  aspect-ratio: 16 / 9; width: 100%;
  background: #000; overflow: hidden;
}
.player-img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .15s; }
.overlay-tl {
  position: absolute; left: 3%; top: 4%;
  white-space: pre-line; font-size: clamp(9px, 2.1vw, 15px); line-height: 1.25;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6);
  pointer-events: none;
}
.overlay-tl:empty { display: none; }
.caption {
  position: absolute; left: 50%; bottom: 10%; transform: translateX(-50%);
  max-width: 88%; text-align: center;
  font-size: clamp(12px, 2.6vw, 20px); line-height: 1.35;
  color: #fff; text-shadow: 0 0 3px #000, 0 1px 2px #000;
  pointer-events: none;
}
.caption.off, .caption:empty { display: none; }
.player-time {
  position: absolute; left: 10px; bottom: 12px;
  font-size: 12px; color: #fff; text-shadow: 0 1px 2px #000;
  opacity: 0; transition: opacity .2s;
}
.cc-btn {
  position: absolute; right: 10px; top: 10px;
  font-size: 11px; font-weight: 700; padding: 3px 6px; border-radius: 4px;
  background: rgba(0,0,0,.45); color: #fff; opacity: 0; transition: opacity .2s;
}
.cc-btn[aria-pressed="false"] { color: #999; text-decoration: line-through; }
.player:hover .player-time, .player:hover .cc-btn, .player.show-ui .player-time, .player.show-ui .cc-btn { opacity: 1; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 14px; cursor: pointer; }
.progress::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.25); }
.progress-fill { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--progress); width: 0; transition: width .2s; }
.progress-knob {
  position: absolute; bottom: -4px; width: 11px; height: 11px; margin-left: -5px;
  border-radius: 50%; background: var(--progress); opacity: 0; transition: left .2s, opacity .2s;
}
.player:hover .progress-knob, .player.show-ui .progress-knob { opacity: 1; }

/* ── 영상 정보 ─────────────────────────────────────── */
.info { padding: 12px 12px 96px; }
.title { font-size: 18px; line-height: 1.35; font-weight: 600; margin: 0 0 6px; }
.meta { font-size: 12px; color: var(--text-2); }
.channel-row { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--surface-3); flex: none; }
.channel-text { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.channel-name { font-weight: 600; font-size: 15px; }
.channel-subs { font-size: 12px; color: var(--text-2); }
.subscribe { background: #f1f1f1; color: #0f0f0f; font-weight: 600; font-size: 14px; padding: 8px 16px; border-radius: 999px; }

.actions { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -12px 12px; padding: 0 12px; }
.actions::-webkit-scrollbar { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--surface-2); font-size: 14px; font-weight: 500;
}
.pill svg { width: 20px; height: 20px; }
.like-pill { padding: 0; gap: 0; }
.pill-part { display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; }
.pill-sep { width: 1px; height: 22px; background: var(--surface-3); }

.card { display: block; width: 100%; text-align: left; background: var(--surface-2); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.card:hover { background: #2f2f2f; }
.desc-meta { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.desc-preview { font-size: 14px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.more { font-size: 14px; font-weight: 600; }
.cc-head { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.cc-first { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.cc-first span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cc-first .mini-av { width: 24px; height: 24px; font-size: 11px; }

/* ── 시트 (모바일: 플레이어 아래 바텀시트) ─────────────── */
.sheet {
  position: fixed; z-index: 30;
  left: 50%; width: 100%; max-width: 720px; transform: translate(-50%, 100%);
  top: var(--player-h); bottom: 0;
  background: var(--bg); border-radius: 14px 14px 0 0;
  display: flex; flex-direction: column;
  transition: transform .28s cubic-bezier(.2,.8,.2,1), visibility .28s;
  visibility: hidden;
}
.sheet.open { transform: translate(-50%, 0); visibility: visible; }
.grabber { width: 40px; height: 4px; border-radius: 2px; background: #5a5a5a; margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 10px 16px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { font-size: 20px; font-weight: 700; margin: 0; }
.sheet-head .spacer { flex: 1; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }
.sheet-body { position: relative; flex: 1; overflow-y: auto; padding: 12px 16px 32px; overscroll-behavior: contain; }

/* ── 스크립트 ─────────────────────────────────────── */
.search-wrap { padding: 14px 16px 6px; flex: none; }
.search {
  width: 100%; height: 44px; border-radius: 22px; border: 0; outline: 0;
  background: var(--surface-2); color: var(--text); padding: 0 20px; font-size: 16px;
}
.search::placeholder { color: var(--text-2); }
.search:focus { box-shadow: 0 0 0 1px #555 inset; }
.transcript { position: relative; flex: 1; overflow-y: auto; padding: 4px 16px 40px; overscroll-behavior: contain; scroll-behavior: smooth; }
.seg {
  display: block; width: 100%; text-align: left;
  padding: 10px 0; font-size: 17px; line-height: 1.5; color: #d9d9d9;
  border-radius: 8px;
}
.seg:hover { background: rgba(255,255,255,.04); }
.ts {
  display: inline-block; vertical-align: 1px;
  font-size: 14px; font-variant-numeric: tabular-nums; color: #e8e8e8;
  background: var(--chip); border-radius: 8px; padding: 2px 7px; margin-right: 8px;
}
.seg.active { color: #fff; font-weight: 700; }
.seg.active .ts { background: var(--chip-active); font-weight: 500; }
.seg mark { background: #6b5a1f; color: #fff; border-radius: 2px; }
.seg .has-img { font-size: 12px; color: var(--text-2); margin-left: 6px; }
.empty { color: var(--text-2); text-align: center; padding: 40px 0; font-size: 14px; }

/* ── 댓글 ─────────────────────────────────────────── */
.comment { display: flex; gap: 12px; padding: 10px 0; }
.comment.linked { cursor: pointer; border-radius: 8px; }
.comment.linked:hover { background: rgba(255,255,255,.04); }
.comment.linked:focus-visible { outline: 1px solid #555; }
.mini-av {
  width: 36px; height: 36px; border-radius: 50%; flex: none; object-fit: cover;
  display: grid; place-items: center; font-weight: 600; font-size: 15px; color: #fff;
}
.comment-body { min-width: 0; flex: 1; }
.comment-meta { font-size: 12px; color: var(--text-2); margin-bottom: 2px; }
.comment-meta b { color: var(--text); font-weight: 500; margin-right: 4px; }
.pinned { font-size: 12px; color: var(--text-2); margin-bottom: 2px; }
.comment-text { font-size: 14px; line-height: 1.45; white-space: pre-line; word-break: break-word; }
.comment-text .tlink { color: var(--accent); cursor: pointer; }
.comment-foot { display: flex; align-items: center; gap: 16px; margin-top: 6px; font-size: 12px; color: var(--text-2); }
.comment-foot svg { width: 16px; height: 16px; }
.comment-foot span { display: inline-flex; align-items: center; gap: 4px; }
.replies { color: var(--accent); font-weight: 600; font-size: 14px; margin-top: 6px; display: inline-block; }
.section-title { font-size: 20px; margin: 24px 0 8px; }

/* ── 설명 ─────────────────────────────────────────── */
.desc-title { font-size: 18px; line-height: 1.35; margin: 4px 0 12px; }
.desc-stats { display: flex; gap: 24px; padding: 12px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.desc-stats div { text-align: center; }
.desc-stats b { display: block; font-size: 17px; }
.desc-stats small { color: var(--text-2); font-size: 12px; }
.desc-full { font-size: 14px; line-height: 1.6; white-space: pre-line; word-break: break-word; }
.desc-full .tag { color: var(--accent); }

/* ── 편집 모드 ─────────────────────────────────────── */
.edit-only { display: none !important; }
body.editing .edit-only { display: flex !important; }
.edit-bar {
  position: fixed; z-index: 50; left: 50%; bottom: 16px; transform: translateX(-50%);
  gap: 6px; align-items: center; padding: 6px; border-radius: 999px;
  background: #1d1d1d; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.5);
  max-width: calc(100vw - 16px); overflow-x: auto;
}
.edit-bar button { padding: 8px 12px; border-radius: 999px; background: var(--surface-2); font-size: 13px; white-space: nowrap; }
.edit-bar button.primary { background: var(--accent); color: #031525; font-weight: 600; }
.edit-badge { font-size: 12px; color: #ffb86b; padding: 0 8px; white-space: nowrap; }
body.editing .transcript, body.editing .sheet-body { padding-bottom: 110px; }
@media (max-width: 480px) {
  .edit-badge { display: none; }
  .edit-bar { bottom: 10px; gap: 4px; padding: 4px; }
  .edit-bar button { padding: 7px 10px; font-size: 12px; }
  .seg-edit { grid-template-columns: 64px 1fr; }
}

.seg-edit { display: grid; grid-template-columns: 74px 1fr; gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid #222; }
.seg-edit.active .ts-in { background: var(--chip-active); }
.ts-in, .field input, .field textarea, .seg-edit textarea, .img-in {
  background: var(--surface-2); color: var(--text); border: 1px solid transparent; border-radius: 8px;
  font: inherit; outline: 0;
}
.ts-in { font-size: 14px; padding: 6px 8px; height: 34px; text-align: center; font-variant-numeric: tabular-nums; }
.seg-edit textarea { font-size: 15px; line-height: 1.45; padding: 6px 10px; resize: vertical; min-height: 34px; }
.ts-in:focus, .field input:focus, .field textarea:focus, .seg-edit textarea:focus, .img-in:focus { border-color: #555; }
.ts-in.bad { border-color: #e05555; }
.seg-tools { grid-column: 2; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.seg-tools button, .field-row button, .add-btn {
  font-size: 12px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2);
}
.seg-tools button:hover, .field-row button:hover, .add-btn:hover { color: var(--text); background: var(--surface-3); }
.seg-tools .danger:hover { color: #ff8a8a; }
.img-in { flex: 1; min-width: 120px; font-size: 12px; padding: 5px 8px; }
.thumb { width: 48px; height: 27px; object-fit: cover; border-radius: 4px; background: #000; }
.add-btn { display: block; width: 100%; margin: 12px 0; padding: 10px; font-size: 14px; border: 1px dashed #444; background: transparent; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.field input, .field textarea { width: 100%; padding: 8px 10px; font-size: 14px; }
.field textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
.field-row { display: flex; gap: 6px; align-items: center; }
.field-row input { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.edit-group { font-size: 15px; font-weight: 700; margin: 22px 0 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.edit-group:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.comment-edit { background: #181818; border-radius: 10px; padding: 12px; margin-bottom: 10px; }

.toast {
  position: fixed; z-index: 60; left: 50%; bottom: 80px; transform: translate(-50%, 20px);
  background: #f1f1f1; color: #0f0f0f; font-size: 14px; padding: 10px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 데스크톱: 스크립트를 오른쪽에 고정 ─────────────────── */
@media (min-width: 1100px) {
  .app {
    max-width: 1600px; padding: 24px; display: grid;
    grid-template-columns: minmax(0, 1fr) var(--side-w); gap: 24px; align-items: start;
  }
  .player { position: relative; border-radius: 12px; }
  .info { padding: 12px 0 96px; }
  .title { font-size: 20px; }
  .actions { margin: 0 0 12px; padding: 0; }
  .mobile-only { display: none !important; }
  .desktop-only { display: block; }
  .sheet.side {
    position: sticky; top: 24px; transform: none; visibility: visible;
    left: auto; width: auto; max-width: none; height: calc(100vh - 48px);
    border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  }
  .sheet.side .grabber { display: none; }
  .sheet.side .sheet-head { padding: 12px 8px 12px 16px; }
  .sheet:not(.side) {
    left: auto; right: 24px; top: 24px; bottom: 24px; width: var(--side-w); max-width: none;
    transform: translateX(calc(100% + 40px)); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,.6);
  }
  .sheet:not(.side).open { transform: none; }
  .sheet:not(.side) .grabber { display: none; }
}
