/* ===== Background Audio Player ===== */
.bg-audio-player {
  position: fixed;
  left: clamp(12px, 3vw, 20px);
  bottom: max(clamp(12px, 3vw, 20px), env(safe-area-inset-bottom));
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: rgba(28, 31, 42, 0.55);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.14));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  color: var(--text, #fff);
  font-family: var(--font-body, 'Inter', sans-serif);
  max-width: calc(100vw - 24px);
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.bg-audio-player:hover {
  border-color: var(--border-strong, rgba(255, 255, 255, 0.28));
}

/* --- Rotating disc / play-pause button --- */
.bg-audio-disc {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.bg-audio-disc-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  pointer-events: none;
  z-index: 2;
}

.bg-audio-disc-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  animation: bg-audio-spin 3.2s linear infinite;
  animation-play-state: paused;
}

.bg-audio-player.is-playing .bg-audio-disc-img {
  animation-play-state: running;
}

.bg-audio-disc:hover {
  filter: brightness(1.1);
}

.bg-audio-disc:active {
  transform: scale(0.97);
}

/* Pulse the whole disc to invite a click while nothing is playing */
.bg-audio-player:not(.is-playing) .bg-audio-disc {
  animation: bg-audio-pulse 1.8s ease-in-out infinite;
}

@keyframes bg-audio-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

@keyframes bg-audio-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .bg-audio-disc-img { animation: none; }
  .bg-audio-player:not(.is-playing) .bg-audio-disc { animation: none; }
}

/* --- Body: mute control + progress --- */
.bg-audio-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 148px;
}

.bg-audio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Status slot: label and visualizer share the same space and crossfade */
.bg-audio-status {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 14px;
}

.bg-audio-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted, #9096a5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.bg-audio-player.is-playing .bg-audio-label {
  opacity: 0;
  pointer-events: none;
}

/* --- Music bar visualizer (shown while playing) --- */
.bg-audio-visualizer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2px;
  width: 100%;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.bg-audio-player.is-playing .bg-audio-visualizer {
  opacity: 1;
}

.bg-audio-bar {
  flex: 1 1 auto;
  max-width: 2px;
  height: 20%;
  border-radius: 1px;
  background: var(--accent, #E06F52);
  animation: bg-audio-bounce 0.9s ease-in-out infinite;
  animation-play-state: paused;
  transform-origin: bottom;
}

.bg-audio-player.is-playing .bg-audio-bar {
  animation-play-state: running;
}

.bg-audio-bar:nth-child(1) { animation-duration: 0.72s; animation-delay: 0s; }
.bg-audio-bar:nth-child(2) { animation-duration: 0.95s; animation-delay: 0.05s; }
.bg-audio-bar:nth-child(3) { animation-duration: 0.65s; animation-delay: 0.1s; }
.bg-audio-bar:nth-child(4) { animation-duration: 1.05s; animation-delay: 0.15s; }
.bg-audio-bar:nth-child(5) { animation-duration: 0.8s; animation-delay: 0.2s; }
.bg-audio-bar:nth-child(6) { animation-duration: 0.6s; animation-delay: 0.25s; }
.bg-audio-bar:nth-child(7) { animation-duration: 1s; animation-delay: 0.3s; }
.bg-audio-bar:nth-child(8) { animation-duration: 0.7s; animation-delay: 0.35s; }
.bg-audio-bar:nth-child(9) { animation-duration: 0.9s; animation-delay: 0.4s; }
.bg-audio-bar:nth-child(10) { animation-duration: 0.68s; animation-delay: 0.45s; }
.bg-audio-bar:nth-child(11) { animation-duration: 1.1s; animation-delay: 0.5s; }
.bg-audio-bar:nth-child(12) { animation-duration: 0.75s; animation-delay: 0.55s; }
.bg-audio-bar:nth-child(13) { animation-duration: 0.85s; animation-delay: 0.6s; }
.bg-audio-bar:nth-child(14) { animation-duration: 0.62s; animation-delay: 0.65s; }
.bg-audio-bar:nth-child(15) { animation-duration: 1s; animation-delay: 0.7s; }
.bg-audio-bar:nth-child(16) { animation-duration: 0.78s; animation-delay: 0.75s; }

@keyframes bg-audio-bounce {
  0%, 100% { height: 20%; }
  50% { height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .bg-audio-bar { animation: none; height: 55%; }
}

.bg-audio-icon-btn {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.bg-audio-icon-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.bg-audio-icon-btn:active {
  transform: scale(0.92);
}

/* --- Progress bar --- */
.bg-audio-progress {
  cursor: pointer;
  padding: 4px 0;
  outline: none;
}

.bg-audio-progress-track {
  position: relative;
  width: 100%;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.bg-audio-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  border-radius: 3px;
  background: var(--accent, #E06F52);
  transition: width 0.1s linear;
}

.bg-audio-progress:focus-visible .bg-audio-progress-track {
  outline: 2px solid var(--accent, #E06F52);
  outline-offset: 2px;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .bg-audio-player {
    gap: 8px;
    padding: 5px 12px 5px 5px;
  }
  .bg-audio-disc { width: 36px; height: 36px; }
  .bg-audio-body { min-width: 120px; }
  .bg-audio-icon-btn { width: 22px; height: 22px; }
  .bg-audio-label { font-size: 10px; }
}

/* Collapse to a compact circular player on very narrow screens: drop the
   label/visualizer slot to save space, but keep the disc and mute control usable. */
@media (max-width: 380px) {
  .bg-audio-player { padding: 5px 10px 5px 5px; gap: 6px; }
  .bg-audio-body { min-width: 76px; }
  .bg-audio-status { display: none; }
}
