:root {
  --bg: #0d0d12;
  --bg-2: #16161d;
  --bg-3: #212129;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f4f7;
  --muted: #9a9aa8;
  --accent: #7c5cff;
  --accent-2: #ff5c8a;
  --radius: 14px;
  --tabs-h: 56px;
  --mini-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; }
svg { display: block; width: 100%; height: 100%; fill: currentColor; }
[hidden] { display: none !important; }

/* ------------------------------- layout -------------------------------- */
#app { height: 100%; display: flex; flex-direction: column; }
#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: linear-gradient(var(--bg) 70%, rgba(13, 13, 18, 0));
}
#topbar h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; outline: none;
  padding: 0 0 calc(var(--tabs-h) + var(--mini-h) + var(--safe-b) + 24px);
}

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(13, 13, 18, 0.86); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
#tabs a.active { color: var(--text); }
#tabs .ico { width: 24px; height: 24px; }

.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.icon-btn > svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--bg-3); }

/* ------------------------------ mini player ----------------------------- */
#mini {
  position: fixed; left: 8px; right: 8px; z-index: 9;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 6px); height: var(--mini-h);
  display: flex; align-items: center; gap: 10px; padding: 0 6px 0 8px;
  background: rgba(38, 38, 48, 0.92); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: var(--radius); overflow: hidden; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
#mini-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255, 255, 255, 0.1); }
#mini-progress span { display: block; height: 100%; width: 0; background: var(--text); }
#mini-cover { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: var(--bg-3); }
#mini-meta { flex: 1; min-width: 0; }
#mini-meta .t, #mini-meta .s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini-meta .t { font-weight: 600; }
#mini-meta .s { color: var(--muted); font-size: 13px; }

/* -------------------------------- content ------------------------------- */
.section { margin: 8px 0 22px; }
.section > h2 { font-size: 20px; margin: 0 16px 10px; letter-spacing: -0.01em; }
.carousel { display: flex; gap: 12px; overflow-x: auto; padding: 0 16px; scroll-padding: 0 16px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.carousel::-webkit-scrollbar { display: none; }
.card { flex: none; width: 150px; scroll-snap-align: start; }
.card img { width: 150px; height: 150px; border-radius: 10px; object-fit: cover; background: var(--bg-3); }
.card.artist img { border-radius: 50%; }
.card.track img { width: 150px; height: 150px; }
.card .t { margin-top: 6px; font-weight: 600; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .s { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list { list-style: none; margin: 0; padding: 0 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 7px 8px; border-radius: 10px; }
.row:active { background: var(--bg-2); }
.row img { width: 50px; height: 50px; border-radius: 6px; object-fit: cover; background: var(--bg-3); flex: none; }
.row.artist img { border-radius: 50%; }
.row .num { width: 24px; text-align: center; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.row .meta { flex: 1; min-width: 0; }
.row .t, .row .s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 13px; }
.row.playing .t { color: var(--accent); }
.row .more { color: var(--muted); }

.hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 4px 24px 16px; }
.hero img { width: min(62vw, 260px); aspect-ratio: 1; border-radius: 12px; object-fit: cover; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55); background: var(--bg-3); }
.hero h2 { margin: 16px 0 2px; font-size: 22px; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }
.hero.artist { position: relative; padding: 0; margin-top: calc(-1 * (var(--safe-t) + 60px)); }
.hero.artist img { width: 100%; height: auto; aspect-ratio: 1; max-height: 60vh; border-radius: 0; box-shadow: none; -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.hero.artist .hero-text { position: absolute; left: 0; right: 0; bottom: 8px; padding: 0 20px; }
.hero.artist h2 { font-size: 36px; font-weight: 800; }
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.btn { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 20px; border-radius: 21px; background: var(--bg-3); font-weight: 600; }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--text); color: #000; }
.btn.round { width: 42px; padding: 0; justify-content: center; }
.btn.round.on { color: var(--accent-2); }

/* -------------------------------- search -------------------------------- */
.searchbar { position: sticky; top: 0; z-index: 4; padding: 0 16px 10px; background: var(--bg); }
.searchbar form { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--bg-3); }
.searchbar svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.searchbar input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--text); font: inherit; font-size: 16px; -webkit-user-select: text; user-select: text; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 32px; padding: 0 14px; border-radius: 16px; background: var(--bg-2); border: 1px solid var(--line); font-size: 14px; }
.chip.on { background: var(--text); color: #000; }
.suggest .row { padding: 10px 8px; }
.suggest svg { width: 18px; height: 18px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.5; }
.spinner { width: 28px; height: 28px; margin: 48px auto; border-radius: 50%; border: 3px solid var(--bg-3); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; scrollbar-width: none; }

/* ------------------------------ full player ----------------------------- */
#player {
  position: fixed; inset: 0; z-index: 20; overflow: hidden;
  transform: translateY(100%); transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  background: #111;
}
#player.open { transform: none; }
.player-bg { position: absolute; inset: -40px; background-size: cover; background-position: center; filter: blur(50px) saturate(1.4) brightness(0.45); transform: scale(1.2); }
.player-inner { position: relative; height: 100%; display: flex; flex-direction: column; padding: calc(var(--safe-t) + 4px) 24px calc(var(--safe-b) + 18px); }
.grabber { display: flex; justify-content: center; }
#player-main { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; min-height: 0; }
#p-video { width: 100%; max-width: 520px; aspect-ratio: 16 / 9; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #000; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); }
#p-video iframe { display: block; width: 100%; height: 100%; border: 0; }
.p-meta { display: flex; align-items: center; gap: 12px; }
.p-meta > div { flex: 1; min-width: 0; }
#p-title { font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#p-artist { display: block; color: rgba(255, 255, 255, 0.7); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#p-fav.on { color: var(--accent-2); }
.p-seek input { width: 100%; margin: 0; -webkit-appearance: none; appearance: none; height: 24px; background: transparent; }
.p-seek input::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, #fff var(--p, 0%), rgba(255, 255, 255, 0.25) var(--p, 0%)); }
.p-seek input::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; }
.p-seek input::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.25); }
.p-seek input::-moz-range-progress { height: 4px; background: #fff; }
.p-times { display: flex; justify-content: space-between; font-size: 12px; color: rgba(255, 255, 255, 0.6); font-variant-numeric: tabular-nums; }
.p-controls { display: flex; align-items: center; justify-content: space-between; }
.icon-btn.big { width: 60px; height: 60px; }
.icon-btn.big > svg { width: 38px; height: 38px; }
.icon-btn.huge { width: 76px; height: 76px; }
.icon-btn.huge > svg { width: 56px; height: 56px; }
.toggle { color: rgba(255, 255, 255, 0.55); }
.toggle.on { color: #fff; }
.toggle.on.icon-btn { background: rgba(255, 255, 255, 0.14); }
.p-extra { display: flex; justify-content: space-between; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px; background: rgba(255, 255, 255, 0.1); font-size: 13px; }
.pill svg { width: 18px; height: 18px; }
.pill.on { background: rgba(255, 255, 255, 0.85); color: #000; }

#queue { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.queue-head { display: flex; align-items: center; justify-content: space-between; }
.queue-head h2 { font-size: 18px; margin: 8px 0; }
.link { color: var(--accent); font-weight: 600; }
#queue-list { list-style: none; padding: 0; margin: 0 -8px; overflow-y: auto; flex: 1; }
#queue-list .row.current { background: rgba(255, 255, 255, 0.1); }
#player.show-queue #player-main { flex: none; }
#player.show-queue .p-seek, #player.show-queue .p-meta { display: none; }
#player.show-queue #p-video { max-width: 60%; }

/* -------------------------------- sheets -------------------------------- */
#sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); animation: fade 0.2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 80vh; overflow-y: auto;
  padding: 8px 8px calc(var(--safe-b) + 12px); background: var(--bg-2); border-radius: 18px 18px 0 0;
  animation: up 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head { display: flex; gap: 12px; align-items: center; padding: 8px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.sheet-head img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; }
.sheet-head .t { font-weight: 600; }
.sheet-head .s { color: var(--muted); font-size: 13px; }
.sheet-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 12px; border-radius: 10px; text-align: left; }
.sheet-item:active { background: var(--bg-3); }
.sheet-item svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; z-index: 40; bottom: calc(var(--tabs-h) + var(--mini-h) + var(--safe-b) + 20px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: 0.25s;
  padding: 10px 16px; border-radius: 12px; background: #f4f4f7; color: #000; font-weight: 600; font-size: 14px; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------- login --------------------------------- */
.login { max-width: 340px; margin: 12vh auto 0; padding: 0 24px; text-align: center; }
.login img { width: 96px; height: 96px; margin: 0 auto 16px; border-radius: 22px; }
.login input { width: 100%; height: 46px; margin: 18px 0 12px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-size: 16px; -webkit-user-select: text; user-select: text; }
.login .btn { width: 100%; justify-content: center; }
.login .err { color: var(--accent-2); min-height: 20px; margin-top: 10px; }

@media (min-width: 700px) {
  #view { max-width: 900px; margin: 0 auto; width: 100%; }
  #mini { max-width: 680px; margin: 0 auto; }
  .player-inner { max-width: 520px; margin: 0 auto; }
}
