:root {
  --cor1: #3f276d;
  --cor1l: #7038ca;
  --cor1d: #2d1b4b;
  --cor2: #ee771b;
  --cor2l: #f29845;
  --cor2d: #e06016;
  --branco: #fff;
  --texto-2: rgba(255, 255, 255, 0.66);
  --texto-3: rgba(255, 255, 255, 0.44);
  /* Cor dominante da capa (r, g, b), atualizada via JS */
  --tint: 112, 56, 202;
  --bar-h: 108px;
  color-scheme: dark;
  font-family: "Poppins", Arial, Helvetica, sans-serif;
  color: var(--branco);
  background: #07050b;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: #07050b;
}

button {
  font: inherit;
  color: inherit;
}

/* ---------- Fundo ambiente (cor da capa) ---------- */

.ambient {
  position: fixed;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.ambient-glow {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(42% 46% at 50% 40%, rgba(var(--tint), 0.62), transparent 72%),
    radial-gradient(38% 40% at 18% 82%, rgba(238, 119, 27, 0.16), transparent 70%),
    radial-gradient(40% 42% at 86% 18%, rgba(112, 56, 202, 0.2), transparent 70%),
    linear-gradient(180deg, rgba(var(--tint), 0.38) 0%, #07050b 78%);
  filter: blur(30px) saturate(115%);
  transition: background 900ms ease;
  animation: drift 26s ease-in-out infinite alternate;
}

.ambient-grain {
  position: absolute;
  inset: 0;
  opacity: 0.09;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes drift {
  from {
    transform: translate3d(-2%, -1%, 0) scale(1);
  }

  to {
    transform: translate3d(2%, 1.5%, 0) scale(1.06);
  }
}

/* ---------- Topo ---------- */

.player-top {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: max(18px, env(safe-area-inset-top)) clamp(16px, 4vw, 40px) 10px;
}

.back-button {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: var(--branco);
  background: rgba(10, 6, 18, 0.45);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.back-button svg {
  width: 22px;
  height: 22px;
  transition: transform 180ms ease;
}

.back-button:hover,
.back-button:focus-visible {
  border-color: rgba(242, 152, 69, 0.7);
  background: rgba(10, 6, 18, 0.7);
  outline: none;
}

.back-button:hover svg {
  transform: translateX(-3px);
}

.top-context {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  text-align: center;
}

.top-eyebrow {
  color: var(--texto-2);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.top-source {
  max-width: 46vw;
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.queue-toggle {
  justify-self: end;
}

/* ---------- Palco / capa ---------- */

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 3.2vh, 30px);
  --size: max(160px, min(440px, 84vw, calc(100dvh - var(--bar-h) - 250px)));
  min-height: 0;
  padding: 8px 24px calc(var(--bar-h) + 20px);
}

.cover {
  position: relative;
  flex: none;
  width: var(--size);
  aspect-ratio: 1;
  margin: 0;
  border-radius: clamp(10px, 1.6vw, 16px);
  overflow: hidden;
  background: #1a1028;
  box-shadow:
    0 40px 90px -20px rgba(0, 0, 0, 0.75),
    0 24px 80px -30px rgba(var(--tint), 0.9);
  transform: scale(0.93);
  transition: transform 520ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 900ms ease;
  animation: rise 700ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.is-playing .cover {
  transform: scale(1);
}

.cover-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(70% 70% at 25% 20%, rgba(242, 152, 69, 0.55), transparent 60%),
    radial-gradient(80% 80% at 85% 90%, rgba(112, 56, 202, 0.85), transparent 65%),
    linear-gradient(145deg, var(--cor1), var(--cor1d));
}

.cover-fallback img {
  width: 34%;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.35));
}

.track-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: var(--size);
  min-width: 0;
  animation: rise 700ms 90ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.track-text {
  min-width: 0;
}

.track-title {
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
  text-wrap: balance;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.track-subtitle {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--texto-2);
  font-size: 0.95rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.equalizer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
  opacity: 0;
  transition: opacity 240ms ease;
}

.equalizer i {
  width: 3px;
  height: 100%;
  border-radius: 2px;
  background: var(--cor2l);
  transform-origin: bottom;
  animation: eq 900ms ease-in-out infinite alternate;
  animation-play-state: paused;
}

.equalizer i:nth-child(2) { animation-delay: -300ms; animation-duration: 700ms; }
.equalizer i:nth-child(3) { animation-delay: -600ms; animation-duration: 1100ms; }
.equalizer i:nth-child(4) { animation-delay: -150ms; animation-duration: 800ms; }

.is-playing .equalizer {
  opacity: 1;
}

.is-playing .equalizer i {
  animation-play-state: running;
}

@keyframes eq {
  from { transform: scaleY(0.2); }
  to { transform: scaleY(1); }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
}

.empty-state {
  max-width: 520px;
  text-align: center;
}

.empty-state h1 {
  margin: 0 0 10px;
  font-size: 1.5rem;
}

.empty-state p {
  margin: 0;
  color: var(--texto-2);
  line-height: 1.7;
}

.empty-state code {
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--cor2l);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.85em;
  word-break: break-all;
}

.is-empty .cover,
.is-empty .track-info {
  display: none;
}

.is-empty .player-bar {
  opacity: 0.4;
  pointer-events: none;
}

/* ---------- Botões ---------- */

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.icon-button:hover {
  color: var(--branco);
  background: rgba(255, 255, 255, 0.08);
}

.icon-button:active {
  transform: scale(0.92);
}

.icon-button:focus-visible,
.play-button:focus-visible,
.speed-button:focus-visible {
  outline: 2px solid var(--cor2l);
  outline-offset: 2px;
}

.icon-button:disabled {
  opacity: 0.3;
  cursor: default;
  background: transparent;
  transform: none;
}

.icon-button.toggle[aria-pressed="true"] {
  color: var(--cor2l);
}

.icon-button.toggle[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
}

.repeat-one {
  position: absolute;
  top: 9px;
  right: 7px;
  display: none;
  min-width: 13px;
  height: 13px;
  border-radius: 50%;
  color: #1a0f2b;
  background: var(--cor2l);
  font-size: 0.55rem;
  font-weight: 800;
  line-height: 13px;
  text-align: center;
}

[data-repeat-mode="one"] .repeat-one {
  display: block;
}

.skip span {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 0.5rem;
  font-weight: 800;
  transform: translate(-50%, -38%);
}

.skip svg {
  width: 26px;
  height: 26px;
}

.play-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #1a0f2b;
  background: linear-gradient(145deg, var(--cor2l), var(--cor2));
  box-shadow: 0 12px 30px rgba(238, 119, 27, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.play-button:hover {
  transform: scale(1.06);
  box-shadow: 0 16px 36px rgba(238, 119, 27, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.play-button:active {
  transform: scale(0.95);
}

.play-button svg {
  grid-area: 1 / 1;
  width: 26px;
  height: 26px;
}

.play-button .icon-pause,
.is-playing .play-button .icon-play {
  display: none;
}

.is-playing .play-button .icon-pause {
  display: block;
}

.spinner {
  position: absolute;
  inset: -5px;
  border: 2px solid transparent;
  border-top-color: var(--cor2l);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: spin 800ms linear infinite;
  transition: opacity 200ms ease;
}

.is-loading .spinner {
  opacity: 1;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.speed-button {
  min-width: 52px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: var(--texto-2);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.speed-button:hover {
  color: var(--branco);
  border-color: rgba(255, 255, 255, 0.4);
}

.speed-button.is-changed {
  color: #1a0f2b;
  border-color: var(--cor2l);
  background: var(--cor2l);
}

/* ---------- Barra inferior ---------- */

.player-bar {
  position: fixed;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 680px) minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  min-height: var(--bar-h);
  padding: 12px clamp(16px, 3vw, 32px) max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 5, 14, 0.72);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  transition: opacity 200ms ease;
}

.bar-now {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.bar-cover {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.bar-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bar-text strong,
.bar-text span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bar-text strong {
  font-size: 0.9rem;
}

.bar-text span {
  color: var(--texto-2);
  font-size: 0.78rem;
}

.bar-center {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.timeline {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time {
  flex: none;
  min-width: 40px;
  color: var(--texto-2);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.bar-extra {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.volume {
  display: flex;
  align-items: center;
  gap: 4px;
  width: min(160px, 100%);
}

.icon-vol .mute-x {
  display: none;
}

.is-muted .icon-vol .mute-x {
  display: block;
}

.is-muted .icon-vol .wave-1,
.is-muted .icon-vol .wave-2,
.is-quiet .icon-vol .wave-2 {
  display: none;
}

/* ---------- Sliders ---------- */

.range {
  --pct: 0%;
  --buf: 0%;
  flex: 1;
  min-width: 0;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    var(--fill, var(--branco)) var(--pct),
    rgba(255, 255, 255, 0.32) var(--pct) var(--buf),
    rgba(255, 255, 255, 0.16) var(--buf));
}

.range::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    var(--fill, var(--branco)) var(--pct),
    rgba(255, 255, 255, 0.32) var(--pct) var(--buf),
    rgba(255, 255, 255, 0.16) var(--buf));
}

.range::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--branco);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 150ms ease, transform 150ms ease;
  -webkit-appearance: none;
  appearance: none;
}

.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--branco);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 150ms ease;
}

.range:hover,
.range:focus-visible,
.range.is-dragging {
  --fill: var(--cor2l);
}

.range:hover::-webkit-slider-thumb,
.range:focus-visible::-webkit-slider-thumb,
.range.is-dragging::-webkit-slider-thumb {
  opacity: 1;
  transform: scale(1);
}

.range:hover::-moz-range-thumb,
.range:focus-visible::-moz-range-thumb,
.range.is-dragging::-moz-range-thumb {
  opacity: 1;
}

.range:focus-visible {
  outline: none;
}

/* ---------- Fila ---------- */

.queue {
  position: fixed;
  z-index: 5;
  top: 0;
  right: 0;
  bottom: var(--bar-h);
  display: flex;
  flex-direction: column;
  width: min(380px, 100vw);
  padding: max(18px, env(safe-area-inset-top)) 18px 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(12, 8, 20, 0.86);
  box-shadow: -30px 0 60px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  animation: slide-in 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
}

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.queue-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.queue-list {
  flex: 1;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease;
}

.queue-item:hover,
.queue-item:focus-visible {
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

.queue-item img,
.queue-thumb {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  background: linear-gradient(145deg, var(--cor1l), var(--cor1d));
}

.queue-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.queue-item-text strong,
.queue-item-text span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.queue-item-text strong {
  font-size: 0.88rem;
  font-weight: 600;
}

.queue-item-text span {
  color: var(--texto-2);
  font-size: 0.76rem;
}

.queue-item[aria-current="true"] strong {
  color: var(--cor2l);
}

/* ---------- Aviso ---------- */

.toast {
  position: fixed;
  z-index: 6;
  bottom: calc(var(--bar-h) + 16px);
  left: 50%;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  color: #1a0f2b;
  background: var(--branco);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsivo ---------- */

@media (max-width: 900px) {
  :root {
    --bar-h: 172px;
  }

  .player-bar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "center"
      "extra";
    gap: 6px;
    padding-top: 14px;
  }

  .bar-now {
    display: none;
  }

  .bar-center {
    grid-area: center;
    flex-direction: column-reverse;
    gap: 8px;
  }

  .bar-extra {
    grid-area: extra;
    justify-content: space-between;
  }

  .volume {
    width: min(180px, 50%);
  }
}

@media (max-width: 420px) {
  .controls {
    gap: 0;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .play-button {
    width: 54px;
    height: 54px;
    margin: 0 4px;
  }

  .back-button span {
    display: none;
  }

  .back-button {
    width: 44px;
    padding: 0;
    justify-content: center;
  }
}

@media (max-height: 560px) and (min-width: 901px) {
  .stage {
    --size: max(140px, min(300px, calc(100dvh - var(--bar-h) - 200px)));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
