/* ===========================================================================
   Music Mini App
   ---------------------------------------------------------------------------
   Artwork carries this interface, so it is drawn large, square and sharp, and
   the rest of the page stays quiet around it. The list is one continuous
   surface with hairline rules rather than a card per row: stacked cards broke
   a long list into competing boxes and made the artwork look incidental.

   Colours follow Telegram's theme variables, and everything derived from them
   (rules, fills, raised surfaces) is mixed from the theme's own text colour
   rather than hardcoded -- a light Mini App theme on a dark phone otherwise
   loses every border. The page is RTL, so spacing uses logical properties.
   ========================================================================= */

:root {
  color-scheme: light dark;

  --bg:        var(--tg-theme-bg-color, #0b0d12);
  --surface:   var(--tg-theme-secondary-bg-color, #141821);
  --text:      var(--tg-theme-text-color, #eef2f8);
  --muted:     var(--tg-theme-hint-color, #8b95a7);
  --accent:    var(--tg-theme-button-color, #7b5cff);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);

  --tint-1: color-mix(in srgb, var(--text) 5%,  transparent);
  --tint-2: color-mix(in srgb, var(--text) 9%,  transparent);
  --rule:   color-mix(in srgb, var(--text) 9%,  transparent);
  --rule-2: color-mix(in srgb, var(--text) 18%, transparent);

  --gold:   #ffc24b;
  --danger: #ff6b6b;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  --ease: cubic-bezier(.2,.7,.3,1);
  --mini-h: 66px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding-bottom: calc(var(--mini-h) + env(safe-area-inset-bottom) + 10px);
  font-family: system-ui, -apple-system, 'Segoe UI', Tahoma, 'Vazirmatn', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); border-radius: var(--r-sm); }
button { font: inherit; cursor: pointer; color: inherit; }
svg { display: block; }

/* --------------------------------------------------------------- header */
.top { padding: 20px 20px 2px; }
h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.who { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

/* --------------------------------------------------------------- search */
.searchbar {
  position: sticky; top: 0; z-index: 30;
  padding: 12px 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}
.searchbar form { position: relative; display: flex; align-items: center; }
.si { position: absolute; inset-inline-start: 15px; color: var(--muted); pointer-events: none; }
#q {
  width: 100%;
  padding: 14px 46px;
  border: 0; border-radius: var(--r-md);
  background: var(--tint-1);
  color: inherit; font: inherit; font-size: 16px;
  transition: background .18s var(--ease), box-shadow .18s var(--ease);
}
#q::placeholder { color: var(--muted); }
#q:focus { outline: none; background: var(--tint-2);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
#q::-webkit-search-cancel-button { display: none; }
.clr { position: absolute; inset-inline-end: 13px; width: 24px; height: 24px;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--rule-2); color: var(--bg); }

/* ----------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 8px; padding: 4px 16px 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 7px 0; border: 0; background: none;
  color: var(--muted); font-size: 14.5px; font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color .18s var(--ease), border-color .18s var(--ease);
}
.tab + .tab { margin-inline-start: 10px; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }

/* ----------------------------------------------------------------- list */
.view { padding: 4px 8px 0; animation: rise .24s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.row {
  display: flex; align-items: center; gap: 13px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  position: relative;
  transition: background .15s var(--ease);
}
.row + .row::before {
  content: ''; position: absolute; top: 0; inset-inline: 79px 10px;
  height: 1px; background: var(--rule);
}
.row:active { background: var(--tint-1); }
.row.playing { background: var(--tint-1); }
.row.playing .t { color: var(--accent); }

/* artwork: the thing this app is actually about */
.art {
  position: relative; flex: 0 0 auto;
  width: 56px; height: 56px; border-radius: 10px;
  background: var(--tint-2) center/cover no-repeat;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.28);
}
.art .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.art .eq { position: absolute; inset: 0; display: none;
  align-items: flex-end; justify-content: center; gap: 3px; padding-bottom: 14px;
  background: rgba(0,0,0,.45); }
.row.playing .art .eq { display: flex; }
.art .eq i { width: 3px; background: #fff; border-radius: 2px; animation: eq .9s ease-in-out infinite; }
.art .eq i:nth-child(2) { animation-delay: .15s; }
.art .eq i:nth-child(3) { animation-delay: .3s; }
@keyframes eq { 0%,100% { height: 5px; } 50% { height: 17px; } }

.meta { min-width: 0; flex: 1; }
.t { font-size: 15px; font-weight: 600; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a { font-size: 12.5px; color: var(--muted); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.acts { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.ico {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  transition: background .15s var(--ease), color .15s var(--ease), transform .12s var(--ease);
}
.ico:active { transform: scale(.88); background: var(--tint-2); }
.ico.on { color: var(--gold); }

/* --------------------------------------------------------------- states */
.empty { padding: 56px 24px; text-align: center; color: var(--muted); font-size: 14px; }
.empty .big { display: block; margin: 0 auto 14px; width: 46px; height: 46px; opacity: .45; }

.skel { display: flex; align-items: center; gap: 13px; padding: 9px 10px; }
.skel .b { background: var(--tint-2); border-radius: 7px; animation: pulse 1.3s ease-in-out infinite; }
.skel .c { width: 56px; height: 56px; border-radius: 10px; }
.skel .l1 { height: 12px; width: 58%; margin-bottom: 8px; }
.skel .l2 { height: 10px; width: 34%; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.sect { padding: 16px 12px 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.plhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px 2px; }
.pill {
  padding: 8px 14px; border: 1px solid var(--rule-2); border-radius: var(--r-pill);
  background: transparent; color: var(--text); font-size: 12.5px; font-weight: 600;
}
.pill.solid { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.sdanger { background: var(--danger); border-color: transparent; color: #fff; }

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; inset-inline: 20px; bottom: calc(var(--mini-h) + 20px);
  z-index: 90; margin-inline: auto; max-width: 400px;
  padding: 12px 18px; border-radius: var(--r-md);
  background: color-mix(in srgb, var(--text) 93%, transparent);
  color: var(--bg); font-size: 13.5px; font-weight: 600; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.show { opacity: 1; transform: none; }

/* ---------------------------------------------------------- mini player */
.dock {
  position: fixed; inset-inline: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 50; height: var(--mini-h);
  display: flex; align-items: center; gap: 11px;
  padding: 0 10px 0 8px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(200%) blur(24px);
  -webkit-backdrop-filter: saturate(200%) blur(24px);
  box-shadow: 0 10px 34px rgba(0,0,0,.4);
  border: 1px solid var(--rule);
  overflow: hidden;
  animation: up .3s var(--ease) both;
}
@keyframes up { from { transform: translateY(130%); } to { transform: none; } }

.miniart { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 11px;
  background: var(--tint-2) center/cover no-repeat; }
.minimeta { flex: 1; min-width: 0; }
.minititle { font-size: 13.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.miniartist { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Progress runs left-to-right even on an RTL page: that is how every media
   player draws it, and it is what the seek handler measures against. */
.miniline { position: absolute; inset-inline: 0; bottom: 0; height: 2px;
  background: var(--rule); direction: ltr; }
.minifill { height: 100%; width: 0; background: var(--accent); transition: width .4s linear; }

.round {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  transition: transform .12s var(--ease), background .15s var(--ease);
}
.round:active { transform: scale(.9); }
.round.sm { width: 34px; height: 34px; background: transparent; color: var(--muted); }
.round.ghost { background: var(--tint-2); color: var(--text); }
.round.big { width: 64px; height: 64px; }

/* --------------------------------------------------------- full player */
.full { position: fixed; inset: 0; z-index: 70; overflow: hidden;
  animation: rise .26s var(--ease) both; }
.fullbg {
  position: absolute; inset: -40px;
  background: var(--bg) center/cover no-repeat;
  filter: blur(46px) saturate(160%) brightness(.55);
  transform: scale(1.2);
}
.fullbg::after { content: ''; position: absolute; inset: 0;
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--bg) 35%, transparent),
    color-mix(in srgb, var(--bg) 88%, transparent)); }
.fullinner {
  position: relative; height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 28px calc(28px + env(safe-area-inset-bottom));
}
.fclose { align-self: flex-start; }
.bigart {
  width: min(74vw, 320px); aspect-ratio: 1; margin: 5vh 0 4vh;
  border-radius: 20px; background: var(--tint-2) center/cover no-repeat;
  box-shadow: 0 26px 60px rgba(0,0,0,.55);
}
.fmeta { width: 100%; text-align: center; }
.ftitle { font-size: 21px; font-weight: 750; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fartist { font-size: 14px; color: var(--muted); margin-top: 3px; }

.fbar { width: 100%; height: 5px; margin-top: 26px; border-radius: 3px;
  background: var(--rule-2); cursor: pointer; direction: ltr; }
.ffill { height: 100%; width: 0; border-radius: 3px; background: var(--text); }
.ftime { width: 100%; display: flex; justify-content: space-between; margin-top: 7px;
  font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; direction: ltr; }

.ftransport { display: flex; align-items: center; gap: 26px; margin-top: 26px; }
.facts { display: flex; gap: 10px; margin-top: auto; padding-top: 22px; }
.chipbtn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 11px 18px; border: 1px solid var(--rule-2); border-radius: var(--r-pill);
  background: var(--tint-1); font-size: 13px; font-weight: 600;
}
.chipbtn.on { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }

/* -------------------------------------------------------- bottom sheet */
.sheetwrap { position: fixed; inset: 0; z-index: 95; }
.sheetbg { position: absolute; inset: 0; background: rgba(0,0,0,.55);
  opacity: 0; transition: opacity .22s var(--ease); backdrop-filter: blur(3px); }
.sheet {
  position: absolute; inset-inline: 0; bottom: 0;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface); border-top: 1px solid var(--rule);
  box-shadow: 0 -14px 40px rgba(0,0,0,.45);
  transform: translateY(100%); transition: transform .24s var(--ease);
  max-height: 76vh; overflow-y: auto;
}
.sheetwrap.open .sheetbg { opacity: 1; }
.sheetwrap.open .sheet { transform: none; }
.grab { width: 38px; height: 4px; margin: 4px auto 12px; border-radius: 2px; background: var(--rule-2); }
.shead { font-size: 15.5px; font-weight: 700; margin-bottom: 12px; }
.sbody { display: flex; flex-direction: column; gap: 7px; }
.srow {
  width: 100%; text-align: start; padding: 14px;
  border: 0; border-radius: var(--r-md); background: var(--tint-1);
  font-size: 14px; font-weight: 600;
  transition: background .15s var(--ease), transform .12s var(--ease);
}
.srow:active { transform: scale(.985); background: var(--tint-2); }
.sinput { width: 100%; margin-top: 4px; padding: 14px;
  border: 0; border-radius: var(--r-md); background: var(--tint-1);
  color: inherit; font: inherit; font-size: 16px; }
.sinput:focus { outline: none;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
.sacts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.sacts .pill { padding: 11px 20px; font-size: 13.5px; }

.hide { display: none !important; }

@media (min-width: 640px) {
  .top, .searchbar, .tabs, .view { max-width: 640px; margin-inline: auto; }
  .dock { inset-inline: auto; left: 50%; transform: translateX(-50%); width: min(620px, 96vw); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
