/* Control flotante de la música de fondo.
   Se dibuja desde comun/musica.js en todas las páginas salvo la portada. */

.musica-pastilla {
  position: fixed;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(26, 26, 28, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.45),
    0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);

  /* Estado inicial: escondida y un poco más chica, para entrar desde ahí */
  opacity: 0;
  transform: translateY(14px) scale(0.9);
  transform-origin: 0% 100%;
  pointer-events: none;
  transition:
    opacity 0.42s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.42s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.musica-pastilla.es-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* En /clases/ hay barra fija de WhatsApp abajo: la pastilla sube */
body[data-pastilla="alto"] .musica-pastilla {
  bottom: calc(100px + env(safe-area-inset-bottom));
}

.musica-pastilla-boton {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.musica-pastilla-boton:hover { background: rgba(255, 255, 255, 0.2); }
.musica-pastilla-boton:active { transform: scale(0.9); }

.musica-pastilla-boton:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.65);
  outline-offset: 2px;
}

.musica-pastilla-boton svg {
  position: absolute;
  width: 14px;
  height: 14px;
  fill: currentColor;
  transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.musica-pastilla-boton .i-play { opacity: 1; transform: scale(1) rotate(0deg); margin-left: 1px; }
.musica-pastilla-boton .i-stop { opacity: 0; transform: scale(0.5) rotate(-90deg); }

.musica-pastilla.suena .musica-pastilla-boton .i-play { opacity: 0; transform: scale(0.5) rotate(90deg); }
.musica-pastilla.suena .musica-pastilla-boton .i-stop { opacity: 1; transform: scale(1) rotate(0deg); }

/* Un latido muy leve mientras suena, para que se lea de reojo */
.musica-pastilla.suena .musica-pastilla-boton::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  animation: latido-musica 2.4s ease-out infinite;
}

@keyframes latido-musica {
  0%   { opacity: 0.7; transform: scale(1); }
  70%  { opacity: 0;   transform: scale(1.5); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* Volumen: se despliega al pasar por arriba o al enfocar */
.musica-pastilla-vol {
  width: 0;
  overflow: hidden;
  transition: width 0.38s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.28s ease;
  opacity: 0;
}

.musica-pastilla:hover .musica-pastilla-vol,
.musica-pastilla:focus-within .musica-pastilla-vol {
  width: 92px;
  opacity: 1;
}

/* En pantallas sin hover el volumen queda siempre a la vista */
@media (hover: none) {
  .musica-pastilla-vol { width: 82px; opacity: 1; }
}

.musica-pastilla-vol input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 84px;
  height: 4px;
  margin: 0 10px 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  cursor: pointer;
}

.musica-pastilla-vol input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.musica-pastilla-vol input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .musica-pastilla,
  .musica-pastilla-boton,
  .musica-pastilla-vol,
  .musica-pastilla-boton svg { transition: none; }
  .musica-pastilla.suena .musica-pastilla-boton::after { animation: none; }
}
