:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --card: min(320px, 84vw, 46vh);
  --refl: calc(var(--card) * 0.46);
  --pad: 24px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #03060b;
  color: #f7f8ff;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; border: none; cursor: pointer; }

/* ── Landing ─────────────────────────────────────────── */

.view-landing {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 40%, #1f3c66 0%, #07111f 55%, #03060b 100%);
  padding: 2rem;
}

.landing-inner {
  text-align: center;
  max-width: 400px;
  width: 100%;
}

/* Staggered entrance: each landing element rises in with a small delay.
   `backwards` keeps them invisible until their turn. Replays whenever the
   landing view is shown again (e.g. after disconnect). */
@keyframes landing-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.landing-inner > * {
  animation: landing-rise 0.6s cubic-bezier(0.22, 0.8, 0.2, 1) backwards;
}

.landing-inner > :nth-child(1) { animation-delay: 0.05s; }
.landing-inner > :nth-child(2) { animation-delay: 0.14s; }
.landing-inner > :nth-child(3) { animation-delay: 0.23s; }
.landing-inner > :nth-child(4) { animation-delay: 0.32s; }
.landing-inner > :nth-child(5) { animation-delay: 0.41s; }
.landing-inner > :nth-child(6) { animation-delay: 0.5s; }

.landing-icon {
  color: #1db954;
  margin-bottom: 1.25rem;
  line-height: 0;
}

.landing-inner h1 {
  font-size: clamp(2.6rem, 9vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0 0 0.6rem;
}

.landing-sub {
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  color: rgba(247, 248, 255, 0.55);
  margin: 0 0 2.25rem;
  line-height: 1.55;
}

.connect-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 1rem 1.5rem;
  background: #1db954;
  color: #000;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 999px;
  transition: background 0.18s, transform 0.18s;
  user-select: none;
}

.connect-btn:hover  { background: #1ed760; transform: scale(1.03); }
.connect-btn:active { transform: scale(0.97); }

.demo-btn {
  display: block;
  margin: 1rem auto 0;
  padding: 0.5rem;
  background: none;
  color: rgba(247, 248, 255, 0.45);
  font-size: 0.88rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.18s;
}

.demo-btn:hover { color: rgba(247, 248, 255, 0.8); }

.landing-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(247, 248, 255, 0.35);
  transition: text-decoration-color 0.18s, color 0.18s;
}
.landing-link:hover { color: #fff; text-decoration-color: rgba(255,255,255,0.7); }

.clientid-setup {
  margin-top: 1.25rem;
  text-align: left;
}

/* ── Player ──────────────────────────────────────────── */

/* Registered so --ambient interpolates — the gradient cross-fades smoothly as
   the album changes. Browsers without @property fall back to an instant swap. */
@property --ambient {
  syntax: '<color>';
  inherits: true;
  initial-value: #1a3358;
}

.view-player {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  --ambient: #1a3358;
  background: radial-gradient(circle at top left, var(--ambient) 0%, #07111f 48%, #03060b 100%);
  transition: --ambient 0.8s ease;
  overflow: hidden;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) calc(8.5rem + env(safe-area-inset-bottom, 0)) env(safe-area-inset-left, 0);
}

/* ── Coverflow ───────────────────────────────────────── */

.coverflow-track {
  position: relative;
  width: 100%;
  flex-shrink: 0;
  height: calc(var(--card) + var(--refl) + var(--pad));
  overflow: hidden;
  perspective: 900px;
  perspective-origin: 50% 70%;
  outline: none;
  touch-action: pan-y;
}

.cover-card {
  position: absolute;
  left: 50%;
  top: calc(var(--card) + var(--pad));
  width: var(--card);
  margin-left: calc(var(--card) / -2);
  margin-top: calc(var(--card) * -1);
  background: transparent;
  border: none;
  transform: translateX(var(--translate-x, 0px)) rotateY(var(--rotate, 0deg)) translateZ(var(--z, 0px)) scale(var(--scale, 1));
  opacity: var(--opacity, 1);
  transition: transform 400ms cubic-bezier(0.22, 0.8, 0.2, 1), opacity 300ms ease;
  will-change: transform, opacity;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.cover-card.is-active .art-frame {
  box-shadow: 0 28px 70px rgba(0,0,0,0.65), 0 8px 24px rgba(0,0,0,0.4);
}

.art-frame {
  position: relative;
  overflow: hidden;
  border-radius: 0;
  box-shadow: 0 16px 50px rgba(0,0,0,0.5);
  transition: filter 300ms ease, box-shadow 300ms ease;
}

.cover-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: rgba(0,0,0,0.1);
  pointer-events: none;
}

.cover-reflection {
  display: block;
  width: 100%;
  height: var(--refl);
  background-size: 100% auto;
  background-position: center bottom;
  transform: scaleY(-1);
  opacity: 0.45;
  mask-image: linear-gradient(to top, rgba(0,0,0,0.52) 0%, rgba(0,0,0,0.18) 40%, transparent 75%);
  -webkit-mask-image: linear-gradient(to top, rgba(0,0,0,0.52) 0%, rgba(0,0,0,0.18) 40%, transparent 75%);
  pointer-events: none;
}

.card-vinyl {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 320ms ease, transform 320ms ease;
  pointer-events: none;
}

.coverflow-track.is-playing .cover-card.is-now-playing .card-vinyl {
  opacity: 1;
  transform: scale(1);
}

.card-vinyl-disc {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-radial-gradient(circle at center, rgba(255, 255, 255, 0.07) 0, rgba(255, 255, 255, 0.07) 1px, transparent 1.5px, transparent 6px),
    radial-gradient(circle at 35% 30%, #2c2c31, #08080a 72%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: vinyl-spin 8s linear infinite;
  animation-play-state: paused;
}

.coverflow-track.is-playing .cover-card.is-now-playing .card-vinyl-disc {
  animation-play-state: running;
}

.card-vinyl-label {
  position: relative;
  width: 38%;
  height: 38%;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.7), 0 6px 18px rgba(0, 0, 0, 0.5);
}

.card-vinyl-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-vinyl-hole {
  position: absolute;
  width: 6%;
  height: 6%;
  border-radius: 50%;
  background: #000;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .card-vinyl-disc { animation: none; }
}

/* ── Track info ──────────────────────────────────────── */

.selected-info {
  --title-size: clamp(1.4rem, 4.5vw, 2.5rem);
  --artist-size: clamp(0.95rem, 2.8vw, 1.45rem);
  --album-size: clamp(0.78rem, 1.8vw, 1rem);
  --info-pad: clamp(0.85rem, 3vh, 1.75rem);
  text-align: center;
  padding: var(--info-pad) 1.5rem 0;
  max-width: 640px;
  width: 100%;
  flex-shrink: 0;
  /* Fixed height so the coverflow never shifts when text is short or long.
     Derived from the actual text sizes so the worst case (2-line title +
     artist + album) always fits instead of getting clipped. */
  height: calc(
    var(--info-pad)
    + var(--title-size) * 1.2 * 2 + 0.3rem
    + var(--artist-size) * 1.4 + 0.2rem
    + var(--album-size) * 1.4 + 0.4rem
  );
  overflow: hidden;
}

.track-title {
  font-size: var(--title-size);
  font-weight: 700;
  margin: 0 0 0.3rem;
  line-height: 1.2;
  color: #fff;
  letter-spacing: -0.02em;
  /* Allow up to 2 lines, ellipsis on overflow */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.track-artist {
  font-size: var(--artist-size);
  line-height: 1.4;
  color: rgba(247, 248, 255, 0.68);
  margin: 0 0 0.2rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-album {
  font-size: var(--album-size);
  line-height: 1.4;
  color: rgba(247, 248, 255, 0.38);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.placeholder {
  color: rgba(247, 248, 255, 0.38);
  font-size: 1rem;
  margin: 0;
}

/* ── Global status toast ─────────────────────────────── */

.global-status {
  position: fixed;
  bottom: calc(7.5rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.4rem 1.1rem;
  background: rgba(4, 8, 16, 0.82);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s;
}

.global-status:not(:empty) { opacity: 1; }

/* ── Corner menu ─────────────────────────────────────── */

.menu-btn {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top, 1rem));
  right: max(1rem, env(safe-area-inset-right, 1rem));
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%;
  color: rgba(255,255,255,0.5);
  font-size: 1.25rem;
  line-height: 1;
  z-index: 200;
  transition: background 0.2s, color 0.2s;
}

.menu-btn:hover { background: rgba(255,255,255,0.14); color: #fff; }

.menu-panel {
  position: fixed;
  top: max(4rem, calc(env(safe-area-inset-top, 0px) + 3.5rem));
  right: max(1rem, env(safe-area-inset-right, 1rem));
  width: min(300px, calc(100vw - 2rem));
  background: rgba(10, 16, 26, 0.96);
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 16px;
  padding: 1.1rem;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.menu-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.38);
}

.menu-row {
  display: flex;
  gap: 0.45rem;
}

.menu-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.11);
  background: rgba(255,255,255,0.06);
  color: #f7f8ff;
  font: inherit;
  font-size: 0.82rem;
}

.menu-input:focus {
  outline: none;
  border-color: rgba(29, 185, 84, 0.5);
}

.menu-action {
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: #f7f8ff;
  font: inherit;
  font-size: 0.82rem;
  white-space: nowrap;
  transition: background 0.18s;
}

.menu-action:hover { background: rgba(255,255,255,0.18); }
.menu-action.danger { color: #ff6b6b; background: rgba(255,80,80,0.09); }
.menu-action.danger:hover { background: rgba(255,80,80,0.18); }

.menu-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.07);
  margin: 0.1rem 0;
}

.playlist-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: min(300px, 38vh);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.18) transparent;
}

.playlist-list .placeholder {
  font-size: 0.78rem;
  padding: 0.3rem 0.45rem;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.4rem 0.45rem;
  border-radius: 10px;
  background: none;
  color: rgba(255,255,255,0.75);
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.playlist-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.playlist-item.is-active { background: rgba(29,185,84,0.14); color: #1ed760; }

.playlist-thumb {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255,255,255,0.08);
  font-size: 0.85rem;
}

.playlist-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.playlist-thumb-liked {
  background: linear-gradient(135deg, #450af5, #8e8ee5);
  color: #fff;
}

.playlist-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.playlist-item-name {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-item-meta {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.4);
}

.playlist-item.is-active .playlist-item-meta { color: rgba(30,215,96,0.65); }

/* ── Miniplayer ──────────────────────────────────────── */

.miniplayer {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom, 1.25rem));
  transform: translateX(-50%);
  z-index: 300;
  width: min(460px, calc(100vw - 2.5rem));
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem 1rem 1rem;
  border-radius: 22px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02) 40%),
    rgba(14, 18, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    0 8px 22px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.miniplayer:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.6),
    0 10px 26px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

@keyframes vinyl-spin {
  to { transform: rotate(360deg); }
}

.miniplayer-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.miniplayer-time {
  width: 2.2rem;
  flex-shrink: 0;
  text-align: center;
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.45);
}

.miniplayer-seek {
  flex: 1;
  height: 4px;
  accent-color: #1db954;
  cursor: pointer;
}

.miniplayer-seek:disabled { cursor: default; opacity: 0.5; }

.miniplayer-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.miniplayer-transport { display: flex; align-items: center; justify-content: center; gap: 0.9rem; }

.miniplayer-lyrics-btn {
  justify-self: start;
  width: auto;
  padding: 0 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.miniplayer-lyrics-btn.is-active { background: rgba(29, 185, 84, 0.18); color: #1ed760; }

.miniplayer-volume {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.miniplayer-volume .miniplayer-btn svg { width: 16px; height: 16px; }

.miniplayer-volume-slider {
  width: 4.5rem;
  height: 4px;
  accent-color: #1db954;
  cursor: pointer;
}

.miniplayer-btn {
  width: 2.15rem;
  height: 2.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  border-radius: 50%;
  transition: background 0.18s, color 0.18s;
}

.miniplayer-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); color: #fff; }

.miniplayer-btn-main {
  width: 2.6rem;
  height: 2.6rem;
  background: #1db954;
  color: #000;
  box-shadow: 0 6px 18px rgba(29, 185, 84, 0.35);
}

.miniplayer-btn-main:hover:not(:disabled) { background: #1ed760; }

.miniplayer-btn:disabled { opacity: 0.32; cursor: default; }

@media (max-height: 520px) {
  .miniplayer { padding: 0.6rem 0.85rem 0.75rem; gap: 0.5rem; }
}

@media (max-width: 420px) {
  .miniplayer-volume-slider { display: none; }
}

/* ── Lyrics ──────────────────────────────────────────── */

.lyrics-view {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  background:
    linear-gradient(180deg, rgba(20, 26, 40, 0.4), rgba(3, 6, 11, 0.52) 55%),
    rgba(6, 10, 18, 0.35);
  backdrop-filter: blur(26px) saturate(160%);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  animation: lyrics-fade-in 0.25s ease;
}

@keyframes lyrics-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lyrics-panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: max(3.5rem, calc(env(safe-area-inset-top, 0px) + 3rem)) 1.75rem calc(2rem + env(safe-area-inset-bottom, 0px));
}

.lyrics-close {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top, 1rem));
  right: max(1rem, env(safe-area-inset-right, 1rem));
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  font-size: 1.3rem;
  line-height: 1;
  transition: background 0.18s, color 0.18s;
}

.lyrics-close:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }

.lyrics-header { text-align: center; margin-bottom: 1.25rem; }

.lyrics-track-title {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.lyrics-track-artist {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(247, 248, 255, 0.55);
}

.lyrics-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  text-align: center;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.lyrics-body::-webkit-scrollbar { display: none; }

.lyrics-text {
  margin: 0;
  font-family: inherit;
  font-size: 1.55rem;
  line-height: 1.9;
  color: rgba(247, 248, 255, 0.88);
  white-space: pre-wrap;
}

/* ── Version credit ──────────────────────────────────── */

.version-credit {
  position: fixed;
  bottom: 0.6rem;
  right: 0.9rem;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.22);
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 400;
  user-select: none;
}

.version-credit a {
  color: inherit;
  text-decoration: none;
  pointer-events: auto;
  transition: color 0.18s;
}

.version-credit a:hover { color: rgba(255, 255, 255, 0.6); }

/* ── Responsive ──────────────────────────────────────── */

@media (max-height: 520px) {
  :root {
    --card: min(260px, 84vw, 40vh);
    --pad: 16px;
  }
  .view-player { padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px)); }
  .selected-info {
    height: auto;
    min-height: 3.8rem;
    padding: 0.35rem 1.5rem 0;
  }
  .track-title   { font-size: 1.1rem; margin-bottom: 0.15rem; }
  .track-artist  { font-size: 0.85rem; }
  .track-album   { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cover-card { transition: none; }
  .landing-inner > * { animation: none; }
}
