:root {
  --bg: #07070d;
  --bg-soft: #0f0f1a;
  --panel: #12121f;
  --panel-2: #171728;
  --line: #23233a;
  --text: #e8e9f3;
  --muted: #9093ad;
  --muted-2: #6b6e88;
  --accent: #7c5cff;
  --accent-2: #36d6c3;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --danger: #ff5e7a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 248px;
  --player-h: 104px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", Inter, Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 700px at 10% -10%, rgba(124, 92, 255, 0.15), transparent 60%),
    radial-gradient(900px 600px at 110% 10%, rgba(54, 214, 195, 0.1), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
input { font: inherit; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }

/* ---------- LAYOUT ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr var(--player-h);
  grid-template-areas:
    "sidebar main"
    "player  player";
  height: 100dvh;
  min-height: 100dvh;
}

.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(23, 23, 40, 0.75), rgba(15, 15, 26, 0.75));
  backdrop-filter: blur(10px);
  padding: 22px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
}
.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
}

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  text-align: left;
  transition: background 150ms, color 150ms;
  position: relative;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(124, 92, 255, 0.35);
}
.nav-item .badge {
  margin-left: auto;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
}
.nav-item.is-active .badge { background: rgba(255,255,255,0.1); color: var(--text); }

.sidebar-footer { margin-top: auto; padding: 10px 6px; font-size: 12px; color: var(--muted); }
.collab { display: flex; align-items: center; gap: 8px; }
.collab .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 10px var(--accent-2);
  animation: pulse 1.8s infinite ease-out;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

/* ---------- MAIN ---------- */
.main {
  grid-area: main;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  padding-bottom: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  height: var(--topbar-h);
  background: linear-gradient(180deg, rgba(7, 7, 13, 0.88), rgba(7, 7, 13, 0.6) 70%, transparent);
  backdrop-filter: blur(10px);
}
.menu-btn { display: none; color: var(--muted); padding: 6px; border-radius: 8px; }
.menu-btn:hover { color: var(--text); background: var(--panel-2); }

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 520px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  height: 40px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 0 14px 0 36px;
  outline: none;
  transition: border-color 150ms, background 150ms;
}
.search-input::placeholder { color: var(--muted-2); }
.search-input:focus { border-color: var(--accent); background: var(--panel-2); }

.search-suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 30;
  padding: 6px;
}
.search-suggest li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.search-suggest li:hover,
.search-suggest li[aria-selected="true"] { background: var(--accent-soft); }
.search-suggest .sg-cover { width: 32px; height: 32px; border-radius: 6px; flex: none; }
.search-suggest .sg-text { display: flex; flex-direction: column; min-width: 0; }
.search-suggest .sg-title { color: var(--text); text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.search-suggest .sg-artist { color: var(--muted); font-size: 12px; }
.search-suggest mark { color: var(--accent-2); background: transparent; }

.net-state {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.net-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.net-state .dot.on { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }

/* ---------- VIEWS ---------- */
.view { padding: 6px 24px 32px; }
.view-title { font-size: 26px; letter-spacing: 0.3px; margin: 16px 0 14px; }
.view-title.sm { font-size: 18px; margin-top: 28px; color: var(--muted); font-weight: 600; }
.view-sub { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.kicker {
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--accent-2);
}
.view-head {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 16px;
  flex-wrap: wrap;
}
.view-head-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  transition: transform 120ms, background 150ms, color 150ms;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #8a6dff; }
.btn.ghost { background: var(--panel); color: var(--muted); border: 1px solid var(--line); }
.btn.ghost:hover { color: var(--text); }

/* ---------- DISCOVER GRID ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
  border-radius: var(--radius);
  transition: transform 200ms, border-color 200ms, background 200ms;
  cursor: pointer;
}
.card:hover { transform: translateY(-2px); border-color: rgba(124, 92, 255, 0.45); background: var(--panel-2); }
.card-cover {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
}
.card-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.18), transparent 60%);
  pointer-events: none;
}
.card-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-artist { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-play {
  position: absolute;
  right: 18px;
  bottom: 62px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(6px);
  opacity: 0;
  box-shadow: 0 10px 20px rgba(124, 92, 255, 0.4);
  transition: transform 200ms, opacity 200ms;
}
.card:hover .card-play { opacity: 1; transform: translateY(0); }

/* ---------- TRACKLIST ---------- */
.tracklist {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}
.track {
  display: grid;
  grid-template-columns: 28px 44px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 150ms;
}
.track:last-child { border-bottom: 0; }
.track:hover { background: var(--panel-2); }
.track.is-playing { background: linear-gradient(90deg, var(--accent-soft), transparent 70%); }
.track.is-playing .t-title { color: var(--accent-2); }
.track.is-new { animation: slideIn 500ms ease-out; background: rgba(54, 214, 195, 0.08); }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}
.t-index { color: var(--muted); font-size: 13px; text-align: center; }
.track.is-playing .t-index {
  color: var(--accent-2);
  font-weight: 600;
}
.t-cover { width: 44px; height: 44px; border-radius: 8px; flex: none; }
.t-meta { display: flex; flex-direction: column; min-width: 0; }
.t-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-artist { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-artist .added-by {
  color: var(--accent-2);
  margin-left: 6px;
  font-size: 11px;
  background: rgba(54, 214, 195, 0.1);
  padding: 1px 6px;
  border-radius: 99px;
}
.t-duration { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.t-actions { display: flex; gap: 4px; }
.t-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--muted);
  transition: background 120ms, color 120ms;
}
.t-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.t-btn.active { color: var(--accent-2); }

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- ACTIVITY ---------- */
.activity {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.activity li {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.activity li b { color: var(--text); font-weight: 600; }
.activity li .who { width: 26px; height: 26px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; }
.activity li .when { margin-left: auto; color: var(--muted-2); font-size: 11px; }

/* ---------- LYRICS ---------- */
.lyrics-view { display: flex; flex-direction: column; gap: 14px; min-height: 60vh; }
.lyrics-hero {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}
.lyrics-cover { width: 76px; height: 76px; border-radius: 12px; flex: none; }
.lyrics-title { font-size: 20px; font-weight: 700; margin-top: 2px; }
.lyrics-artist { color: var(--muted); font-size: 13px; }
.lyrics-scroll {
  padding: 16px 20px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.7;
  max-height: 58vh;
}
.lyric-line {
  font-size: 16px;
  color: var(--muted-2);
  transition: color 250ms, transform 250ms, font-weight 150ms;
  padding: 2px 0;
}
.lyric-line.active {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  transform: scale(1.02);
  text-shadow: 0 0 20px rgba(124, 92, 255, 0.4);
}
.lyric-line.passed { color: var(--muted); }
.lyric-placeholder { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- PLAYER ---------- */
.player {
  grid-area: player;
  display: grid;
  grid-template-columns: 280px 1fr 240px;
  gap: 18px;
  align-items: center;
  padding: 10px 22px;
  background: rgba(10, 10, 20, 0.85);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
  min-height: var(--player-h);
  position: relative;
  z-index: 10;
}
.player-track { display: flex; align-items: center; gap: 12px; min-width: 0; }
.player-cover { width: 54px; height: 54px; border-radius: 10px; flex: none; background: var(--panel-2); }
.player-info { min-width: 0; }
.player-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-artist { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.player-center { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.controls { display: flex; justify-content: center; align-items: center; gap: 10px; }
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--muted);
  transition: background 120ms, color 120ms, transform 120ms;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn.fav.active { color: var(--danger); }
.icon-btn.active { color: var(--accent-2); }
.play-btn {
  width: 42px; height: 42px;
  background: var(--text);
  color: #0a0a12;
}
.play-btn:hover { background: #fff; color: #0a0a12; }

.timeline {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}
.time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; min-width: 34px; text-align: center; }
.wave-wrap { position: relative; height: 40px; }
.waveform { height: 100%; cursor: pointer; }
.wave-wrap::before {
  /* subtle track baseline when empty */
  content: "";
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.wave-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted-2); font-size: 12px;
  pointer-events: none;
}
.wave-wrap.has-audio .wave-placeholder { display: none; }

.player-actions { display: flex; align-items: center; gap: 12px; justify-content: flex-end; }
.volume { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.volume input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  background: var(--line);
  border-radius: 99px;
  outline: none;
}
.volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 120ms;
}
.volume input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
.volume input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  background: var(--text);
  border-radius: 50%;
  border: 0;
  cursor: pointer;
}

/* ---------- TOAST ---------- */
.toast-host {
  position: fixed;
  bottom: calc(var(--player-h) + 14px);
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  min-width: 220px;
  max-width: 320px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toastIn 200ms ease-out, toastOut 200ms ease-in 2.7s both;
  display: flex;
  gap: 10px;
  align-items: center;
}
.toast.collab { border-color: rgba(54, 214, 195, 0.4); }
.toast.offline { border-color: rgba(124, 92, 255, 0.4); }
.toast .t-ico {
  width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px; color: #fff;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 960px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "main"
      "player";
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 80%;
    max-width: 300px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 220ms ease-out;
    border-right: 1px solid var(--line);
  }
  .sidebar.is-open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .app.has-overlay::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 40;
    backdrop-filter: blur(2px);
  }
  .player {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "track  actions"
      "center center";
    gap: 10px;
    padding: 10px 14px;
    min-height: 128px;
  }
  .player-track { grid-area: track; }
  .player-actions { grid-area: actions; }
  .player-center { grid-area: center; }
  .volume { display: none; }
  .view { padding: 4px 16px 24px; }
}

@media (max-width: 560px) {
  :root { --player-h: 134px; }
  .player-cover { width: 46px; height: 46px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .track { grid-template-columns: 24px 40px 1fr auto; }
  .track .t-actions { display: none; }
  .wave-wrap { height: 36px; }
}

/* Landscape phones: keep player compact, ensure playback isn't disturbed */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --player-h: 96px; }
  .player { min-height: 96px; grid-template-columns: 220px 1fr 160px; grid-template-areas: "track center actions"; padding: 6px 14px; }
  .player-track { grid-area: track; }
  .player-center { grid-area: center; }
  .player-actions { grid-area: actions; }
  .volume { display: flex; }
  .view-title { font-size: 20px; margin: 10px 0 8px; }
  .lyrics-scroll { max-height: 38vh; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
