:root {
  --bg: #f5f4ff;
  --surface: #ffffff;
  --surface2: #f0effe;
  --primary: #7c6af7;
  --primary-dark: #5b4dd6;
  --text: #1a1a2e;
  --text-muted: #6b6b8a;
  --border: #e2e0f8;
  --nav-h: 64px;
  --radius: 14px;
}

/* System dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface2: #22223a;
    --text: #f0effe;
    --text-muted: #9090b0;
    --border: #2e2e4a;
  }
}

/* Manual theme overrides (beat the media query) */
[data-theme="dark"] {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #22223a;
  --text: #f0effe;
  --text-muted: #9090b0;
  --border: #2e2e4a;
}
[data-theme="light"] {
  --bg: #f5f4ff;
  --surface: #ffffff;
  --surface2: #f0effe;
  --text: #1a1a2e;
  --text-muted: #6b6b8a;
  --border: #e2e0f8;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Bottom Nav ─────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 8px 0;
  transition: color 0.15s;
}

.nav-btn.active { color: var(--primary); }
.nav-btn .nav-icon { font-size: 1.4rem; line-height: 1; }

.nav-badge {
  position: absolute;
  top: 6px; right: calc(50% - 22px);
  background: var(--primary);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Pages ──────────────────────────────────── */
.page {
  display: none;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
  min-height: 100dvh;
}
.page.active { display: block; }

/* ── Header ─────────────────────────────────── */
.page-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 10px;
  z-index: 10;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.page-header h1 { font-size: 1.1rem; font-weight: 700; }

/* ── Dark mode toggle button ────────────────── */
.theme-btn {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.theme-btn:active { background: var(--primary); border-color: var(--primary); }

/* ── Search ─────────────────────────────────── */
.search-input {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--surface2);
  color: var(--text);
  outline: none;
  margin-bottom: 8px;
}
.search-input:focus { border-color: var(--primary); }

/* ── Category filter ─────────────────────────── */
.cat-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.cat-scroll::-webkit-scrollbar { display: none; }

.cat-pill {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.cat-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Song list ───────────────────────────────── */
.song-list { padding: 8px 12px; }

.song-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.song-item:active { box-shadow: 0 0 0 2px var(--primary); }
.song-item.in-playlist { border-color: var(--primary); }

.song-item-info { flex: 1; min-width: 0; }
.song-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Favourite button ────────────────────────── */
.fav-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: none;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0.3;
  transition: opacity 0.15s, transform 0.15s;
  padding: 0;
}
.fav-btn.active { opacity: 1; }
.fav-btn:active { transform: scale(1.3); }

/* Lyrics match indicator */
.lyrics-match {
  background: #fef3c7;
  color: #92400e;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 500;
}
[data-theme="dark"] .lyrics-match {
  background: #3a2e00;
  color: #fcd34d;
}

.add-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: none;
  color: var(--primary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.add-btn.added {
  background: var(--primary);
  color: #fff;
}

/* ── Playlist page ───────────────────────────── */
.playlist-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 0.95rem;
  line-height: 1.8;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.playlist-item:active { box-shadow: 0 0 0 2px var(--primary); }
.playlist-item.now-playing { border: 2px solid var(--primary); }

.play-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* ── Share song button (playlist page) ──────── */
.share-song-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.share-song-btn:active { background: var(--primary); color: #fff; border-color: var(--primary); }

.remove-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.remove-btn:active { background: #fee; border-color: #f88; color: #e44; }

/* ── Player page ─────────────────────────────── */
#playerPage { padding-bottom: 0; }

.player-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.back-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--primary);
  padding: 4px 8px 4px 0;
  flex-shrink: 0;
}

.player-song-title {
  font-size: 0.95rem;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.youtube-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #000;
}
.youtube-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}
.youtube-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: #111;
  gap: 8px;
  font-size: 0.9rem;
}
.youtube-placeholder .big { font-size: 2.5rem; }

.lyrics-panel {
  padding: 16px;
  overflow-y: auto;
  height: calc(100dvh - var(--nav-h) - 56.25vw - 54px - env(safe-area-inset-bottom));
  min-height: 160px;
}

.lyrics-text {
  font-size: 1.25rem;
  line-height: 2.2;
  color: var(--text);
  white-space: pre-wrap;
}

.lyrics-text .chord {
  color: var(--primary);
  font-weight: 600;
  font-size: 0.8rem;
}

/* ── Prev/Next controls ──────────────────────── */
.player-controls {
  display: flex;
  gap: 10px;
  padding: 10px 16px 6px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.ctrl-btn {
  flex: 1;
  padding: 13px 6px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ctrl-btn:disabled { opacity: 0.35; cursor: default; }
.ctrl-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Tag chips ───────────────────────────────── */
.tag {
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.tag-praise  { background: #fef3c7; color: #92400e; }
.tag-worship { background: #dbeafe; color: #1e40af; }
.tag-slow    { background: #ede9fe; color: #5b21b6; }
.tag-fast    { background: #dcfce7; color: #15803d; }
.tag-dialect { background: #fce7f3; color: #9d174d; }

/* ── Loading / empty ─────────────────────────── */
.loading, .empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
  line-height: 1.8;
}

/* ── Toast notification ──────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a2e;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
