/* ==========================================================================
   B2 Player — player.css
   Mobile-first, dark theme, clean card layout
   ========================================================================== */

/* --------------------------------------------------------------------------
   Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Ensure the HTML `hidden` attribute always wins over explicit display rules */
[hidden] { display: none !important; }

/* Used to toggle play/pause SVG icons — more reliable than [hidden] inside flex containers */
.icon-hidden { display: none !important; }

:root {
  --bg:          #0f0f13;
  --surface:     #1a1a24;
  --surface2:    #22222f;
  --border:      #2e2e40;
  --accent:      #7c6af7;
  --accent-dim:  #4e3fc8;
  --accent-glow: rgba(124, 106, 247, 0.25);
  --text:        #e8e8f0;
  --text-muted:  #8888a8;
  --danger:      #e05c5c;
  --radius:      14px;
  --radius-sm:   8px;
  --transition:  0.2s ease;
}

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
  /* Prevent overscroll bounce on iOS */
  overscroll-behavior: none;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  /* Enough clearance for the player bar (~155px) plus the iOS home indicator.
     env(safe-area-inset-bottom) is ~34px on Face ID iPhones, 0 elsewhere. */
  padding: 0 0 calc(175px + env(safe-area-inset-bottom));
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Push content below the iOS status bar in standalone PWA mode.
     env(safe-area-inset-top) is ~44-54px on notched iPhones, ~20px on older
     models, and 0 in a normal browser tab — so this is harmless elsewhere. */
  padding: calc(18px + env(safe-area-inset-top)) 16px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
}

header h1 span { color: var(--text); font-weight: 400; }

.header-actions { display: flex; gap: 8px; }

/* --------------------------------------------------------------------------
   Buttons (shared)
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dim); }

.btn-ghost {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

.btn-icon {
  padding: 8px;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  line-height: 1;
}
.btn-icon:hover { background: var(--accent); border-color: var(--accent); }
.btn-icon.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 10px var(--accent-glow);
}

/* --------------------------------------------------------------------------
   Search bar
   -------------------------------------------------------------------------- */
#search-wrap {
  padding: 10px 16px;
  background: var(--bg);
  position: sticky;
  /* The sticky offset must account for the taller header in PWA mode.
     57px = normal header height; safe-area-inset-top shifts it down further. */
  top: calc(57px + env(safe-area-inset-top));
  z-index: 99;
}

#search {
  width: 100%;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  /* 16px minimum prevents iOS Safari from auto-zooming on input focus */
  font-size: 16px;
  outline: none;
  transition: border-color var(--transition);
}
#search::placeholder { color: var(--text-muted); }
#search:focus { border-color: var(--accent); }

/* --------------------------------------------------------------------------
   Playlist / track list
   -------------------------------------------------------------------------- */
#playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
}

#track-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

#playlist {
  list-style: none;
  padding: 0 8px;
}

.track-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid transparent;
}

.track-item:hover { background: var(--surface); }

.track-item.active {
  background: var(--surface2);
  border-color: var(--border);
}

.track-item.active .track-title {
  color: var(--accent);
}

/* Album art thumbnail */
.track-art {
  width: 46px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}

.track-art-placeholder {
  width: 46px;
  height: 46px;
  border-radius: 6px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 1.2rem;
}

.track-info { flex: 1; min-width: 0; }

.track-title {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-num {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 22px;
  text-align: right;
  flex-shrink: 0;
}

/* Playing indicator (animated bars) */
.now-playing-icon {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  flex-shrink: 0;
}
.track-item.active .now-playing-icon { display: flex; }
.track-item.active .track-num { display: none; }

.now-playing-icon span {
  display: block;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: equalizer 0.8s ease-in-out infinite alternate;
}
.now-playing-icon span:nth-child(1) { height: 8px;  animation-delay: 0s;    }
.now-playing-icon span:nth-child(2) { height: 14px; animation-delay: 0.15s; }
.now-playing-icon span:nth-child(3) { height: 6px;  animation-delay: 0.3s;  }

@keyframes equalizer {
  from { transform: scaleY(0.4); }
  to   { transform: scaleY(1);   }
}

/* Paused state — freeze bars */
body.paused .now-playing-icon span { animation-play-state: paused; }

/* --------------------------------------------------------------------------
   Empty / loading states
   -------------------------------------------------------------------------- */
#empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
#empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
#empty-state p { font-size: 0.9rem; }

/* --------------------------------------------------------------------------
   Now-Playing sticky bar (bottom)
   -------------------------------------------------------------------------- */
#player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 16px 14px;
  /* Safe area for iPhone home bar */
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Limit width on desktop */
#player-bar-inner {
  max-width: 680px;
  margin: 0 auto;
}

/* Track info row */
#now-playing-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

#now-art {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}

#now-art-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.3rem;
  flex-shrink: 0;
}

#now-text { flex: 1; min-width: 0; }

#now-title {
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#now-artist {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Controls row */
#controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.ctrl-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
/* All SVGs inside control buttons inherit colour and never capture pointer events */
.ctrl-btn svg {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
  flex-shrink: 0;
}
.ctrl-btn:active { transform: scale(0.92); }
.ctrl-btn:hover  { color: var(--text); background: var(--surface2); }
.ctrl-btn.active { color: var(--accent); }

/* Play / Pause — large purple circle */
#play-pause-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px var(--accent-glow);
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}
#play-pause-btn svg { width: 22px; height: 22px; }
/* Nudge play triangle 1 px right for optical centering */
#icon-play { transform: translateX(1px); }
#play-pause-btn:hover  { background: var(--accent-dim); }
#play-pause-btn:active { transform: scale(0.94); }

/* Progress bar */
#progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

#progress-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

#progress-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  margin-top: -5px;
}

#progress-bar::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
}

#progress-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.time-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  width: 36px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.time-label:last-child { text-align: right; }

/* --------------------------------------------------------------------------
   Toast notification
   -------------------------------------------------------------------------- */
#toast {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 300;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --------------------------------------------------------------------------
   Sync status
   -------------------------------------------------------------------------- */
#sync-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0 8px;
}

/* --------------------------------------------------------------------------
   Scrollbar (desktop)
   -------------------------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* --------------------------------------------------------------------------
   Desktop tweaks (≥ 600 px)
   -------------------------------------------------------------------------- */
@media (min-width: 600px) {
  header { padding: calc(20px + env(safe-area-inset-top)) 24px 14px; }
  #search-wrap { padding: 10px 24px; }
  #playlist { padding: 0 16px; }
  #playlist-header { padding: 10px 24px 6px; }
  #player-bar { padding: 12px 24px 16px; }
  .track-item { padding: 11px 12px; }
  #play-pause-btn { width: 56px; height: 56px; font-size: 1.6rem; }
}

/* --------------------------------------------------------------------------
   Share button (per track row)
   -------------------------------------------------------------------------- */
.share-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition),
              background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.share-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  pointer-events: none;
}

/* Always visible on touch devices (no hover state) */
@media (hover: none) {
  .share-btn { opacity: 1; }
}

/* Show on hover for mouse users */
.track-item:hover .share-btn { opacity: 1; }
.track-item.active .share-btn { opacity: 1; }

.share-btn:hover  { color: var(--accent); background: var(--surface2); }
.share-btn:active { transform: scale(0.88); }

/* --------------------------------------------------------------------------
   Lock / passcode screen
   -------------------------------------------------------------------------- */
#lock-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

#lock-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#lock-logo {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.04em;
}

#lock-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

#lock-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  text-align: center;
  outline: none;
  letter-spacing: 0.1em;
  transition: border-color var(--transition);
}
#lock-input:focus { border-color: var(--accent); }

#lock-submit {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

#lock-error {
  font-size: 0.82rem;
  color: var(--danger);
  min-height: 1.2em;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Upload modal
   -------------------------------------------------------------------------- */
#upload-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#upload-modal {
  position: fixed;
  inset: 0;
  z-index: 401;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 env(safe-area-inset-bottom);
  pointer-events: none;
}

#upload-card {
  pointer-events: all;
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#upload-card h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.upload-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

#upload-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 28px 16px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  color: var(--text-muted);
  text-align: center;
}
#upload-drop-zone:hover {
  border-color: var(--accent);
  background: rgba(124, 106, 247, 0.06);
  color: var(--text);
}
#upload-drop-zone svg { flex-shrink: 0; }

#upload-drop-label {
  font-size: 0.88rem;
  word-break: break-all;
}

#upload-progress-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

#upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s ease;
}

#upload-status {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-height: 1.2em;
  text-align: center;
}

.upload-actions {
  display: flex;
  gap: 10px;
}

.upload-actions .btn {
  flex: 1;
  justify-content: center;
}

/* Desktop: show modal as a centered card instead of bottom sheet */
@media (min-width: 600px) {
  #upload-modal {
    align-items: center;
    padding: 0;
  }
  #upload-card {
    border-radius: var(--radius);
    max-width: 440px;
    padding: 28px 24px 32px;
  }
}
