* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22223a;
  --accent: #7c6af7;
  --accent2: #a78bfa;
  --text: #f0f0f5;
  --muted: #6b6b8a;
  --border: #2a2a3d;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}

/* ── Header ── */
header {
  padding: 5px 20px 0;
  text-align: center;
  position: relative;
}
header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
#track-count {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Now Playing card ── */
#now-playing {
  margin: 10px 16px 0;
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  border: 1px solid var(--border);
}

#album-art {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 16px;
  box-shadow: 0 8px 32px rgba(124,106,247,0.35);
  transition: transform 0.3s;
}
#album-art.playing { animation: spin-slow 8s linear infinite; }
@keyframes spin-slow { to { transform: rotate(360deg); } }

#track-title {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
#track-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 16px;
}

/* Progress */
#progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
#progress-wrap span { font-size: 0.72rem; color: var(--muted); min-width: 34px; }
#progress-wrap span:last-child { text-align: right; }
#progress {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
#progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent2);
  cursor: pointer;
}

/* Controls */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.ctrl-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  font-size: 1.1rem;
}
.ctrl-btn:hover { color: var(--text); }
.ctrl-btn.active { color: var(--accent2); }
#play-btn {
  width: 54px; height: 54px;
  background: var(--accent);
  color: white;
  font-size: 1.3rem;
  box-shadow: 0 4px 20px rgba(124,106,247,0.45);
  transition: background 0.2s, transform 0.1s;
}
#play-btn:hover { background: var(--accent2); transform: scale(1.05); }
#play-btn:active { transform: scale(0.96); }

/* Volume */
#volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
#volume-row svg { color: var(--muted); flex-shrink: 0; }
#volume {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--muted);
  cursor: pointer;
}

/* ── Search ── */
#search-wrap {
  margin: 16px 16px 0;
  position: relative;
}
#search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
#search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px 10px 40px;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--muted); }

/* ── Track list ── */
#playlist-wrap {
  flex: 1;
  overflow-y: auto;
  margin: 12px 16px 0;
  margin-bottom: 0;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  min-height: 0;
}
#playlist { list-style: none; }
.track-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.track-item:last-child { border-bottom: none; }
.track-item:hover { background: var(--surface2); }
.track-item.active {
  background: rgba(124,106,247,0.12);
}
.track-num {
  width: 22px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
}
.track-item.active .track-num { display: none; }
.track-playing-icon {
  display: none;
  width: 22px;
  flex-shrink: 0;
  justify-content: center;
}
.track-item.active .track-playing-icon { display: flex; }
.track-playing-icon svg { color: var(--accent2); }
.track-info { flex: 1; min-width: 0; }
.track-name {
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.track-item.active .track-name { color: var(--accent2); }
.track-dur {
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}
.track-plays {
  font-size: 0.68rem;
  color: var(--muted);
  flex-shrink: 0;
  margin-right: 6px;
  letter-spacing: 0.02em;
}

/* scrollbar */
#playlist-wrap::-webkit-scrollbar { width: 4px; }
#playlist-wrap::-webkit-scrollbar-track { background: transparent; }
#playlist-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* pull-to-refresh indicator */
#ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
#ptr-indicator.visible {
  opacity: 1;
}
#ptr-indicator.refreshing svg {
  animation: ptr-spin 0.8s linear infinite;
}
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* ── Search Modal ── */
#yt-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
#yt-modal-backdrop.open { display: flex; }
#yt-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-up 0.25s ease;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
#yt-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
#yt-search-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
#yt-search-input:focus { border-color: var(--accent); }
#yt-search-input::placeholder { color: var(--muted); }
#yt-search-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 0.88rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
#yt-search-btn:hover { background: var(--accent2); }
#yt-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  flex-shrink: 0;
}
#yt-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
#yt-results::-webkit-scrollbar { width: 4px; }
#yt-results::-webkit-scrollbar-track { background: transparent; }
#yt-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.yt-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.yt-item:last-child { border-bottom: none; }
.yt-item:hover { background: var(--surface2); }
.yt-thumb {
  width: 72px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}
.yt-info { flex: 1; min-width: 0; }
.yt-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.yt-meta { font-size: 0.72rem; color: var(--muted); margin-top: 3px; }
.yt-dl-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent2);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.yt-dl-btn:hover { background: rgba(124,106,247,0.15); }
.yt-dl-btn:disabled { color: var(--muted); border-color: var(--border); cursor: default; }
.yt-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 5px;
  overflow: hidden;
}
.yt-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s;
}
#yt-status-msg {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ── Header search icon ── */
#open-yt-btn {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}
#open-yt-btn:hover { color: var(--accent2); }
