/* Melodili Mini App — theme-aware, Telegram-native. Colors fall back to a
   dark palette when the Telegram theme vars are absent (e.g. plain browser). */
:root {
  --bg: var(--tg-theme-bg-color, #0b1014);
  --card: var(--tg-theme-secondary-bg-color, #151b22);
  --text: var(--tg-theme-text-color, #e8edf2);
  --muted: var(--tg-theme-hint-color, #8a97a6);
  --accent: var(--tg-theme-button-color, #4db6ac);
  --accent-text: var(--tg-theme-button-text-color, #04140f);
  --line: color-mix(in srgb, var(--text) 12%, var(--bg));
  --player-height: 0px;
  --safe-top: 0px;
  --safe-bottom: 0px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--player-height) + var(--safe-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- header / search ---- */
header {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 6px; margin: 4px 0 10px; }
.tab {
  flex: 0 0 auto; padding: 7px 16px; border-radius: 999px; font-size: 15px; font-weight: 600;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
}
.tab.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.section {
  list-style: none; font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; padding: 16px 8px 6px;
}
.seg { display: flex; gap: 4px; margin-top: 10px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segbtn { flex: 1; padding: 7px 0; border: none; border-radius: 8px; background: none;
  color: var(--muted); font-size: 14px; font-weight: 600; }
.segbtn.active { background: var(--accent); color: var(--accent-text); }
.artist-row { display: flex; align-items: center; gap: 12px; padding: 8px;
  border-bottom: 1px solid var(--line); background: none; border-left: none; border-right: none;
  border-top: none; width: 100%; color: inherit; text-align: left; }
.artist-row .art { border-radius: 50%; }
.artist-row .a-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artist-row .a-count { color: var(--muted); font-size: 13px; }
#search {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 16px; outline: none; /* 16px avoids iOS focus zoom */
}

/* ---- library list ---- */
main { padding: 6px 8px 12px; }
.status { color: var(--muted); text-align: center; padding: 28px 12px; }
.status .link { color: var(--accent); font-weight: 600; }
.tracks { list-style: none; margin: 0; padding: 0; }
.track { border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.track .row {
  display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0;
  padding: 9px 8px; background: none; border: none; color: inherit; text-align: left;
}
.track .heart { color: var(--accent); font-size: 13px; flex: 0 0 auto; }
.more-btn {
  flex: 0 0 auto; width: 40px; height: 44px; border: none; background: none;
  color: var(--muted); font-size: 20px; line-height: 1;
}
.track .row:active { background: var(--card); }
.art {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 8px;
  display: grid; place-items: center; overflow: hidden;
  background: var(--card); color: var(--muted);
}
.art img { width: 100%; height: 100%; object-fit: cover; }
.art svg { width: 20px; height: 20px; opacity: .7; }
.meta { min-width: 0; flex: 1; }
.meta .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dur { color: var(--muted); font-size: 12px; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.track.playing .t { color: var(--accent); }
.track.playing .eq { display: inline-flex; }
.eq { display: none; gap: 2px; align-items: flex-end; height: 14px; margin-right: 2px; }
.eq i { width: 3px; background: var(--accent); border-radius: 1px; animation: eq .9s ease-in-out infinite; }
.eq i:nth-child(2){ animation-delay:.2s } .eq i:nth-child(3){ animation-delay:.4s }
@keyframes eq { 0%,100%{height:4px} 50%{height:14px} }

.more { display: block; margin: 16px auto; padding: 9px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); }
.more:disabled { opacity: .5; }

/* ---- shared icon button ---- */
.iconbtn, .ctl {
  display: grid; place-items: center; border: none; background: none;
  color: var(--text); border-radius: 50%;
}
.iconbtn svg, .ctl svg { width: 22px; height: 22px; }
.iconbtn { width: 44px; height: 44px; }
.iconbtn:disabled, .ctl:disabled { opacity: .35; }

/* ---- compact player ---- */
#player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex; align-items: center; gap: 10px;
}
#miniprog { position: absolute; left: 0; top: 0; height: 2px; width: 100%; background: var(--line); }
#miniprog span { display: block; height: 100%; width: 0; background: var(--accent); }
.mini-art { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 8px; padding: 0; border: none;
  background: var(--bg); color: var(--muted); display: grid; place-items: center; overflow: hidden; }
.mini-art img { width: 100%; height: 100%; object-fit: cover; }
.mini-art svg { width: 18px; height: 18px; }
.mini-meta { flex: 1; min-width: 0; background: none; border: none; color: inherit; text-align: left; padding: 0; }
.np-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-sub { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toggle-accent { background: var(--accent) !important; color: var(--accent-text) !important; }

/* ---- expanded now-playing ---- */
.now {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  transform: translateY(0); transition: transform .25s ease;
}
.now[hidden] { display: none !important; }
.now.closing { transform: translateY(100%); }
.now-art {
  width: min(72vw, 300px); aspect-ratio: 1; border-radius: 16px; margin-top: 6px;
  background: var(--card); color: var(--muted); display: grid; place-items: center; overflow: hidden;
}
.now-art img { width: 100%; height: 100%; object-fit: cover; }
.now-art svg { width: 33%; height: 33%; opacity: .6; }
.now-title { font-size: 20px; font-weight: 700; text-align: center; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { color: var(--muted); text-align: center; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-status { color: var(--muted); font-size: 13px; min-height: 18px; text-align: center; }
.seekrow { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 420px; }
.seekrow span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.seek { flex: 1; min-height: 44px; accent-color: var(--accent); }
.seek:disabled { opacity: .4; }
.now-controls { display: flex; align-items: center; gap: 14px; margin-top: 2px; }
.ctl { width: 48px; height: 48px; }
.ctl.big { width: 64px; height: 64px; background: var(--accent); color: var(--accent-text); }
.ctl.big svg { width: 28px; height: 28px; }
.ctl.on { color: var(--accent); }
.queue-label { color: var(--muted); font-size: 12px; margin-top: 2px; }
.likebtn { position: absolute; top: calc(var(--safe-top) + 20px); right: 20px;
  width: 44px; height: 44px; border: none; background: none; color: var(--muted); }
.likebtn svg { width: 26px; height: 26px; }
.likebtn.on { color: var(--accent); }

/* ---- playlists ---- */
.pl-card { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.pl-open { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  padding: 12px 8px; background: none; border: none; color: inherit; text-align: left; }
.pl-t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-c { color: var(--muted); font-size: 13px; }
.pl-newrow { list-style: none; padding: 14px 8px; }
.pl-newrow .more { margin: 0; width: 100%; }

/* ---- bottom sheet ---- */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet-panel {
  position: relative; width: 100%; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 8px 12px calc(12px + var(--safe-bottom));
  max-height: 80vh; overflow-y: auto;
}
.sheet-title { font-weight: 700; padding: 12px 8px 8px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-act { display: block; width: 100%; text-align: left; padding: 13px 10px;
  background: none; border: none; border-radius: 10px; color: var(--text); font-size: 16px; }
.sheet-act:active { background: var(--bg); }
.sheet-act.danger { color: #e5484d; }
.sheet-act.cancel { color: var(--muted); text-align: center; margin-top: 4px; }
.pl-new { display: flex; gap: 8px; padding: 6px 8px; }
.pl-name { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px; }
.pl-new .sheet-act { width: auto; background: var(--accent); color: var(--accent-text); text-align: center; }

.toast { position: fixed; left: 50%; bottom: calc(var(--player-height) + var(--safe-bottom) + 20px);
  transform: translateX(-50%); z-index: 40; background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; }
