/*
 * Playlist pill + player card, carried over from design.tarrafa.club.
 *
 * Both take the same slot in the top-centre, clear of the shared chrome's
 * corner words: the pill rests there until it is clicked, then the card
 * takes its place. Horizontal centring uses the `translate` property so
 * hover and open animations can still own `transform`. Colours come from
 * --playlist-page-color / --playlist-ink-color, which the site sets, so
 * this file itself is identical across the landings.
 */

.listen,
.player {
  --playlist-page: var(--playlist-page-color, #fff);
  --playlist-ink: var(--playlist-ink-color, #111);
  /* The widths below are the whole card, padding and border included —
     otherwise a phone gets a gutter of one pixel. */
  box-sizing: border-box;
  position: fixed;
  left: 50%;
  top: max(1.25rem, calc(env(safe-area-inset-top, 0px) + 1rem));
  translate: -50% 0;
  z-index: 20;
  font-family: "Montserrat", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.listen {
  appearance: none;
  display: inline-flex;
  /* Hidden until playlist.js sees the site's opening finish. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  align-items: center;
  gap: 0.55rem;
  background: color-mix(in srgb, var(--playlist-page) 72%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid color-mix(in srgb, var(--playlist-ink) 30%, var(--playlist-page));
  border-radius: 999px;
  padding: 0.6rem 1.05rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--playlist-ink);
  /* Hover only — arriving and leaving are the two animations below. */
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

/* Arrives once the mark has settled, so it never competes with it. */
.listen.is-ready {
  visibility: visible;
  pointer-events: auto;
  animation: playlist-rise 1.1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes playlist-rise {
  from { opacity: 0; transform: translateY(-0.6rem); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes playlist-fall {
  from { opacity: 1; transform: translateY(0); visibility: visible; }
  to   { opacity: 0; transform: translateY(-0.4rem); visibility: hidden; }
}

.listen:hover {
  background: var(--playlist-ink);
  border-color: var(--playlist-ink);
  color: var(--playlist-page);
  transform: translateY(-1px);
}

.listen:focus-visible {
  outline: 2px solid var(--playlist-ink);
  outline-offset: 3px;
}

/* Out of the way while the card is up. The exit is its own animation rather
   than a transition: the rise is still filling opacity when the click lands,
   and a transition cannot take a property back off an animation mid-fill. */
.listen.is-ready.is-gone {
  animation: playlist-fall 0.26s ease both;
  pointer-events: none;
}

/* Every arrival after the first answers a tap, so it comes back at the
   speed of a tap — the slow rise is for the opening only. */
.listen.is-ready.is-back {
  animation-duration: 0.32s;
}

.listen__icon {
  position: relative;
  flex: none;
  width: 1rem;
  height: 1rem;
}

.listen__note {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 70%;
  transition: transform 0.18s ease;
}

.listen:hover .listen__note {
  transform: translateY(-1px) rotate(-8deg);
}

/* --- player --- */

.player {
  /* Keep clear of a notch in landscape, where the card is beside it. */
  width: min(
    24rem,
    calc(100vw - 2.5rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px))
  );
  padding: 0.55rem 0.6rem 0.6rem;
  background: color-mix(in srgb, var(--playlist-page) 92%, transparent);
  backdrop-filter: blur(16px);
  border: 1px solid color-mix(in srgb, var(--playlist-ink) 18%, var(--playlist-page));
  border-radius: 14px;
  box-shadow: 0 12px 40px color-mix(in srgb, var(--playlist-ink) 16%, transparent);
  opacity: 0;
  transform: translateY(-0.75rem) scale(0.985);
  transform-origin: 50% 0;
  visibility: hidden;
  pointer-events: none;
  /* `visibility` is left out of the transition on purpose: it flips with
     the class, so the card can take focus the moment it opens. */
  transition:
    opacity 0.26s ease,
    transform 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

.player.is-open {
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: auto;
}

.player__bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.4rem;
}

.player__title {
  margin: 0;
  font-family: "Instrument Serif", "Times New Roman", Times, serif;
  font-size: 1.05rem;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--playlist-ink);
}

.player__actions {
  display: flex;
  gap: 0.7rem;
  flex-shrink: 0;
}

.player__toggle,
.player__close {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--playlist-ink) 60%, transparent);
  transition: color 0.18s ease;
}

.player__toggle:hover,
.player__close:hover {
  color: var(--playlist-ink);
}

.player__toggle:focus-visible,
.player__close:focus-visible {
  outline: 2px solid var(--playlist-ink);
  outline-offset: 3px;
}

/* 80px is Spotify's own minimal bar — cover, title, transport, one line. The
   list is what `Tracks` is for, so collapsed asks the embed for nothing more. */
.player__stage {
  height: 80px;
  overflow: hidden;
  border-radius: 10px;
  background: color-mix(in srgb, var(--playlist-ink) 8%, var(--playlist-page));
  transition: height 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

/* The track list is worth having only as far as the screen goes: on a phone
   held sideways a fixed 352px would run off the bottom. */
.player.is-expanded .player__stage {
  height: min(352px, 58vh);
}

.player__stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.player__fallback {
  margin: 0;
  padding: 0.8rem;
  font-size: 0.85rem;
  color: var(--playlist-ink);
}

.player__fallback a {
  color: inherit;
}

/* Touch: the words stay the size they are — they are set in the mark's own
   voice — but the box you can hit around them grows to a finger, pulled back
   out of the layout by an equal margin so the bar keeps its line. */
@media (hover: none) and (pointer: coarse) {
  .listen {
    padding: 0.75rem 1.15rem;
  }

  .player {
    width: min(26rem, calc(100vw - 1.75rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  }

  /* Padding and margin cancel, so the baseline the bar aligns on — and the
     0.7rem the words sit apart — are exactly where they were; the two hit
     areas simply meet in the middle of that gap instead of leaving it dead. */
  .player__toggle,
  .player__close {
    padding: 0.9rem 0.35rem;
    margin: -0.9rem -0.35rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .listen,
  .listen__note,
  .player,
  .player__stage {
    transition: none;
  }

  /* No rise, no fall — but the pill still has to arrive and leave, so hand
     each state what the animation would otherwise have filled in. */
  .listen.is-ready {
    animation: none;
    opacity: 1;
  }

  .listen.is-ready.is-gone {
    animation: none;
    opacity: 0;
    visibility: hidden;
  }

  .listen:hover {
    transform: none;
  }
}
