:root {
  --bg: #0e0e11;
  --surface: #17171c;
  --surface-2: #1f1f26;
  --line: #2a2a33;
  --text: #ecedf1;
  --muted: #8f92a1;
  --accent: #7c6cff;
  /* Отдельный, светлее: #7c6cff как текст на подложке даёт 4.27:1 — ниже нормы. */
  --accent-text: #9b8dff;
  --accent-soft: rgba(124, 108, 255, 0.16);
  --ok: #4ec98a;
  /* Standalone-режим прячет панель под жестовую полосу без этого. */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --player-h: 73px;
}

* { box-sizing: border-box; }

/* Классы вроде .pl-cover.ph задают display и по специфичности побеждают
   браузерное [hidden]{display:none} — без !important скрытое остаётся видимым. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 0 calc(12px + var(--safe-b));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

/* Список на планшете и десктопе растягивался во всю ширину — колонка держит меру. */
.wrap { max-width: 720px; margin-inline: auto; }

/* ---------- шапка ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(10px + var(--safe-t)) 16px 8px;
  /* Непрозрачно: сквозь полупрозрачную шапку строки списка обрезались жёстким краем. */
  background: var(--bg);
}
/* Мягкий переход к списку вместо среза. */
.top::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 100%;
  height: 14px;
  background: linear-gradient(var(--bg), transparent);
  pointer-events: none;
}

.top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.top h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.counter { color: var(--muted); font-size: 12px; margin-top: 2px; min-height: 16px; }

.search-wrap { position: relative; margin-top: 10px; }

.search {
  width: 100%;
  padding: 11px 44px 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;   /* меньше 16px — iOS зумит страницу при фокусе */
  outline: none;
}
.search:focus { border-color: var(--accent); }
.search::placeholder { color: var(--muted); }
/* Свой крестик: Chrome на Android нативный не рисует. */
.search::-webkit-search-cancel-button { display: none; }

.clear {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

/* ---------- плашка офлайна ---------- */

.offline-bar {
  margin-top: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---------- список ---------- */

.list { padding: 4px 8px 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 8px;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  /* Долгий тап по строке — это меню удаления, а не «выделить и скопировать». */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.row + .row { margin-top: 2px; }
.row:active { background: var(--surface); }
.row.current { background: var(--accent-soft); }
/* Нескачанные треки в офлайне: видно, что слушать нечего, до нажатия. */
.row.unavailable { opacity: 0.45; }

.cover {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--muted);
  overflow: hidden;
}
/* Нота лежит под обложкой: не загрузилась картинка — остаётся нота, а не серый квадрат. */
.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.row-meta { flex: 1 1 auto; min-width: 0; }
.row-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.current .row-title { color: var(--accent-text); }
.row-sub {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; margin-bottom: 6px; color: var(--text); font-weight: 600; }
.empty .empty-act {
  display: inline-block;
  margin-top: 14px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* ---------- подборки ---------- */

.lists { margin-bottom: 12px; }
.lists-head {
  padding: 6px 8px 2px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.list-row .cover { color: var(--accent-text); }

/* Шапка открытой подборки: из неё видно, куда вернуться и что удалить. */
.list-head { display: flex; align-items: center; gap: 6px; padding: 2px 0 8px; }
.list-head .row-meta { flex: 1 1 auto; min-width: 0; }
.list-head .row-title { font-weight: 600; }

.text-btn {
  flex: 0 0 auto;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-size: 14px;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.text-btn:active { background: var(--surface-2); }

/* ---------- диалог ---------- */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
}
.dialog-box {
  width: 100%;
  max-width: 380px;
  padding: 18px 18px 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.dialog-title { font-size: 17px; font-weight: 600; }
.dialog-text { margin-top: 8px; color: var(--muted); font-size: 13px; }
.dialog-acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px; margin-top: 12px; }
.dlg-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dlg-btn.accent { color: var(--accent-text); }
.dlg-btn.danger { color: #e06c75; }
.dlg-btn:active { background: var(--surface-2); }

/* ---------- скелетон загрузки ---------- */

.sk { display: flex; align-items: center; gap: 12px; padding: 9px 8px; }
.sk-box { border-radius: 8px; background: var(--surface-2); }
.sk-cover { flex: 0 0 46px; width: 46px; height: 46px; }
.sk-lines { flex: 1 1 auto; }
.sk-line { height: 11px; border-radius: 6px; background: var(--surface-2); }
.sk-line + .sk-line { margin-top: 8px; width: 45%; }
/* Появляется с задержкой: быстрый ответ не должен давать вспышку скелетонов. */
.sk-wrap { opacity: 0; animation: skIn 0.2s ease 0.15s forwards; }
@keyframes skIn { to { opacity: 1; } }
.sk-box, .sk-line { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- кнопки ---------- */

.icon-btn {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 21px;   /* задаёт размер иконки, не габарит кнопки */
  line-height: 1;
  padding: 0;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.on { color: var(--accent-text); }
.icon-btn.play {
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  border-radius: 14px;
}
.icon-btn.play:active { filter: brightness(1.12); background: var(--accent); }
.icon-btn.play.big { min-width: 64px; min-height: 64px; font-size: 26px; border-radius: 20px; }

.dl { font-size: 20px; color: var(--muted); }
.dl.saved { color: var(--ok); }
.dl.busy { color: var(--accent-text); }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { transform-origin: 50% 50%; animation: spin 0.9s linear infinite; }

.icon-btn svg { display: block; }
.cover svg { width: 22px; height: 22px; }

/* ---------- свёрнутый плеер ---------- */

.player {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  /* Без альфы: сквозь панель просвечивал текст списка прямо под названием трека. */
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.player::before {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 100%;
  height: 14px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
}
.player .wrap { padding: 0 8px; }

/* Тонкая полоса прогресса вместо ползунка — перемотка живёт в полном плеере. */
.mini-progress { height: 2px; background: var(--line); border-radius: 2px; margin: 0 8px; }
.mini-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; }

.pl-body { display: flex; align-items: center; gap: 8px; padding: 8px 0 10px; }

/* Вся левая часть — одна большая кнопка «открыть плеер». */
.pl-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
}
.pl-open:active { background: var(--surface-2); }

.pl-cover {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
}
.pl-cover.ph { display: grid; place-items: center; color: var(--muted); }
.pl-cover.ph svg { width: 20px; height: 20px; }

.pl-meta { flex: 1 1 auto; min-width: 0; display: block; }
.pl-title {
  display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.pl-artist {
  display: block;
  color: var(--muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.pl-controls { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

/* ---------- полноэкранный плеер ---------- */

.full {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  overflow-y: auto;
  transform: translateY(0);
  transition: transform 0.24s ease, opacity 0.24s ease;
}
.full[hidden] { display: none; }
.full.closing { transform: translateY(100%); opacity: 0.6; }
@keyframes fullIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
.full.opening { animation: fullIn 0.24s ease; }

.full-inner {
  max-width: 480px;
  margin-inline: auto;
  min-height: 100%;
  padding: calc(8px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.full-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.full-head > :first-child { justify-self: start; }
.full-head-actions { justify-self: end; }
.full-head-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
@media (max-width: 383px) {
  .full-head-label { display: none; }
}

.full-art {
  display: grid;
  place-items: center;
  /* Забирает свободную высоту и центрует обложку в ней: иначе на высоком
     экране между названием и перемоткой зияет пустота. */
  flex: 1 1 auto;
  min-height: 0;
}
.full-cover {
  width: min(72vw, 320px);
  aspect-ratio: 1;
  border-radius: 18px;
  object-fit: cover;
  background: var(--surface-2);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}
.full-cover.ph { display: grid; place-items: center; color: var(--muted); }
.full-cover.ph svg { width: 34%; height: 34%; }

.full-meta { text-align: center; min-width: 0; }
.full-title {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.full-artist { color: var(--muted); margin-top: 4px; }

.full-progress { margin-top: 0; }

.full-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-bottom: 8px;
}
.full-head-actions { display: flex; gap: 8px; }
.full-controls .icon-btn { font-size: 22px; }

/* ---------- ползунок перемотки ---------- */

.seek {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  /* Высокая зона касания: 18px промахивались в соседние элементы. */
  height: 36px;
  background: none;
  margin: 0;
  /* Иначе перетаскивание на Android конкурирует со скроллом страницы. */
  touch-action: none;
}
/* Залитая часть показывает прогресс — раньше двигалась только точка. */
.seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background:
    linear-gradient(var(--accent), var(--accent)) left / calc(8px + (100% - 16px) * var(--p, 0)) 100% no-repeat,
    var(--line);
}
.seek::-moz-range-track { height: 4px; border-radius: 3px; background: var(--line); }
.seek::-moz-range-progress { height: 4px; border-radius: 3px; background: var(--accent); }
.seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(124, 108, 255, 0.16);
}
.seek::-moz-range-thumb {
  width: 16px; height: 16px; border: 0; border-radius: 50%;
  background: var(--accent);
}

.pl-times {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}

/* ---------- тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 8px);
  z-index: 30;
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
/* Поверх полноэкранного плеера — над рядом управления, а не на нём. Два класса
   в селекторе: full-open всегда идёт вместе с player-visible, и при равном весе
   побеждало бы то правило, что стоит ниже. */
body.full-open .toast,
body.full-open.player-visible .toast {
  top: calc(64px + var(--safe-t));
  bottom: auto;
}

/* Полноэкранный плеер открыт — список под ним не скроллится. */
body.full-open { overflow: hidden; }

/* Тост держится над панелью, пока она есть. */
body.player-visible .toast { bottom: calc(var(--player-h) + 12px + var(--safe-b)); }

/* Панель занимает место только когда играет: иначе под списком висела пустота. */
body.player-visible { padding-bottom: calc(var(--player-h) + var(--safe-b)); }
