/* WebPlayer — estilos derivados de panel.css del bot de Discord (mismo tema
   oscuro, misma paleta y componentes: tarjetas de canción, barra de
   reproducción fija, playlists con carátula mosaico). */
:root {
  --bg: #1a1b1e; --panel: #2b2d31; --panel2: #313338; --panel3: #3a3c42;
  --accent: #5865f2; --accent2: #4752c4; --accent-glow: rgba(88,101,242,.35);
  --text: #f2f3f5; --muted: #949ba4; --danger: #da373c; --ok: #23a55a;
  --radius: 14px; --shadow: 0 6px 20px rgba(0,0,0,.28);
  --border: 1px solid rgba(255,255,255,.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }
body {
  background:
    radial-gradient(1100px 520px at 110% -15%, rgba(88,101,242,.18), transparent 55%),
    radial-gradient(900px 500px at -10% 0%, rgba(35,165,90,.08), transparent 50%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh; padding: 24px;
  padding-bottom: 104px; /* espacio para la barra de reproducción fija */
  -webkit-font-smoothing: antialiased;
}
.container { max-width: 1500px; margin: 0 auto; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--panel3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--panel3); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: #50535b; }

/* Topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-size: 1.4rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.brand-text { display: flex; flex-direction: column; }
.brand h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; }
.brand .sub { color: var(--muted); font-size: .8rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-pill {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--panel); border: var(--border);
  padding: 9px 16px; border-radius: 999px; font-size: .85rem; color: var(--muted);
  box-shadow: var(--shadow);
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.status-pill .dot.on { background: var(--ok); animation: pulse 2.2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(35,165,90,.5); }
  70% { box-shadow: 0 0 0 8px rgba(35,165,90,0); }
  100% { box-shadow: 0 0 0 0 rgba(35,165,90,0); }
}

/* Tabs y páginas */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 12px 22px; border: none; border-radius: 10px;
  background: var(--panel); color: var(--muted); cursor: pointer;
  font-size: 1rem; font-weight: 600; transition: background .15s, color .15s, box-shadow .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: #fff; box-shadow: 0 4px 14px var(--accent-glow); }
.page { display: none; background: var(--panel2); border: var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.page.active { display: block; }

/* Toolbar de la biblioteca */
.lib-toolbar { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin-bottom: 12px; }
.search {
  flex: 1; min-width: 220px; padding: 12px 16px; border: var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); font-size: .95rem;
}
.search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.sb-action {
  padding: 12px 16px; border: var(--border); border-radius: 10px; cursor: pointer;
  background: var(--panel); color: var(--text); font-weight: 600; font-size: .9rem;
  white-space: nowrap; transition: background .12s;
}
.sb-action:hover { background: var(--panel3); }
.sb-action.primary { background: var(--accent); color: #fff; border-color: transparent; }
.sb-action.primary:hover { background: var(--accent2); }
.lib-count { color: var(--muted); font-size: .82rem; margin-bottom: 12px; }
.lib-pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 20px; }
.lib-pager-label { color: var(--muted); font-size: .85rem; }

/* Tarjetas de canción (grilla estilo Spotify / YouTube Music) */
.song-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.song-grid .empty { grid-column: 1 / -1; }
.song-card {
  position: relative; cursor: pointer;
  background: var(--panel); border: var(--border); border-radius: 12px;
  padding: 10px; transition: background .12s;
}
.song-card:hover { background: var(--panel3); }
.song-card.now-playing { outline: 2px solid var(--accent); }
.song-art {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  border-radius: 8px; overflow: hidden; background: var(--panel2);
  display: grid; place-items: center; margin-bottom: 10px;
}
.song-art::after { content: '🎵'; font-size: 2rem; opacity: .4; }
.song-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.song-card .s-title {
  font-weight: 600; font-size: .9rem; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.song-card .s-artist { color: var(--muted); font-size: .8rem; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-card .s-plays { color: var(--muted); font-size: .72rem; margin-top: 3px; }
/* Botón flotante sobre la carátula (agregar a playlist) */
.song-add {
  position: absolute; right: 8px; bottom: 8px;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 1.1rem; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(6px);
  transition: opacity .14s, transform .14s, background .12s;
}
.song-card:hover .song-add { opacity: 1; transform: translateY(0); }
.song-add:hover { background: var(--accent2); }
.song-add:disabled { opacity: 1; transform: none; background: var(--ok); cursor: default; }
/* Botón secundario (esquina opuesta): agregar a una playlist en vez de a la cola */
.song-playlist-add {
  position: absolute; left: 8px; bottom: 8px;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.62); color: #fff; font-size: .78rem; cursor: pointer;
  display: grid; place-items: center;
  opacity: 0; transform: translateY(6px);
  transition: opacity .14s, transform .14s, background .12s;
}
.song-card:hover .song-playlist-add { opacity: 1; transform: translateY(0); }
.song-playlist-add:hover { background: var(--accent); }
@media (hover: none) { .song-add, .song-playlist-add { opacity: 1; transform: none; } }

/* Estado "cargando" mientras se pre-cachea en el worker antes de reproducir */
.ctrl.btn-loading { position: relative; color: transparent; pointer-events: none; }
.ctrl.btn-loading::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px;
  border: 2px solid var(--text); border-top-color: transparent; border-radius: 50%;
  animation: wp-spin .6s linear infinite;
}
@keyframes wp-spin { to { transform: rotate(360deg); } }

/* Playlists (tarjetas con carátula mosaico) */
.pl-create { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pl-create input {
  flex: 1; min-width: 0; padding: 10px 13px; border: var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); font-size: .92rem;
}
.pl-create input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.pl-create button {
  padding: 10px 16px; border: none; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.pl-create button:hover { background: var(--accent2); }
.playlists-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.playlists-list .empty { grid-column: 1 / -1; }
.pl-card { cursor: pointer; background: var(--panel); border: var(--border); border-radius: 12px; padding: 10px; transition: background .12s; }
.pl-card:hover { background: var(--panel3); }
.pl-cover {
  position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: 8px;
  overflow: hidden; background: var(--panel2); margin-bottom: 10px;
  display: grid; place-items: center;
}
.pl-cover::after { content: '🎶'; font-size: 2.4rem; opacity: .45; }
.pl-cover.has::after { content: none; }
.pl-cover.single img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pl-cover.mosaic { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.pl-cover.mosaic img { width: 100%; height: 100%; object-fit: cover; }
.pl-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-meta { color: var(--muted); font-size: .78rem; margin-top: 4px; }

/* Detalle de playlist (pantalla completa) */
.pl-detail {
  position: fixed; inset: 0; z-index: 14; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel2), var(--bg) 40%);
  padding: 22px 24px 116px;
}
.pl-detail-head { display: flex; gap: 20px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 20px; }
.pl-detail-cover {
  width: 180px; height: 180px; flex: none; border-radius: 12px; overflow: hidden;
  background: var(--panel3); display: grid; place-items: center;
  box-shadow: 0 16px 56px rgba(0,0,0,.55);
}
.pl-detail-cover::after { content: '🎶'; font-size: 3rem; opacity: .45; }
.pl-detail-cover.has::after { content: none; }
.pl-detail-cover.single img { width: 100%; height: 100%; object-fit: cover; }
.pl-detail-cover.mosaic { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.pl-detail-cover.mosaic img { width: 100%; height: 100%; object-fit: cover; }
.pl-detail-info { flex: 1; min-width: 260px; }
.pl-detail-name { display: flex; align-items: center; gap: 8px; }
.pl-detail-name h2 { font-size: 1.8rem; }
.pl-detail-meta { color: var(--muted); font-size: .85rem; margin: 6px 0 4px; }
.pl-rename-btn { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; padding: 2px 4px; border-radius: 6px; line-height: 1; }
.pl-rename-btn:hover { color: var(--text); background: var(--panel); }
.pl-modal-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pl-modal-actions button { padding: 9px 14px; border: var(--border); border-radius: 9px; cursor: pointer; background: var(--panel); color: var(--text); font-weight: 600; font-size: .85rem; }
.pl-modal-actions button.primary { background: var(--accent); color: #fff; border-color: transparent; }
.pl-modal-actions button.primary:hover { background: var(--accent2); }
.pl-modal-actions button.danger { color: var(--danger); }
.pl-modal-actions button.danger:hover { background: var(--danger); color: #fff; border-color: transparent; }
.pl-detail-items { max-width: 900px; }

/* Filas de cola / ítems de playlist */
.queue-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.queue-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: var(--border); border-radius: 10px; padding: 11px 14px;
  cursor: pointer; transition: background .1s, box-shadow .1s, opacity .1s;
}
.queue-item:hover { background: var(--panel3); }
.queue-item.dragging { opacity: .4; }
.queue-item.drag-over { box-shadow: 0 -3px 0 0 var(--accent); }
.queue-item.current {
  background: linear-gradient(90deg, rgba(88,101,242,.18), var(--panel));
  border-color: rgba(88,101,242,.4);
}
.queue-item .grip { color: var(--muted); cursor: grab; user-select: none; }
.queue-item .num { color: var(--muted); min-width: 22px; font-variant-numeric: tabular-nums; }
.queue-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .title small { color: var(--muted); }
.queue-item .dur { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.queue-item button { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px; }
.queue-item button:hover { color: var(--text); }
.queue-item button.del:hover { color: var(--danger); }
.q-art {
  width: 32px; height: 32px; border-radius: 6px; flex: none; overflow: hidden;
  background: var(--panel3) center/cover no-repeat;
  display: grid; place-items: center; font-size: .85rem; color: var(--muted);
}

.empty { color: var(--muted); text-align: center; padding: 18px; }

/* Barra de reproducción fija (estilo Spotify) */
.player-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; gap: 16px; padding: 10px 18px;
  background: var(--panel2); border-top: var(--border);
  box-shadow: 0 -6px 24px rgba(0,0,0,.4);
  cursor: pointer;
}
.player-bar .controls, .player-bar .pb-progress, .player-bar .pb-right { cursor: default; }
.pb-track { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.pb-art {
  position: relative; width: 52px; height: 52px; flex-shrink: 0;
  border-radius: 8px; background: var(--panel3); overflow: hidden; display: grid; place-items: center;
}
.pb-art::after { content: '🎵'; font-size: 1.2rem; opacity: .5; }
.pb-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pb-text { min-width: 0; }
.pb-title { font-weight: 600; font-size: .95rem; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-artist { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-center { display: flex; flex-direction: column; gap: 7px; flex: 0 1 560px; max-width: 620px; }
.pb-right { flex: 1; display: flex; align-items: center; justify-content: flex-end; }
.pb-volume { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 200px; }
.pb-volume input[type=range] { flex: 1; min-width: 70px; accent-color: var(--accent); cursor: pointer; }
.pb-vol-ico { font-size: 1rem; opacity: .85; flex-shrink: 0; cursor: pointer; }
.pb-vol-pct { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; width: 34px; text-align: right; }
.pb-progress { display: flex; align-items: center; gap: 10px; }
.pb-progress span { color: var(--muted); font-size: .72rem; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.progress { flex: 1; height: 6px; background: var(--bg); border-radius: 6px; cursor: pointer; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #7c86ff); border-radius: 6px; width: 0%; }
.controls { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: nowrap; }
.ctrl {
  padding: 8px 12px; border: var(--border); border-radius: 9px;
  background: var(--panel); color: var(--text); cursor: pointer;
  font-size: .95rem; min-width: 0; white-space: nowrap; transition: background .12s, transform .05s;
}
.ctrl:hover:not(:disabled) { background: var(--accent); border-color: transparent; }
.ctrl:active:not(:disabled) { transform: scale(.95); }
.ctrl:disabled { opacity: .35; cursor: not-allowed; }
.ctrl.on { background: var(--accent); border-color: transparent; color: #fff; }
.ctrl-play { font-size: 1.1rem; padding: 8px 16px; }
@media (max-width: 820px) {
  .pb-center { flex: 0 1 auto; }
  .pb-right { display: none; }
}
@media (max-width: 560px) {
  body { padding: 16px; padding-bottom: 104px; }
  .player-bar { gap: 10px; padding: 8px 12px; }
  .pb-art { width: 44px; height: 44px; }
  .pb-progress span { display: none; }
}

/* Vista "reproduciendo ahora" (estilo YouTube Music) */
/* El display de estas capas pisa al [hidden] del UA — hay que re-ocultarlas */
.np-view[hidden], .pl-detail[hidden] { display: none; }
.np-view {
  position: fixed; inset: 0; z-index: 14;
  background: linear-gradient(180deg, var(--panel2), var(--bg) 60%);
  display: flex; flex-direction: column;
  padding: 18px 24px 104px;
  animation: npv-up .25s ease;
}
@keyframes npv-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.npv-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-shrink: 0; }
.npv-close {
  width: 40px; height: 40px; border-radius: 50%; border: var(--border);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 1.3rem;
  display: grid; place-items: center; transition: background .12s; flex: none;
}
.npv-close:hover { background: var(--panel3); }
.npv-head-label { color: var(--muted); font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.npv-body { flex: 1; min-height: 0; display: flex; gap: 32px; }
.npv-art-side { flex: 0 1 340px; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.npv-art {
  width: min(38vh, 100%); max-width: 300px; aspect-ratio: 1 / 1;
  border-radius: 16px; overflow: hidden; background: var(--panel3);
  display: grid; place-items: center; box-shadow: 0 16px 56px rgba(0,0,0,.55);
}
.npv-art::after { content: '🎵'; font-size: 3rem; opacity: .4; }
.npv-art img { width: 100%; height: 100%; object-fit: cover; }
.npv-title { font-size: 1.4rem; font-weight: 700; text-align: center; }
.npv-artist { color: var(--muted); text-align: center; margin-top: 6px; }
.npv-queue-side { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.npv-queue-side .queue-list { overflow-y: auto; flex: 1; min-height: 0; padding-right: 4px; }
.pl-col-title { font-size: .92rem; margin-bottom: 8px; }
@media (max-width: 820px) {
  .np-view { padding: 14px 16px 96px; }
  .npv-body { flex-direction: column; gap: 16px; }
  .npv-art-side { flex: 0 0 auto; }
  .npv-art { width: min(30vh, 60%); }
  .npv-title { font-size: 1.2rem; }
}

/* Modales */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 1100; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel2); border: var(--border); border-radius: 16px; padding: 24px;
  width: 100%; max-width: 440px; box-shadow: 0 12px 48px rgba(0,0,0,.5);
}
.modal h2 { font-size: 1.2rem; margin-bottom: 6px; }
.modal-folder { color: var(--muted); font-size: .88rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { padding: 11px 18px; border: none; border-radius: 10px; cursor: pointer; background: var(--accent); color: #fff; font-weight: 600; }
.modal-actions button:hover { background: var(--accent2); }
.modal-actions .cancel { background: var(--panel); color: var(--muted); }
.modal-actions .cancel:hover { background: var(--bg); color: var(--text); }
.pl-modal { max-width: 1100px; max-height: 92vh; display: flex; flex-direction: column; }
.pl-lib-list { max-height: 62vh; overflow-y: auto; padding: 2px; }
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 42vh; overflow-y: auto; }
.pick-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--panel); border: var(--border); border-radius: 10px; padding: 11px 14px;
  color: var(--text); cursor: pointer; font-size: .92rem; font-weight: 600; transition: background .1s;
}
.pick-item:hover { background: var(--accent); border-color: transparent; }
.pick-item .pick-count { margin-left: auto; color: var(--muted); font-weight: 400; font-size: .8rem; }
.pick-item:hover .pick-count { color: rgba(255,255,255,.8); }

/* Toast */
#toast {
  position: fixed; bottom: 104px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 13px 26px;
  border-radius: 10px; font-weight: 600; display: none; z-index: 1200;
  box-shadow: var(--shadow);
}
#toast.ok { background: var(--ok); }

#audio { display: none; }
