:root {
  --bg: #0e0e12;
  --bg-2: #17171d;
  --bg-3: #212129;
  --line: #2b2b34;
  --text: #f4f4f6;
  --muted: #9a9aa6;
  --accent: #a855f7;
  --accent-2: #ec4899;
  --grad: linear-gradient(135deg, #7c3aed, #ec4899);
  --danger: #f87171;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabs-h: 56px;
  --mini-h: 64px;
  color-scheme: dark;
}

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

.splash { position: fixed; inset: 0; display: grid; place-items: center; }
.splash img { width: 84px; height: 84px; border-radius: 20px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; transform: scale(.95); } }

/* ---------- layout ---------- */

#view {
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--tabs-h) + var(--mini-h) + var(--safe-bottom) + 24px);
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
}

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabs-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(14, 14, 18, .92);
  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;
  color: var(--muted); font-size: 11px;
}
#tabs a svg { width: 24px; height: 24px; }
#tabs a.active { color: var(--text); }

/* ---------- typography & common ---------- */

h1 { font-size: 30px; margin: 4px 0 18px; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 28px 0 12px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.section-head a { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border-radius: 999px;
  background: var(--bg-3); font-weight: 600; font-size: 15px;
}
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--grad); color: white; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--text); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.sm svg { width: 20px; height: 20px; }
.icon-btn.on { color: var(--accent); }
.icon-btn.fav-on { color: var(--accent-2); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .search-input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2); outline: none;
  font-size: 16px; /* prevents iOS zoom on focus */
}
.field input:focus, .search-input:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; color: var(--muted); font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.card { background: var(--bg-2); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.loading { display: grid; place-items: center; height: 40vh; }
.loading::after {
  content: ""; width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--bg-3); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: .6; }
.empty h3 { color: var(--text); margin: 0 0 6px; }
.empty .btn { margin-top: 18px; }

/* ---------- covers ---------- */

.cover {
  position: relative; overflow: hidden; flex-shrink: 0;
  background: var(--grad); border-radius: 6px;
  display: grid; place-items: center; color: rgba(255,255,255,.85);
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover svg { width: 40%; height: 40%; }
.cover.round { border-radius: 50%; }

/* ---------- song rows ---------- */

.songs { margin: 0 -8px; }
.song {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer; user-select: none; -webkit-user-select: none;
}
.song:active { background: var(--bg-2); }
@media (hover: hover) { .song:hover { background: var(--bg-2); } }
.song .cover { width: 48px; height: 48px; }
.song .num { width: 28px; text-align: center; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.song .info { flex: 1; min-width: 0; }
.song .t, .song .a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .t { font-size: 16px; }
.song .a { font-size: 14px; color: var(--muted); }
.song .dur { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.song .fav-dot { color: var(--accent-2); }
.song .fav-dot svg { width: 14px; height: 14px; }
.song.playing .t { color: var(--accent); }
.song .dl-dot { color: #4ade80; }
.song .dl-dot svg { width: 15px; height: 15px; }
.song .dl-dot.pending { color: var(--muted); animation: pulse 1s ease-in-out infinite; }

#offline-bar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: #3a2a12; color: #fcd34d; font-size: 13px; font-weight: 600;
}
#offline-bar svg { width: 16px; height: 16px; }
#offline-bar:not(.hidden) + #view { padding-top: 16px; }
.song .more { width: 36px; height: 36px; display: grid; place-items: center; color: var(--muted); }
.song .more svg { width: 22px; height: 22px; }

/* ---------- grids & carousels ---------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 14px; }
.carousel {
  display: grid; grid-auto-flow: column; grid-auto-columns: 140px; gap: 14px;
  overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.carousel::-webkit-scrollbar { display: none; }
.tile { display: block; min-width: 0; scroll-snap-align: start; }
.tile .cover { width: 100%; aspect-ratio: 1; height: auto; border-radius: 8px; }
.tile .t { margin-top: 8px; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .a { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list-links { margin: 0 -8px 8px; }
.list-link { display: flex; align-items: center; gap: 14px; padding: 8px; border-radius: 8px; }
.list-link:active { background: var(--bg-2); }
button.list-link { width: 100%; text-align: left; }
.list-link .cover { width: 56px; height: 56px; }
.list-link .ico { width: 56px; height: 56px; border-radius: 6px; display: grid; place-items: center; background: var(--bg-3); }
.list-link .ico svg { width: 26px; height: 26px; }
.list-link .ico.grad { background: var(--grad); }
.list-link .t { font-size: 16px; }
.list-link .a { font-size: 14px; color: var(--muted); }
.list-link .chev { margin-left: auto; color: var(--muted); }
.list-link .chev svg { width: 18px; height: 18px; }

/* ---------- detail header (album, artist, playlist) ---------- */

.back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); margin: -4px 0 12px -6px; height: 32px; }
.back svg { width: 22px; height: 22px; }
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 18px; }
.hero .cover { width: min(62vw, 240px); aspect-ratio: 1; height: auto; border-radius: 10px; box-shadow: 0 16px 48px rgba(0,0,0,.5); }
.hero .cover.round { border-radius: 50%; }
.hero h1 { margin: 18px 0 4px; font-size: 24px; }
.hero .sub { color: var(--muted); font-size: 15px; }
.hero .sub a { color: var(--text); font-weight: 600; }
.actions { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 16px 0 8px; }
.actions .btn { min-width: 130px; }

/* ---------- search ---------- */

.search-bar { position: relative; margin-bottom: 18px; }
.search-bar svg { position: absolute; left: 14px; top: 13px; width: 20px; height: 20px; color: var(--muted); }
.search-input { padding-left: 44px; }

/* ---------- mini player ---------- */

#mini {
  position: fixed; z-index: 19; left: 8px; right: 8px;
  bottom: calc(var(--tabs-h) + var(--safe-bottom) + 6px);
  height: var(--mini-h); max-width: 884px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 0 6px 0 8px;
  background: #2a2333; border-radius: 10px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); cursor: pointer;
}
#mini .cover { width: 46px; height: 46px; }
#mini .info { flex: 1; min-width: 0; }
#mini .t, #mini .a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini .t { font-size: 15px; font-weight: 600; }
#mini .a { font-size: 13px; color: var(--muted); }
#mini .bar { position: absolute; left: 8px; right: 8px; bottom: 0; height: 2px; background: rgba(255,255,255,.15); border-radius: 2px; }
#mini .bar i { display: block; height: 100%; width: 0; background: var(--text); border-radius: 2px; }

/* ---------- full player ---------- */

#full {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 8px) 24px calc(var(--safe-bottom) + 20px);
  background: linear-gradient(180deg, #3b2350 0%, var(--bg) 70%);
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
  visibility: hidden;
}
#full.open { transform: none; visibility: visible; }
#full .top { display: flex; align-items: center; justify-content: space-between; height: 48px; }
#full .top .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: center; }
#full .top .lbl b { display: block; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
#full .art { flex: 1; display: grid; place-items: center; min-height: 0; padding: 12px 0; }
#full .art .cover {
  width: min(100%, 52vh, 420px); aspect-ratio: 1; height: auto; border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,.55); transition: transform .3s;
}
#full.paused .art .cover { transform: scale(.88); }
#full .meta { display: flex; align-items: center; gap: 12px; max-width: 520px; width: 100%; margin: 0 auto; }
#full .meta .info { flex: 1; min-width: 0; }
#full .meta .t { font-size: 22px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#full .meta .a { font-size: 16px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#full .seek { max-width: 520px; width: 100%; margin: 14px auto 0; }
#full .times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
#full .controls { display: flex; align-items: center; justify-content: space-between; max-width: 400px; width: 100%; margin: 10px auto 0; }
#full .controls .icon-btn svg { width: 28px; height: 28px; }
#full .controls .icon-btn.sm svg { width: 22px; height: 22px; }
#full .play-big { width: 72px; height: 72px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
#full .play-big svg { width: 34px; height: 34px; }
#full .bottom { display: flex; justify-content: flex-end; max-width: 520px; width: 100%; margin: 10px auto 0; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0;
  --p: 0%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 4px;
  background: linear-gradient(to right, var(--text) var(--p), rgba(255,255,255,.2) var(--p));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--text); margin-top: -5px;
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255,255,255,.2); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--text); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--text); }

/* ---------- sheets, dialogs, toast ---------- */

.backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s;
}
.backdrop.center { align-items: center; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 85vh; overflow-y: auto;
  background: var(--bg-2); border-radius: 16px 16px 0 0;
  padding: 8px 8px calc(var(--safe-bottom) + 12px);
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--bg-3); margin: 0 auto 10px; }
.sheet .head { display: flex; align-items: center; gap: 12px; padding: 4px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.sheet .head .cover { width: 48px; height: 48px; }
.sheet .head .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .head .a { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .head > div { min-width: 0; }
.sheet .item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 12px; border-radius: 8px; text-align: left; font-size: 16px; }
.sheet .item:active { background: var(--bg-3); }
.sheet .item svg { width: 22px; height: 22px; color: var(--muted); flex-shrink: 0; }
.sheet .item.danger, .sheet .item.danger svg { color: var(--danger); }
.sheet h3 { margin: 4px 12px 10px; font-size: 18px; }

.dialog {
  width: 100%; max-width: 400px; background: var(--bg-2); border-radius: 16px; padding: 20px;
  animation: up .2s;
}
.dialog h3 { margin: 0 0 14px; font-size: 18px; }
.dialog p { margin: 0 0 18px; color: var(--muted); }
.dialog .buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.dialog .buttons .btn { flex: 1; }

#toast {
  position: fixed; left: 50%; z-index: 80; transform: translate(-50%, 20px);
  bottom: calc(var(--tabs-h) + var(--mini-h) + var(--safe-bottom) + 20px);
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- queue ---------- */

.queue .song .cover { width: 40px; height: 40px; }
.queue .song.current { background: var(--bg-3); }
.queue .song.current .t { color: var(--accent); }
.queue .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 12px 6px; }

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

.login { min-height: 100vh; display: grid; place-items: center; padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px); }
.login form { width: 100%; max-width: 360px; }
.login .logo { width: 76px; height: 76px; border-radius: 18px; display: block; margin: 0 auto 18px; box-shadow: 0 12px 40px rgba(168,85,247,.35); }
.login h1 { text-align: center; margin-bottom: 6px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 24px; }

/* ---------- upload ---------- */

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 32px 16px; color: var(--muted);
  cursor: pointer; transition: border-color .2s, background .2s;
}
.drop svg { width: 40px; height: 40px; color: var(--accent); }
.drop b { color: var(--text); font-size: 17px; }
.drop.over { border-color: var(--accent); background: rgba(168,85,247,.08); }
.uploads { margin-top: 18px; }
.up { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.up .info { flex: 1; min-width: 0; }
.up .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.up .s { font-size: 13px; color: var(--muted); }
.up .s.ok { color: #4ade80; }
.up .s.err { color: var(--danger); }
.up .prog { height: 3px; background: var(--bg-3); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.up .prog i { display: block; height: 100%; width: 0; background: var(--grad); transition: width .2s; }
.tips { font-size: 14px; color: var(--muted); }

.seg {
  display: flex; gap: 4px; padding: 4px; margin: -4px 0 18px;
  background: var(--bg-2); border-radius: 12px;
}
.seg a {
  flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.seg a.on { background: var(--bg-3); color: var(--text); }
.seg.small-seg { margin-top: 0; }
.seg.small-seg a { padding: 7px 6px; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { padding: 8px 14px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); font-size: 14px; }
.chip:active { background: var(--bg-3); }
textarea.search-input { font: inherit; resize: vertical; }
.tips li { margin-bottom: 6px; }
.tips a { color: var(--accent); }

.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); color: var(--muted); margin-left: 6px; }

@media (min-width: 700px) {
  .carousel { grid-auto-columns: 170px; }
}
