*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* Registered so the accent can be transitioned. Unregistered custom properties
   swap instantly, which would make a source switch (or expanding into the cover
   art's colour) snap. `inherits: true` is required or descendants would keep
   reading the initial value instead of the animating one. */
@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #b79dff;
}

@property --accent-var {
  syntax: "<color>";
  inherits: true;
  initial-value: #d6c7ff;
}

@property --accent-1 {
  syntax: "<color>";
  inherits: true;
  initial-value: #a97bff;
}

@property --accent-2 {
  syntax: "<color>";
  inherits: true;
  initial-value: #7a3cf5;
}

@property --accent-container {
  syntax: "<color>";
  inherits: true;
  initial-value: #33265c;
}

@property --ring {
  syntax: "<color>";
  inherits: true;
  initial-value: rgba(167, 131, 255, 0.45);
}

:root {
  /* Modern dark surfaces — borderless, depth from tone */
  --bg: #0e0e11;
  --s1: #16161a;
  --s2: #1e1e24;
  --s3: #26262d;
  --s4: #303038;

  --on: #edeaf2;
  --on-var: #b6b3c1;
  --dim: #86838f;

  --accent: #b79dff;
  --accent-var: #d6c7ff;
  --accent-1: #a97bff;
  --accent-2: #7a3cf5;
  --accent-container: #33265c;
  --ring: rgba(167, 131, 255, 0.45);

  --danger: #ff8f86;

  --content: 960px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.3, 0.5, 1);
  --player-h: 72px;
  color-scheme: dark;

  /* Slow and soft: a source change should read as one coordinated shift, not a
     flicker of five separate swaps. */
  transition:
    --accent 0.45s var(--ease),
    --accent-var 0.45s var(--ease),
    --accent-1 0.45s var(--ease),
    --accent-2 0.45s var(--ease),
    --accent-container 0.45s var(--ease),
    --ring 0.45s var(--ease);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 50% -25%, rgba(124, 77, 255, 0.1), transparent 72%),
    var(--bg);
  background-attachment: fixed;
  color: var(--on);
  font: 14px/1.5 Roboto, "Roboto Flex", "Google Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: 0;
  background: none;
}

img {
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  fill: currentColor;
}

::selection {
  background: var(--accent-container);
  color: var(--accent-var);
}

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--s4) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-thumb {
  background: var(--s4);
  border-radius: 999px;
}

/* ---------- app bar (borderless, glass) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(14, 14, 17, 0.72);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
}

.topbar-inner {
  max-width: var(--content);
  margin: 0 auto;
  min-height: 64px;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

/* ---------- segmented control (borderless) ---------- */
.modes {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--s2);
}

.mode {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--on-var);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 16px;
  white-space: nowrap;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.mode-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 5px;
}

.mode:hover {
  color: var(--on);
  background: rgba(255, 255, 255, 0.05);
}

.mode.is-active {
  background: var(--accent-container);
  color: var(--accent-var);
}

/* ---------- search (filled pill) ---------- */
.search {
  position: relative;
  flex: 1 1 220px;
  max-width: 360px;
  margin-left: auto;
}

.search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--on-var);
  pointer-events: none;
  transition: color 0.2s var(--ease);
}

.search input {
  width: 100%;
  height: 44px;
  padding: 0 42px 0 44px;
  border: 0;
  border-radius: 999px;
  background: var(--s2);
  color: var(--on);
  font-size: 14px;
  outline: none;
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.search input::placeholder {
  color: var(--dim);
}

.search input:hover {
  background: var(--s3);
}

.search input:focus {
  background: var(--s3);
  box-shadow: 0 0 0 3px rgba(167, 131, 255, 0.25);
}

.search:focus-within .search-icon {
  color: var(--accent);
}

.search-clear {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: var(--on-var);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.search-clear svg {
  width: 16px;
  height: 16px;
}

.search-clear:hover {
  color: var(--on);
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- layout ---------- */
.app {
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 16px calc(var(--player-h) + 30px);
}

/* ---------- empty state (centered, compact) ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 64px - 92px);
  padding: 24px 0;
  text-align: center;
  animation: rise-in 0.4s var(--ease);
}

.empty-title {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.6px;
  line-height: 1.2;
  color: var(--on);
}

.empty-state p {
  max-width: 420px;
  margin: 0 auto 22px;
  color: var(--on-var);
  font-size: 14.5px;
  line-height: 1.55;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--s2);
  color: var(--on-var);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.12s var(--ease);
  animation: pop-in 0.3s var(--ease) backwards;
  animation-delay: calc(min(var(--i, 0), 6) * 26ms);
}

.chip:hover {
  background: var(--s3);
  color: var(--on);
}

.chip:active {
  transform: scale(0.97);
}

/* ---------- results ---------- */
.results {
  padding-top: 6px;
}

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 8px 10px;
  animation: fade-in 0.28s var(--ease);
}

.results-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.muted {
  color: var(--dim);
  font-size: 12px;
}

.track-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.track {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px 38px 38px;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  min-height: 60px;
  border-radius: 18px;
  cursor: pointer;
  transition: background 0.2s var(--ease);
  /* Results cascade in, capped so a long list never feels slow to settle. */
  animation: rise-in 0.3s var(--ease) backwards;
  animation-delay: calc(min(var(--i, 0), 7) * 18ms);
}

.track:hover {
  background: rgba(255, 255, 255, 0.045);
}

.track:active {
  background: rgba(255, 255, 255, 0.07);
}

.track.is-current {
  background: var(--accent-container);
}

.track.is-current .track-name {
  color: var(--accent-var);
  font-weight: 600;
}

.track.is-current .track-artists,
.track.is-current .track-duration {
  color: rgba(214, 199, 255, 0.72);
}

.track-art {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--s3);
}

.track-main {
  min-width: 0;
}

.track-name {
  display: block;
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-artists {
  display: block;
  margin-top: 1px;
  color: var(--on-var);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--s4);
  color: var(--on-var);
  font-size: 9px;
  font-weight: 700;
  vertical-align: middle;
}

.track.is-current .badge {
  background: rgba(255, 255, 255, 0.14);
  color: var(--accent-var);
}

.track-duration {
  color: var(--on-var);
  font-size: 12.5px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.track-dl {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  color: var(--on-var);
  opacity: 0;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), opacity 0.2s var(--ease);
}

.track-dl svg {
  width: 18px;
  height: 18px;
}

.track:hover .track-dl,
.track:focus-within .track-dl {
  opacity: 1;
}

@media (hover: none) {
  .track-dl {
    opacity: 1;
  }
}

.track-dl:hover {
  color: var(--on);
  background: rgba(255, 255, 255, 0.1);
}

/* Add-to-queue stays visible (unlike download) because it is the primary way to
   build a queue across sources. */
.track-add {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  color: var(--dim);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.12s var(--ease);
}

.track-add svg {
  width: 18px;
  height: 18px;
}

.track-add:hover {
  color: var(--on);
  background: rgba(255, 255, 255, 0.1);
}

.track-add:active {
  transform: scale(0.94);
}

.track-add.is-queued {
  color: var(--accent-1);
}

/* ---------- status ---------- */
.status {
  padding: 56px 0;
  color: var(--on-var);
  font-size: 14px;
  text-align: center;
  animation: fade-in 0.22s var(--ease);
}

.status p {
  margin: 12px 0 0;
}

.status.is-error {
  color: var(--danger);
}

.spinner {
  width: 24px;
  height: 24px;
  margin: 0 auto;
  border: 3px solid var(--s4);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.btn {
  margin-top: 16px;
  height: 42px;
  padding: 0 24px;
  border-radius: 999px;
  background: var(--s3);
  color: var(--on);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.2s var(--ease), transform 0.12s var(--ease);
}

.btn:hover {
  background: var(--s4);
}

.btn:active {
  transform: scale(0.97);
}

/* ---------- mini player (floating, aligned to content) ---------- */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  isolation: isolate;
  width: 100%;
  height: var(--player-h);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas: "track center right";
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: rgba(28, 28, 31, 0.96);
  backdrop-filter: blur(30px) saturate(150%);
  -webkit-backdrop-filter: blur(30px) saturate(150%);
  transition: opacity 0.14s var(--ease), background 0.3s var(--ease);
}

/* Desktop bar: one flat row, like YT Music. The progress line rides the top
   edge, and every control and the time readout sit in a single grid. */
.player:not(.is-expanded) {
  grid-template-columns: minmax(0, 1fr) auto repeat(6, auto);
  grid-template-areas: none;
  gap: 0 14px;
}

.player:not(.is-expanded) .player-track {
  grid-column: 1;
  grid-row: 1;
}

.player:not(.is-expanded) .player-center {
  grid-column: 2;
  grid-row: 1;
}

.player:not(.is-expanded) .player-progress,
.player:not(.is-expanded) .player-right {
  display: contents;
}

.player:not(.is-expanded) .player-backdrop {
  display: none;
}

.player:not(.is-expanded) #time-cur {
  grid-column: 3;
  grid-row: 1;
}

.player:not(.is-expanded) #time-dur {
  grid-column: 4;
  grid-row: 1;
}

.player:not(.is-expanded) .quality {
  grid-column: 5;
  grid-row: 1;
}

.player:not(.is-expanded) #btn-queue {
  grid-column: 6;
  grid-row: 1;
}

.player:not(.is-expanded) .volume {
  grid-column: 7;
  grid-row: 1;
}

.player:not(.is-expanded) #btn-download {
  grid-column: 8;
  grid-row: 1;
}

.player:not(.is-expanded) #time-cur,
.player:not(.is-expanded) #time-dur {
  display: block;
  color: var(--on-var);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.player:not(.is-expanded) #time-cur::after {
  content: "/";
  margin: 0 4px;
  color: var(--dim);
}

.player.is-switching {
  opacity: 0;
}

.player-backdrop {
  position: absolute;
  inset: -30%;
  z-index: 0;
  background-image: var(--np-art, none);
  background-size: cover;
  background-position: center;
  filter: blur(70px) saturate(1.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s var(--ease);
}

.player.is-expanded .player-backdrop {
  opacity: 0.55;
}

.player.is-expanded .player-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 10, 13, 0.55), rgba(10, 10, 13, 0.85));
}

.player-top {
  display: none;
}

.np-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--on-var);
}

.player-top-spacer {
  width: 38px;
  height: 38px;
}

/* ---------- now playing (expanded) ---------- */
.player.is-expanded {
  z-index: 50;
  top: 0;
  bottom: 0;
  width: 100vw;
  height: auto;
  padding: max(14px, env(safe-area-inset-top)) 24px max(18px, env(safe-area-inset-bottom));
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto;
  grid-template-areas:
    "top"
    "art"
    "meta"
    "progress"
    "controls"
    "right";
  gap: 12px;
  align-items: center;
  justify-items: center;
  background: #0b0b0e;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.player.is-expanded .player-top {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.player.is-expanded .player-track,
.player.is-expanded .player-center {
  display: contents;
}

.player.is-expanded .player-art {
  grid-area: art;
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  border-radius: 26px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55);
}

.player.is-expanded .player-meta {
  grid-area: meta;
  max-width: 82%;
  text-align: center;
}

.player.is-expanded .player-title {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.player.is-expanded .player-artist {
  margin-top: 3px;
  font-size: 14.5px;
}

.player.is-expanded .player-progress {
  grid-area: progress;
  max-width: 560px;
}

.player.is-expanded .player-progress {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  height: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.player.is-expanded .bar {
  position: relative;
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.player.is-expanded .bar:hover {
  height: 4px;
  top: auto;
  bottom: auto;
}

.player.is-expanded .player-progress > span {
  display: block;
  font-size: 12px;
}

.player.is-expanded .quality {
  display: inline-block;
}

.player.is-expanded .player-controls {
  grid-area: controls;
  gap: 16px;
}

.player.is-expanded .player-center,
.player.is-expanded .player-controls,
.player.is-expanded .player-progress,
.player.is-expanded .player-art,
.player.is-expanded .player-meta,
.player.is-expanded .player-right,
.player.is-expanded .player-top {
  position: relative;
  z-index: 1;
}

.player.is-expanded .icon-btn svg {
  width: 24px;
  height: 24px;
}

.player.is-expanded .play-btn {
  width: 68px;
  height: 68px;
  margin: 0;
}

.player.is-expanded .play-btn svg {
  width: 32px;
  height: 32px;
}

.player.is-expanded .player-right {
  grid-area: right;
  justify-content: center;
  gap: 6px;
}

/* The pill crossfades into the sheet (see .is-switching); its contents then
   settle in a shallow stagger so the whole thing reads as one arrival rather
   than four elements blinking into place. */
.player.is-expanded .player-top {
  animation: rise-in 0.34s var(--ease) backwards;
}

.player.is-expanded .player-art {
  animation: art-in 0.42s var(--ease) backwards;
}

.player.is-expanded .player-meta {
  animation: rise-in 0.38s var(--ease) 60ms backwards;
}

.player.is-expanded .player-progress {
  animation: rise-in 0.38s var(--ease) 100ms backwards;
}

.player.is-expanded .player-controls {
  animation: rise-in 0.38s var(--ease) 140ms backwards;
}

.player.is-expanded .player-right {
  animation: rise-in 0.38s var(--ease) 180ms backwards;
}

body.np-open {
  overflow: hidden;
}

.player-track {
  grid-area: track;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.player-art {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--s4);
  flex: 0 0 auto;
}

.player-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Re-applied by app.js on every track change (a re-set `src` alone would not
   restart an animation), so the cover fades in instead of snapping. */
.player-art img.entering {
  animation: art-in 0.36s var(--ease);
}

.player-meta {
  min-width: 0;
}

.player-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-title:hover {
  color: var(--accent);
}

.player-artist {
  display: block;
  margin-top: 1px;
  color: var(--on-var);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  color: var(--on-var);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.12s var(--ease);
}

.icon-btn:hover {
  color: var(--on);
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.play-btn {
  width: 44px;
  height: 44px;
  margin: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--on);
  transition: transform 0.12s var(--ease), background 0.2s var(--ease);
}

.play-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.player.is-expanded .play-btn {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff;
  box-shadow: 0 10px 24px -10px var(--accent-2);
}

.player.is-expanded .play-btn:hover {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  filter: brightness(1.08);
}

.play-btn:active {
  transform: scale(0.94);
}

.play-btn svg {
  width: 22px;
  height: 22px;
  /* app.js swaps this glyph via innerHTML, so the new element replays it. */
  animation: icon-pop 0.26s var(--ease-spring);
}

.player-progress {
  display: contents;
}

/* Direct children only: the scrub tooltip is a span nested in the bar. */
.player-progress > span {
  display: none;
  min-width: 32px;
  color: var(--on-var);
  font-size: 10.5px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  outline: none;
  /* A horizontal drag must scrub, not scroll the page on touch. */
  touch-action: none;
  transition: height 0.2s var(--ease);
}

.bar:hover,
.bar.is-scrubbing {
  height: 5px;
  top: -2px;
  bottom: auto;
}

/* Larger invisible hit area so the thin scrubber is easy to grab on touch. */
.bar::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -12px;
  bottom: -12px;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-var));
  /* timeupdate only lands ~4x a second; gliding between them stops the bar
     from stepping. Short enough to still feel immediate after a seek. */
  transition: width 0.2s linear;
}

.bar-fill::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) scale(0);
  transition: transform 0.18s var(--ease);
}

.bar:hover .bar-fill::after,
.bar:focus-visible .bar-fill::after,
.bar.is-scrubbing .bar-fill::after {
  transform: translateY(-50%) scale(1);
}

/* While scrubbing the fill tracks the pointer exactly, so the glide that hides
   the timeupdate stepping would only make it lag behind the finger. */
.bar.is-scrubbing .bar-fill {
  transition: none;
}

/* Time readout that follows the pointer while hovering or dragging the bar. */
.bar-tip {
  position: absolute;
  bottom: calc(100% + 9px);
  left: 0;
  padding: 3px 8px;
  border-radius: 9px;
  background: var(--s4);
  color: var(--on);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translate(-50%, 4px);
  pointer-events: none;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}

.bar-tip.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.player-right {
  grid-area: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}

.quality select {
  appearance: none;
  -webkit-appearance: none;
  height: 32px;
  padding: 0 21px 0 7px;
  border: 0;
  border-radius: 9px;
  /* A <select> is intrinsically as wide as its WIDEST option, which leaves a
     short label like "High" floating in a pill built for "Data saver". This sizes
     it to the option actually showing. Browsers without support just keep the
     roomier box. */
  field-sizing: content;
  background: transparent
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b6b3c1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4.48 8.97l4.68 4.7c1.34 1.33 2 2 2.83 2s1.5-.67 2.83-2l4.7-4.7'/%3E%3C/svg%3E")
    no-repeat right 3px center;
  background-size: 14px;
  color: var(--on-var);
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}

.quality select:hover,
.quality select:focus-visible {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--on);
}

/* Chrome counts a <select> and a slider as :focus-visible even on a mouse click,
   so the global ring lands on them every time one is clicked. They get the
   borderless cue above instead (and the volume icon lighting up below). */
.quality select:focus-visible,
.volume input:focus-visible {
  outline: none;
}

.volume:focus-within svg {
  color: var(--on);
}

.quality select option {
  background: var(--s3);
  color: var(--on);
}

.volume {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 4px;
  color: var(--on-var);
}

.volume svg {
  width: 19px;
  height: 19px;
}

.volume input[type="range"] {
  width: 72px;
  accent-color: var(--accent);
}

.player[data-empty="true"] .player-center,
.player[data-empty="true"] .player-right,
.player[data-empty="true"] .player-right > * {
  opacity: 0.4;
  pointer-events: none;
}

.player[data-empty="true"] .bar,
.player[data-empty="true"] .player-progress > span {
  opacity: 0;
}

.player[data-empty="true"] .player-art img {
  opacity: 0;
}

.player[data-empty="true"] .play-btn {
  background: var(--s4);
  color: var(--dim);
  box-shadow: none;
}

/* ---------- queue (borderless side sheet) ---------- */
.queue-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--player-h) + 26px);
  background: var(--s1);
  border-radius: 24px 0 0 24px;
  box-shadow: -20px 0 48px rgba(0, 0, 0, 0.45);
  transform: translateX(101%);
  transition: transform 0.32s var(--ease);
}

.queue-panel.open {
  transform: none;
}

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 12px;
}

.queue-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--on);
}

.queue-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.queue-clear {
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--on-var);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.queue-clear:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--on);
}

.queue-list {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 2px 12px 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.queue-item {
  display: grid;
  grid-template-columns: 20px 40px minmax(0, 1fr) 34px 30px;
  align-items: center;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s var(--ease);
}

/* Keyed off .open so the queue cascades as the sheet slides in, rather than
   animating off-screen every time the list is rebuilt. */
.queue-panel.open .queue-item {
  animation: rise-in 0.28s var(--ease) backwards;
  animation-delay: calc(min(var(--i, 0), 8) * 18ms);
}

.queue-item:hover {
  background: rgba(255, 255, 255, 0.045);
}

.queue-item.is-current {
  background: var(--accent-container);
}

.queue-item.is-current .queue-main span {
  color: var(--accent-var);
  font-weight: 600;
}

.queue-item.is-current .queue-main small,
.queue-item.is-current .queue-dur {
  color: rgba(214, 199, 255, 0.72);
}

.queue-item img {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  object-fit: cover;
  background: var(--s3);
}

/* Cover with the source's brand mark pinned to its corner, so a queue that
   mixes all three sources stays readable at a glance. */
.queue-art {
  position: relative;
  width: 40px;
  height: 40px;
}

.queue-art .queue-src {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: none;
}

.queue-remove {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: var(--dim);
  opacity: 0;
  transition: opacity 0.2s var(--ease), background 0.2s var(--ease), color 0.2s var(--ease);
}

.queue-remove svg {
  width: 15px;
  height: 15px;
}

.queue-item:hover .queue-remove,
.queue-item:focus-within .queue-remove {
  opacity: 1;
}

@media (hover: none) {
  .queue-remove {
    opacity: 1;
  }
}

.queue-remove:hover {
  color: var(--danger);
  background: rgba(255, 255, 255, 0.1);
}

.queue-index {
  color: var(--dim);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.queue-index svg {
  display: block;
  width: 15px;
  height: 15px;
  margin: 0 auto;
}

.queue-item.is-current .queue-index {
  color: var(--accent-var);
}

.queue-main {
  min-width: 0;
}

.queue-main span {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-main small {
  display: block;
  margin-top: 1px;
  color: var(--on-var);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-dur {
  color: var(--on-var);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.queue-empty {
  padding: 40px 0;
  color: var(--dim);
  font-size: 13px;
  text-align: center;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s var(--ease);
}

.scrim.open {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- download quality menu ---------- */
.dl-menu {
  position: fixed;
  z-index: 90;
  width: 196px;
  padding: 6px;
  background: rgba(38, 38, 45, 0.9);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
  border-radius: 20px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
  /* Grows from the edge nearest its anchor — the menu is right-aligned to it. */
  transform-origin: 100% 0;
  animation: pop-in 0.16s var(--ease);
}

.dl-menu-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dl-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 15px;
  border-radius: 999px;
  color: var(--on);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background 0.2s var(--ease);
}

.dl-option:hover,
.dl-option:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.dl-option-note {
  color: var(--on-var);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------- snackbar ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--player-h) + 26px);
  transform: translate(-50%, 14px) scale(0.96);
  z-index: 80;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--s4);
  color: var(--on);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.26s var(--ease), transform 0.26s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* ---------- motion primitives ---------- */
/* Short, small movements: the polish should register as responsiveness, not as
   decoration. Entrances use `backwards` so staggered items stay hidden until
   their delay elapses. */

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes art-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Plays whenever the play/pause glyph is swapped, since app.js replaces the
   <svg> rather than toggling a class. */
@keyframes icon-pop {
  0% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  60% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---------- responsive ---------- */
@media (max-width: 780px) {
  .volume {
    display: none;
  }

  .empty-state {
    min-height: calc(100vh - 64px - 150px);
  }

  .app {
    padding-bottom: calc(var(--player-h) + 116px);
  }
}

@media (max-width: 640px) {
  /* Phones get the YT Music mini bar: art, title, play and next only. */
  .player:not(.is-expanded) {
    left: 50%;
    right: auto;
    bottom: 8px;
    transform: translateX(-50%);
    width: min(calc(100vw - 16px), var(--content));
    height: 64px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto;
    padding: 0 10px;
    gap: 8px;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(34, 34, 40, 0.94);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }

  .player:not(.is-expanded) .player-right,
  .player:not(.is-expanded) #time-cur,
  .player:not(.is-expanded) #time-dur,
  .player:not(.is-expanded) #btn-prev {
    display: none;
  }

  .player:not(.is-expanded) .player-track {
    grid-column: 1;
    grid-row: 1;
  }

  .player:not(.is-expanded) .player-center {
    grid-column: 2;
    grid-row: 1;
  }

  .search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
    margin-left: 0;
  }

  .empty-title {
    font-size: 23px;
  }

  .empty-state {
    min-height: 0;
    justify-content: flex-start;
    padding: 40px 0 24px;
  }
}

@media (max-width: 520px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar-inner {
    padding: 12px;
  }

  .quality {
    display: none;
  }

  .track {
    grid-template-columns: 44px minmax(0, 1fr) 38px 38px;
    gap: 11px;
    padding: 7px 8px;
  }

  .track-duration {
    display: none;
  }
}

@media (max-width: 440px) {
  .mode-label {
    display: none;
  }

  .mode {
    gap: 0;
    padding: 8px 12px;
  }
}

/* ---------- reduced motion ---------- */
/* Honour the OS setting: entrances collapse to nothing and the stagger is
   dropped, while the spinner keeps turning because it carries meaning. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }

  .spinner {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }
}
