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

:root {
  /* Paleta del gato: negro y blanco. Lo activo no se marca con color sino
     invirtiendo — tinta oscura sobre el blanco del ícono. */
  --bg: #0b0d10;
  --card: #151a21;
  --card2: #1e242d;
  --line: #262d37;
  --edge: #3a434f;
  --text: #e4e8ee;
  --dim: #8b939e;
  --accent: #f0f0f0;
  --ink: #0b0d10;
  --danger: #f87171;
  --radius: 14px;
}

html, body { height: 100%; }

/* Columna de altura fija: #scroll (header+stats+add+lista) escrollea adentro
   y el player es un footer en flujo — nada puede quedar tapado por él.
   (Antes el player era fixed + padding-bottom en el body: en el WebView del
   S10+ el scroll del documento no respondía y los tracks quedaban ocultos.) */
body {
  background: linear-gradient(180deg, #12151b 0%, var(--bg) 40%);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
  height: 100%;    /* fallback si el WebView no soporta dvh */
  height: 100dvh;
  overflow: hidden;
}
#scroll {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;   /* la fila que se desliza no ensancha la página */
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
}
.logo { width: 44px; height: 44px; border-radius: 11px; }
.title h1 { font-size: 1.3rem; letter-spacing: .5px; }
.title .sub { font-size: .72rem; color: var(--dim); letter-spacing: 2px; text-transform: uppercase; }
.icon-btn {
  margin-left: auto; background: none; border: none; color: var(--dim);
  font-size: 1.4rem; cursor: pointer; padding: 8px;
}
.icon-btn + .icon-btn { margin-left: 0; }

/* ---------- stats ---------- */
.stats { display: flex; gap: 10px; padding: 4px 16px 12px; }
.chip {
  flex: 1; min-width: 0; background: var(--card); border-radius: var(--radius);
  padding: 10px 6px; text-align: center; overflow: hidden;
}
.chip span { font-size: 1.05rem; font-weight: 600; color: var(--accent); display: block; }
.chip label { font-size: .68rem; color: var(--dim); letter-spacing: 1px; text-transform: uppercase; }

/* el chip de la vista activa abre la barra lateral: se ve pulsable y el nombre
   de la playlist se recorta en vez de desarmar la fila de chips */
.chip-list {
  border: 1px solid var(--line); font: inherit; color: inherit; cursor: pointer;
  display: block; transition: transform .12s, border-color .12s;
}
.chip-list:active { transform: scale(.96); border-color: var(--accent); }
.chip-list span {
  font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-list label { cursor: pointer; }

/* ---------- add ---------- */
.log-mini {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 10px;
  background: #090a0d; border: none; border-radius: 10px; padding: 8px 10px;
  font: .7rem/1.4 ui-monospace, Menlo, monospace; color: #9aa3ae; text-align: left; cursor: pointer;
}
.log-mini[hidden] { display: none; }
.log-mini span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-mini b { flex: none; font-weight: 400; color: var(--dim); font-family: -apple-system, Roboto, sans-serif; }
.log-mini b::after { content: " ▾"; }
.add { padding: 0 16px 12px; }
.add-row { display: flex; gap: 8px; }
#urlInput {
  /* min-width: 0 — sin esto el input no se encoge (ancho intrínseco ~20ch) y
     en pantallas angostas o con fuente grande empuja el botón fuera de la pantalla */
  flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 12px 14px; font-size: .95rem; outline: none;
}
#urlInput:focus { border-color: var(--accent); }
#btnAdd {
  background: var(--accent); color: var(--ink); border: none; border-radius: var(--radius);
  padding: 0 18px; font-weight: 700; font-size: .95rem; cursor: pointer;
  flex-shrink: 0; white-space: nowrap;
}
#btnAdd:disabled { opacity: .5; }
.scan-btn {
  flex: none; width: 48px; display: flex; align-items: center; justify-content: center;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.scan-btn svg { width: 22px; height: 22px; }
.scan-btn:active { transform: scale(.95); }

.files-btn {
  width: 100%; margin-top: 8px; padding: 11px; background: none; color: var(--text);
  border: 1px dashed var(--edge); border-radius: var(--radius); font: inherit; font-size: .88rem; cursor: pointer;
}
.install {
  display: flex; align-items: center; gap: 12px; margin-top: 10px; padding: 10px 12px;
  background: var(--card2); border: 1px solid var(--edge); border-radius: var(--radius); font-size: .82rem; line-height: 1.45;
}
.install span { flex: 1; }
.install button { flex: none; background: var(--accent); color: var(--ink); border: none; border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 700; cursor: pointer; }
.files-btn[hidden], .install[hidden], .install button[hidden] { display: none; }

/* ---------- escáner ---------- */
dialog.scan { padding: 14px; }
.scan-view { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #000; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 18%; border: 2px solid rgba(255, 255, 255, .85); border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
}
.scan-msg { font-size: .85rem; text-align: center; margin: 12px 4px; min-height: 2.6em; line-height: 1.4; }
.scan-msg.bad { color: var(--danger); }
#dlgScan .dlg-actions { justify-content: center; margin-bottom: 0; }
#btnAdd.cancel { background: var(--danger); color: #2a0606; }
.log {
  margin-top: 10px; background: #090a0d; border-radius: 10px; padding: 10px;
  font-size: .7rem; line-height: 1.5; color: #9aa3ae; max-height: 130px;
  overflow-y: auto; white-space: pre-wrap; word-break: break-all; cursor: pointer;
}

/* ---------- playlist ---------- */
.playlist { list-style: none; }
.playlist li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; user-select: none;
}
.playlist li.playing { background: var(--card2); outline: 1px solid var(--edge); }
.playlist li.drag { opacity: .85; outline: 2px dashed var(--accent); }
.tr-main { flex: 1; min-width: 0; cursor: pointer; }
.tr-title { font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
li.playing .tr-title { color: var(--accent); }
.tr-meta { font-size: .7rem; color: var(--dim); margin-top: 2px; }
.tr-btn {
  background: none; border: none; color: var(--dim); font-size: 1.05rem;
  padding: 8px 6px; cursor: pointer;
}
.tr-fav svg, .np-fav svg, .icon-btn.star svg { width: 20px; height: 20px; display: block; fill: none; }
.tr-fav.on, .np-fav.on { color: var(--accent); }
.tr-fav.on svg, .np-fav.on svg { fill: currentColor; }
.icon-btn.star svg { width: 24px; height: 24px; }
.tr-del:active { color: var(--danger); }
.tr-add:active { color: var(--accent); }
.tr-handle { cursor: grab; touch-action: none; font-size: 1.2rem; }

/* la lista que se está mirando: biblioteca o una playlist */

/* barras de "reproduciendo" */
.eq { display: none; align-items: flex-end; gap: 2px; height: 16px; width: 16px; flex: none; }
li.playing .eq { display: flex; }
.eq i { width: 4px; background: var(--accent); animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: .25s; }
.eq i:nth-child(3) { animation-delay: .5s; }
@keyframes eq { 0%,100% { height: 4px; } 50% { height: 15px; } }
li.playing.paused .eq i { animation-play-state: paused; }

.empty { text-align: center; color: var(--dim); padding: 40px 20px; line-height: 1.8; }

/* ---------- aviso con deshacer ---------- */
.toast {
  flex: none; display: flex; align-items: center; gap: 12px; margin: 0 16px 8px;
  background: var(--card2); border: 1px solid var(--edge); border-radius: var(--radius);
  padding: 8px 8px 8px 14px; font-size: .85rem;
}
.toast[hidden] { display: none; }
.toast span { flex: 1; }
.toast button { background: none; border: none; color: var(--accent); font: inherit; font-weight: 700; padding: 8px; cursor: pointer; }

/* ---------- player ---------- */
.player {
  flex: none;
  background: rgba(13, 16, 20, .97);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
}
.np { display: flex; align-items: center; padding-bottom: 6px; }
.np-fav { flex: none; background: none; border: none; color: var(--dim); padding: 6px; margin: -6px -6px -6px 0; cursor: pointer; }
.np-fav[hidden] { display: none; }
.np-title {
  flex: 1; min-width: 0; cursor: pointer;
  text-align: center; font-size: .9rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
}
.seek-row { display: flex; align-items: center; gap: 10px; }
.time { font-size: .7rem; color: var(--dim); min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; }
#seek { flex: 1; accent-color: var(--accent); height: 4px; }
/* Los controles son SVG, no emoji: Android pinta los emoji con su propia fuente
   de color e ignora el `color` del CSS, así que el estado activo no se veía. */
.controls { display: flex; justify-content: center; align-items: center; gap: 10px; padding-top: 8px; }
.ctl {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; padding: 0; border: none; border-radius: 50%;
  background: none; color: var(--text); cursor: pointer;
  transition: transform .12s ease, background-color .15s ease, color .15s ease;
}
.ctl .ico { width: 26px; height: 26px; display: block; }
.ctl:active { transform: scale(.9); }          /* el tap-highlight está apagado: el feedback lo da esto */
.ctl.big {
  width: 58px; height: 58px;
  background: var(--accent); color: var(--ink);
  box-shadow: 0 6px 18px rgba(240, 240, 240, .22);
}
.ctl.big .ico { width: 28px; height: 28px; }
.ctl.big:active { background: #ffffff; }
.ctl.small { width: 40px; height: 40px; color: var(--dim); }
.ctl.small .ico { width: 21px; height: 21px; }
/* activo = acento + pastilla tenue: se lee de un vistazo, no sólo por el tono */
.ctl.small.on { color: var(--ink); background: var(--accent); }

/* ---------- barra lateral de playlists ----------
   Fija a la derecha y fuera de pantalla; se abre con translateX. Mientras el
   dedo la arrastra manda el transform inline y .dragging apaga la transición
   para que no le pelee al gesto. */
.scrim {
  position: fixed; inset: 0; z-index: 20; background: rgba(4, 5, 7, .55);
  opacity: 0; pointer-events: none; transition: opacity .28s ease;
}
body.side-open .scrim { opacity: 1; pointer-events: auto; }
.side {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(88vw, 380px);
  display: flex; flex-direction: column;
  background: #12151b; border-left: 1px solid var(--line);
  box-shadow: -18px 0 44px rgba(0, 0, 0, .5);
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom));
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
}
body.side-open .side { transform: translateX(0); }
.side.dragging, .scrim.dragging { transition: none; }

.side-head { display: flex; align-items: flex-start; gap: 8px; padding: 0 4px 12px; }
.side-ttl { flex: 1; min-width: 0; }
.side-ttl h2 { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-meta { font-size: .68rem; color: var(--dim); letter-spacing: 1px; text-transform: uppercase; }
.side #playlist { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.side .playlist li { padding: 8px 6px 8px 10px; margin-bottom: 6px; }
.side .empty { padding: 30px 10px; font-size: .85rem; }
.side-hint { font-size: .66rem; color: var(--dim); line-height: 1.5; padding: 8px 4px 0; border-top: 1px solid var(--line); }

/* ---------- inicio: grilla de portadas ---------- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: 10px 14px; padding: 4px 16px 24px;
  grid-auto-flow: dense;   /* una fila de tema no deja un hueco al lado de una portada */
}
.tile {
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
  background: none; border: none; color: var(--text); text-align: left; cursor: pointer;
  font: inherit; padding: 0; -webkit-tap-highlight-color: transparent;
}
.tile:active .cov { transform: scale(.97); }
.tile .cov { margin-bottom: 6px; transition: transform .12s; }
.tile-name { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { font-size: .7rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid .tile:not(.tile-track) { margin-bottom: 8px; }
/* lo que suena se marca invirtiendo, como el resto de lo activo */
.tile.now .tile-name::before { content: "▶ "; font-size: .7em; vertical-align: 1px; }
.tile.now .cov { outline: 2px solid var(--accent); outline-offset: 3px; }
.tile { position: relative; -webkit-touch-callout: none; user-select: none; }
.tile img { -webkit-user-drag: none; pointer-events: none; }
/* un tema suelto: fila de lado a lado */
.tile-track {
  grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); padding: 8px 10px 8px 8px;
}
.tile-track { touch-action: pan-y; transition: transform .16s ease, opacity .16s ease; }
.tile-track.swiping { transition: none; }
.tile-track .cov { flex: none; width: 48px; margin: 0; border-radius: 8px; box-shadow: none; }
.tile-track .tr-main { display: flex; flex-direction: column; gap: 2px; }
.tile-track.now { background: var(--card2); outline: 1px solid var(--edge); }
.tile-track.now .cov { outline: none; }
/* mantenida apoyada: lista para borrar */
.tile.armed .cov { outline: 3px solid var(--danger); outline-offset: 3px; animation: armed .18s ease-out; }
@keyframes armed { from { transform: scale(.94); } }
/* la capa oscura va encima (no un filter en la portada: apagaría también el rojo del borde) */
.tile-del {
  position: absolute; top: 0; left: 0; right: 0; aspect-ratio: 1; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .5);
}
.tile-track.armed { outline: 3px solid var(--danger); }
.tile-track.armed .cov { outline: none; animation: none; }
.tile-track .tile-del { bottom: 0; aspect-ratio: auto; border-radius: var(--radius); justify-content: flex-end; padding-right: 10px; }
.tile-track .tile-del svg { width: 46px; height: 46px; padding: 11px; }
.tile-del svg {
  width: 58px; height: 58px; padding: 14px; border-radius: 50%;
  background: var(--danger); color: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
}

.cov {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 12px; background: var(--card); box-shadow: 0 8px 22px rgba(0, 0, 0, .45);
}
/* portada dibujada (playlists hechas a mano, Todo, Sueltos): sólo el ícono */
.cov.gen {
  display: flex; align-items: center; justify-content: center; color: var(--dim);
  background: linear-gradient(150deg, var(--card2) 0%, var(--card) 60%, #0e1116 100%);
  border: 1px solid var(--line);
}
.cov.gen svg { width: 34%; height: auto; }
.tile-new .cov.gen { align-items: center; justify-content: center; border-style: dashed; background: none; box-shadow: none; }
.tile-new .cov.gen b { font-size: 2.4rem; font-weight: 300; color: var(--dim); }
.tile-new .tile-name { color: var(--dim); }

/* ---------- una portada abierta ---------- */
#disc {
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px 18px; min-height: 100%;
}
#disc[hidden] { display: none; }
body.in-disc header { display: none; }
.disc-bar {
  /* pegada arriba: con una lista larga, «volver» queda siempre a mano */
  position: sticky; top: 0; z-index: 2; background: #12151b;
  align-self: stretch; display: flex; align-items: center; margin: 0 -16px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 6px;
}
.disc-bar .back { margin-left: 0; margin-right: auto; font-size: 2.1rem; line-height: 1; padding: 2px 12px 6px 0; color: var(--text); }
.disc-bar .icon-btn + .icon-btn { margin-left: 0; }
.disc-cover {
  position: relative; flex: none; width: min(60vw, 32vh, 300px); margin: 4px 0 0; padding: 0;
  background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .2s;
}
.disc-cover:active { transform: scale(.98); }
.disc-cover .cov { border-radius: 16px; box-shadow: 0 18px 50px rgba(0, 0, 0, .6); }
.disc-play {
  position: absolute; right: 10px; bottom: 10px; width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--ink); box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
}
.disc-play[hidden] { display: none; }
.disc-play svg { width: 24px; height: 24px; }
.disc-name { margin-top: 16px; font-size: 1.25rem; text-align: center; line-height: 1.25; }
.disc-meta { margin-top: 4px; font-size: .72rem; color: var(--dim); letter-spacing: 1.5px; text-transform: uppercase; }
.disc-meta { margin-bottom: 18px; }
#discList { align-self: stretch; }
#discList li { padding: 9px 6px 9px 12px; margin-bottom: 6px; gap: 6px; }
#discList .tr-btn { padding: 8px 5px; }

/* ---------- elegir playlist ---------- */
.pick { list-style: none; max-height: 46vh; overflow-y: auto; }
.pick-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: .88rem; padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
}
.pick-row.on { border-color: var(--accent); }
.pick-ck { flex: none; width: 14px; color: var(--accent); }
.pick-name { flex: 1; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-n { flex: none; font-size: .7rem; color: var(--dim); }

/* ---------- dialog ---------- */
dialog {
  background: var(--card2); color: var(--text); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 20px; width: min(92vw, 420px);
  margin: auto;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { font-size: 1.05rem; margin-bottom: 14px; }
.ver { font-size: .72rem; color: var(--dim); font-weight: 400; }
.field { display: block; font-size: .8rem; color: var(--dim); margin-bottom: 12px; }
.field input {
  width: 100%; margin-top: 6px; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: .9rem; outline: none;
}
.field.check { display: flex; gap: 8px; align-items: flex-start; line-height: 1.4; }
.field.check input { width: auto; margin-top: 2px; accent-color: var(--accent); }
.dlg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.dlg-actions button {
  background: var(--card); color: var(--text); border: 1px solid var(--edge);
  border-radius: 10px; padding: 9px 12px; font-size: .82rem; cursor: pointer;
}
.dlg-actions .primary { background: var(--accent); color: var(--ink); border: none; font-weight: 700; }
.msg { font-size: .78rem; color: var(--accent); min-height: 1.2em; margin-bottom: 8px; }
.credits { font-size: .74rem; color: var(--dim); text-align: center; margin-top: 14px; }
.credits a { color: var(--accent); text-decoration: none; }
.hint { font-size: .72rem; color: var(--dim); line-height: 1.5; margin-bottom: 12px; }
code { color: var(--accent); }
