:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --card: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #fff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  /* сплошная подложка: тема Telegram может отдавать полупрозрачный фон,
     и тогда панели просвечивают. Красим её поверх этого цвета. */
  --solid: #ffffff;
  --bottom-h: calc(58px + env(safe-area-inset-bottom));
  --ease: cubic-bezier(.22, .68, .32, 1);
}

html[data-theme="dark"] { --solid: #17212b; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) { --solid: #17212b; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: linear-gradient(var(--bg), var(--bg)), var(--solid);
  font: 15px/1.35 -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { background: var(--card); }

.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
       stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* --- шапка --- */
#head {
  position: sticky; top: 0; z-index: 20;
  padding: 10px 16px 10px;
  background: linear-gradient(var(--bg), var(--bg)), var(--solid);
}
#head[hidden] { display: none; }
.search { display: flex; align-items: center; gap: 8px;
          background: var(--card); border-radius: 10px; padding: 0 12px; height: 40px; }
.search .ico { color: var(--hint); }
#q { flex: 1; min-width: 0; height: 100%; border: 0; background: none; color: var(--text);
     font-size: 16px; outline: none; }
#q::-webkit-search-cancel-button { display: none; }
.clear { color: var(--hint); font-size: 15px; padding: 4px; }
.clear[hidden] { display: none; }

/* --- переходы между экранами --- */
#view { position: relative; overflow-x: clip; padding: 0 16px calc(var(--bottom-h) + 120px); }
.page {
  position: relative; z-index: 2;
  background: linear-gradient(var(--bg), var(--bg)), var(--solid);
  min-height: calc(100vh - 220px);
  will-change: transform, opacity;
}
.page.anim { transition: transform .26s var(--ease), opacity .2s linear; }
.from-right { transform: translateX(100%); opacity: .35; }
.from-left  { transform: translateX(-28%); opacity: .35; }
.to-left    { transform: translateX(-28%); opacity: 0; }
.to-right   { transform: translateX(100%); opacity: 0; }
.page.leaving {
  position: absolute; left: 16px; right: 16px; top: 0;
  z-index: 1;                      /* всегда под приходящей страницей */
  pointer-events: none;
}
.page.in { transform: none; opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .page.anim { transition: opacity .15s linear; }
  .from-right, .from-left { transform: none; }
}

/* --- строки списка --- */
.row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.row:active { opacity: .65; }
.art-wrap { position: relative; flex: none; }
.art { width: 50px; height: 50px; border-radius: 8px; object-fit: cover; display: block; }
.art-wrap .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.34); border-radius: 8px; color: #fff; font-size: 13px;
  opacity: .82; transition: opacity .15s, background .15s;
}
.art-wrap:active .play { opacity: 1; background: rgba(0,0,0,.55); }
.art-wrap.playing .play { opacity: 1; background: rgba(0,0,0,.5); }
.row.locked .art-wrap .play { display: none; }
.round { border-radius: 50%; }

.meta { flex: 1; min-width: 0; }
.t1 { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t2 { color: var(--hint); font-size: 13px; margin-top: 2px;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.by { color: var(--hint); }
.by:active { color: var(--link); }
.row.now .t1 { color: var(--accent); }

.send { flex: none; width: 34px; height: 34px; border-radius: 50%;
        background: var(--accent); color: var(--on-accent);
        display: flex; align-items: center; justify-content: center; font-size: 15px; }
.send:active { opacity: .6; }
.send.done, .send.busy { background: var(--card); color: var(--hint); }
.chev { color: var(--hint); font-size: 18px; padding-left: 4px; }
.locked { opacity: .45; }

/* --- шапка сущности --- */
.hero { display: flex; gap: 14px; align-items: center; padding: 8px 0 16px; }
.hero img { width: 88px; height: 88px; border-radius: 10px; object-fit: cover; }
.hero img.round { border-radius: 50%; }
.hero h2 { margin: 0 0 4px; font-size: 19px; }
.hero p { margin: 0; color: var(--hint); font-size: 13px; }
.hero .bulk { margin-top: 10px; background: var(--accent); color: var(--on-accent);
              border-radius: 8px; padding: 7px 14px; font-size: 14px; font-weight: 500; }

.tabs { display: flex; gap: 20px; padding: 4px 2px 10px; }
.tab { color: var(--hint); font-size: 15px; font-weight: 500; padding-bottom: 6px;
       border-bottom: 2px solid transparent; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }

.section { display: flex; align-items: baseline; justify-content: space-between;
           color: var(--hint); font-size: 13px; margin: 6px 0 4px; }
.section b { color: var(--text); font-size: 17px; font-weight: 600; }

.empty { text-align: center; color: var(--hint); padding: 56px 24px; font-size: 14px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }
.empty .em { font-size: 32px; display: block; margin-bottom: 10px; }

.skel { height: 50px; margin: 7px 0; border-radius: 8px; background: var(--card);
        animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
/* контейнер строк: по нему собирается очередь плеера */
.list { display: block; }

/* маячок подгрузки в конце списка */
.sentinel { min-height: 12px; padding: 4px 0; }
.sentinel .skel { height: 50px; }
.more-err { text-align: center; color: var(--hint); font-size: 13px; padding: 12px; }

/* --- шторка результатов поиска --- */
#sheet {
  margin: 0 -16px; padding: 12px 16px calc(var(--bottom-h) + 40px);
  background: var(--card);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -1px 0 var(--line), 0 -12px 28px rgba(0,0,0,.10);
  min-height: 70vh;
  animation: sheetUp .26s var(--ease);
}
#sheet[hidden] { display: none; }
#sheet .art, #sheet .skel { background: color-mix(in srgb, var(--bg) 55%, var(--card)); }
#sheet .send { box-shadow: 0 1px 4px rgba(0,0,0,.15); }
@keyframes sheetUp { from { transform: translateY(14px); opacity: 0; } }

/* --- привязка профиля --- */
.bind { padding: 40px 8px; text-align: center; }
.bind p { color: var(--hint); font-size: 14px; margin: 0 0 18px; }
.bind input { width: 100%; height: 42px; border: 0; border-radius: 10px; padding: 0 14px;
              background: var(--card); color: var(--text); font-size: 16px; outline: none; }
.bind button { margin-top: 12px; width: 100%; height: 42px; border-radius: 10px;
               background: var(--accent); color: var(--on-accent); font-weight: 500; }

/* --- плеер --- */
#player { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; }
#player[hidden] { display: none; }

#mini {
  position: absolute; left: 0; right: 0; bottom: var(--bottom-h);
  display: flex; align-items: center; gap: 10px;
  /* два слоя: тонировка поверх сплошного фона — панель не просвечивает,
     даже если тема отдаёт полупрозрачный secondary_bg_color */
  background: linear-gradient(var(--card), var(--card)), var(--solid);
  border-top: 1px solid var(--line);
  padding: 8px 12px 9px;
  transition: opacity .2s, transform .26s var(--ease);
  touch-action: pan-y;
  cursor: pointer;
}
#mini:active { background: linear-gradient(var(--line), var(--line)), var(--solid); }
#mini-bar { position: absolute; left: 0; right: 0; top: 0; height: 2px;
            background: var(--line); overflow: hidden; }
#mini-bar i { display: block; height: 100%; width: 0; background: var(--accent); }
#mini img { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; }
.p-meta { flex: 1; min-width: 0; }
#p-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#p-artist { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-btn { width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
         color: var(--on-accent); font-size: 12px; flex: none; }
.p-btn.ghost { background: none; color: var(--hint); font-size: 15px; }

#full {
  position: fixed; inset: 0; z-index: 35;
  touch-action: none;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 28px calc(24px + env(safe-area-inset-bottom));
  /* полностью непрозрачно: под экраном не должно быть видно список */
  background: linear-gradient(var(--bg), var(--bg)), var(--solid);
  transform: translateY(100%);
  transition: transform .3s var(--ease);
  will-change: transform;
  backface-visibility: hidden;
  overflow: hidden;
}
#player.open #full { transform: none; }
#player.open #mini { opacity: 0; pointer-events: none; transform: translateY(12px); }

#grip { width: 100%; padding: 12px 0 6px; display: flex; justify-content: center; flex: none; }
#grip span { width: 38px; height: 4px; border-radius: 2px; background: var(--line); }

#f-art { width: min(74vw, 320px); aspect-ratio: 1; border-radius: 14px; object-fit: cover;
         margin: auto 0 0; box-shadow: 0 14px 40px rgba(0,0,0,.25); }
#f-info { width: 100%; text-align: center; margin: 22px 0 0; }
#f-title { font-size: 19px; font-weight: 600; margin-bottom: 4px;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#f-artist { font-size: 15px; color: var(--hint); max-width: 100%;
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
#f-artist:active { color: var(--link); }

#f-seek { width: 100%; margin-top: 20px; }
#seek { width: 100%; height: 22px; touch-action: none; background: none; -webkit-appearance: none; appearance: none; }
#seek::-webkit-slider-runnable-track { height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--pct, 0%), var(--line) var(--pct, 0%)); }
#seek::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -4.5px;
  border-radius: 50%; background: var(--accent); }
#seek::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
#seek::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
#seek::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: var(--accent); }
.times { display: flex; justify-content: space-between; color: var(--hint); font-size: 12px;
         font-variant-numeric: tabular-nums; margin-top: -2px; }

#f-controls { display: flex; align-items: center; gap: 34px; margin: 18px 0 auto; }
#f-controls button { font-size: 24px; color: var(--text); }
#f-controls button:active { opacity: .5; }
#f-controls button:disabled { opacity: .25; }
#f-controls .big { width: 64px; height: 64px; border-radius: 50%; font-size: 20px;
                   background: var(--accent); color: var(--on-accent); }

#f-send { width: 100%; max-width: 340px; height: 46px; border-radius: 12px; flex: none;
          background: var(--card); color: var(--text); font-size: 15px; font-weight: 500;
          margin-top: 20px; }
#f-send:active { opacity: .6; }
#f-send.done { color: var(--hint); }

/* --- нижняя навигация --- */
#bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; border-top: 1px solid var(--line);
  background: linear-gradient(var(--bg), var(--bg)), var(--solid);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
       padding: 8px 0; color: var(--hint); font-size: 11px; }
.nav.on { color: var(--accent); }

/* --- тост --- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 78px); transform: translate(-50%, 12px);
  z-index: 40; max-width: 88vw;
  background: rgba(0,0,0,.85); color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-color-scheme: dark) {
  #toast { background: rgba(255,255,255,.16); backdrop-filter: blur(12px); }
}
