/* Pulse Design System — tokens + base styles */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  /* Palette — Purple theme */
  --bg: #0B0912;
  --surface: #151020;
  --surface2: #201831;
  --surface-interactive: #2A2040;
  --line: #382B50;
  --text: #F6F2FF;
  --muted: #AAA0BC;
  --accent: #9B72F2;        /* Primary purple — buttons, active states, progress */
  --accent-light: #B9A0FF;  /* Light purple — highlights, active elements */
  --accent-soft: #D6C5FF;   /* Soft lilac — decorative, subtle accents */
  --accent-pink: #E879F9;   /* Pink-violet — rare accent for viz, special picks */
  --error: #ff6b6b;
  --warning: #ffb347;
  --success: #6bffb8;

  /* Legacy aliases (mapped to new palette) */
  --lime: var(--accent);
  --pink: var(--accent-pink);
  --cyan: var(--accent-light);

  /* Spacing scale */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 12px;
  --sp-lg: 16px;
  --sp-xl: 24px;
  --sp-2xl: 32px;
  --sp-3xl: 48px;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-2xl: 28px;
  --r-full: 99px;

  /* Type scale */
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-lg: 18px;
  --fs-xl: 24px;
  --fs-2xl: 34px;
  --fs-display: clamp(34px, 5vw, 52px);

  /* Safe areas (Telegram WebView) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Player height for content padding */
  --mini-player-h: 72px;
  --bottom-nav-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { border: 0; cursor: pointer; color: inherit; background: transparent; }
a { color: inherit; text-decoration: none; }

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Shell with safe area padding */
.shell {
  max-width: 1180px;
  margin: auto;
  padding: calc(var(--sp-xl) + var(--safe-top)) var(--sp-xl) calc(var(--mini-player-h) + var(--bottom-nav-h) + var(--sp-3xl) + var(--safe-bottom));
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-xl);
  padding-top: var(--safe-top);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-size: 23px;
}

.mark {
  width: 32px;
  height: 32px;
  border-radius: 11px 11px 11px 4px;
  background: var(--lime);
  transform: rotate(-8deg);
  position: relative;
}
.mark:after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 3px solid #201831;
  border-radius: 50%;
  left: 8px;
  top: 7px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), #7046ff);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* Compact Hero */
.hero-compact {
  display: flex;
  align-items: center;
  gap: var(--sp-lg);
  padding: var(--sp-xl);
  border-radius: var(--r-2xl);
  background: linear-gradient(130deg, #2A2040, #151020 65%);
  margin-bottom: var(--sp-xl);
  position: relative;
  overflow: hidden;
}
.hero-compact::after {
  content: '';
  position: absolute;
  width: 200px;
  height: 200px;
  right: -60px;
  bottom: -100px;
  border-radius: 50%;
  background: var(--lime);
  opacity: 0.6;
  filter: blur(40px);
  pointer-events: none;
}
.hero-content { position: relative; z-index: 1; flex: 1; min-width: 0; }
.hero-wave-mini {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 48px;
  flex-shrink: 0;
}
.hero-wave-mini .bar {
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(var(--pink), var(--cyan));
  animation: breathe 1.2s ease-in-out infinite alternate;
}
.hero-wave-mini .bar:nth-child(2n) { animation-delay: 0.2s; }
.hero-wave-mini .bar:nth-child(3n) { animation-delay: 0.5s; }

.eyebrow {
  color: var(--lime);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: var(--fs-xs);
  font-weight: 700;
}
h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: var(--fs-display);
  line-height: 0.98;
  letter-spacing: -0.065em;
  margin: var(--sp-sm) 0;
}
.hero-copy {
  color: var(--muted);
  max-width: 390px;
  line-height: 1.5;
  font-size: var(--fs-sm);
}
.hero-btn {
  margin-top: var(--sp-md);
  background: var(--lime);
  color: #0B0912;
  border-radius: var(--r-md);
  padding: 12px 20px;
  font-weight: 700;
  display: inline-block;
}

/* Wave card (legacy, kept for compatibility) */
.wave-card {
  padding: var(--sp-xl);
  border-radius: var(--r-2xl);
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.wave-title { display: flex; justify-content: space-between; align-items: center; }
.wave-title h2 { margin: 0; font-size: var(--fs-lg); }
.pill {
  padding: 7px 10px;
  background: var(--surface-interactive);
  border-radius: var(--r-full);
  color: var(--cyan);
  font-size: var(--fs-xs);
  font-weight: 700;
}
.wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 100px;
}
.bar {
  width: 5px;
  border-radius: 9px;
  background: linear-gradient(var(--pink), var(--cyan));
  animation: breathe 1.2s ease-in-out infinite alternate;
}
.bar:nth-child(2n) { animation-delay: 0.2s; }
.bar:nth-child(3n) { animation-delay: 0.5s; }
@keyframes breathe { to { transform: scaleY(0.35); opacity: 0.65; } }

/* Section headings */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: var(--sp-lg);
  gap: var(--sp-md);
}
h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: var(--fs-xl);
  letter-spacing: -0.04em;
  margin: 0;
}
.sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 5px; }

/* Filters / chips */
.filters {
  display: flex;
  gap: var(--sp-sm);
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: var(--sp-lg);
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 9px 15px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: 0.15s;
}
.chip:hover { color: var(--text); border-color: #4A3868; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #0B0912; }

/* Track grid */
.track-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-lg);
  min-width: 0;
}

/* Track card */
.track {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-md);
  border: 1px solid transparent;
  transition: 0.2s;
  min-width: 0;
}
.track:hover { border-color: var(--line); transform: translateY(-2px); }
.track.playing { border-color: var(--lime); }

.cover-wrap { position: relative; }
.cover {
  aspect-ratio: 1;
  border-radius: var(--r-md);
  object-fit: cover;
  width: 100%;
  display: block;
  margin-bottom: var(--sp-md);
  background: var(--surface2);
}
.cover.placeholder {
  display: grid;
  place-items: center;
  color: #5A4878;
  font-size: 30px;
}

.track-title {
  font-weight: 700;
  font-size: var(--fs-base);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-artist {
  color: var(--muted);
  font-size: var(--fs-sm);
  margin-top: var(--sp-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--sp-md);
  gap: var(--sp-sm);
}
.track-meta { color: var(--muted); font-size: var(--fs-xs); margin-top: 6px; }
.track-source { color: var(--cyan); font-size: var(--fs-xs); margin-top: 6px; }

/* License badges */
.lic {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 7px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.lic.cc { background: rgba(155,114,242,0.16); color: var(--accent-soft); }
.lic.reserved { background: rgba(232,121,249,0.16); color: #F0B0FF; }
.lic.unknown { background: var(--surface2); color: var(--muted); }

/* Icon buttons */
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: 0.15s;
}
.play { background: var(--accent); color: #0B0912; font-size: 14px; }
.play:hover { transform: scale(1.07); }
.like { color: var(--muted); font-size: 17px; }
.like:hover { color: var(--pink); }
.like.active { color: var(--pink); }
.like[disabled] { opacity: 0.45; cursor: wait; }
.add { color: var(--muted); font-size: 19px; font-weight: 700; }
.add:hover { color: var(--cyan); }

/* Search */
.search {
  display: flex;
  gap: 10px;
  margin-bottom: var(--sp-xl);
  flex-wrap: wrap;
  position: relative;
  z-index: 10;
}
.search input {
  flex: 1 1 240px;
  width: 100%;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  color: var(--text);
  outline: none;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
}
.search input:focus { border-color: var(--cyan); }
.search button {
  background: var(--lime);
  color: #0B0912;
  border-radius: var(--r-md);
  padding: 0 22px;
  font-weight: 700;
  min-height: 48px;
}
.search .source-btn {
  background: var(--surface);
  color: var(--cyan);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.source-picker {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  margin-bottom: var(--sp-lg);
  padding: var(--sp-md) var(--sp-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.source-picker .chip { cursor: pointer; }

.more {
  display: block;
  margin: var(--sp-xl) auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px 26px;
  font-weight: 600;
  color: var(--text);
}
.more:hover { border-color: var(--cyan); }
.more[disabled] { opacity: 0.5; cursor: wait; }

/* Mini player */
.player {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-h) + var(--sp-sm) + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100% - 28px));
  padding: 10px 14px;
  border: 1px solid #4A3868;
  background: rgba(21, 16, 32, 0.94);
  backdrop-filter: blur(18px);
  border-radius: var(--r-xl);
  display: none;
  gap: var(--sp-md);
  box-shadow: 0 15px 50px rgba(0,0,0,0.5);
  z-index: 5;
}
.player.show { display: block; }
.player-row { display: flex; align-items: center; gap: var(--sp-md); }
.player-cover {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface2);
  flex: 0 0 auto;
}
.player-info { min-width: 0; flex: 1; }
.player-info strong, .player-info span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-info span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.player button { font-size: 21px; padding: 2px 4px; }
.player .main-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--lime);
  color: #0B0912;
  font-size: 14px;
}

.seek {
  width: 100%;
  height: 4px;
  border-radius: var(--r-full);
  background: #382B50;
  margin-top: 9px;
  cursor: pointer;
  position: relative;
}
.seek-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--pink), var(--cyan));
  width: 0;
}
.seek-times {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
  margin-top: 5px;
}
.volume-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
}
.volume-row input[type="range"] {
  flex: 1;
  min-width: 90px;
  accent-color: var(--lime);
  cursor: pointer;
}

/* Bottom navigation (mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(21, 16, 32, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: none;
  justify-content: space-around;
  align-items: center;
  z-index: 4;
}
.bottom-nav.show { display: flex; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  transition: 0.15s;
  background: none;
  border: none;
}
.nav-item.active { color: var(--lime); }
.nav-item svg { width: 22px; height: 22px; fill: currentColor; }

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* States */
.empty { color: var(--muted); padding: 30px 0; }
.err { color: var(--pink); padding: 14px 0; font-size: 14px; }
.availability { color: #F0B0FF; font-size: 11px; line-height: 1.35; margin-top: 7px; }

/* Skeleton loading */
.skel {
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface2) 50%, var(--surface) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: var(--r-lg);
  height: 250px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--line);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 60px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(18px + var(--safe-top));
  transform: translate(-50%, -140%);
  background: var(--surface2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: var(--r-md);
  font-size: 13px;
  z-index: 20;
  transition: transform 0.25s;
  max-width: calc(100% - 32px);
}
.toast.show { transform: translate(-50%, 0); }

/* Profile modal */
.profile-modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,0.6);
  z-index: 30;
  padding: 20px;
}
.profile-modal.show { display: grid; }
.profile-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 22px;
  box-shadow: 0 20px 70px rgba(0,0,0,0.7);
}
.profile-card h3 { margin: 0 0 10px; font-family: 'Space Grotesk', sans-serif; }
.profile-card p { color: var(--muted); line-height: 1.5; font-size: 14px; }
.profile-card a, .profile-card button {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--r-md);
  text-align: center;
  font-weight: 700;
}
.profile-card a { background: var(--lime); color: #10131a; text-decoration: none; }
.profile-card button { border: 1px solid var(--line); background: var(--surface2); }

/* Responsive */
@media (max-width: 760px) {
  .shell {
    padding: var(--sp-lg) var(--sp-lg) calc(var(--mini-player-h) + var(--bottom-nav-h) + var(--sp-2xl) + var(--safe-bottom));
  }
  header { margin-bottom: var(--sp-lg); }
  .hero-compact { padding: var(--sp-lg); }
  h1 { font-size: clamp(26px, 7vw, 34px); }
  .track-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-md); }
  .track { padding: 9px; }
  .search button { padding: 0 15px; }
  h2 { font-size: 21px; }
  .player { bottom: calc(var(--bottom-nav-h) + var(--sp-xs) + var(--safe-bottom)); }
  .bottom-nav { display: flex; }
  /* Hide desktop tabs on mobile when bottom nav is active */
  .desktop-tabs { display: none; }
}

@media (min-width: 761px) {
  .bottom-nav { display: none !important; }
}

@media (min-width: 1024px) {
  .track-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Full-screen Now Playing */
.now-playing {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 10;
  display: none;
  flex-direction: column;
  padding: calc(var(--sp-xl) + var(--safe-top)) var(--sp-xl) calc(var(--sp-xl) + var(--safe-bottom));
  overflow-y: auto;
}
.now-playing.show { display: flex; }
.np-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-xl);
}
.np-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 20px;
}
.np-cover {
  width: min(360px, 100%);
  aspect-ratio: 1;
  border-radius: var(--r-xl);
  object-fit: cover;
  background: var(--surface2);
  margin: 0 auto var(--sp-xl);
  display: block;
}
.np-info { text-align: center; margin-bottom: var(--sp-xl); }
.np-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: var(--fs-xl);
  font-weight: 700;
  margin-bottom: var(--sp-xs);
}
.np-artist { color: var(--muted); font-size: var(--fs-lg); }
.np-artist-link {
  color: var(--cyan);
  font-size: var(--fs-sm);
  margin-top: var(--sp-xs);
  display: inline-block;
}
.np-seek {
  width: 100%;
  max-width: 480px;
  margin: 0 auto var(--sp-md);
}
.np-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-xl);
  margin-bottom: var(--sp-xl);
}
.np-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  transition: 0.15s;
}
.np-btn:hover { background: var(--surface); }
.np-btn.main {
  width: 64px;
  height: 64px;
  background: var(--lime);
  color: #0B0912;
  font-size: 24px;
}
.np-btn.main:hover { transform: scale(1.05); }
.np-btn.active { color: var(--lime); }
.np-extras {
  display: flex;
  justify-content: center;
  gap: var(--sp-lg);
  flex-wrap: wrap;
}
.np-volume {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  max-width: 200px;
  width: 100%;
  margin: var(--sp-lg) auto 0;
  color: var(--muted);
}
.np-volume input[type="range"] {
  flex: 1;
  accent-color: var(--lime);
}

/* Queue panel */
.queue-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  z-index: 9;
  display: none;
  flex-direction: column;
  padding: var(--sp-lg);
  overflow-y: auto;
}
.queue-panel.show { display: flex; }
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-md);
}
.queue-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.queue-item:hover { background: var(--surface2); }
.queue-item.current { border-left: 3px solid var(--lime); }
.queue-cover {
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}
.queue-info { min-width: 0; flex: 1; }
.queue-title { font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-artist { color: var(--muted); font-size: var(--fs-xs); }
.queue-remove {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}
.queue-remove:hover { background: var(--surface2); color: var(--pink); }

@media (max-width: 760px) {
  .np-cover { width: min(280px, 80vw); }
  .np-controls { gap: var(--sp-lg); }
  .np-btn { width: 44px; height: 44px; font-size: 18px; }
  .np-btn.main { width: 56px; height: 56px; font-size: 22px; }
}

@media (min-width: 761px) and (max-width: 1023px) {
  .track-grid { grid-template-columns: repeat(3, 1fr); }
}
