:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --surface-3: #242424;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #fafafa;
  --text-2: rgba(255, 255, 255, 0.62);
  --text-3: rgba(255, 255, 255, 0.38);
  --accent: #ff9f43;
  --accent-glow: rgba(255, 159, 67, 0.14);
  --like: #ff6b6b;
  --ok: #43e97b;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --topbar-h: 88px;
  --player-h: 120px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
svg { fill: currentColor; }
.ic { width: 24px; height: 24px; display: block; }
.ic-lg { width: 32px; height: 32px; display: block; }

/* ===== top bar ===== */
.topbar {
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
}
.logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: linear-gradient(135deg, #ff9f43, #ff6b6b);
  display: flex; align-items: center; justify-content: center;
  color: #000; font-weight: 700; font-size: 22px;
}
.nav {
  display: flex; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 5px;
  justify-self: start;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 22px; border-radius: 10px;
  font-size: 15px; font-weight: 600;
  color: var(--text-2);
  white-space: nowrap; flex-shrink: 0;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active { background: var(--text); color: #000; }
.nav-btn.disabled { opacity: 0.45; pointer-events: none; }
.nav-cover {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--surface-3) center/cover;
  flex-shrink: 0;
}
.gate-btn {
  width: 64px; height: 64px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  overflow: hidden;
  padding: 6px;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}
.gate-btn:active { transform: scale(0.96); }
.gate-btn.pending { opacity: 0.85; }
.gate-btn.ok { background: rgba(67, 233, 123, 0.18); border-color: var(--ok); }
.gate-btn.err { background: rgba(255, 107, 107, 0.18); border-color: var(--like); }
.gate-svg {
  width: 100%; height: 100%;
  display: block;
  overflow: visible;  /* чтобы поднятая стрела не обрезалась рамкой */
}
.gate-boom {
  transform-origin: 14px 24.5px;
  transform-box: view-box;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Подъём стрелы во время отправки запроса и при успехе.
   -30° — максимум при котором поднятая стрела ещё помещается в viewBox 64×64. */
.gate-btn.pending .gate-boom,
.gate-btn.ok .gate-boom {
  transform: rotate(-30deg);
}

/* ===== content area ===== */
.content {
  position: absolute;
  top: var(--topbar-h); left: 0; right: 0; bottom: var(--player-h);
  overflow-y: auto;
  padding: 24px 28px 32px;
  scroll-behavior: smooth;
}
.content::-webkit-scrollbar { width: 8px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

.loading, .empty {
  color: var(--text-2); font-size: 16px; padding: 24px;
}
.error-box {
  padding: 16px 20px; border: 1px solid var(--like);
  border-radius: var(--radius-sm); color: var(--like);
  font-size: 15px;
}

/* ===== section header (likes / playlist / wave) ===== */
.section-head {
  display: flex; align-items: center; gap: 18px;
  padding: 8px 6px 20px;
}
.section-cover {
  width: 72px; height: 72px; border-radius: 12px;
  background: var(--surface-2) center/cover;
  flex-shrink: 0;
  position: relative;
}
.section-cover.wave {
  background: linear-gradient(135deg, #ff9f43, #ff6b6b 50%, #8e44ad);
}
.section-cover.likes {
  background: linear-gradient(135deg, #ff6b6b, #c44569);
}
.section-cover.likes::after {
  content: '';
  position: absolute; inset: 0;
  background: center/32px no-repeat url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' opacity='0.92'><path d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/></svg>");
}
.section-cover.fallback {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
}
.section-cover.fallback::after {
  content: '';
  position: absolute; inset: 0;
  background: center/28px no-repeat url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' opacity='0.85'><path d='M15 6H3v2h12V6zm0 4H3v2h12v-2zM3 16h8v-2H3v2zM17 6v8.18c-.31-.11-.65-.18-1-.18-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3V8h3V6h-5z'/></svg>");
}
.section-title { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.section-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.section-back {
  padding: 10px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13px; font-weight: 500;
  margin-right: 4px;
  display: flex; align-items: center; gap: 6px;
}
.section-back:hover { color: var(--text); }

/* ===== track list ===== */
.tracklist { display: flex; flex-direction: column; gap: 2px; }
.trow {
  display: grid; grid-template-columns: 40px 56px 1fr auto auto;
  gap: 18px; align-items: center;
  padding: 12px 16px; border-radius: var(--radius-sm);
  transition: background 0.12s;
}
.trow:hover { background: var(--surface-2); }
.trow.playing {
  background: var(--accent-glow);
  border: 1px solid rgba(255, 159, 67, 0.3);
  padding: 11px 15px;
}
.trow.playing .trow-title { color: var(--accent); }
.trow-num { font-size: 15px; color: var(--text-3); text-align: center; font-variant-numeric: tabular-nums; }
.trow-cover { width: 56px; height: 56px; border-radius: var(--radius-xs); background: var(--surface-2) center/cover; flex-shrink: 0; }
.trow-main { overflow: hidden; cursor: pointer; }
.trow-title { font-size: 17px; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow-artist { font-size: 13px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow-dur { font-size: 14px; color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.trow-like {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
}
.trow-like:hover { background: var(--surface-3); color: var(--text); }
.trow-like.liked { color: var(--like); }
.trow-like.pending { opacity: 0.5; }

.playing-bars { display: inline-flex; gap: 3px; align-items: end; height: 20px; margin: 0 auto; }
.playing-bars span {
  width: 3px; background: var(--accent); border-radius: 2px;
  animation: bar 1s ease-in-out infinite;
}
.playing-bars span:nth-child(1) { height: 50%; animation-delay: 0s; }
.playing-bars span:nth-child(2) { height: 100%; animation-delay: 0.2s; }
.playing-bars span:nth-child(3) { height: 70%; animation-delay: 0.4s; }
@keyframes bar { 0%, 100% { height: 20%; } 50% { height: 100%; } }

/* ===== playlists grid ===== */
.pl-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px; padding: 6px;
}
.pl-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; transition: background 0.12s;
}
.pl-card:hover { background: var(--surface-2); }
.pl-card-cover {
  width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm);
  background: var(--surface-2) center/cover;
}
.pl-card-title { font-size: 16px; font-weight: 600; line-height: 1.3; }
.pl-card-sub { font-size: 12px; color: var(--text-3); }

/* ===== search ===== */
.search-wrap { display: flex; flex-direction: column; gap: 18px; padding: 4px; }
.search-input-box {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 0 22px;
  height: 64px;
  color: var(--text-3);
}
.search-input-box svg { width: 24px; height: 24px; flex-shrink: 0; }
.search-input-box:focus-within { border-color: var(--accent); color: var(--text); }
.search-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-family: inherit; font-size: 18px; color: var(--text);
  padding: 0; height: 100%;
}
.search-input::placeholder { color: var(--text-3); }
.search-results { min-height: 200px; }

.trow-actions { display: flex; align-items: center; gap: 4px; }
.trow-add, .trow-remove {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); cursor: pointer; border: none; background: transparent;
}
.trow-add svg, .trow-remove svg { width: 22px; height: 22px; }
.trow-add:hover { background: var(--surface-3); color: var(--text); }
.trow-remove:hover { background: var(--surface-3); color: var(--like); }

/* ===== popover (add to playlist) ===== */
.popover {
  position: fixed; z-index: 200;
  min-width: 220px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 14px; padding: 6px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  display: flex; flex-direction: column; gap: 2px;
}
.popover-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 10px;
  background: transparent; border: none; color: var(--text);
  font-family: inherit; font-size: 15px; font-weight: 500;
  cursor: pointer; text-align: left; width: 100%;
}
.popover-item:hover { background: var(--surface-2); }
.popover-item svg { width: 20px; height: 20px; opacity: 0.7; flex-shrink: 0; }
.popover-item span { flex: 1; }

/* ===== wave hero ===== */
.wave-hero {
  display: flex; flex-direction: column; align-items: center;
  /* cover масштабируется под доступную высоту, чтобы кнопка «Следующий»
     не уезжала под persistent-плеер на меньших viewport'ах. */
  padding: 12px 24px 16px;
  gap: 14px;
}
.wave-hero-cover {
  width: min(280px, 38vh);
  height: min(280px, 38vh);
  border-radius: 20px;
  background: var(--surface-2) center/cover;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  flex-shrink: 0;
}
.wave-hero-title {
  font-size: 26px; font-weight: 700; letter-spacing: -0.01em;
  text-align: center; max-width: 700px;
  line-height: 1.2;
}
.wave-hero-artist {
  font-size: 15px; color: var(--text-2);
  text-align: center;
  margin-top: -6px;
}
.wave-skip-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 32px; border-radius: 999px;
  background: var(--text); color: #000;
  font-size: 16px; font-weight: 700;
  margin-top: 4px;
  transition: transform 0.1s;
}
.wave-skip-btn:hover { transform: scale(1.03); }
.wave-skip-btn:active { transform: scale(0.97); }

/* ===== bottom player ===== */
.player {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--player-h);
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 28px; gap: 32px;
  background: var(--surface); border-top: 1px solid var(--border);
  z-index: 10;
}
.pl-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.pl-cover {
  width: 88px; height: 88px; border-radius: 14px;
  background: var(--surface-2) center/cover; flex-shrink: 0;
}
.pl-meta { min-width: 0; overflow: hidden; }
.pl-title { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-artist { font-size: 13px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pl-center { display: flex; flex-direction: column; gap: 10px; min-width: 420px; }
.pl-controls { display: flex; align-items: center; justify-content: center; gap: 16px; }
.btn-circle {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.btn-circle:hover { background: var(--surface-3); }
.btn-play {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--text); color: #000;
  display: flex; align-items: center; justify-content: center;
}
.btn-play:hover { transform: scale(1.03); }

.pl-progress-row { display: flex; align-items: center; gap: 12px; }
.pl-time { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 40px; text-align: center; }
.pl-progress {
  flex: 1; height: 5px; background: var(--surface-3); border-radius: 3px;
  overflow: hidden; cursor: pointer;
}
.pl-progress-fill { height: 100%; background: var(--text); width: 0%; }

.pl-right { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.ld-btn {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
}
.ld-btn:hover { background: var(--surface-3); color: var(--text); }
.ld-btn.liked { background: var(--like); border-color: var(--like); color: #fff; }
.ld-btn.pending { opacity: 0.55; }

/* ===== toast ===== */
.toast {
  position: fixed; top: calc(var(--topbar-h) + 12px); left: 50%;
  transform: translateX(-50%) translateY(-12px);
  padding: 12px 20px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border-strong);
  font-size: 14px; font-weight: 500;
  max-width: min(70vw, 600px);
  /* HTML error-page в message'е может быть огромный — режем до 3 строк */
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  word-break: break-word;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: var(--ok); color: var(--ok); }
.toast.err { border-color: var(--like); color: var(--like); }

/* hidden audio element */
audio { display: none; }
