/* ── Reset ──────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface2: #282828;
  --surface3: #333;
  --accent: #ff0000;
  --accent-hover: #cc0000;
  --text: #fff;
  --text-dim: #aaa;
  --text-dimmer: #666;
  --header-bg: rgba(18, 18, 18, 0.92);
  --header-border: rgba(255, 255, 255, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--header-border);
  padding-top: var(--safe-top);
}

.header-inner {
  padding: 12px 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  cursor: pointer;
}

.logo h1 {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-bar {
  display: flex;
  gap: 6px;
  align-items: center;
}

.search-bar input {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  border: none;
  border-radius: 21px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: background 0.2s, box-shadow 0.2s;
}

.search-bar input::placeholder { color: var(--text-dimmer); }
.search-bar input:focus {
  background: var(--surface3);
  box-shadow: 0 0 0 2px rgb(from var(--accent) r g b / 0.3);
}

.search-bar button[type="submit"] {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}

.search-bar button[type="submit"]:active {
  transform: scale(0.92);
}

.search-input-wrap {
  position: relative;
  flex: 1;
}

.btn-eye {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dimmer);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity .15s;
}

.btn-eye:hover { opacity: 1; color: var(--text); }
.btn-eye.hidden { opacity: 0.3; }

.search-history {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--surface3);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
}

.sh-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s;
}

.sh-item:hover { background: var(--surface2); color: var(--text); }

.sh-item-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sh-item-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dimmer);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity .15s;
}

.sh-item-del:hover { opacity: 1; color: var(--accent); }

.sh-item:first-child {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.sh-item:last-child {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.btn-icon-header {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.btn-icon-header:active {
  background: var(--surface3);
}

/* ── Settings Panel ─────────────────────────────── */
.panel-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface3);
  margin: 8px auto 0;
  flex-shrink: 0;
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 449;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.panel-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 450;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 90vh;
}

.settings-panel.open {
  transform: translateY(0);
}

.settings-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(var(--safe-top) + 12px);
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--header-border);
}

.settings-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.panel-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-list {
  padding: 8px 0 calc(var(--safe-bottom) + 24px);
}

.settings-group {
  margin-bottom: 8px;
}

.settings-group-title {
  padding: 16px 20px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  transition: background 0.15s;
}

.setting-item.clickable {
  cursor: pointer;
}

.setting-item.clickable:active {
  background: var(--surface2);
}

.setting-info {
  flex: 1;
  min-width: 0;
}

.setting-label {
  font-size: 0.95rem;
  font-weight: 500;
}

.setting-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Toggle Switch ──────────────────────────────── */
.toggle {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface3);
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ── Theme Picker Floating Window ─────────────────── */
.theme-picker-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.theme-picker {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.theme-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--surface3);
}

.theme-picker-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.theme-picker-body {
  padding: 12px 16px 20px;
}

.theme-group {
  margin-bottom: 18px;
}

.theme-group:last-child {
  margin-bottom: 0;
}

.theme-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.theme-group-items {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-option {
  flex-shrink: 0;
  width: 76px;
  text-align: center;
  cursor: pointer;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  transition: background 0.2s, transform 0.15s;
  position: relative;
}

.theme-option:active {
  transform: scale(0.93);
}

.theme-option.active {
  background: var(--surface2);
}

.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin: 0 auto 4px;
  border: 2px solid var(--surface3);
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
  z-index: 1;
}

.theme-option.active .theme-swatch {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

.theme-swatch-bg {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  z-index: 0;
  opacity: 0.5;
}

.theme-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
  margin-top: 2px;
}

.theme-option.active .theme-label {
  color: var(--text);
  font-weight: 600;
}

/* ── Main ───────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(80px + var(--safe-bottom));
  scroll-behavior: smooth;
}

#yt-player-container {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.search-results {
  padding: 8px 12px;
  touch-action: pan-y;
}

.pull-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  color: var(--text-dim);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* ── Results Header ─────────────────────────────── */
.results-header {
  padding: 8px 0 12px;
}

.btn-play-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 20px;
  background: var(--accent);
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}

.btn-play-all:active { transform: scale(0.95); }
.btn-play-all .play-icon { font-size: 0.8rem; }

/* ── Video Card ─────────────────────────────────── */
.video-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  animation: fadeSlideIn 0.3s ease both;
}

.video-card:active { background: var(--surface2); }

.thumb-wrap {
  position: relative;
  flex-shrink: 0;
  width: 120px;
  height: 68px;
  border-radius: 6px;
  overflow: hidden;
}

.video-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--surface2);
}

.duration-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 1px 5px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 3px;
  font-size: 0.7rem;
  color: white;
  font-weight: 500;
}

.video-info {
  flex: 1;
  min-width: 0;
}

.video-title {
  font-size: 0.9rem;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.video-channel {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 3px;
  cursor: pointer;
  transition: color 0.15s;
}

.video-channel:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ── Card Action Buttons ───────────────────────── */
.btn-card-fav,
.btn-card-pl {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgb(from var(--text) r g b / 0.08);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, transform 0.15s;
  opacity: 0;
}

.btn-card-fav {
  right: 8px;
}

.btn-card-pl {
  right: 46px;
}

.video-card:hover .btn-card-fav,
.video-card:hover .btn-card-pl,
.video-card:active .btn-card-fav,
.video-card:active .btn-card-pl {
  opacity: 1;
}

.btn-card-fav:active,
.btn-card-pl:active {
  transform: translateY(-50%) scale(0.9);
}

.btn-card-fav.active {
  opacity: 1;
  color: var(--accent);
}

.btn-card-fav:hover {
  background: rgb(from var(--accent) r g b / 0.15);
  color: var(--accent);
}

.btn-card-pl:hover {
  background: rgb(from var(--text) r g b / 0.15);
  color: var(--text);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Load More Button ───────────────────────────── */
.load-more-container {
  display: flex;
  justify-content: center;
  padding: 20px 16px;
}

.btn-load-more {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  border: 1px solid var(--surface3);
  border-radius: 24px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-load-more:hover {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-load-more:active {
  transform: scale(0.97);
}

.btn-load-more:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spinner.small {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

/* ── Loading ────────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 0;
  color: var(--text-dim);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Mini Player ────────────────────────────────── */
.mini-player {
  position: fixed;
  bottom: calc(60px + var(--safe-bottom));
  left: 8px;
  right: 8px;
  z-index: 200;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
}

.mini-player.hidden {
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
}

.mini-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  transition: width 0.3s linear;
  z-index: 1;
}

.mini-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.mini-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}

.mini-info {
  flex: 1;
  min-width: 0;
}

.mini-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-channel {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.mini-ctrl-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
}

.mini-ctrl-btn:active {
  transform: scale(0.85);
  background: rgb(from var(--text) r g b / 0.1);
}

.mini-ctrl-btn.mini-stop {
  color: var(--text-dim);
}

.mini-play-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.mini-play-btn:active { transform: scale(0.85); }

/* ── Full Player ────────────────────────────────── */
.full-player {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}

.full-player.open {
  transform: translateY(0);
}

.fp-content {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--safe-top) 24px var(--safe-bottom);
}

.fp-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.fp-header-title {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.fp-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.fp-close svg { transform: rotate(180deg); }

#fp-fav svg { transform: rotate(0deg); }
#fp-fav.active svg { fill: var(--accent) !important; }
#fp-fav { transition: color 0.2s; }

.fp-artwork {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  margin-top: 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  animation: artworkIn 0.5s ease both;
}

.fp-artwork img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fp-info {
  width: 100%;
  max-width: 400px;
  text-align: center;
  margin-top: 24px;
}

.fp-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fp-channel {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.fp-progress {
  width: 100%;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.fp-time {
  font-size: 0.75rem;
  color: var(--text-dim);
  min-width: 36px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fp-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--surface3);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.fp-progress-bar::before {
  content: '';
  position: absolute;
  inset: -8px 0;
}

.fp-progress-filled {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0;
  transition: width 0.3s linear;
}

.fp-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
}

.fp-extra-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.fp-main-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.fp-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.2s;
}

.fp-btn:active { transform: scale(0.88); }
.fp-btn-play {
  width: 64px;
  height: 64px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
}

/* ── A-B Repeat ─────────────────────────────────── */
.fp-ab-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  width: 100%;
  max-width: 400px;
}

.fp-ab-letter {
  width: 44px;
  height: 44px;
  border: 2px solid var(--surface3);
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fp-ab-letter:active {
  transform: scale(0.9);
}

.fp-ab-letter.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgb(from var(--accent) r g b / 0.1);
}

.fp-ab-status {
  font-size: 0.8rem;
  color: var(--accent);
  text-align: center;
  font-weight: 500;
  min-width: 80px;
}

.fp-btn-abdel {
  color: var(--text-dimmer);
}

.fp-btn-abdel:active {
  color: #ff4444;
}

/* ── Repeat Button ──────────────────────────────── */
.fp-btn-repeat.active {
  color: var(--accent);
}

.mini-ctrl-btn.active {
  color: var(--accent);
}

/* ── A-B Markers ────────────────────────────────── */
.ab-marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 12px;
  background: var(--accent);
  z-index: 2;
  transform: translateX(-1px);
}

.ab-marker span {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
}

.ab-region {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgb(from var(--accent) r g b / 0.25);
  z-index: 1;
  border-radius: 2px;
}

/* ── Toast ───────────────────────────────────────── */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 9999;
  padding: 12px 24px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--surface3);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  max-width: 90vw;
  white-space: nowrap;
}

.toast.html {
  white-space: normal;
  line-height: 1.6;
  text-align: left;
  max-width: 85vw;
  font-weight: 400;
}

.toast.open {
  transform: translateX(-50%) translateY(0);
}

/* ── Accessibility: Reduced Motion ─────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Queue Panel ────────────────────────────────── */
.queue-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 450;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 90vh;
}

.queue-panel.open {
  transform: translateY(0);
}

.queue-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(var(--safe-top) + 12px);
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--header-border);
}

.queue-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.queue-body {
  padding: 0 0 calc(var(--safe-bottom) + 24px);
}

/* ── Queue Sub Header ──────────────────────────── */
.q-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.95rem;
}

.q-back {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.q-actions {
  display: flex;
  gap: 4px;
}

.q-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.q-btn:active {
  background: var(--surface3);
}

.q-btn.q-accent {
  background: var(--accent);
  color: white;
}

.q-btn.q-danger {
  color: var(--text-dimmer);
}

.q-btn.q-danger:active {
  color: #ff4444;
}

/* ── Now Playing ────────────────────────────────── */
.q-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  font-weight: 600;
  padding: 8px 16px 4px;
}

.q-now-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgb(from var(--accent) r g b / 0.08);
  border-left: 3px solid var(--accent);
}

.q-now-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}

.q-now-info {
  flex: 1;
  min-width: 0;
}

.q-now-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.q-now-channel {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.q-fav {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.q-fav:active {
  transform: scale(1.2);
}

.q-fav.active {
  color: var(--accent);
}

/* ── Queue List ─────────────────────────────────── */
.q-list {
  padding: 0 8px;
}

.q-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  animation: fadeSlideIn 0.2s ease both;
}

.q-item:active {
  background: var(--surface2);
}

.q-item.active {
  background: rgb(from var(--accent) r g b / 0.12);
}

.q-item.active .q-item-title {
  color: var(--accent);
}

.q-item-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}

.q-item-text {
  flex: 1;
  min-width: 0;
}

.q-item-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.q-item-channel {
  font-size: 0.73rem;
  color: var(--text-dim);
}

.q-item-dur {
  font-size: 0.72rem;
  color: var(--text-dimmer);
  flex-shrink: 0;
}

.q-item-rm {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dimmer);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.q-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.q-item.dragging {
  opacity: 0.4;
}

.q-item.drag-over {
  border-top: 2px solid var(--accent);
}

.q-item.swiping {
  transition: transform 0.3s ease;
}

/* ── Queue to Queue Link ────────────────────────── */
.q-to-queue {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin: 0 12px 8px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
  color: var(--accent);
}

.q-to-queue:active {
  background: var(--surface2);
}

.q-to-queue-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.q-to-queue-count {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ── Playlist Cards ─────────────────────────────── */
.pl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 8px 16px;
}

.pl-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s;
  animation: fadeSlideIn 0.3s ease both;
}

.pl-card:active {
  transform: scale(0.97);
}

.pl-card-cover {
  aspect-ratio: 1;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-dimmer);
}

.pl-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pl-card-info {
  padding: 10px;
}

.pl-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pl-card-count {
  font-size: 0.73rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.pl-card-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.pl-card:hover .pl-card-del {
  opacity: 1;
}

.pl-fav {
  background: linear-gradient(135deg, rgb(from var(--accent) r g b / 0.15), rgb(from var(--accent) r g b / 0.05));
  border: 1px solid rgb(from var(--accent) r g b / 0.2);
}

.pl-fav .pl-card-cover {
  background: transparent;
}

.pl-fav-svg { color: var(--accent); }

/* ── Playlist Detail ────────────────────────────── */
.dt-title {
  font-size: 0.95rem;
  font-weight: 600;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dt-cover {
  width: 120px;
  height: 120px;
  margin: 8px auto 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  color: var(--text-dimmer);
}

.dt-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dt-stats {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.queue-item-remove {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dimmer);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  flex-shrink: 0;
}

.queue-item-remove:hover { color: var(--accent); }

.empty-queue {
  text-align: center;
  padding: 40px 0;
  color: var(--text-dim);
}

/* ── Animations ─────────────────────────────────── */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes artworkIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ── Scrollbar ──────────────────────────────────── */
.main::-webkit-scrollbar,
.queue-list::-webkit-scrollbar {
  width: 4px;
}

.main::-webkit-scrollbar-thumb,
.queue-list::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 2px;
}

/* ── Discovery Feed ──────────────────────────────── */
.discover-section {
  padding: 12px 0;
}

.discover-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.discover-refresh {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s, transform 0.15s;
}

.discover-refresh:hover {
  color: var(--text);
  background: var(--surface2);
}

.discover-refresh:active {
  transform: rotate(60deg);
}

.discover-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px;
}

.discover-chip {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.discover-chip:active {
  background: var(--surface3);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chip-remove:hover {
  color: var(--text);
  background: var(--surface3);
}

.discover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.discover-card {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.15s;
}

.discover-card:active {
  transform: scale(0.97);
}

.discover-thumb {
  position: relative;
  padding-top: 56.25%;
}

.discover-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.discover-info {
  padding: 8px 10px 10px;
}

.discover-name {
  font-size: 0.82rem;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.discover-channel {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.discover-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* ── Responsive ─────────────────────────────────── */
@media (min-width: 768px) {
  .search-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 4px;
    padding: 12px 16px;
  }

  .results-header {
    grid-column: 1 / -1;
  }

  .video-card {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    border-radius: var(--radius);
    overflow: hidden;
  }

  .thumb-wrap {
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
  }

  .thumb-wrap img {
    position: absolute;
    inset: 0;
  }

  .video-info {
    padding: 10px 12px;
  }

  .btn-card-fav,
  .btn-card-pl {
    right: 10px;
    top: 10px;
    transform: none;
    opacity: 1;
    background: rgba(0, 0, 0, 0.6);
  }

  .btn-card-pl {
    right: 48px;
  }

  .mini-player {
    left: auto;
    right: 16px;
    bottom: calc(80px + var(--safe-bottom));
    width: 380px;
    border-radius: var(--radius);
  }

  .fp-artwork {
    max-width: 360px;
    margin-top: 30px;
  }

  .fp-controls {
    margin-top: 32px;
  }
}

@media (min-width: 1024px) {
  .header-inner {
    max-width: 800px;
    margin: 0 auto;
  }

  .search-results {
    max-width: 1000px;
    margin: 0 auto;
  }
}

/* ── Compact Mode ───────────────────────────────── */
.compact-mode .search-results {
  display: block !important;
}

.compact-mode .video-card {
  flex-direction: row !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden !important;
  padding: 8px !important;
}

.compact-mode .thumb-wrap {
  width: 72px !important;
  height: 40px !important;
  flex-shrink: 0;
}

.compact-mode .thumb-wrap img {
  position: static !important;
}

.compact-mode .video-info {
  padding: 0 8px !important;
}

.compact-mode .btn-card-fav,
.compact-mode .btn-card-pl {
  position: static !important;
  transform: none !important;
  opacity: 1 !important;
  background: var(--surface2) !important;
}

.grid-mode.compact-mode .search-results {
  display: block !important;
}

.grid-mode.compact-mode .video-card {
  flex-direction: row !important;
}

/* ── Grid Mode ───────────────────────────────────── */
.grid-mode .search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  padding: 8px;
}

.grid-mode .results-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid-mode .video-card {
  flex-direction: column;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  padding: 0;
}

.grid-mode .thumb-wrap {
  width: 100%;
  padding-top: 56.25%;
  position: relative;
}

.grid-mode .thumb-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
}

.grid-mode .duration-badge {
  bottom: 6px;
  right: 6px;
  font-size: 0.72rem;
}

.grid-mode .video-info {
  padding: 8px 10px 10px;
}

.grid-mode .video-title {
  font-size: 0.82rem;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.grid-mode .video-channel {
  font-size: 0.72rem;
  margin-top: 2px;
}

.grid-mode .video-channel:hover {
  color: var(--accent);
  text-decoration: underline;
}

.grid-mode .btn-card-fav {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 1;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  width: 30px;
  height: 30px;
  transform: none;
}

.grid-mode .btn-card-pl {
  display: none;
}

.grid-mode.compact-mode .btn-card-pl {
  display: flex;
}

/* ── Grid Toggle Button ─────────────────────────── */
.btn-grid-toggle {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.btn-grid-toggle:active {
  background: var(--surface3);
}

/* ── Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.open .modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 12px 16px;
}

.modal-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--surface3);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 8px;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-input::placeholder {
  color: var(--text-dimmer);
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 8px 16px 16px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.modal-btn:active {
  transform: scale(0.97);
}

.modal-btn.cancel {
  background: var(--surface2);
  color: var(--text-dim);
}

.modal-btn.confirm {
  background: var(--accent);
  color: white;
}

/* ── Landscape Full Player ─────────────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  .fp-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 4px 12px;
    align-items: start;
    max-width: 100%;
  }

  .fp-header { grid-column: 1 / -1; grid-row: 1; }

  .fp-artwork {
    grid-column: 1;
    grid-row: 2 / 4;
    max-width: 180px;
    justify-self: center;
  }

  .fp-artwork img { max-width: 160px; max-height: 160px; }

  .fp-info { grid-column: 2; grid-row: 2; }

  .fp-progress {
    grid-column: 2;
    grid-row: 3;
    max-width: 100%;
    margin-top: 8px;
  }

  .fp-ab-buttons { display: none; }

  .fp-controls {
    grid-column: 1 / -1;
    grid-row: 4;
    justify-content: center;
    gap: 16px;
    margin-top: 4px;
  }

  .fp-controls .fp-btn { width: 40px; height: 40px; }
  .fp-controls .fp-btn svg { width: 28px; height: 28px; }
  .fp-controls .fp-btn-play { width: 52px; height: 52px; }
  .fp-controls .fp-btn-play svg { width: 36px; height: 36px; }
}

/* ── Add to Playlist Modal ──────────────────────── */
.modal-playlist-list {
  max-height: 300px;
  overflow-y: auto;
  padding: 4px 0;
}

.modal-playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-playlist-item:active {
  background: var(--surface2);
}

.modal-playlist-item span {
  font-size: 0.9rem;
}

.modal-playlist-item.new-playlist {
  color: var(--accent);
  border-top: 1px solid var(--surface3);
  margin-top: 4px;
  padding-top: 16px;
}

/* ── Storage Panel ────────────────────────────────── */
.storage-panel {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9998;
  background: var(--bg);
  flex-direction: column;
  padding: 16px;
  padding-top: calc(var(--safe-top) + 16px);
  overflow-y: auto;
}

.storage-panel.open {
  display: flex;
}

.storage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.storage-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
}

.storage-total {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
  font-size: 1rem;
  border: 1px solid var(--surface3);
}

.storage-total .num {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
}

.storage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.storage-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  border: 1px solid var(--surface3);
}

.storage-item .info {
  flex: 1;
  min-width: 0;
}

.storage-item .label {
  font-weight: 600;
  font-size: 0.9rem;
}

.storage-item .size {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.storage-item .clear-btn {
  background: none;
  border: 1px solid var(--surface3);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.15s;
}

.storage-item .clear-btn:hover,
.storage-item .clear-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

@media (min-width: 600px) {
  .storage-panel {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--surface3);
    border-right: 1px solid var(--surface3);
  }
}
