:root {
  --bg: #0A0A0F;
  --surface: #16161F;
  --surface-2: #1F1F2B;
  --text: #F2F2F7;
  --text-2: #A0A0AE;
  --text-3: #6B6B7B;
  --primary: #5B8CFF;
  --danger: #FF4D5E;
  --like: #FF4D6D;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { user-select: none; -webkit-user-select: none; }
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
img { -webkit-user-drag: none; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
#main {
  padding: calc(var(--safe-top) + 8px) 16px 160px;
  min-height: 100vh;
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.top h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; margin: 0; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  color: var(--text); background: var(--surface-2);
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- Suche ---------- */
.searchbar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: var(--radius);
  padding: 0 12px; height: 42px; margin-bottom: 14px; color: var(--text-3);
}
.searchbar input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 16px; height: 100%;
  -webkit-user-select: text; user-select: text;
}
.searchbar input::placeholder { color: var(--text-3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 9px; border-radius: 10px; font-size: 15px; font-weight: 600;
  color: var(--text-2); background: var(--surface);
}
.tab.active { color: #fff; background: var(--primary); }

/* ---------- Pills / Buttons ---------- */
.bulk-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.pill {
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
}
.pill:active { transform: scale(0.96); }
.pill.active { background: var(--primary); color: #fff; }
.btn-primary {
  margin-top: 16px; padding: 12px 22px; border-radius: 999px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 700;
}
.lib-count { font-size: 13px; color: var(--text-3); margin: -2px 0 10px 4px; }

/* ---------- Liste ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 6px; border-radius: 10px;
  transition: background 0.1s;
}
.row:active { background: var(--surface); }
.row.playing { background: rgba(91,140,255,0.12); }
.row.selected { background: rgba(91,140,255,0.15); }
.row-art {
  width: 48px; height: 48px; border-radius: 8px; object-fit: cover;
  background: var(--surface-2); flex-shrink: 0;
}
.row-art.placeholder { display: grid; place-items: center; color: var(--text-3); font-size: 20px; }
.row-meta { flex: 1; min-width: 0; }
.row-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.playing .row-title { color: var(--primary); }
.row-sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row-fav { color: var(--like); font-size: 13px; margin-left: 2px; }
.row-menu { width: 34px; height: 34px; display: grid; place-items: center; color: var(--text-3); font-size: 20px; flex-shrink: 0; }

/* ---------- Auswahl-Checkbox ---------- */
.row-check {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--text-3);
  display: grid; place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.row.selected .row-check { background: var(--primary); border-color: var(--primary); }
.row.selected .row-check::after {
  content: ''; display: block; width: 6px; height: 10px;
  border: 2.5px solid #fff; border-top: none; border-left: none;
  transform: rotate(45deg) translate(-1px, -2px);
}

/* ---------- Playlist-Cover (Mosaik) ---------- */
.pl-cover {
  width: 48px; height: 48px; border-radius: 8px; overflow: hidden; flex-shrink: 0;
  background: var(--surface-2); display: grid; place-items: center;
  color: var(--text-3); font-size: 20px;
}
.pl-cover.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 1px; }
.pl-cover.grid-4 img, .pl-cover.single img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pl-cover.single { display: block; }
.pl-cover.fav { background: linear-gradient(135deg, #ff6b8b, #c44dff); color: #fff; font-size: 22px; }

/* ---------- Leerzustand ---------- */
.empty { text-align: center; padding: 60px 20px; }
.empty-emoji { font-size: 56px; }
.empty-title { font-size: 19px; font-weight: 700; margin: 14px 0 6px; }
.empty-sub { font-size: 14px; color: var(--text-2); line-height: 1.5; max-width: 280px; margin: 0 auto; }

.back { font-size: 16px; color: var(--primary); padding: 6px 0; margin-bottom: 8px; }
#plName { font-size: 24px; font-weight: 800; margin: 4px 0 16px; }

/* ---------- Mini-Player ---------- */
.mini {
  position: fixed; left: 8px; right: 8px;
  bottom: calc(var(--safe-bot) + 8px);
  height: 62px; border-radius: 16px;
  background: rgba(31,31,43,0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  display: flex; align-items: center; gap: 12px; padding: 0 10px 0 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  z-index: 50;
}
.mini-art { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; background: var(--surface-2); }
.mini-meta { flex: 1; min-width: 0; }
.mini-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-artist { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.select-mode #miniPlayer { display: none !important; }

/* ---------- Now-Playing ---------- */
.np {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(180deg, #1a1a2e 0%, var(--bg) 60%);
  padding: calc(var(--safe-top) + 12px) 28px calc(var(--safe-bot) + 28px);
  display: flex; flex-direction: column; align-items: center;
  transition: transform 0.28s ease;
}
.np.hidden { display: flex !important; transform: translateY(100%); pointer-events: none; }
.np-close { font-size: 30px; color: var(--text-2); align-self: center; padding: 4px 40px; }
.np-art-wrap { flex: 1; display: grid; place-items: center; width: 100%; padding: 20px 0; }
.np-art {
  width: min(78vw, 360px); aspect-ratio: 1; border-radius: 18px; object-fit: cover;
  background: var(--surface-2); box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  transition: transform 0.12s;
}
.np-art:active { transform: scale(0.97); }
.np-meta { width: 100%; display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.np-meta-text { flex: 1; min-width: 0; text-align: left; }
.np-title { font-size: 24px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { font-size: 17px; color: var(--text-2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-fav { font-size: 27px; color: var(--text-2); width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center; }
.np-fav.on { color: var(--like); }
.np-fav:active { transform: scale(0.82); }

.seek { width: 100%; margin: 0; accent-color: var(--primary); height: 6px; }
.np-times { display: flex; justify-content: space-between; width: 100%; font-size: 12px; color: var(--text-3); margin-top: 6px; }

.np-controls { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 26px; }
.ctl { display: grid; place-items: center; color: var(--text); }
.ctl:active { transform: scale(0.9); }
.ctl.small { font-size: 22px; color: var(--text-2); width: 44px; height: 44px; }
.ctl.small.on { color: var(--primary); }
.ctl.play { width: 72px; height: 72px; border-radius: 50%; background: var(--primary); color: #fff; }
.ctl.play svg, .icon-btn svg { display: block; }
.play-glyph { width: 24px; height: 24px; }

/* ---------- Song-Picker (Vollbild) ---------- */
.picker {
  position: fixed; inset: 0; z-index: 350; background: var(--bg);
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bot) + 20px);
  overflow-y: auto;
}
.picker.hidden { display: none !important; }
.picker-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.picker-cancel { color: var(--primary); font-size: 16px; padding: 6px 0; flex-shrink: 0; }
.picker-done { color: var(--primary); font-size: 16px; font-weight: 700; padding: 6px 0; flex-shrink: 0; }
.picker-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bot) + 84px);
  transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5); z-index: 200;
  max-width: 90vw; text-align: center;
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Overlay (Import-Fortschritt) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.6); display: grid; place-items: center;
  backdrop-filter: blur(4px);
}
.overlay-card {
  background: var(--surface-2); padding: 26px 34px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  font-size: 15px; font-weight: 600; max-width: 80vw; text-align: center;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--surface); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Action Sheet / Bottom Sheet ---------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; flex-direction: column; justify-content: flex-end;
}
.sheet-overlay.hidden { display: none !important; }
.sheet {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 0 10px calc(var(--safe-bot) + 10px);
  max-height: 80vh; overflow-y: auto;
  animation: sheetUp 0.28s cubic-bezier(0.34, 1.2, 0.64, 1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-drag { width: 36px; height: 4px; border-radius: 2px; background: var(--text-3); margin: 10px auto 14px; }
.sheet-title {
  font-size: 14px; font-weight: 600; color: var(--text-2);
  text-align: center; padding: 0 16px 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sheet-btn {
  display: block; width: 100%; padding: 16px;
  font-size: 17px; text-align: left; border-radius: 14px;
  margin-bottom: 3px; background: var(--surface-2);
}
.sheet-btn:active { opacity: 0.65; }
.sheet-btn-danger { color: var(--danger); }
.sheet-btn-cancel { margin-top: 10px; font-weight: 700; text-align: center; color: var(--text); background: var(--surface-2); }

/* ---------- Name-Eingabe Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.65); display: grid; place-items: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-overlay.hidden { display: none !important; }
.modal-card {
  background: var(--surface-2); border-radius: 20px;
  padding: 26px 22px 18px; width: min(320px, 90vw);
  animation: popIn 0.2s ease;
}
@keyframes popIn { from { transform: scale(0.88); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card h3 { margin: 0 0 18px; font-size: 18px; font-weight: 800; text-align: center; }
.name-input {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  background: var(--surface); border: none; outline: none;
  color: var(--text); font-size: 16px; font-family: inherit;
  margin-bottom: 16px; -webkit-user-select: text; user-select: text;
}
.modal-btns { display: flex; gap: 10px; }
.modal-btn { flex: 1; padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 700; background: var(--surface); color: var(--text-2); }
.modal-btn-primary { background: var(--primary); color: #fff; }
.modal-btn:active { filter: brightness(0.85); }

/* ---------- Selection Bar ---------- */
.sel-bar {
  position: fixed; left: 8px; right: 8px;
  bottom: calc(var(--safe-bot) + 8px);
  height: 62px; border-radius: 16px;
  background: rgba(31,31,43,0.96);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  display: flex; align-items: center; padding: 0 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.55); z-index: 55; gap: 8px;
}
.sel-bar.hidden { display: none !important; }
.sel-cancel { font-size: 15px; color: var(--primary); font-weight: 600; flex-shrink: 0; padding: 8px 4px; }
.sel-all { font-size: 15px; color: var(--primary); font-weight: 600; flex-shrink: 0; padding: 8px 4px; }
#selCount { flex: 1; font-size: 13px; font-weight: 600; text-align: center; color: var(--text); }
.sel-actions { display: flex; gap: 8px; }
.sel-action-btn { width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--text); }
.sel-action-btn:disabled { opacity: 0.3; }
.sel-action-btn.danger { color: var(--danger); }
.sel-action-btn:not(:disabled):active { filter: brightness(0.75); }
