/* ============================================================
   PERSISTENT PLAYER BAR
   ============================================================ */

#persistent-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: 76px;
  display: none; /* shown via JS when a track is loaded */
  align-items: center;
  gap: 20px;
  padding: 0 28px;
  background: rgba(10, 10, 10, 0.88);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#persistent-player.active { display: flex; }

/* Thumbnail */
#pp-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.08);
}

/* Track info */
#pp-info {
  flex-shrink: 0;
  min-width: 120px;
  max-width: 200px;
  overflow: hidden;
}
#pp-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  color: #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#pp-artist {
  display: block;
  font-size: 0.75rem;
  color: rgba(240,240,240,0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Progress */
#pp-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
#pp-current, #pp-duration {
  font-size: 0.72rem;
  color: rgba(240,240,240,0.45);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
}
#pp-seek {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 20px;             /* hit target — visual track is 2px via pseudo-element */
  background: transparent;
  cursor: pointer;
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
  width: 100%;
  touch-action: manipulation;
}
/* ── Track ── */
#pp-seek::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 100px;
  background: linear-gradient(to right, rgba(255,255,255,0.78) var(--seek-pct, 0%), rgba(255,255,255,0.13) var(--seek-pct, 0%));
}
#pp-seek::-moz-range-track {
  height: 2px;
  border-radius: 100px;
  background: rgba(255,255,255,0.13);
}
#pp-seek::-moz-range-progress {
  height: 2px;
  border-radius: 100px;
  background: rgba(255,255,255,0.78);
}

/* Controls */
#pp-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#pp-play {
  -webkit-appearance: none;
  appearance: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
#pp-play:hover { background: rgba(255,255,255,0.22); transform: scale(1.06); }

#pp-volume {
  -webkit-appearance: none;
  appearance: none;
  width: 72px;
  height: 3px;
  background: linear-gradient(to right, rgba(240,240,240,0.55) var(--vol-pct, 53%), rgba(255,255,255,0.15) var(--vol-pct, 53%));
  border-radius: 100px;
  cursor: pointer;
  border: none;
  padding: 0;
  touch-action: manipulation;
}
#pp-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(240,240,240,0.7);
  cursor: pointer;
}
#pp-volume::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(240,240,240,0.7);
  cursor: pointer;
  border: none;
}

/* Prev / Next skip buttons */
.pp-skip-btn {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  color: rgba(240,240,240,0.5);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 5px 7px;
  margin: 0;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  flex-shrink: 0;
}
.pp-skip-btn:hover { color: rgba(240,240,240,0.9); }

/* Shuffle / Repeat mode buttons */
.pp-mode-btn {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  color: rgba(240,240,240,0.35);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 5px 7px;
  margin: 0;
  position: relative;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  flex-shrink: 0;
}
.pp-mode-btn:hover { color: rgba(240,240,240,0.75); }
.pp-mode-btn.active { color: #4f9ef8; }
.pp-repeat-badge {
  position: absolute;
  top: 0;
  right: -1px;
  font-size: 0.55rem;
  font-weight: 600;
  line-height: 1;
  color: #4f9ef8;
}

/* Head tracking button */
#pp-headtrack {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: rgba(240,240,240,0.45);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 5px 9px;
  margin: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  flex-shrink: 0;
}
#pp-headtrack:hover { color: #f0f0f0; border-color: rgba(255,255,255,0.3); }
#pp-headtrack.active {
  color: #4f9ef8;
  border-color: #4f9ef8;
  background: rgba(79,158,248,0.12);
}

/* ── Mute toggle: hidden on desktop, shown on mobile via media query ── */
#pp-mute {
  display: none;
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  color: rgba(240,240,240,0.5);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 5px 7px;
  margin: 0;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
#pp-mute:hover { color: rgba(240,240,240,0.9); }
#pp-mute.muted { color: rgba(240,240,240,0.35); }

/* ── Desktop seek thumb — white ball, centered on 2px track ── */
#pp-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  margin-top: -5px;   /* center: -(thumbH - trackH) / 2 = -(12-2)/2 */
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}
#pp-seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}

/* ── Mobile: Tidal-style layout ──────────────────────────────────────────────
   Progress bar occupies a full-width top row (edge-to-edge).
   Time labels sit below it, small, left/right aligned.
   Second row: thumbnail · track info (flex:1) · playback controls.
   ─────────────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #persistent-player {
    flex-wrap: wrap;
    align-items: center;
    height: auto;
    min-height: 82px;
    gap: 4px 0;         /* row-gap between progress row and controls row */
    padding: 0;
    padding-bottom: 6px;
  }

  /* ── Top row: seek bar + time labels + headtrack ── */
  #pp-progress {
    order: -1;          /* always first regardless of DOM order */
    flex: 0 0 100%;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 36px;  /* 36px reserved for headtrack */
    grid-template-rows: auto auto;
    gap: 0;
    padding: 0 16px;    /* side margins — bar stays within the layout */
    margin: 0;
    min-width: 0;
    align-items: stretch;
    box-sizing: border-box;
  }

  /* Seek bar — same track+ball as desktop, with proper touch handling */
  #pp-seek {
    grid-column: 1 / 3;  /* spans columns 1–2, leaving col 3 for headtrack */
    width: 100%;
    height: 28px;       /* larger hit target for fingers */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: none; /* give all touch directly to the range input;
                           prevents iOS from treating horizontal drag as scroll */
  }
  /* Mobile thumb: slightly larger than desktop for touch accuracy */
  #pp-seek::-webkit-slider-thumb {
    width: 14px;
    height: 14px;
    margin-top: -6px;   /* center 14px thumb on 2px track: -(14-2)/2 */
  }
  #pp-seek::-moz-range-thumb {
    width: 14px;
    height: 14px;
  }

  /* Time labels: below the bar, aligned to progress padding edges */
  #pp-current {
    grid-column: 1;
    text-align: left;
    font-size: 0.57rem;
    color: rgba(240,240,240,0.28);
    padding: 2px 0 0;
    min-width: unset;
  }
  #pp-duration {
    grid-column: 2;
    text-align: right;
    font-size: 0.57rem;
    color: rgba(240,240,240,0.28);
    padding: 2px 0 0;
    min-width: unset;
  }

  #pp-headtrack {
    grid-column: 3;
    grid-row: 1 / 3;   /* spans both rows, vertically centred */
    align-self: center;
    justify-self: center;
    padding: 4px 6px;
    font-size: 0.78rem;
  }

  /* ── Second row: thumbnail + info + controls ── */
  #pp-thumb {
    width: 36px;
    height: 36px;
    margin-left: 14px;
    flex-shrink: 0;
  }

  #pp-info {
    flex: 1;
    min-width: 0;
    max-width: none;
    flex-shrink: 1;
    padding: 0 10px;
  }

  #pp-artist { display: none; }

  #pp-controls {
    flex-shrink: 0;
    gap: 4px;
    padding-right: 14px;
  }

  #pp-volume { display: none; }
  #pp-mute   { display: flex; }

  #pp-shuffle, #pp-repeat {
    font-size: 0.72rem;
    padding: 4px 5px;
  }
  .pp-skip-btn {
    padding: 5px 6px;
  }

}

/* ── Very small phones (≤380px): drop thumbnail, tighten spacing ── */
@media (max-width: 380px) {
  #pp-thumb    { display: none; }
  #pp-info     { padding: 0 6px; }
  #pp-controls { gap: 2px; }
  .pp-skip-btn { padding: 4px 5px; }
  #pp-shuffle, #pp-repeat { padding: 4px 3px; }
}
