/* ═══════════════════════════════════════════════════════════════════════════════
   GLOBAL MINI-PLAYER — Premium Claymorphism Edition
   3D Soft UI • Persistent Floating Audio Bar • GPU-accelerated 60fps
   ═══════════════════════════════════════════════════════════════════════════════ */

:root {
  --gmp-gold: #D4860A;
  --gmp-gold-light: #F5C842;
  --gmp-gold-glow: rgba(212, 134, 10, 0.4);
  --gmp-shadow-outer: 12px 12px 24px rgba(0, 0, 0, 0.15), -8px -8px 20px rgba(255, 255, 255, 0.8), inset 1px 1px 2px rgba(255, 255, 255, 0.9);
  --gmp-shadow-inner: inset 3px 3px 6px rgba(0, 0, 0, 0.08), inset -3px -3px 6px rgba(255, 255, 255, 0.7);
}

.gmp {
  position: fixed;
  /* Position snugly right above floating tab bar (bottom: 32px + height ~60px = 92px top edge) */
  bottom: calc(98px + max(env(safe-area-inset-bottom, 0px), 4px)) !important;
  left: 12px;
  right: 12px;
  /* Mini-player tier: above page content and the nav pill, but BELOW every
     sheet, modal and dialog. At 9000 this painted over the Insights modal,
     the Favorites note modal and Home's radio sheet. */
  z-index: var(--z-mini-player, 300);

  display: none; /* Hidden by default — shown via JS with display: flex */
  align-items: center;
  gap: 14px;
  padding: 10px 16px 10px 10px;
  min-height: 68px;

  /* Claymorphism: Soft 3D shape with dual shadows */
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(245, 245, 250, 0.75));
  border-radius: 20px;
  box-shadow:
    16px 16px 40px rgba(0, 0, 0, 0.12),
    -12px -12px 30px rgba(255, 255, 255, 0.9),
    inset 0 1px 1px rgba(255, 255, 255, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.5);

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.gmp--visible {
  display: flex;
}

/* ─── Artwork Thumbnail — Claymorphic Pill ─── */
.gmp__art {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  box-shadow:
    4px 4px 10px rgba(0, 0, 0, 0.2),
    -2px -2px 6px rgba(255, 255, 255, 0.1),
    inset 0 1px 2px rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.08);
}

.gmp__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ─── Track Info ─── */
.gmp__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gmp__title {
  font-family: -apple-system, 'SF Pro Display', 'Inter', BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #1d1d1f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gmp__live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #FF3B30;
  flex-shrink: 0;
  animation: gmpPulse 1.5s ease-in-out infinite;
}

@keyframes gmpPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.gmp__sub {
  font-size: 12px;
  font-weight: 400;
  color: rgba(60, 60, 67, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Controls — Claymorphic Buttons ─── */
.gmp__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.gmp__btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  color: #1d1d1f;
  padding: 0;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  
  /* Claymorphism */
  background: linear-gradient(145deg, rgba(255,255,255,0.9), rgba(240,240,240,0.6));
  box-shadow:
    4px 4px 8px rgba(0, 0, 0, 0.1),
    -2px -2px 6px rgba(255, 255, 255, 0.8),
    inset 0 1px 1px rgba(255, 255, 255, 0.9);
}

.gmp__btn:active {
  transform: scale(0.88);
  box-shadow:
    inset 3px 3px 6px rgba(0, 0, 0, 0.1),
    inset -2px -2px 4px rgba(255, 255, 255, 0.8);
}

.gmp__btn svg {
  width: 22px;
  height: 22px;
}

.gmp__btn--play {
  width: 48px;
  height: 48px;
  background: linear-gradient(145deg, #1d1d1f, #2a2a2a);
  color: #fff;
  border-radius: 50%;
  box-shadow:
    6px 6px 16px rgba(0, 0, 0, 0.2),
    -4px -4px 12px rgba(255, 255, 255, 0.3),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.gmp__btn--play::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.2) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.gmp__btn--play:active::after {
  opacity: 1;
}

.gmp__btn--play:active {
  background: linear-gradient(145deg, #151515, #1f1f1f);
  box-shadow:
    inset 4px 4px 8px rgba(0, 0, 0, 0.3),
    inset -2px -2px 6px rgba(255, 255, 255, 0.1);
}

.gmp__btn--play svg {
  width: 20px;
  height: 20px;
  transition: opacity 0.15s ease;
}

.gmp__btn--close {
  color: rgba(60, 60, 67, 0.4);
}

.gmp__btn--close svg {
  width: 16px;
  height: 16px;
}

/* ─── Progress Bar — Claymorphic Track ─── */
.gmp__progress {
  position: absolute;
  bottom: 6px;
  left: 18px;
  right: 18px;
  height: 4px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.08), inset -1px -1px 2px rgba(255, 255, 255, 0.6);
}

.gmp__progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #D4860A, #F5C842, #D4860A);
  background-size: 200% 100%;
  border-radius: 4px;
  width: 0%;
  transition: width 1s linear;
  will-change: width;
  animation: progressShine 3s ease-in-out infinite;
}

@keyframes progressShine {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   DARK MODE — Claymorphic Shadows
   ═══════════════════════════════════════════════════════════════════════════════ */

body.dark-mode .gmp,
[data-theme="dark"] .gmp {
  background: linear-gradient(145deg, rgba(20, 20, 20, 0.95), rgba(10, 10, 10, 0.9));
  box-shadow:
    16px 16px 40px rgba(0, 0, 0, 0.5),
    -8px -8px 30px rgba(255, 255, 255, 0.05),
    inset 0 1px 1px rgba(255, 255, 255, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

body.dark-mode .gmp__art,
[data-theme="dark"] .gmp__art {
  background: linear-gradient(145deg, #3a3a3a, #1f1f1f);
  box-shadow:
    4px 4px 10px rgba(0, 0, 0, 0.4),
    -2px -2px 6px rgba(255, 255, 255, 0.05),
    inset 0 1px 2px rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .gmp__btn,
[data-theme="dark"] .gmp__btn {
  background: linear-gradient(145deg, rgba(60, 50, 80, 0.8), rgba(40, 30, 60, 0.6));
  color: #f5f5f7;
  box-shadow:
    4px 4px 8px rgba(0, 0, 0, 0.3),
    -2px -2px 6px rgba(255, 255, 255, 0.05),
    inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

body.dark-mode .gmp__btn:active,
[data-theme="dark"] .gmp__btn:active {
  box-shadow:
    inset 3px 3px 6px rgba(0, 0, 0, 0.4),
    inset -2px -2px 4px rgba(255, 255, 255, 0.05);
}

body.dark-mode .gmp__btn--play,
[data-theme="dark"] .gmp__btn--play {
  background: linear-gradient(145deg, #D4860A, #C07808);
  color: #fff;
  box-shadow:
    6px 6px 16px rgba(212, 134, 10, 0.4),
    -4px -4px 12px rgba(255, 255, 255, 0.1),
    inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

body.dark-mode .gmp__btn--play:active,
[data-theme="dark"] .gmp__btn--play:active {
  box-shadow:
    inset 4px 4px 8px rgba(0, 0, 0, 0.3),
    inset -2px -2px 6px rgba(255, 255, 255, 0.2);
}

/* ─── Light mode override — Premium Claymorphism ─── */
[data-theme="light"] .gmp {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(250, 250, 252, 0.85));
  box-shadow:
    16px 16px 40px rgba(0, 0, 0, 0.1),
    -12px -12px 30px rgba(255, 255, 255, 1),
    inset 0 1px 1px rgba(255, 255, 255, 0.9),
    0 0 0 1px rgba(255, 255, 255, 0.7);
}

[data-theme="light"] .gmp__art {
  background: linear-gradient(145deg, #f0f0f0, #e0e0e0);
  box-shadow:
    4px 4px 10px rgba(0, 0, 0, 0.12),
    -2px -2px 6px rgba(255, 255, 255, 0.8),
    inset 0 1px 2px rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.6);
}

body.dark-mode .gmp__title,
[data-theme="dark"] .gmp__title { color: #f5f5f7; }
body.dark-mode .gmp__sub,
[data-theme="dark"] .gmp__sub { color: rgba(255, 255, 255, 0.8); }

[data-theme="light"] .gmp__title { color: #1A0A2E; }
[data-theme="light"] .gmp__sub { color: rgba(26, 10, 46, 0.6); }

[data-theme="light"] .gmp__btn--play {
  background: linear-gradient(145deg, #ffffff, #f5f5f7);
  color: #1A0A2E;
  box-shadow:
    6px 6px 16px rgba(0, 0, 0, 0.1),
    -4px -4px 12px rgba(255, 255, 255, 0.8),
    inset 0 1px 2px rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .gmp__btn--play:active {
  background: linear-gradient(145deg, #f0f0f0, #e8e8e8);
  box-shadow:
    inset 4px 4px 8px rgba(0, 0, 0, 0.1),
    inset -2px -2px 6px rgba(255, 255, 255, 0.5);
}

[data-theme="light"] .gmp__btn--close {
  color: rgba(60, 60, 67, 0.7);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   NO NAV BAR PAGES — position lower
   ═══════════════════════════════════════════════════════════════════════════════ */

.gmp--no-nav {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   DESKTOP OVERRIDE — Move mini player to sidebar
   ═══════════════════════════════════════════════════════════════════════════════ */
@media screen and (min-width: 1024px) {
  .gmp {
    left: 12px !important;
    right: auto !important;
    bottom: 60px !important;
    width: 256px !important;
    max-width: none !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
  }
  
  .gmp--visible {
    display: flex;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .gmp__live-dot {
    animation: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   VIEW TRANSITIONS — Persistent Mini Player During Navigation
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Mark mini player for view transition */
#gmp {
  view-transition-name: mini-player;
}

/* Hide the old snapshot of mini player (we want the real element) */
::view-transition-old(mini-player) {
  animation: none;
  display: none;
}

/* Show new snapshot instantly without animation */
::view-transition-new(mini-player) {
  animation: none;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   INSTANT VISIBILITY — Show immediately on page load if audio was playing
   ═══════════════════════════════════════════════════════════════════════════════ */

/* When body has this class, force mini player visible immediately */
body.gmp-should-be-visible #gmp {
  display: flex !important;
}

/* Prevent flash of hidden mini player on load */
#gmp {
  /* Start with opacity 0 but still in layout for instant fade-in */
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#gmp.gmp--visible {
  opacity: 1;
  transform: translateY(0);
}

/* Quick fade in animation for smooth appearance */
@keyframes gmp-quick-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#gmp.gmp--visible.gmp--animate-in {
  animation: gmp-quick-fade-in 0.2s ease-out;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   LOADING STATE — Spinner animation while audio buffers
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Loading overlay on artwork */
.gmp__loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 14px;
  backdrop-filter: blur(2px);
}

.gmp__loading-overlay.active {
  display: flex;
}

/* Spinner animation */
.gmp__spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: gmp-spin 0.8s linear infinite;
}

@keyframes gmp-spin {
  to { transform: rotate(360deg); }
}

/* Button spinner (inside play button) */
.gmp__btn-spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: gmp-spin 0.8s linear infinite;
}

.gmp__btn--play .gmp__btn-spinner {
  border-top-color: #fff;
}

body.dark-mode .gmp__btn-spinner,
[data-theme="dark"] .gmp__btn-spinner {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
}

/* Loading text indicator */
.gmp__loading-text {
  font-size: 11px;
  color: rgba(60, 60, 67, 0.6);
  margin-top: 2px;
  display: none;
}

.gmp--loading .gmp__loading-text {
  display: block;
}

body.dark-mode .gmp__loading-text,
[data-theme="dark"] .gmp__loading-text {
  color: rgba(255, 255, 255, 0.6);
}

/* Artwork position for overlay */
.gmp__art {
  position: relative;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   NAVIGATION TRANSITION STATE
   Keep mini player visible during view transitions
   ═══════════════════════════════════════════════════════════════════════════════ */

::view-transition-group(mini-player) {
  animation-duration: 0ms;
}

/* Ensure mini player stays above transition overlay */
html::view-transition {
  z-index: 2147483647;
}

/* Hide default view transition background for seamless feel */
::view-transition-image-wrapper(mini-player) {
  isolation: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SPOTIFY-STYLE FULL-SCREEN BACKGROUND
   ═══════════════════════════════════════════════════════════════════════════════ */

.gmp-background {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.5s ease, background-image 0.5s ease;
  pointer-events: none;
}

.gmp-background--visible {
  opacity: 1;
}

/* Blur effect for background */
.gmp-background::before {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  filter: blur(60px) saturate(1.2);
  transform: scale(1.1);
}

/* Dark overlay for better readability */
.gmp-background::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONNECTION STATES
   The singleton tracks connectionState ('reconnecting' | 'failed') but nothing
   ever read it, so a dead stream was visually identical to a paused one — the
   player sat there showing a play button that did nothing. These give the two
   failure states a quiet, non-alarming presence in keeping with the rest of the
   app, and mark the subtitle as the retry affordance.
═══════════════════════════════════════════════════════════════════════════ */
.gmp--reconnecting .gmp__sub {
  opacity: 0.75;
  font-style: italic;
}

.gmp--error .gmp__sub {
  color: #C2410C;
  font-weight: 600;
}

[data-theme="dark"] .gmp--error .gmp__sub,
html.dark-mode .gmp--error .gmp__sub {
  color: #FDBA74;
}

/* Subtle pulse while retrying, so it reads as "working" rather than "stuck". */
.gmp--reconnecting .gmp__art {
  animation: gmp-reconnect-pulse 1.6s ease-in-out infinite;
}

@keyframes gmp-reconnect-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  .gmp--reconnecting .gmp__art { animation: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   DEFER TO MODALS

   The z-scale already puts the mini player (--z-mini-player) below every sheet
   and modal tier, so a modal cannot be painted over. This is the second half of
   that contract: while a modal is open the player is also removed from the
   picture entirely, exactly as the bottom nav pill already is
   (Insights/insights.css `body.modal-open .tab-bar`).

   Why both: z-order alone still leaves an ambient control sitting on screen
   competing for attention and for taps at the bottom edge during a deliberate
   interruption. Playback is unaffected — this is purely visual.
═══════════════════════════════════════════════════════════════════════════ */
body.modal-open #gmp,
body.modal-open .gmp {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
