* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --card: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eee;
  --text-dim: #888;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-h: 44px;
}
body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
#app {
  max-width: 800px; margin: 0 auto; padding: 0 12px;
  padding-bottom: calc(var(--safe-bottom) + 20px);
}

/* Header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px 4px;
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
}
header h1 { margin: 0; font-size: 20px; font-weight: 600; }
#count { color: var(--text-dim); font-size: 14px; }

/* Tabs */
#tabs {
  display: flex; gap: 0; position: sticky; top: 48px; z-index: 9;
  background: var(--bg); padding: 4px 0 0;
}
.tab-btn {
  flex: 1; background: none; border: none; color: var(--text-dim);
  font-size: 14px; font-weight: 500;
  padding: 10px 8px; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: 0.15s;
}
.tab-btn.active {
  color: var(--text); border-bottom-color: var(--accent);
}
.tab-btn:active { opacity: 0.7; }

/* Tab content */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Player bar */
#player-bar {
  padding: 8px 0; margin-top: 4px;
}
#player-info {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
#now-playing { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-time { font-size: 11px; color: var(--text-dim); }
#player-controls {
  display: flex; justify-content: center; align-items: center; gap: 16px;
  margin: 6px 0;
}
.ctrl-btn {
  background: none; border: none; color: var(--text); font-size: 22px;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: 0.15s;
}
.ctrl-btn:active { background: var(--card); }
.ctrl-btn.primary {
  background: var(--accent); color: #fff; font-size: 20px;
  width: 52px; height: 52px;
}
#progress-wrapper { padding: 2px 0; }
#progress {
  width: 100%; height: 4px; -webkit-appearance: none; appearance: none;
  background: var(--card); border-radius: 2px; outline: none;
  cursor: pointer;
}
#progress::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  background: var(--accent); border-radius: 50%; border: none;
}

/* Playlist header */
#playlist-header { padding: 4px 4px 8px; }
#cache-stats { font-size: 12px; color: var(--text-dim); }

/* Library toolbar */
#library-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 8px 0; position: sticky; top: 92px; z-index: 8;
  background: var(--bg);
}
.tool-btn {
  background: var(--card); border: none; color: var(--text);
  padding: 8px 12px; border-radius: 20px; font-size: 12px;
  cursor: pointer; transition: 0.15s; white-space: nowrap;
}
.tool-btn:active { opacity: 0.7; }
.tool-btn.hl { background: var(--accent2); }
.tool-btn.danger { background: #5a1a1a; }
.spacer { flex: 1; }

/* Song list */
#song-list, #library-list { display: flex; flex-direction: column; gap: 1px; background: transparent; }
.song-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; background: var(--surface);
  border-radius: 8px; cursor: pointer; transition: 0.1s;
  user-select: none;
}
.song-item:active { background: var(--card); }
.song-item.active { border-left: 3px solid var(--accent); }
.song-item.disabled { opacity: 0.45; }
.song-item.disabled .song-title { text-decoration: line-through; }
.song-num {
  font-size: 11px; color: var(--text-dim); min-width: 28px;
  font-variant-numeric: tabular-nums;
}
.song-title { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-check {
  width: 22px; height: 22px; border-radius: 4px;
  border: 2px solid var(--text-dim); background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: 0.1s; flex-shrink: 0;
}
.song-check.checked { background: var(--accent); border-color: var(--accent); }
.song-check.checked::after { content: '✓'; color: #fff; font-size: 14px; font-weight: bold; }
.song-dl {
  font-size: 14px; cursor: pointer; padding: 4px;
  width: 30px; text-align: center; flex-shrink: 0;
  transition: 0.15s;
}
.song-dl.cached { color: #4caf50; }
.song-dl:not(.cached) { color: var(--text-dim); }
.song-dl:not(.cached):active { color: var(--accent2); }

/* Empty state */
.empty-state {
  padding: 40px 16px; text-align: center; color: var(--text-dim); font-size: 14px; line-height: 1.6;
}
.empty-state a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--card); color: var(--text); padding: 10px 20px;
  border-radius: 24px; font-size: 13px;
  opacity: 0; transition: 0.3s; pointer-events: none; z-index: 200;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* iOS PWA safe area */
@supports (padding-top: env(safe-area-inset-top)) {
  header { padding-top: calc(12px + env(safe-area-inset-top)); }
}
