/* ── Global Persistent Player Bar (Spotify-style) ── */
#global-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #181818;
  border-top: 1px solid rgba(255,255,255,.08);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
#global-player.active { transform: translateY(0); }
body.gp-active { padding-bottom: 130px; }

/* ── 3-column layout ── */
.gp-content {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(360px, 2fr) minmax(240px, 1fr);
  align-items: center;
  padding: 16px 24px;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
  height: 120px;
  box-sizing: border-box;
}

/* ── LEFT column ── */
.gp-col-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.gp-artwork {
  width: 84px;
  height: 84px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #282828;
}

.gp-info {
  flex: 1;
  min-width: 0;
}
.gp-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.gp-artist {
  font-size: 0.85rem;
  color: #a7a7a7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* ── CENTER column ── */
.gp-col-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.gp-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Progress row */
.gp-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.gp-time {
  font-size: 0.85rem;
  color: #a7a7a7;
  flex-shrink: 0;
  min-width: 42px;
  font-variant-numeric: tabular-nums;
}
.gp-time-current { text-align: right; }
.gp-time-total { text-align: left; }

.gp-progress {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,.15);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.gp-progress:hover { height: 6px; }
.gp-progress-fill {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  width: 0;
  pointer-events: none;
  transition: background 0.2s;
}
.gp-progress:hover .gp-progress-fill { background: #1db954; }

/* ── RIGHT column ── */
.gp-col-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* ── Buttons ── */
.gp-btn {
  background: none;
  border: none;
  color: #a7a7a7;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, transform 0.1s;
}
.gp-btn:hover { color: #fff; }
.gp-btn svg { width: 27px; height: 27px; fill: currentColor; }

/* Play button - Spotify circle */
.gp-btn.gp-play-btn {
  background: #fff;
  color: #000;
  width: 48px;
  height: 48px;
  padding: 0;
}
.gp-btn.gp-play-btn:hover {
  transform: scale(1.06);
  background: #fff;
  color: #000;
}
.gp-btn.gp-play-btn svg { width: 27px; height: 27px; fill: #000; }

.gp-btn.gp-close { color: #666; }
.gp-btn.gp-close:hover { color: #e94560; }

.gp-speed {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 40px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 12px;
  padding: 2px 6px;
  color: #a7a7a7;
}
.gp-speed:hover { color: #fff; border-color: #fff; }

/* ── Volume ── */
.gp-volume-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}
.gp-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: rgba(255,255,255,.15);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.gp-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.gp-volume-wrap:hover .gp-volume-slider::-webkit-slider-thumb { opacity: 1; }
.gp-volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
}
.gp-volume-slider::-webkit-slider-runnable-track {
  background: linear-gradient(to right, #fff var(--volume-pct, 100%), rgba(255,255,255,.15) var(--volume-pct, 100%));
  border-radius: 2px;
  height: 4px;
}
.gp-volume-wrap:hover .gp-volume-slider::-webkit-slider-runnable-track {
  background: linear-gradient(to right, #1db954 var(--volume-pct, 100%), rgba(255,255,255,.15) var(--volume-pct, 100%));
}

/* ── Queue button badge ── */
.gp-queue-btn { position: relative; }
.gp-queue-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: #1db954;
  color: #000;
  font-size: 0.55rem;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.gp-queue-badge:empty { display: none; }

/* ── Queue panel ── */
.gp-queue-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: #181818;
  border-top: 1px solid rgba(255,255,255,.08);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.gp-queue-panel.open { max-height: 320px; overflow-y: auto; }
.gp-queue-panel::-webkit-scrollbar { width: 4px; }
.gp-queue-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.gp-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  color: #a7a7a7;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  background: #181818;
  z-index: 1;
}
.gp-queue-clear {
  background: none;
  border: none;
  color: #666;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}
.gp-queue-clear:hover { color: #1db954; background: rgba(29,185,84,.1); }

.gp-queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.2s;
  color: #a7a7a7;
}
.gp-queue-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.gp-queue-item.active { background: rgba(29,185,84,.12); color: #fff; }

.gp-queue-item .gp-qi-num {
  font-size: 0.7rem;
  color: #666;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.gp-queue-item.active .gp-qi-num { color: #1db954; }

.gp-queue-item .gp-qi-thumb {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}
.gp-queue-item .gp-qi-info { flex: 1; min-width: 0; overflow: hidden; }
.gp-queue-item .gp-qi-title {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gp-queue-item .gp-qi-artist {
  font-size: 0.68rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gp-queue-item .gp-qi-remove {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  transition: all 0.2s;
}
.gp-queue-item .gp-qi-remove:hover { color: #e94560; background: rgba(233,69,96,.1); }
.gp-queue-item .gp-qi-remove svg { width: 14px; height: 14px; fill: currentColor; }
.gp-queue-item.active .gp-qi-remove { visibility: hidden; }

/* ── Mobile (<640px) ── */
@media (max-width: 640px) {
  body.gp-active { padding-bottom: 96px; }

  .gp-content {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    height: 96px;
    position: relative;
  }

  /* Mobile progress bar on top via pseudo-element */
  .gp-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 3px;
    width: var(--gp-progress, 0%);
    background: #1db954;
    transition: width 0.3s linear;
  }

  .gp-artwork { width: 72px; height: 72px; border-radius: 6px; }

  .gp-col-left {
    flex: 1;
    min-width: 0;
  }

  /* Hide desktop center column on mobile */
  .gp-col-center { display: none; }

  /* Right col: simplified mobile controls */
  .gp-col-right { gap: 0; }
  .gp-volume-wrap,
  .gp-speed,
  .gp-close,
  .gp-queue-btn { display: none; }

  /* Show play + next on mobile right */
  .gp-col-right .gp-play-btn,
  .gp-col-right .gp-next-btn { display: flex; }

  /* Hide prev on mobile */
  .gp-col-right .gp-prev-btn { display: none; }
}

/* ── Mobile: move play/next controls to right col ── */
/* On mobile, the center col is hidden. We need play/next visible.
   Since they're in center col (hidden on mobile), we clone them via JS.
   OR we use CSS to show specific buttons.
   Approach: On mobile, unhide the .gp-col-right play/next that are actually
   in .gp-col-center. We'll handle this with JS mobile clone approach. */

/* Mobile play controls injected by JS */
.gp-mobile-controls {
  display: none;
}
@media (max-width: 640px) {
  .gp-mobile-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }
  .gp-mobile-controls .gp-btn { padding: 8px; }
  .gp-mobile-controls .gp-btn svg { width: 27px; height: 27px; }
  .gp-mobile-controls .gp-play-btn {
    background: #fff;
    color: #000;
    width: 48px;
    height: 48px;
    padding: 0;
  }
  .gp-mobile-controls .gp-play-btn svg { width: 27px; height: 27px; fill: #000; }

  /* Hide the col-right entirely on mobile since we use mobile-controls */
  .gp-col-right { display: none; }
}

/* ══════════════════════════════════════════════════════
   Now Playing Popup (Spotify mobile expanded view)
   ══════════════════════════════════════════════════════ */

/* ── Overlay ── */
.gp-popup {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.gp-popup.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ── Blurred background ── */
.gp-popup-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: blur(60px) brightness(0.3);
  transform: scale(1.3);
}
.gp-popup-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

/* ── Inner container ── */
.gp-popup-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 420px;
  margin: 0 auto;
  padding: 24px 24px 32px;
  overflow-y: auto;
  max-height: 100vh;
  box-sizing: border-box;
  transform: translateY(30px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.gp-popup.open .gp-popup-inner {
  transform: translateY(0);
  opacity: 1;
}

/* ── Header ── */
.gp-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 24px;
}
.gp-popup-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.gp-popup-close:hover { opacity: 1; }
.gp-popup-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.gp-popup-header-spacer { width: 28px; }

/* ── Artwork ── */
.gp-popup-artwork {
  width: 280px;
  height: 280px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  background: #282828;
  margin-bottom: 32px;
}

/* ── Info + bookmark ── */
.gp-popup-info {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
  margin-bottom: 24px;
}
.gp-popup-info-text {
  flex: 1;
  min-width: 0;
}
.gp-popup-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.gp-popup-artist {
  font-size: 0.875rem;
  color: rgba(255,255,255,0.6);
  margin-top: 4px;
}
/* ── Progress bar ── */
.gp-popup-progress {
  width: 100%;
  margin-bottom: 24px;
}
.gp-popup-pbar {
  position: relative;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  cursor: pointer;
  transition: height 0.15s;
}
.gp-popup-pbar:hover { height: 6px; }
.gp-popup-pfill {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  width: 0;
  pointer-events: none;
  transition: background 0.2s;
}
.gp-popup-pbar:hover .gp-popup-pfill { background: #1db954; }
.gp-popup-pthumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.gp-popup-pbar:hover .gp-popup-pthumb { opacity: 1; }
.gp-popup-times {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.5);
  font-variant-numeric: tabular-nums;
}

/* ── Controls ── */
.gp-popup-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin-bottom: 32px;
}
.gp-popup-prev,
.gp-popup-next {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  display: flex;
  transition: transform 0.1s, opacity 0.2s;
  opacity: 0.8;
}
.gp-popup-prev:hover,
.gp-popup-next:hover { opacity: 1; }
.gp-popup-prev svg,
.gp-popup-next svg { width: 36px; height: 36px; fill: currentColor; }

.gp-popup-play {
  background: #fff;
  border: none;
  color: #000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.gp-popup-play:hover { transform: scale(1.06); }
.gp-popup-play svg { width: 28px; height: 28px; fill: #000; }

/* Speed button + picker (in controls row) */
.gp-popup-speed-wrap { position: relative; }
.gp-popup-speed {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.8);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 36px;
  text-align: center;
}
.gp-popup-speed:hover { border-color: #fff; color: #fff; }
.gp-popup-speed-picker {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #282828;
  border-radius: 12px;
  padding: 8px 4px;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  z-index: 10;
  min-width: 64px;
}
.gp-popup-speed-picker.open { display: flex; }
.gp-popup-speed-picker button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.gp-popup-speed-picker button:hover { background: rgba(255,255,255,0.1); color: #fff; }
.gp-popup-speed-picker button.active { color: #1db954; }

/* AirPlay button */
.gp-popup-airplay {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  display: flex;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.gp-popup-airplay:hover { opacity: 1; }
.gp-popup-airplay svg { width: 24px; height: 24px; fill: currentColor; }

/* ── Queue section ── */
.gp-popup-queue {
  width: 100%;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 16px;
}
.gp-popup-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
  font-weight: 600;
}
.gp-popup-qclear {
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}
.gp-popup-qclear:hover { color: #1db954; background: rgba(29,185,84,0.1); }
.gp-popup-qlist {
  max-height: 240px;
  overflow-y: auto;
}
.gp-popup-qlist::-webkit-scrollbar { width: 4px; }
.gp-popup-qlist::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* Reuse queue item styles in popup — larger thumbs */
.gp-popup-qlist .gp-queue-item { border-radius: 6px; }
.gp-popup-qlist .gp-qi-thumb { width: 48px; height: 48px; border-radius: 6px; }

/* ── Body scroll lock ── */
body.gp-popup-open { overflow: hidden; }

/* ── Toast notification ── */
.tusach-toast {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1db954;
  color: #000;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.875rem;
  z-index: 10002;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.tusach-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
@media (max-width: 640px) {
  .tusach-toast { bottom: 120px; }
}

/* ── Mobile popup ── */
@media (max-width: 640px) {
  .gp-popup-inner {
    max-width: none;
    padding: 16px 20px 32px;
    transform: translateY(100%);
    opacity: 1;
  }
  .gp-popup.open .gp-popup-inner {
    transform: translateY(0);
  }

  .gp-popup-artwork {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    max-width: 320px;
  }
}
