:root {
  --bg: #0b0b0f;
  --bg-elev: #13131b;
  --bg-elev-2: #1b1b25;
  --bg-hover: #22222e;
  --line: #262633;
  --text: #f3f3f7;
  --muted: #9696a8;
  --accent: #8b7cf6;
  --accent-soft: rgba(139, 124, 246, 0.16);
  --good: #4ade80;
  --danger: #ff6161;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
.hidden { display: none !important; }

.app { height: 100%; }

/* ---------------------------------------------------------------- utility */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  transition: background 0.15s, border-color 0.15s, transform 0.06s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #9a8bff, #7a68f0);
  border-color: transparent;
  color: #0d0b1a;
  font-weight: 700;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg-elev-2); color: var(--text); }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: rgba(255, 97, 97, 0.3); background: rgba(255, 97, 97, 0.08); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 0;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.danger:hover { background: rgba(255, 97, 97, 0.14); color: var(--danger); }

.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

.boot {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 16px;
  justify-items: center;
  color: var(--muted);
  font-size: 14px;
}
.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ login */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60% 50% at 50% 0%, rgba(139, 124, 246, 0.18), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .logo {
  display: block;
  width: 88px; height: 88px;
  margin: 0 auto 14px;
  border-radius: 22px;
  background: #000;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line);
}
.login-card p { color: var(--muted); font-size: 14px; line-height: 1.55; }
.login-card .btn { width: 100%; height: 46px; margin-top: 22px; }
.login-error {
  margin-top: 16px;
  font-size: 13px;
  color: var(--danger);
  background: rgba(255, 97, 97, 0.1);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------------------------------------------------------------- desktop */

.shell {
  height: 100%;
  display: grid;
  grid-template-columns: 296px 1fr;
  min-height: 0;
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 14px;
  padding: 20px 16px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 1px var(--line);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-name { font-weight: 750; letter-spacing: -0.02em; font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: -2px; }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.user-chip img, .avatar-fallback {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  background: var(--accent-soft);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--accent);
  flex: 0 0 auto;
}
.user-chip .who { min-width: 0; flex: 1; }
.user-chip .who b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who span { font-size: 11px; color: var(--muted); }

.sidebar-actions { display: grid; gap: 8px; }
.sidebar-actions .btn { width: 100%; justify-content: flex-start; padding-left: 12px; }

.playlists {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 2px;
  scrollbar-width: thin;
}
.playlists::-webkit-scrollbar { width: 8px; }
.playlists::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  padding: 8px 10px 6px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  color: var(--text);
}
.playlist-item:hover { background: var(--bg-hover); }
.playlist-item.active { background: var(--accent-soft); border-color: rgba(139, 124, 246, 0.35); }
.playlist-item .pl-cover {
  width: 32px; height: 32px; border-radius: 7px; flex: 0 0 auto;
  object-fit: cover;
  background: var(--bg-elev-2);
  display: grid; place-items: center;
  font-size: 13px; color: var(--muted);
}
.playlist-item .pl-name { flex: 1; min-width: 0; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-item .pl-count { font-size: 11px; color: var(--muted); }

.main {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.main-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 26px 30px 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.main-head h1 { font-size: 26px; }
.main-head .sub { color: var(--muted); font-size: 13px; margin-top: 6px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.main-body { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 30px 60px; }

.stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  font-size: 12px;
  color: var(--muted);
}
.stat b { color: var(--text); font-size: 15px; font-weight: 650; margin-right: 4px; }

.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 18px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone b { color: var(--text); }

.track-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.track-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.track-table td { padding: 9px 10px; border-bottom: 1px solid rgba(38, 38, 51, 0.6); vertical-align: middle; }
.track-table tbody tr:hover { background: var(--bg-elev); }
.track-table .num { color: var(--muted); width: 42px; font-variant-numeric: tabular-nums; }
.track-table .t-title { font-weight: 550; }
.track-table .t-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.track-table .right { text-align: right; white-space: nowrap; }
.track-table .row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0.55; }
.track-table tr:hover .row-actions { opacity: 1; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 0 16px; font-size: 13.5px; line-height: 1.5; }

/* --------------------------------------------------------------- uploading */

.upload-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: min(360px, calc(100vw - 44px));
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  z-index: 60;
}
.upload-panel .up-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 10px; }
.upload-panel .up-file { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }
.bar { height: 6px; border-radius: 999px; background: var(--bg-elev-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #8b7cf6, #5eead4); transition: width 0.2s; }

/* ----------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  padding: 11px 15px;
  border-radius: 11px;
  background: #23232f;
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-color: rgba(255, 97, 97, 0.4); color: #ffb3b3; }
.toast.ok { border-color: rgba(74, 222, 128, 0.35); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 90;
  animation: fade 0.15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(460px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; line-height: 1.5; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.segmented { display: flex; gap: 6px; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; }
.segmented button {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.segmented button.active { background: var(--accent-soft); color: var(--text); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ----------------------------------------------------------------- mobile */

.mobile {
  height: 100dvh;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 10px) 18px calc(env(safe-area-inset-bottom) + 14px);
  gap: 14px;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(139, 124, 246, 0.22), transparent 60%),
    var(--bg);
  overflow: hidden;
}
.m-top { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.offline-banner {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(139, 124, 246, 0.14);
  border: 1px solid rgba(139, 124, 246, 0.38);
  color: #cfc6ff;
  font-size: 11.5px;
  text-align: center;
  letter-spacing: 0.01em;
}

.m-top .m-title { flex: 1; min-width: 0; }
.m-top .m-title b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.m-top select {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 620;
  padding: 0;
  outline: none;
  text-overflow: ellipsis;
}
.m-top select option { background: var(--bg-elev); }

.cover-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 6px 0;
}
.cover {
  width: min(100%, 420px);
  aspect-ratio: 1;
  border-radius: 20px;
  object-fit: cover;
  background: linear-gradient(150deg, #2a2440, #15151f);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  font-size: 15vw;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }

.m-meta { flex: 0 0 auto; text-align: center; padding: 2px 6px; }
.m-meta h2 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-meta p { margin: 4px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.seek-row { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seek {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 22px;
  background: transparent;
}
.seek::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--p, 0%), #2b2b3a var(--p, 0%));
}
.seek::-moz-range-track { height: 5px; border-radius: 999px; background: #2b2b3a; }
.seek::-moz-range-progress { height: 5px; border-radius: 999px; background: var(--accent); }
.seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.seek::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; }

.controls { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 2px 8px 4px; }
.controls .icon-btn { width: 44px; height: 44px; }
.controls .icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.play-btn {
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #a294ff, #7a68f0);
  color: #0d0b1a;
  box-shadow: 0 10px 26px rgba(122, 104, 240, 0.4);
}
.play-btn:active { transform: scale(0.96); }

.buffering {
  position: fixed;
  left: 0; right: 0;
  top: 0;
  height: 2px;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
  z-index: 70;
}

.queue-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 79;
  animation: fade-in 0.18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }

.queue-sheet {
  position: fixed;
  inset: auto 0 0 0;
  max-height: 62dvh;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.5);
  z-index: 80;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
  animation: sheet-up 0.2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(20px); opacity: 0; } }
.queue-sheet .sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line);
}
.queue-sheet .sheet-head h3 { font-size: 15px; }
.queue-list { overflow-y: auto; overscroll-behavior: contain; padding: 6px 8px 10px; }
.queue-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  border: 0; border-radius: 10px;
  background: transparent; text-align: left;
}
.queue-item:hover { background: var(--bg-hover); }
.queue-item.active { background: var(--accent-soft); }
.queue-item.active .qi-index { color: var(--accent); font-weight: 700; }
.queue-item.active .qi-main b { color: var(--accent); }
.queue-item.missing { opacity: 0.42; }
.queue-item.missing .qi-main span { font-style: italic; }
.queue-item .qi-index { width: 20px; font-size: 11px; color: var(--muted); text-align: right; }
.queue-item .qi-main { flex: 1; min-width: 0; }
.queue-item .qi-main b { display: block; font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .qi-main span { font-size: 11.5px; color: var(--muted); }
.queue-item .qi-dur { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.m-footer { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); padding: 0 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}
.pill.good { color: var(--good); border-color: rgba(74, 222, 128, 0.3); }
