:root{
  --toggle-right: 24px;
  --toggle-top: 24px;

  --btn-width: 140px;
  --btn-height: 48px;
  --btn-gap: 10px;

  --panel-right: 24px;
  --panel-width: 360px;

  /* overlays start exactly under the two buttons */
  --overlay-top: calc(var(--toggle-top) + (var(--btn-height) * 2) + var(--btn-gap) + 12px);

  /* distance between playlist overlay and favorites overlay */
  --stack-gap: 12px;

  /* playlist overlay height (for stacking favorites under it) */
  --playlist-panel-height: 420px;
}


/* =========================== */
/* Playlist Toggle Button       */
/* =========================== */
.playlist-toggle-btn{
  position: fixed;
  width: var(--btn-width);
  height: var(--btn-height);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px) saturate(125%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4),
              0 0 12px rgba(var(--accent-b),0.25),
              0 0 24px rgba(var(--accent-a),0.15),
              0 0 36px rgba(var(--accent-c),0.1);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: buttonGlow 3s ease-in-out infinite;
}

.playlist-toggle-btn:hover{
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.5),
              0 0 18px rgba(var(--accent-b),0.4),
              0 0 36px rgba(var(--accent-a),0.3),
              0 0 54px rgba(var(--accent-c),0.2);
}

.playlist-toggle-btn:active{ transform: scale(0.98); }
.playlist-toggle-btn.playing{ animation: buttonBeat 0.8s ease-in-out infinite; }

.playlist-icon{ font-size: 18px; }
.playlist-text{ white-space: nowrap; }


#playlist-toggle{
  position: fixed;
  top: var(--toggle-top);
  right: var(--toggle-right);
  z-index: 120;
}

#favorites-toggle{
  position: fixed;
  top: calc(var(--toggle-top) + var(--btn-height) + var(--btn-gap));
  right: var(--toggle-right);
  z-index: 120;
}



/* Toggle Button Animations */
@keyframes buttonGlow{
  0%, 100%{
    box-shadow: 0 4px 12px rgba(0,0,0,0.4),
                0 0 12px rgba(var(--accent-b),0.3),
                0 0 24px rgba(var(--accent-a),0.2),
                0 0 36px rgba(var(--accent-c),0.15);
  }
  33%{
    box-shadow: 0 4px 12px rgba(0,0,0,0.4),
                0 0 12px rgba(var(--accent-a),0.3),
                0 0 24px rgba(var(--accent-c),0.2),
                0 0 36px rgba(var(--accent-b),0.15);
  }
  66%{
    box-shadow: 0 4px 12px rgba(0,0,0,0.4),
                0 0 12px rgba(var(--accent-c),0.3),
                0 0 24px rgba(var(--accent-b),0.2),
                0 0 36px rgba(var(--accent-a),0.15);
  }
}

@keyframes buttonBeat{
  0%,100%{
    box-shadow: 0 4px 12px rgba(0,0,0,0.4),
                0 0 10px rgba(var(--accent-b),0.25),
                0 0 20px rgba(var(--accent-a),0.2),
                0 0 30px rgba(var(--accent-c),0.15);
  }
  50%{
    box-shadow: 0 4px 12px rgba(0,0,0,0.4),
                0 0 20px rgba(var(--accent-b),0.5),
                0 0 40px rgba(var(--accent-a),0.4),
                0 0 60px rgba(var(--accent-c),0.3);
  }
}


/* =========================== */
/* Playlist Overlay (TOP PANEL) */
/* =========================== */
.playlist-overlay{
  position: fixed;
  top: var(--overlay-top);
  bottom: 15px;
  right: var(--panel-right);
  width: var(--panel-width);
  max-height: calc(100vh - 120px);
  z-index: 99;

  display: flex;
  flex-direction: column;

  background: linear-gradient(135deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04));
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  backdrop-filter: blur(16px) saturate(130%);
  box-shadow: 0 12px 40px rgba(0,0,0,0.6),
              0 0 0 1px rgba(255,255,255,0.1),
              0 0 30px rgba(var(--accent-b),0.4),
              0 0 60px rgba(var(--accent-a),0.3),
              0 0 90px rgba(var(--accent-c),0.2);
  overflow: hidden;

  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;

  transition: transform 0.4s cubic-bezier(0.4,0,0.2,1), opacity 0.3s ease;
  animation: playlistGlow 3s ease-in-out infinite;
}

.playlist-overlay.show{
  transform: translateX(0);
  opacity: 1;
  pointer-events: all;
}

.playlist-overlay.playing{
  animation: musicBeat 0.8s ease-in-out infinite;
}


/* Overlay Animations */
@keyframes playlistGlow{
  0%,100%{
    box-shadow: 0 12px 40px rgba(0,0,0,0.6),
                0 0 0 1px rgba(255,255,255,0.1),
                0 0 20px rgba(var(--accent-b),0.35),
                0 0 40px rgba(var(--accent-a),0.25),
                0 0 60px rgba(var(--accent-c),0.2);
  }
  33%{
    box-shadow: 0 12px 40px rgba(0,0,0,0.6),
                0 0 0 1px rgba(255,255,255,0.1),
                0 0 20px rgba(var(--accent-a),0.35),
                0 0 40px rgba(var(--accent-c),0.25),
                0 0 60px rgba(var(--accent-b),0.2);
  }
  66%{
    box-shadow: 0 12px 40px rgba(0,0,0,0.6),
                0 0 0 1px rgba(255,255,255,0.1),
                0 0 20px rgba(var(--accent-c),0.35),
                0 0 40px rgba(var(--accent-b),0.25),
                0 0 60px rgba(var(--accent-a),0.2);
  }
}

@keyframes musicBeat{
  0%,100%{
    box-shadow: 0 12px 40px rgba(0,0,0,0.6),
                0 0 0 1px rgba(255,255,255,0.1),
                0 0 16px rgba(var(--accent-b),0.25),
                0 0 32px rgba(var(--accent-a),0.2),
                0 0 48px rgba(var(--accent-c),0.15);
  }
  50%{
    box-shadow: 0 12px 40px rgba(0,0,0,0.6),
                0 0 0 1px rgba(255,255,255,0.1),
                0 0 28px rgba(var(--accent-b),0.5),
                0 0 56px rgba(var(--accent-a),0.4),
                0 0 84px rgba(var(--accent-c),0.3);
  }
}


/* ===============================
   FAVORITES OVERLAY (SAME SIZE & POSITION AS PLAYLIST)
=============================== */
#favorites-overlay{
  position: fixed;
  top: var(--overlay-top);
  bottom: 15px;
  right: var(--panel-right);
  width: var(--panel-width);
  max-height: calc(100vh - 120px);
  z-index: 98;

  display: flex;
  flex-direction: column;

  background: linear-gradient(135deg, rgba(255,255,255,0.08), rgba(255,255,255,0.04));
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  backdrop-filter: blur(16px) saturate(130%);
  box-shadow: 0 12px 40px rgba(0,0,0,0.6),
              0 0 0 1px rgba(255,255,255,0.1),
              0 0 30px rgba(var(--accent-b),0.4),
              0 0 60px rgba(var(--accent-a),0.3),
              0 0 90px rgba(var(--accent-c),0.2);
  overflow: hidden;

  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;

  transition: transform 0.4s cubic-bezier(0.4,0,0.2,1), opacity 0.3s ease;
  animation: playlistGlow 3s ease-in-out infinite;
}

#favorites-overlay.show{
  transform: translateX(0);
  opacity: 1;
  pointer-events: all;
}



/* =========================== */
/* Playlist Header & Close Btn  */
/* =========================== */
.playlist-header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.playlist-header h3{
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.3px;
}

.playlist-close{
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.playlist-close:hover{
  background: rgba(255,255,255,0.08);
  transform: rotate(90deg);
  box-shadow: 0 0 12px rgba(var(--accent-a),0.3),
              0 0 24px rgba(var(--accent-b),0.2);
}

.playlist-close:active{
  transform: scale(0.95) rotate(90deg);
}


/* =========================== */
/* Playlist Search & Sort       */
/* =========================== */
.playlist-search{
  width: calc(100% - 24px);
  margin: 10px 12px;
  padding: 8px 12px;
  border-radius: 12px;
  border: none;
  outline: none;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 14px;
  backdrop-filter: blur(8px) saturate(120%);
  transition: all 0.18s ease;
}

.playlist-search::placeholder{ color: rgba(255,255,255,0.5); }

.playlist-search:focus{
  border-color: rgba(var(--accent-a),0.5);
  box-shadow: 0 0 12px rgba(var(--accent-a),0.2);
}

.playlist-sort{
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  flex-wrap: wrap;
  align-items: center;
}

.sort-btn{
  flex: 1;
  padding: 6px 14px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,0.02);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  backdrop-filter: blur(6px) saturate(120%);
}

.sort-btn:hover{ background: rgba(255,255,255,0.06); transform: translateY(-2px); }
.sort-btn.active{
  background: linear-gradient(135deg, rgba(var(--accent-a),0.12), rgba(var(--accent-b),0.08));
  box-shadow: 0 0 16px rgba(var(--accent-a),0.2);
  font-weight: 700;
}


/* =========================== */
/* Playlist Tracks & Items      */
/* =========================== */
.playlist-tracks{
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 260px);
  overflow-y: auto;
  padding: 12px;
}

.playlist-tracks::-webkit-scrollbar{ width: 8px; }
.playlist-tracks::-webkit-scrollbar-track{ background: rgba(255,255,255,0.02); border-radius: 4px; }
.playlist-tracks::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.1); border-radius: 4px; }

.playlist-item{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.playlist-item:hover{ background: rgba(255,255,255,0.06); transform: translateX(-2px); }

.playlist-item.active,
.playlist-item.clicked span{
  color: transparent;
  background: linear-gradient(135deg, #6a5af9, #9b8cff);
  -webkit-background-clip: text;
  -moz-background-clip: text;
  background-clip: text;
  font-weight: 700;
}

.playlist-item.active::before{
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  border-radius: 2px;
  background: linear-gradient(180deg, #6a5af9, #9b8cff);
  animation: pulse 1.2s infinite;
}

.playlist-item-cover{
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.06);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.playlist-item-info{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.playlist-item-title{
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.playlist-item-artist{
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}


/* =========================== */
/* Collapsible Artist Groups    */
/* =========================== */
.playlist-artist-header{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #9b8cff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.playlist-artist-header:hover{ background: rgba(255,255,255,0.08); }
.artist-collapsed + .artist-group{ display: none; }
.artist-group{ display: flex; flex-direction: column; gap: 8px; }

.playlist-fav-btn{
  background: none;
  border: none;
  font-size: 18px;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  transition: transform .2s, color .2s;
}

.playlist-fav-btn.active{ color: #ff4f9a; }
.playlist-fav-btn:hover{ transform: scale(1.2); }


/* =========================== */
/* Animations & Pulse           */
/* =========================== */
@keyframes pulse{ 0%,100%{ opacity:0.6; } 50%{ opacity:1; } }


/* =========================== */
/* RESPONSIVE BREAKPOINTS       */
/* =========================== */

/* Small phones (iPhone SE, 320px-374px) */
@media (max-width: 374px){
  :root{
    --toggle-right: 10px;
    --toggle-top: 12px;
    --btn-width: 110px;
    --btn-height: 42px;
    --btn-gap: 8px;
    --panel-right: 10px;
    --panel-width: calc(100vw - 20px);
    --playlist-panel-height: 320px;
    --overlay-top: calc(var(--toggle-top) + (var(--btn-height) * 2) + var(--btn-gap) + 8px);
  }

  .playlist-toggle-btn{
    padding: 0 12px;
    font-size: 12px;
    gap: 6px;
  }

  .playlist-icon{ font-size: 14px; }
  .playlist-text{ font-size: 12px; }

  .playlist-overlay,
  #favorites-overlay{
    top: 120px !important;
    bottom: 15px;
    right: 10px !important;
    width: calc(100vw - 20px) !important;
    max-width: 100% !important;
    max-height: calc(100vh - 140px) !important;
  }

  .playlist-item-cover{ width: 44px; height: 44px; }
  .playlist-item-title{ font-size: 12px; }
  .playlist-item-artist{ font-size: 11px; }

  .playlist-search{
    width: calc(100% - 24px);
    margin: 8px 12px;
    font-size: 12px;
  }

  .playlist-sort{
    padding: 8px 12px;
    gap: 6px;
  }

  .sort-btn{
    padding: 5px 10px;
    font-size: 11px;
  }
}

/* iPhone 12/13/14 Pro, standard phones (375px-428px) */
@media (min-width: 375px) and (max-width: 428px){
  :root{
    --toggle-right: 12px;
    --toggle-top: 16px;
    --btn-width: 120px;
    --btn-height: 44px;
    --btn-gap: 8px;
    --panel-right: 12px;
    --panel-width: calc(100vw - 24px);
    --playlist-panel-height: 340px;
    --overlay-top: calc(var(--toggle-top) + (var(--btn-height) * 2) + var(--btn-gap) + 10px);
  }

  .playlist-toggle-btn{
    padding: 0 14px;
    font-size: 13px;
    gap: 6px;
  }

  .playlist-icon{ font-size: 16px; }

  .playlist-overlay,
  #favorites-overlay{
    top: 130px !important;
    bottom: 15px;
    right: 12px !important;
    width: calc(100vw - 24px) !important;
    max-width: 100% !important;
    max-height: calc(100vh - 150px) !important;
  }

  .playlist-item-cover{ width: 48px; height: 48px; }
  .playlist-item-title{ font-size: 13px; }
  .playlist-item-artist{ font-size: 11px; }

  .playlist-search{
    width: calc(100% - 24px);
    margin: 8px 12px;
    font-size: 13px;
  }

  .playlist-sort{
    padding: 10px 12px;
    gap: 6px;
  }

  .sort-btn{
    padding: 6px 12px;
    font-size: 12px;
  }
}

/* iPhone 14 Pro Max, large phones (429px-640px) */
@media (min-width: 429px) and (max-width: 640px){
  :root{
    --toggle-right: 16px;
    --toggle-top: 18px;
    --btn-width: 130px;
    --btn-height: 46px;
    --btn-gap: 10px;
    --panel-right: 16px;
    --panel-width: calc(100vw - 32px);
    --playlist-panel-height: 360px;
    --overlay-top: calc(var(--toggle-top) + (var(--btn-height) * 2) + var(--btn-gap) + 12px);
  }

  .playlist-toggle-btn{
    padding: 0 14px;
    font-size: 13px;
  }

  .playlist-overlay,
  #favorites-overlay{
    top: 140px !important;
    bottom: 15px;
    right: 16px !important;
    width: calc(100vw - 32px) !important;
    max-width: 380px !important;
    max-height: calc(100vh - 160px) !important;
  }

  .playlist-item-cover{ width: 50px; height: 50px; }

  .playlist-search{
    width: calc(100% - 24px);
    margin: 10px 12px;
  }

  .playlist-sort{
    padding: 12px 16px;
  }
}

/* iPad Mini portrait (744px-820px) */
@media (min-width: 641px) and (max-width: 820px){
  :root{
    --toggle-right: 20px;
    --toggle-top: 20px;
    --btn-width: 135px;
    --btn-height: 48px;
    --panel-right: 20px;
    --panel-width: 340px;
    --playlist-panel-height: 400px;
  }

  .playlist-overlay,
  #favorites-overlay{
    top: var(--overlay-top);
    bottom: 15px;
  }
}

/* iPad Air portrait, iPad Mini landscape (821px-1024px) */
@media (min-width: 821px) and (max-width: 1024px){
  :root{
    --toggle-right: 24px;
    --toggle-top: 24px;
    --btn-width: 140px;
    --btn-height: 48px;
    --panel-right: 24px;
    --panel-width: 360px;
    --playlist-panel-height: 420px;
  }

  .playlist-overlay,
  #favorites-overlay{
    top: var(--overlay-top);
    bottom: 15px;
  }
}

/* iPad Pro portrait (1025px-1366px) */
@media (min-width: 1025px) and (max-width: 1366px){
  :root{
    --toggle-right: 28px;
    --toggle-top: 28px;
    --btn-width: 145px;
    --btn-height: 50px;
    --panel-right: 28px;
    --panel-width: 380px;
    --playlist-panel-height: 440px;
  }

  .playlist-overlay,
  #favorites-overlay{
    top: var(--overlay-top);
    bottom: 15px;
  }
}

/* Small laptops (1367px-1440px) */
@media (min-width: 1367px) and (max-width: 1440px){
  :root{
    --toggle-right: 32px;
    --toggle-top: 32px;
    --btn-width: 150px;
    --btn-height: 52px;
    --panel-right: 32px;
    --panel-width: 400px;
    --playlist-panel-height: 460px;
  }

  .playlist-overlay,
  #favorites-overlay{
    top: var(--overlay-top);
    bottom: 15px;
  }
}

/* Large screens (1441px+) */
@media (min-width: 1441px){
  :root{
    --toggle-right: 40px;
    --toggle-top: 40px;
    --btn-width: 160px;
    --btn-height: 54px;
    --panel-right: 40px;
    --panel-width: 420px;
    --playlist-panel-height: 480px;
  }

  .playlist-overlay,
  #favorites-overlay{
    top: var(--overlay-top);
    bottom: 15px;
  }
}


/* =========================== */
/* Reduced Motion (Accessibility) */
/* =========================== */
@media (prefers-reduced-motion: reduce){
  .playlist-overlay,
  .playlist-toggle-btn,
  .playlist-item,
  .playlist-close:hover,
  .playlist-item.active::before{
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }
}