/* MusicX — Telegram chrome × Spotify player */
:root {
  --bg: #0e1621;
  --bg-elev: #17212b;
  --bg-elev-2: #242f3d;
  --text: #f5f5f5;
  --text-muted: #708499;
  --accent: #1db954;
  --accent-press: #17a348;
  --danger: #e53935;
  --hairline: rgba(255, 255, 255, 0.08);
  --tap-min: 48px;
  --mini-h: 64px;
  --tabs-h: 56px;
  --radius: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f1f3f5;
  --bg-elev-2: #e7ebef;
  --text: #0e1621;
  --text-muted: #708499;
  --hairline: rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}
img { display: block; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }
a { color: var(--accent); text-decoration: none; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.btn-icon:active { transform: scale(0.94); }
.btn-icon:disabled { opacity: 0.35; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---------------- layout ---------------- */
.app { display: flex; height: 100dvh; height: 100vh; }
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.sidebar { display: none; }
.topbar {
  padding: calc(var(--safe-t) + 12px) 16px 8px;
  display: flex; align-items: center; gap: 8px;
  font-size: 20px; font-weight: 700;
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.topbar .grow { flex: 1; }
.topbar .btn-icon { color: var(--text); }
.view { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 0 12px; -webkit-overflow-scrolling: touch; }

/* ---------------- lists ---------------- */
.sec-title { font-size: 15px; font-weight: 700; padding: 14px 16px 6px; display: flex; align-items: center; }
.sec-title .all { margin-left: auto; font-size: 13px; font-weight: 400; color: var(--accent); }

.row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: var(--tap-min); }
.row:active { background: var(--bg-elev-2); }
.row-cover { width: 52px; height: 52px; border-radius: 10px; background: var(--bg-elev-2); flex: none; object-fit: cover; }
.row-meta { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-artist { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row-side { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.row.unavailable { opacity: 0.4; }
.row .num { width: 18px; text-align: right; color: var(--text-muted); font-size: 14px; flex: none; }

.chips { display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 16px; background: var(--bg-elev-2); color: var(--text-muted); font-size: 13px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.active { background: rgba(29, 185, 84, 0.16); color: var(--accent); }
.chip .x { margin-left: 6px; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 28px; border-radius: 24px;
  background: var(--accent); color: #08130a; font-size: 15px; font-weight: 700;
}
.btn-primary:active { background: var(--accent-press); transform: scale(0.98); }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; padding: 8px; }
.btn-ghost svg { width: 20px; height: 20px; }

/* hero album header */
.hero { display: flex; gap: 16px; padding: 12px 16px 4px; align-items: flex-end; }
.hero img { width: 128px; height: 128px; border-radius: var(--radius); background: var(--bg-elev-2); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.hero h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.hero .sub { color: var(--text-muted); font-size: 13px; margin-top: 6px; }
.hero-actions { display: flex; gap: 8px; padding: 12px 16px; }

/* horizontal scroller (recent) */
.scroller { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 12px; padding: 8px 16px 12px; overflow-x: auto; scrollbar-width: none; }
.scroller::-webkit-scrollbar { display: none; }
.hcard { min-width: 0; }
.hcard img { width: 132px; height: 132px; border-radius: var(--radius); background: var(--bg-elev-2); object-fit: cover; margin-bottom: 6px; }
.hcard .t { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hcard .a { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* skeletons */
.sk-row { height: 68px; margin: 0 16px 4px; border-radius: 10px; }
.sk { background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-elev-2) 50%, var(--bg-elev) 75%); background-size: 400% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* empty state */
.empty { text-align: center; color: var(--text-muted); padding: 48px 24px; }
.empty svg { width: 56px; height: 56px; opacity: 0.5; margin: 0 auto 12px; }

/* ---------------- search input ---------------- */
.searchbox { padding: 6px 16px 10px; position: sticky; top: 0; background: var(--bg); z-index: 4; }
.searchbox .field { display: flex; align-items: center; gap: 8px; background: var(--bg-elev-2); border-radius: 12px; padding: 0 12px; height: 44px; }
.searchbox svg { width: 20px; height: 20px; color: var(--text-muted); flex: none; }
.searchbox input { flex: 1; background: none; border: 0; color: var(--text); outline: none; min-width: 0; }
.suggests { margin-top: 6px; background: var(--bg-elev); border-radius: 12px; overflow: hidden; }
.suggests .row { min-height: 44px; padding: 6px 12px; }

/* ---------------- tabs (mobile) ---------------- */
.tabs {
  display: flex; height: calc(var(--tabs-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bg-elev); border-top: 1px solid var(--hairline);
  position: relative; z-index: 6;
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-muted); font-size: 11px; padding-top: 6px; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button.active { color: var(--text); }

/* ---------------- mini player ---------------- */
.mini {
  position: relative; z-index: 6; background: var(--bg-elev);
  border-top: 1px solid var(--hairline); flex: none;
}
.mini-bar { position: absolute; top: -1px; left: 0; height: 2px; background: var(--accent); width: 0%; z-index: 1; }
.mini-inner { display: flex; align-items: center; gap: 10px; height: var(--mini-h); padding: 0 8px 0 10px; }
.mini-cover { width: 44px; height: 44px; border-radius: 8px; background: var(--bg-elev-2); object-fit: cover; flex: none; }
.mini-meta { flex: 1; min-width: 0; cursor: pointer; }
.mini-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-artist { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-play { width: 44px; height: 44px; flex: none; }
.mini-play svg { width: 26px; height: 26px; }

/* ---------------- full player ---------------- */
.player {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  padding: max(var(--safe-t), 10px) 24px calc(var(--safe-b) + 18px);
  transform: translateY(100%); transition: transform 0.32s cubic-bezier(0.32, 0.72, 0.24, 1);
  background: var(--bg); overflow: hidden;
}
.player.open { transform: translateY(0); }
.player[hidden] { display: none; }
.player-bg, .player-bg-img, .player-bg-grad { position: absolute; inset: 0; }
.player-bg { z-index: -1; }
.player-bg-img { background-size: cover; background-position: center; filter: blur(48px) saturate(1.4); transform: scale(1.2); opacity: 0.55; }
.player-bg-grad { background: linear-gradient(180deg, transparent 0%, var(--bg) 72%); }
.player-top { display: flex; align-items: center; padding: 2px 0; }
.player-src { flex: 1; text-align: center; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-cover-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 12px 0; }
.player-cover { width: min(68vw, 400px); aspect-ratio: 1; border-radius: 16px; object-fit: cover; background: var(--bg-elev-2); box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5); transition: transform 0.25s; }
body.playing .player-cover { transform: scale(1); }
.player-info { display: flex; align-items: center; gap: 12px; }
.player-info > div { flex: 1; min-width: 0; }
.player-title { font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-artist { font-size: 15px; color: var(--text-muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.like-btn.on svg { fill: var(--accent); stroke: var(--accent); }
.player-progress { margin-top: 18px; }
.bar { height: 24px; display: flex; align-items: center; touch-action: none; cursor: pointer; }
.bar-track { height: 4px; width: 100%; background: var(--bg-elev-2); border-radius: 2px; }
.bar-fill { height: 100%; width: 0%; background: var(--text); border-radius: 2px; position: relative; transition: background 0.15s; }
.bar-thumb { position: absolute; right: -6px; top: 50%; width: 12px; height: 12px; border-radius: 50%; background: #fff; transform: translateY(-50%) scale(0); transition: transform 0.12s; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.bar:hover .bar-thumb, .bar.dragging .bar-thumb { transform: translateY(-50%) scale(1); }
.bar.dragging .bar-fill, .bar:hover .bar-fill { background: var(--accent); }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.player-controls { display: flex; align-items: center; justify-content: space-between; margin: 14px auto 0; width: 100%; max-width: 420px; }
.play-big {
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: #06130a;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.play-big:active { background: var(--accent-press); transform: scale(0.95); }
.play-big svg { width: 30px; height: 30px; }
#pl-shuffle.on, #pl-repeat.on { color: var(--accent); }
.ctl { position: relative; }
.rep-one { position: absolute; right: 2px; top: 2px; font-size: 9px; font-style: normal; color: var(--accent); }
.player-actions { display: flex; justify-content: space-around; margin-top: 14px; }

/* ---------------- sheet ---------------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 24; opacity: 0; transition: opacity 0.25s; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; max-height: 70dvh;
  background: var(--bg-elev); border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.32, 0.72, 0.24, 1);
  padding-bottom: var(--safe-b);
}
.sheet.open { transform: translateY(0); }
.sheet[hidden] { display: none; }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--hairline); margin: 8px auto 4px; }
.sheet-title { font-weight: 700; font-size: 16px; padding: 4px 16px 8px; }
.queue-list { overflow-y: auto; padding-bottom: 8px; }
.q-current .eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; margin-right: 8px; }
.eq i { width: 3px; background: var(--accent); height: 40%; animation: eq 1s infinite ease-in-out; }
.eq i:nth-child(2) { animation-delay: 0.25s; }
.eq i:nth-child(3) { animation-delay: 0.5s; }
body:not(.playing) .eq i { animation-play-state: paused; }
@keyframes eq { 0%, 100% { height: 30%; } 50% { height: 100%; } }
.q-del { color: var(--text-muted); }
.q-del:active { color: var(--danger); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--mini-h) + var(--tabs-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(8px); max-width: min(88vw, 420px);
  background: var(--bg-elev-2); color: var(--text); border-radius: 12px; padding: 10px 16px;
  font-size: 14px; z-index: 40; opacity: 0; transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- desktop ---------------- */
@media (min-width: 900px) {
  .sidebar {
    display: flex; flex-direction: column; gap: 4px; width: 240px; flex: none;
    background: var(--bg-elev); padding: 20px 12px; border-right: 1px solid var(--hairline);
  }
  .sidebar .logo { font-size: 18px; font-weight: 800; padding: 4px 12px 16px; display: flex; align-items: center; gap: 8px; }
  .sidebar button { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text-muted); font-size: 15px; font-weight: 500; text-align: left; }
  .sidebar button:hover { background: var(--bg-elev-2); color: var(--text); }
  .sidebar button.active { color: var(--text); background: var(--bg-elev-2); }
  .sidebar button svg { width: 22px; height: 22px; }
  .tabs { display: none; }
  .view { padding: 0; }
  .topbar { padding: 20px 24px 8px; }
  .player { inset: 12px auto 12px 12px; width: 380px; border-radius: 16px; transform: translateX(-120%); box-shadow: 0 24px 64px rgba(0,0,0,.5); }
  .player.open { transform: translateX(0); }
  .sheet { left: auto; right: 0; bottom: 0; top: 0; width: 380px; border-radius: 16px 0 0 16px; transform: translateX(120%); }
  .sheet.open { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
