/**
 * ====================================================================
 * WEBSITE CHÚC MỪNG 20/10 - CSS ĐIỀU KHIỂN NHẠC NỀN (MUSIC MODULE CSS)
 * ====================================================================
 * Định dạng giao diện nút bật/tắt nhạc nền góc trên bên phải màn hình:
 * - Phong cách Glassmorphism đồng bộ với tông màu Rose Gold & Night Sky của website.
 * - Hiệu ứng đĩa nhạc tự xoay nhịp nhàng và cột sóng âm thanh khi phát nhạc.
 * - Hiệu ứng nhịp thở phát sáng (pulse) và tooltip gợi ý khi trình duyệt chặn tự động phát.
 * - Đảm bảo khả năng tương tác độc lập, không che khuất hay ảnh hưởng đến các màn hình khác.
 */

/* Container cố định ở góc trên bên phải màn hình */
.music-control-container {
  position: fixed;
  top: clamp(14px, 2.5vh, 26px);
  right: clamp(14px, 2.5vw, 26px);
  z-index: 9999; /* Đảm bảo luôn nổi trên tất cả các layer */
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

/* Nút bấm điều khiển âm thanh dạng tròn cao cấp */
.music-toggle-btn {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 133, 162, 0.4);
  background: rgba(18, 8, 28, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #ff85a2;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  padding: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 14px rgba(255, 77, 136, 0.25);
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1),
              border-color 0.3s ease,
              box-shadow 0.3s ease,
              background-color 0.3s ease;
}

.music-toggle-btn:hover {
  transform: scale(1.08);
  border-color: rgba(255, 133, 162, 0.85);
  background: rgba(28, 12, 42, 0.85);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6), 0 0 22px rgba(255, 77, 136, 0.5);
  color: #ffffff;
}

.music-toggle-btn:active {
  transform: scale(0.94);
}

.music-toggle-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 133, 162, 0.6), 0 0 20px rgba(255, 77, 136, 0.4);
}

/* Đĩa nhạc xoay tròn */
.music-disc {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s ease;
}

.music-toggle-btn.is-playing .music-disc {
  animation: musicDiscSpin 4s linear infinite;
}

@keyframes musicDiscSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Biểu tượng nốt nhạc SVG */
.music-icon {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 0 4px rgba(255, 133, 162, 0.5));
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.music-icon.icon-muted {
  display: block;
}

.music-icon.icon-note {
  display: none;
}

/* Khi đang phát nhạc */
.music-toggle-btn.is-playing .music-icon.icon-muted {
  display: none;
}

.music-toggle-btn.is-playing .music-icon.icon-note {
  display: block;
}

/* Cột sóng âm thanh mini sinh động góc dưới nút */
.music-wave-bars {
  position: absolute;
  bottom: 5px;
  right: 5px;
  display: flex;
  align-items: flex-end;
  gap: 1.5px;
  height: 10px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.music-toggle-btn.is-playing .music-wave-bars {
  opacity: 1;
}

.music-wave-bars .bar {
  width: 2px;
  background: #ff85a2;
  border-radius: 1px;
  box-shadow: 0 0 4px #ff4d88;
}

.music-wave-bars .bar-1 {
  height: 4px;
}
.music-wave-bars .bar-2 {
  height: 8px;
}
.music-wave-bars .bar-3 {
  height: 5px;
}

.music-toggle-btn.is-playing .bar-1 {
  animation: musicWaveAnim 0.7s ease-in-out infinite alternate;
}
.music-toggle-btn.is-playing .bar-2 {
  animation: musicWaveAnim 0.5s ease-in-out 0.2s infinite alternate;
}
.music-toggle-btn.is-playing .bar-3 {
  animation: musicWaveAnim 0.8s ease-in-out 0.4s infinite alternate;
}

@keyframes musicWaveAnim {
  0% {
    height: 3px;
  }
  100% {
    height: 10px;
  }
}

/* Trạng thái bị trình duyệt chặn (Blocked Autoplay): nhấp nháy thu hút sự chú ý */
.music-toggle-btn.is-blocked {
  animation: musicPulseAttention 2s infinite;
  border-color: rgba(255, 133, 162, 0.8);
}

@keyframes musicPulseAttention {
  0%, 100% {
    box-shadow: 0 0 10px rgba(255, 77, 136, 0.3), 0 4px 16px rgba(0, 0, 0, 0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 24px rgba(255, 77, 136, 0.85), 0 0 35px rgba(255, 133, 162, 0.45);
    transform: scale(1.06);
  }
}

/* Tooltip gợi ý nhẹ nhàng "Nhấn để bật nhạc ♫" khi bị chặn */
.music-tooltip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  background: rgba(20, 8, 30, 0.88);
  border: 1px solid rgba(255, 133, 162, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff5f8;
  font-family: 'Montserrat', sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 12px rgba(255, 77, 136, 0.2);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s;
}

/* Hiển thị tooltip khi bị chặn hoặc hover */
.music-toggle-btn.is-blocked .music-tooltip,
.music-toggle-btn:hover .music-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}

/* Mũi tên nhỏ bên phải tooltip */
.music-tooltip::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  border-width: 4px;
  border-style: solid;
  border-color: transparent transparent transparent rgba(255, 133, 162, 0.45);
}

/* Ẩn tooltip khi nhạc đã bắt đầu phát thành công */
.music-toggle-btn.is-playing .music-tooltip {
  opacity: 0;
  visibility: hidden;
}

/* Thiết bị di động: Tối ưu kích thước cảm ứng và vị trí */
@media (max-width: 768px) {
  .music-control-container {
    top: 14px;
    right: 14px;
  }
  .music-toggle-btn {
    width: 42px;
    height: 42px;
  }
  .music-tooltip {
    font-size: 11px;
    padding: 4px 9px;
    right: calc(100% + 8px);
  }
}
