/* Тёмная тема фиксирована: музыкальному приложению так идёт больше, а Telegram
   на светлой теме всё равно отдал бы блёклые серые панели. */
:root {
  --bg: #0d0d10;
  --bg-elev: #16161c;
  --bg-hover: #1e1e26;
  --text: #f2f2f5;
  --muted: #8f8fa0;
  --accent: #c04bff;
  --accent-2: #ff5b8a;
  --line: rgba(255, 255, 255, .07);
  /* Типографическая шкала: пять ступеней с заметным шагом. Размеры шрифта
     берём только отсюда — иначе набегают 12/13/14/15, где разница в пиксель
     читается не как замысел, а как небрежность. */
  --t-meta: 12px;   /* длительность, счётчики, подписи */
  --t-sub:  14px;   /* исполнитель, вкладки, вторичный текст */
  --t-body: 16px;   /* название трека, поиск — основной текст */
  --t-lead: 20px;   /* название в развёрнутом плеере */
  --t-head: 26px;   /* заголовок экрана */

  /* Шаг сетки 4px: все отступы кратны ему. */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --player-h: 62px;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: var(--t-body); line-height: 1.4;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.fill { fill: currentColor; stroke: none; }

.icon-btn {
  display: grid; place-items: center;
  background: none; border: 0; color: var(--text);
  padding: 8px; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: var(--bg-hover); }

/* ── шапка ─────────────────────────────────────────────────────────────── */

.top {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + var(--s3)) var(--s4) 0;
  background: linear-gradient(180deg, #1a1024 0%, var(--bg) 100%);
}
.top-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: var(--t-head); font-weight: 700; margin: 0; letter-spacing: -.02em; }

.search { position: relative; margin: var(--s3) 0; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
#search {
  width: 100%; padding: var(--s3) var(--s3) var(--s3) 40px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-size: var(--t-body); outline: none;
}
#search:focus { border-color: var(--accent); }
#search::-webkit-search-cancel-button { filter: invert(.6); }

.tabs { display: flex; gap: var(--s2); padding-bottom: var(--s3); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: var(--s2) var(--s4); border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--muted); font-size: var(--t-sub); font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--text); border-color: var(--text); color: #000; }

/* ── список ────────────────────────────────────────────────────────────── */

main { padding: var(--s1) var(--s2) calc(var(--player-h) + var(--safe-bottom) + var(--s5)); }
.list { display: flex; flex-direction: column; }

/* Высота строки зафиксирована: по ней виртуальный список считает, что показать.
   Если менять — поправить ROW_H в app.js. */
.row {
  display: flex; align-items: center; gap: var(--s3);
  height: 64px; padding: var(--s2); border-radius: 12px; cursor: pointer;
}

/* В режиме коллекции в DOM живут только видимые строки, а каждая стоит на своём
   месте по координате. Иначе браузер строил бы все 89 строк ради 13 видимых. */
.list.virtual { position: relative; }
.list.virtual .row {
  position: absolute; left: 0; right: 0;
  contain: layout paint;
}
.row:active { background: var(--bg-hover); }
.row.playing .row-title { color: var(--accent); }

.cover {
  flex: none; border-radius: 8px; overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: rgba(0,0,0,.45);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.md { width: 48px; height: 48px; }
.cover.sm { width: 40px; height: 40px; border-radius: 6px; }
.cover.lg { width: min(74vw, 300px); aspect-ratio: 1; border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.55); }
.cover .note {
  font-size: 20px; font-weight: 800; letter-spacing: -.02em;
  color: rgba(0, 0, 0, .38);
  /* Тонкая светлая подсветка сверху — буква не выглядит грязным пятном
     на насыщенном градиенте. */
  text-shadow: 0 1px 0 rgba(255, 255, 255, .22);
}
.cover.sm .note { font-size: 17px; }
.cover.lg .note { font-size: 96px; }

.row-meta { flex: 1; min-width: 0; }
.row-title { font-size: var(--t-body); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: var(--t-sub); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row-sub .dot { opacity: .5; margin: 0 var(--s1); }
.row-heart { color: var(--accent-2); }
.row-more { color: var(--muted); flex: none; width: 34px; height: 34px; }
/* Три точки рисуем символом, а не SVG: на 89 строк это было 89 лишних
   векторных элементов в разметке. */
.row-more::after {
  content: '⋮'; font-size: 20px; line-height: 1;
}

.empty { text-align: center; color: var(--muted); padding: 56px 32px; }
.empty .big { font-size: 40px; margin-bottom: 12px; }
.empty h2 { color: var(--text); font-size: var(--t-lead); margin: 0 0 var(--s2); }
.empty p { margin: 0; font-size: var(--t-sub); line-height: 1.5; }

.skel-row { height: 64px; margin: 4px 8px; border-radius: 12px; background: var(--bg-elev); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.section-head { padding: var(--s5) var(--s2) var(--s2); font-size: var(--t-meta); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ── мини-плеер ────────────────────────────────────────────────────────── */

.player {
  position: fixed; left: 8px; right: 8px; z-index: 30;
  bottom: calc(var(--safe-bottom) + 8px);
  /* Размытие фона тут выглядело красиво, но iPhone пересчитывает его на каждом
     кадре прокрутки списка — из-за этого всё и подтормаживало. Непрозрачная
     подложка на тёмном фоне выглядит почти так же, а стоит копейки. */
  background: #1c1c24;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
.player-progress { height: 2px; background: rgba(255,255,255,.1); }
.player-progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.player-body { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; }
.player-body .meta { flex: 1; min-width: 0; }
.player-body .title { font-size: var(--t-body); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-body .artist { font-size: var(--t-sub); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── развёрнутый плеер ─────────────────────────────────────────────────── */

/* Каркас плеера жёсткий: кнопки и полоса перемотки всегда на одном месте.
   Тянется только обложка, а название ограничено двумя строками — иначе длинный
   заголовок сдвигал бы всё управление вниз. */
.full {
  position: fixed; inset: 0; z-index: 40;
  background: linear-gradient(180deg, #2a1240 0%, var(--bg) 55%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  justify-items: center;
  padding: calc(var(--safe-top) + 8px) 24px calc(var(--safe-bottom) + 28px);
  animation: rise .26s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
.full-close { justify-self: start; }

.cover-slot { min-height: 0; width: 100%; display: grid; place-items: center; padding: 8px 0 20px; }
.cover.lg {
  height: 100%; width: auto; max-height: min(74vw, 320px); max-width: 100%;
  aspect-ratio: 1;
}

/* Высота с запасом: две строки названия занимают 66px впритык, а при более
   крупном системном шрифте вылезли бы за край. Растягивается только обложка —
   кнопки внизу от этого не двигаются. */
.full-meta { width: 100%; height: 76px; display: flex; flex-direction: column; justify-content: center; }
.full-title {
  font-size: var(--t-lead); font-weight: 700; letter-spacing: -.02em; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.full-artist {
  font-size: var(--t-body); color: var(--muted); margin-top: var(--s1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.seek { width: 100%; margin-top: 22px; }
#seek {
  width: 100%; height: 22px; -webkit-appearance: none; appearance: none;
  background: none; outline: none;
}
#seek::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,.18); }
#seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; margin-top: -4.5px;
  border-radius: 50%; background: var(--text);
}
#seek::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,.18); }
#seek::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: var(--text); }
.times { display: flex; justify-content: space-between; font-size: var(--t-meta); color: var(--muted); margin-top: var(--s1); }

.controls { display: flex; align-items: center; gap: 18px; margin-top: 20px; }
.ctl { color: var(--muted); }
.ctl.on { color: var(--accent); }
.big-play, .play {
  background: var(--text); color: #000;
  width: 62px; height: 62px; border-radius: 50%;
}

/* Загрузка: полоска мини-плеера бежит, вокруг большой кнопки крутится кольцо.
   Без этого пауза на медленной сети выглядит как зависшее приложение. */
/* Двигаем через transform, а не margin: так браузер не пересчитывает вёрстку
   на каждом кадре и полоска не подтормаживает список под собой. */
.player.buffering .player-progress-fill {
  width: 35% !important; transition: none;
  animation: slide 1.1s ease-in-out infinite;
  will-change: transform;
}
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(286%); }
}

.full.buffering .big-play { position: relative; }
.full.buffering .big-play::after {
  content: ''; position: absolute; inset: -6px;
  border: 2px solid transparent; border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.play { width: 34px; height: 34px; }
.big-play svg, .play svg { width: 26px; height: 26px; }
.play svg { width: 16px; height: 16px; }

/* ── нижнее меню ───────────────────────────────────────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet-card {
  position: relative; width: 100%;
  background: var(--bg-elev); border-radius: 18px 18px 0 0;
  padding: 8px 8px calc(var(--safe-bottom) + 12px);
  animation: rise .24s cubic-bezier(.2, .8, .3, 1);
  max-height: 80vh; overflow-y: auto;
}
.sheet-head { padding: 12px 14px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.sheet-title { font-weight: 700; }
.sheet-sub { font-size: var(--t-sub); color: var(--muted); margin-top: var(--s1); }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 14px; border-radius: 12px; cursor: pointer;
  font-size: var(--t-body); background: none; border: 0; color: var(--text); width: 100%; text-align: left;
}
.sheet-item:active { background: var(--bg-hover); }
.sheet-item.danger { color: #ff5f56; }
.sheet-item svg { flex: none; color: var(--muted); }
.sheet-item.danger svg { color: #ff5f56; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--player-h) + var(--safe-bottom) + 28px); z-index: 60;
  background: var(--text); color: #000; font-size: var(--t-sub); font-weight: 600;
  padding: 9px 16px; border-radius: 999px; animation: fade .2s;
  max-width: 80vw; text-align: center;
}
