*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg2: #161616;
  --bg3: #1e1e1e;
  --bg4: #252525;
  --border: #2a2a2a;
  --border2: #333;
  --text: #e8e8e8;
  --text2: #999;
  --text3: #555;
  --primary: #ff4444;
  --primary-dim: rgba(255,68,68,0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 6px;
  --ch-w: 220px;
  --vid-w: 320px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Noto Sans KR', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: var(--ch-w) var(--vid-w) 1fr;
  height: 100vh;
}

/* ── Panel ── */
.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.panel:last-child { border-right: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 44px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.panel-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
}
.panel-head-actions { display: flex; gap: 4px; align-items: center; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Buttons ── */
.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg4); color: var(--text); }

.icon-btn-text {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text2);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  padding: 3px 10px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.icon-btn-text:hover { background: var(--bg4); color: var(--text); border-color: #444; }
.icon-btn-text:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn-text.loading { opacity: 0.5; pointer-events: none; }

/* ── Channel List ── */
.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  position: relative;
}
.channel-item:hover { background: var(--bg3); }
.channel-item.active { background: var(--bg4); }
.channel-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}
.ch-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg4);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.ch-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ch-info { flex: 1; min-width: 0; }
.ch-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-meta { font-size: 11px; color: var(--text3); margin-top: 1px; }
/* ── Video List ── */
.video-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  position: relative;
}
.video-item:hover { background: var(--bg3); }
.video-item.active { background: var(--bg4); }
.video-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}
.vid-thumb {
  width: 80px;
  height: 45px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg4);
  overflow: hidden;
  position: relative;
}
.vid-thumb img { width: 100%; height: 100%; object-fit: cover; }
.vid-thumb-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.transcript-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  border: 1px solid var(--bg);
}
.deleted-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #f87171;
  letter-spacing: 0.05em;
}
.video-item.deleted { opacity: 0.55; }
.video-item.deleted .vid-title { text-decoration: line-through; color: var(--text3); }

.ch-deleted-badge {
  display: inline-block;
  background: rgba(239,68,68,0.12);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.25);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
}
.vid-info { flex: 1; min-width: 0; }
.vid-title {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 3px;
}
.vid-meta { font-size: 11px; color: var(--text3); margin-bottom: 4px; }
.vid-tags { display: flex; flex-wrap: wrap; gap: 3px; }
.vtag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
}
.vtag-lang {
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(255,68,68,0.2);
}
.vtag-manual {
  background: rgba(34,197,94,0.1);
  color: #86efac;
  border: 1px solid rgba(34,197,94,0.2);
}
.vtag-auto {
  background: rgba(245,158,11,0.1);
  color: #fcd34d;
  border: 1px solid rgba(245,158,11,0.2);
}

/* ── Video Detail ── */
.detail-wrap { display: flex; flex-direction: column; height: 100%; }

.detail-player-wrap {
  width: 100%;
  background: #000;
  flex-shrink: 0;
}
.detail-thumb-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  cursor: pointer;
  overflow: hidden;
  background: #000;
}
.detail-thumb-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s;
}
.detail-thumb-preview:hover img { opacity: 0.7; }
.thumb-placeholder-lg {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  background: var(--bg4);
}
.play-btn-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.play-btn-icon {
  width: 56px;
  height: 56px;
  background: rgba(255,68,68,0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  padding-left: 4px;
  transition: transform 0.15s, background 0.15s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.detail-thumb-preview:hover .play-btn-icon {
  transform: scale(1.1);
  background: var(--primary);
}
.yt-iframe {
  width: 100%;
  aspect-ratio: 16/9;
  display: block;
  border: none;
}

.detail-meta-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.detail-meta { min-width: 0; }
.detail-title { font-size: 14px; font-weight: 700; line-height: 1.4; margin-bottom: 4px; }
.detail-date { font-size: 11px; color: var(--text3); margin-bottom: 6px; }
.yt-link { color: var(--text3); text-decoration: none; transition: color 0.15s; }
.yt-link:hover { color: var(--primary); }
.detail-tags { display: flex; flex-wrap: wrap; gap: 5px; }

.tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
}
.tag-lang {
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(255,68,68,0.25);
}
.tag-manual {
  background: rgba(34,197,94,0.1);
  color: #86efac;
  border: 1px solid rgba(34,197,94,0.25);
}
.tag-auto {
  background: rgba(245,158,11,0.1);
  color: #fcd34d;
  border: 1px solid rgba(245,158,11,0.25);
}

/* ── Transcript ── */
.transcript-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tab-bar {
  display: flex;
  gap: 2px;
  padding: 0 16px 0 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text3);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  padding: 10px 14px;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text2); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 14px 16px;
  overflow: hidden;
}
.tab-panel.active { display: flex; }
.transcript-divider {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  flex-shrink: 0;
}
.transcript-content {
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text2);
  word-break: keep-all;
}
.transcript-content::-webkit-scrollbar { width: 4px; }
.transcript-content::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.transcript-empty-msg {
  color: var(--text3);
  font-size: 12px;
  padding: 8px 0;
}

/* ── Books ── */
.books-toolbar { margin-bottom: 12px; flex-shrink: 0; }
.books-status {
  font-size: 12px;
  color: var(--text3);
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 12px;
  flex-shrink: 0;
}
.books-raw {
  margin-bottom: 12px;
  flex-shrink: 0;
}
.books-raw summary {
  font-size: 11px;
  color: var(--text3);
  cursor: pointer;
  padding: 6px 0;
}
.books-raw-content {
  font-size: 11px;
  color: var(--text2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}
.books-list { flex: 1; overflow-y: auto; }
.books-empty {
  color: var(--text3);
  font-size: 12px;
  text-align: center;
  padding: 24px 16px;
  line-height: 1.8;
}
.book-item {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: border-color 0.15s;
}
.book-item:hover { border-color: var(--border2); }
.book-title { font-size: 13px; font-weight: 600; color: var(--text); display: block; }
.book-author { font-size: 11px; color: var(--text3); margin-top: 2px; display: block; }

/* ── States ── */
.loading, .placeholder, .empty-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text3);
  font-size: 12px;
  text-align: center;
  padding: 20px;
  line-height: 1.8;
}

.load-more-btn {
  width: 100%;
  padding: 10px;
  background: var(--bg3);
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text2);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.load-more-btn:hover { background: var(--bg4); color: var(--text); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  width: 440px;
  max-width: 90vw;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg4); color: var(--text); }
.modal-body { padding: 20px; }
.modal-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.modal-input:focus { border-color: var(--primary); }
.modal-hint { font-size: 11px; color: var(--text3); margin-top: 6px; }
.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}
.modal-error {
  flex: 1;
  font-size: 12px;
  color: #f87171;
}
.modal-error[hidden] { display: none; }
.btn-cancel, .btn-confirm {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border: none;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-cancel { background: var(--bg4); color: var(--text2); margin-left: auto; }
.btn-cancel:hover { background: var(--border2); color: var(--text); }
.btn-confirm { background: var(--primary); color: #fff; }
.btn-confirm:hover { background: #e03c3c; }
.btn-confirm:disabled { opacity: 0.5; pointer-events: none; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 2000;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
