/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

:root {
  --bg: #0d0d14;
  --surface: #15151f;
  --surface-2: #1c1c2a;
  --surface-3: #232335;
  --border: #2a2a40;
  --primary: #7c6ff7;
  --primary-hover: #9084f9;
  --primary-dim: rgba(124, 111, 247, 0.15);
  --danger: #e05252;
  --text: #e0e0f0;
  --text-muted: #7070a0;
  --text-dim: #4a4a70;
  --green: #4ade80;
  --track-active: rgba(124, 111, 247, 0.12);
  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== Inputs & Buttons ===== */
.input {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.input:focus { border-color: var(--primary); }
.input::placeholder { color: var(--text-dim); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--surface-3); border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 22px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

.btn-sm {
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(124,111,247,0.3);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-sm:hover { background: var(--primary); color: #fff; }

.btn-danger {
  background: rgba(224, 82, 82, 0.1);
  color: var(--danger);
  border: 1px solid rgba(224,82,82,0.3);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.active { color: var(--primary); }

.error-msg {
  background: rgba(224,82,82,0.1);
  border: 1px solid rgba(224,82,82,0.3);
  color: #ff7070;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-top: 10px;
}

/* ===== Auth Overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
}

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}

.overlay-logo {
  width: 56px;
  height: 56px;
  background: var(--primary-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: var(--primary);
}
.overlay-logo svg { width: 30px; height: 30px; }

.overlay-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.overlay-desc {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.6;
}

.auth-step { display: flex; flex-direction: column; gap: 12px; }
.form-group { display: flex; flex-direction: column; }

.auth-demo-block {
  margin-top: 24px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  text-align: center;
}
.auth-demo-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 12px;
  line-height: 1.5;
}
.auth-demo-block .btn-secondary { min-width: 140px; }

.setup-steps {
  color: var(--text-muted);
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.8;
}
.setup-steps li { margin-bottom: 4px; }

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--green);
  overflow-x: auto;
}

/* ===== Spinner ===== */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== App Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* mobile: avoid address bar shrinking area */
  overflow: hidden;
}

/* ===== Header ===== */
.app-header {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}
.app-logo {
  width: 32px;
  height: 32px;
  background: var(--primary-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}
.app-logo svg { width: 18px; height: 18px; }
.app-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.channel-select {
  flex: 1;
  max-width: 300px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 12px;
  font-size: 14px;
  outline: none;
  cursor: pointer;
}
.channel-select:focus { border-color: var(--primary); }
.channel-select option { background: var(--surface-2); }

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ===== Player spacer (mobile: reserves space under fixed player) ===== */
.player-spacer {
  display: none;
}

/* ===== Resize Handle ===== */
.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative;
  z-index: 10;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: var(--primary);
}
.resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  border-left: 1px dotted rgba(255,255,255,0.2);
  border-right: 1px dotted rgba(255,255,255,0.2);
}

/* ===== Player Side ===== */
.player-side {
  width: clamp(380px, 50%, 680px); /* ~half screen by default, draggable */
  min-width: 320px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

/* Video */
.video-wrapper {
  position: relative;
  background: #000;
  aspect-ratio: 16/9;
  overflow: hidden;
  flex-shrink: 0;
}

#main-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ===== Audio thumbnail overlay ===== */
.thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
}

.thumb-bg {
  position: absolute;
  inset: -30px;
  background-size: cover;
  background-position: center;
  filter: blur(28px) brightness(0.35) saturate(1.4);
  transform: scale(1.1);
}

.thumb-center {
  width: 52%;
  max-width: 180px;
  min-width: 80px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7), 0 2px 8px rgba(0,0,0,0.5);
  position: relative;
  z-index: 1;
  animation: thumb-appear 0.3s ease;
}
@keyframes thumb-appear {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.thumb-note {
  position: relative;
  z-index: 1;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
}
.thumb-note svg { width: 64px; height: 64px; }

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 12px;
}
.video-placeholder svg { width: 48px; height: 48px; }
.video-placeholder p { font-size: 13px; }

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  opacity: 1;
  transition: opacity 0.25s ease;
  background: rgba(0,0,0,0.3);
}
.video-overlay.overlay-hidden {
  opacity: 0;
  pointer-events: none;
}

.video-overlay-btn {
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  color: white;
}
.video-overlay-btn:hover {
  background: rgba(124,111,247,0.8);
  transform: scale(1.08);
}
.video-overlay-btn svg { width: 22px; height: 22px; }

.play-center-btn {
  background: rgba(124,111,247,0.85);
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
  color: white;
}
.play-center-btn:hover { transform: scale(1.1); }
.play-center-btn svg { width: 22px; height: 22px; }

/* Track Info */
.track-info {
  padding: 14px 16px 10px;
  flex-shrink: 0;
}
.track-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.track-position {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--surface-3);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s;
}
.track-position:hover { background: var(--primary-dim); }

/* Progress */
.progress-section {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 10px;
  flex-shrink: 0;
}

.time-label {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: center;
}

.progress-bar {
  flex: 1;
  height: 5px;
  background: var(--surface-3);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  /* Bigger invisible tap area for mobile */
  padding: 8px 0;
  margin: -8px 0;
  box-sizing: content-box;
}
.progress-bar:hover > .progress-fill { height: 7px; }
.progress-bar:hover > .progress-fill,
.progress-bar:hover { height: 7px; }
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
}
.progress-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  left: 0%;
  transition: transform 0.1s;
  pointer-events: none;
}
.progress-bar:hover .progress-thumb { transform: translate(-50%, -50%) scale(1); }

/* Controls */
.controls-row {
  display: flex;
  align-items: center;
  padding: 8px 12px 16px;
  gap: 6px;
  flex-shrink: 0;
}

.controls-left { display: flex; align-items: center; gap: 4px; flex: 1; }
.controls-center { display: flex; align-items: center; gap: 4px; }
.controls-right { display: flex; align-items: center; gap: 2px; flex: 1; justify-content: flex-end; }

.ctrl-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  min-width: 36px;
  min-height: 36px;
}
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn:hover { color: var(--text); background: var(--surface-2); }

.ctrl-lg svg { width: 26px; height: 26px; }

.ctrl-play {
  background: var(--primary);
  color: #fff !important;
  border-radius: 50%;
  width: 54px;
  height: 54px;
  margin: 0 6px;
  flex-shrink: 0;
}
.ctrl-play:hover { background: var(--primary-hover) !important; transform: scale(1.06); }
.ctrl-play svg { width: 22px; height: 22px; }

.mode-btn.active { color: var(--primary) !important; }
.mode-btn.active svg { filter: drop-shadow(0 0 4px var(--primary)); }

.volume-step-btn {
  min-width: 36px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  padding: 0;
}
.volume-wrap {
  flex: 1;
  max-width: 90px;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 8px 0;
}
.volume-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  margin-top: 0;
}
.volume-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  background: var(--primary);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}
/* Touch: larger thumb and track for easier dragging */
@media (hover: none) {
  .volume-wrap { min-height: 48px; padding: 10px 0; }
  .volume-slider { height: 10px; }
  .volume-slider::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
  }
  .volume-slider::-moz-range-thumb {
    width: 32px;
    height: 32px;
  }
}

/* Repeat Count */
.repeat-count-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 4px;
}
.count-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.15s;
  padding: 0;
}
.count-btn:hover { color: var(--text); background: var(--surface-3); }
.count-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  min-width: 22px;
  text-align: center;
}

/* ===== Playlist Side ===== */
.playlist-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.playlist-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.playlist-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.playlist-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.playlist-title {
  font-size: 16px;
  font-weight: 600;
}
.playlist-count {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 8px;
  font-weight: 500;
}

.playlist-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); }
.search-input::placeholder { color: var(--text-dim); }

.sort-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sort-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}
.sort-select option { background: var(--surface-2); }

.sort-dir-btn { transition: transform 0.2s; }
.sort-dir-btn.desc svg { transform: rotate(180deg); }

/* Playlist Body */
.playlist-body {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.empty-state, .loading-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 12px;
}
.empty-state svg { width: 48px; height: 48px; }
.empty-state p { font-size: 14px; color: var(--text-muted); }
.empty-state span { font-size: 12px; }
.loading-state p { font-size: 13px; color: var(--text-muted); margin-top: 12px; }

/* Playlist List */
.playlist-list {
  list-style: none;
  padding: 4px 0;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  position: relative;
  min-height: 58px;  /* must match ITEM_HEIGHT in playlist.js */
  box-sizing: border-box;
}
.playlist-item:hover { background: var(--surface-2); }
.playlist-item.active { background: var(--track-active); }
.playlist-item.active .item-title { color: var(--primary); }

.item-num {
  min-width: 28px;
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.playlist-item.active .item-num {
  display: none;
}
.item-playing-icon {
  display: none;
  min-width: 28px;
  text-align: right;
  color: var(--primary);
}
.item-playing-icon svg { width: 14px; height: 14px; animation: pulse 1.5s ease-in-out infinite; }
.playlist-item.active .item-playing-icon { display: flex; justify-content: flex-end; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.item-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  position: relative;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-thumb svg { width: 16px; height: 16px; }
.item-thumb-regen {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 4px 0 0 0;
  background: rgba(0,0,0,0.6);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
}
.item-thumb-regen:hover { opacity: 1; background: var(--surface-3); }
.item-thumb-regen:disabled { opacity: 0.5; cursor: not-allowed; }
.item-thumb-regen svg { width: 10px; height: 10px; }

.item-info { flex: 1; overflow: hidden; }
.item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-dur {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  width: 460px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
  z-index: 1;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-card h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Settings Modal */
.settings-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.settings-section:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
.settings-section h4 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.channels-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.channel-item-name { flex: 1; font-size: 14px; }
.channel-item-username { font-size: 12px; color: var(--text-muted); }
.channel-item-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
  display: flex;
}
.channel-item-remove:hover { color: var(--danger); background: rgba(224,82,82,0.1); }
.channel-item-remove svg { width: 16px; height: 16px; }
.channel-item-default {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
  display: flex;
}
.channel-item-default:hover { color: var(--accent); background: rgba(0,0,0,0.06); }
.channel-item-default svg { width: 18px; height: 18px; }

.user-info {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

/* ===== Caption Panel ===== */
.caption-panel {
  margin: 0 16px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.caption-body { padding: 10px 12px 8px; }

.caption-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.65;
  max-height: 3.3em; /* ~2 lines */
  overflow: hidden;
  transition: max-height 0.3s ease;
  white-space: pre-wrap;
  word-break: break-word;
}
.caption-text.expanded { max-height: 300px; }

.caption-toggle {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 0 2px;
  display: block;
}
.caption-toggle:hover { text-decoration: underline; }

/* ===== Speed Dropdown ===== */
.speed-btn {
  font-size: 12px;
  font-weight: 700;
  min-width: 32px;
  color: var(--text-muted);
  letter-spacing: -0.02em;
}
.speed-btn:hover { color: var(--text); }
.speed-btn.active { color: var(--primary); }

.speed-dropdown {
  position: fixed;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 900;
  box-shadow: var(--shadow);
  min-width: 80px;
}

.speed-option {
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.1s;
  text-align: center;
}
.speed-option:hover { background: var(--surface-2); color: var(--text); }
.speed-option.active { color: var(--primary); font-weight: 700; background: var(--primary-dim); }

/* ===== Sleep timer ===== */
.sleep-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
}
.sleep-countdown {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-dim);
  padding: 2px 6px;
  border-radius: 8px;
  white-space: nowrap;
  animation: pulse 2s ease-in-out infinite;
}

/* ===== Controls extras ===== */
.ctrl-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

/* ===== Fullscreen ===== */
#video-wrapper:fullscreen { background: #000; }
#video-wrapper:fullscreen #main-video { width: 100vw; height: 100vh; }
#video-wrapper:-webkit-full-screen { background: #000; }

/* ===== Download in playlist items ===== */
.item-download-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.item-download-btn svg { width: 14px; height: 14px; }
.item-download-btn:hover { color: var(--primary); background: var(--primary-dim); }
.item-download-btn.done { color: var(--green); cursor: default; }
.item-download-btn.error { color: var(--danger); }
.item-download-btn.downloading { color: var(--primary); cursor: default; }

/* Circular progress for download */
.dl-progress-ring {
  width: 20px;
  height: 20px;
  transform: rotate(-90deg);
}
.dl-progress-ring circle {
  fill: none;
  stroke: var(--border);
  stroke-width: 2;
}
.dl-progress-ring circle.track {
  stroke: var(--primary);
  stroke-dasharray: 50.27;
  stroke-dashoffset: 50.27;
  transition: stroke-dashoffset 0.3s;
}

/* ===== Settings downloads section ===== */
.downloads-info-box {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.dl-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.dl-file-item:last-child { border-bottom: none; }
.dl-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-file-size { color: var(--text-dim); white-space: nowrap; }

.settings-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== Now Playing Banner ===== */
.now-playing-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(135deg, rgba(124,111,247,0.18), rgba(124,111,247,0.08));
  border-bottom: 1px solid rgba(124,111,247,0.3);
  padding: 7px 16px;
  animation: npb-slide-in 0.2s ease;
  flex-shrink: 0;
}
@keyframes npb-slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.npb-left {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  flex: 1;
}
.npb-icon {
  width: 14px;
  height: 14px;
  color: var(--primary);
  flex-shrink: 0;
  animation: pulse 1.5s ease-in-out infinite;
}
.npb-pos {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-dim);
  padding: 1px 6px;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.npb-title {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.npb-goto {
  background: var(--primary-dim);
  border: 1px solid rgba(124,111,247,0.3);
  color: var(--primary);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s;
}
.npb-goto:hover { background: var(--primary); color: #fff; }

/* ===== Playlist show-more row ===== */
.show-more-row {
  list-style: none;
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

/* ===== Toggle row (checkbox + label) ===== */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-label {
  font-size: 13px;
  color: var(--text-muted);
}
.toggle-row:hover .toggle-label { color: var(--text); }

/* ===== 2FA block ===== */
.twofa-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.twofa-hint {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
}
.twofa-hint::before { content: 'Hint: '; color: var(--text-dim); }

/* ===== Auth tabs ===== */
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }

/* ===== QR Code ===== */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 16px;
  min-height: 220px;
  margin: 0 auto;
  width: 220px;
}
.qr-container img {
  width: 188px;
  height: 188px;
  display: block;
  image-rendering: pixelated;
}
.qr-expired {
  text-align: center;
  color: #999;
  font-size: 12px;
  margin-top: 8px;
}
.qr-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--green);
  font-size: 14px;
  font-weight: 600;
}
.qr-success svg { width: 48px; height: 48px; }

/* ===== Excluded tracks ===== */
.playlist-item.excluded {
  opacity: 0.38;
}
.playlist-item.excluded .item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}
.playlist-item.excluded:hover {
  opacity: 0.6;
}

.item-exclude-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.item-exclude-btn svg { width: 14px; height: 14px; }
.item-exclude-btn:hover { color: #f59e0b; background: rgba(245,158,11,0.1); }
.item-exclude-btn.is-excluded { color: #f59e0b; }
.item-exclude-btn.is-excluded:hover { color: var(--green); background: rgba(74,222,128,0.1); }

.excluded-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.25);
  color: #f59e0b;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.excluded-reset {
  background: none;
  border: none;
  color: #f59e0b;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.excluded-reset:hover { opacity: 1; text-decoration: underline; }

/* ===== Form Labels ===== */
.form-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.path-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.path-input-row .input { flex: 1; }

/* ===== Source badge in selector ===== */
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  background: var(--surface-3);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 6px;
}

/* ===== Folder Browser Modal ===== */
.browser-card {
  width: 540px;
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.browser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.browser-header h3 { font-size: 16px; font-weight: 700; }

.browser-path {
  padding: 10px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

#browser-current-path {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.browser-drives {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drive-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.drive-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-dim); }

.browser-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  min-height: 200px;
}

.browser-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text);
}
.browser-entry:hover { background: var(--surface-2); }
.browser-entry.go-up { color: var(--text-muted); }
.browser-entry svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--primary); }
.browser-entry.go-up svg { color: var(--text-dim); }
.browser-entry-name { font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browser-entry-hint { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.browser-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 16px;
  font-size: 13px;
}

.browser-footer {
  display: flex;
  align-items: center;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}
.browser-media-count {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
}
.browser-media-count strong { color: var(--primary); }
.browser-actions { display: flex; gap: 8px; }

/* ===== Optgroup separator in selector ===== */
.channel-select optgroup { color: var(--text-muted); font-size: 11px; }
.channel-select option  { color: var(--text); font-size: 14px; padding: 4px; }

/* ===== Source type icon in playlist ===== */
.source-label {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}
.source-label.channel { background: rgba(124,111,247,0.15); color: var(--primary); }
.source-label.local   { background: rgba(74,222,128,0.12); color: var(--green); }

/* ===== Responsive ===== */
@media (max-width: 700px) {
  .video-overlay-btn { width: 44px; height: 44px; }
  .video-overlay-btn svg { width: 20px; height: 20px; }

  .player-side {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 10;
    background: var(--surface);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  }
  .player-spacer {
    display: block;
    flex-shrink: 0;
    width: 100%;
    min-height: 1px;
    box-sizing: border-box;
  }
  /* Portrait: guarantee spacer is tall enough so first playlist items are never under the fixed player */
  @media (max-width: 700px) and (orientation: portrait) {
    .player-spacer { min-height: 58vh; }
  }
  .main-content {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .playlist-side {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .playlist-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y; /* allow vertical scroll on touch */
    overflow-anchor: none; /* don't preserve scroll when content updates */
  }
  .resize-handle { display: none; }

  /* Controls: wrap so all buttons fit (2–3 rows) */
  .controls-row {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px 12px;
  }
  .controls-left { flex: 0 1 auto; }
  .controls-center { flex: 0 0 auto; }
  .controls-right {
    flex-basis: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    margin-top: 2px;
    padding-top: 2px;
    border-top: 1px solid var(--border);
  }
  .controls-right .ctrl-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 6px;
  }
  .controls-right .ctrl-btn svg { width: 18px; height: 18px; }
  .controls-right .speed-btn { font-size: 12px; }

  /* Volume on mobile: only icon + big −/+ buttons, no slider */
  .volume-wrap { display: none; }
  .volume-step-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 22px;
  }
  .controls-left .ctrl-btn#btn-volume-toggle {
    min-width: 44px;
    min-height: 44px;
  }
}
