/*
 * Audio grid + morph player — /media/audio. "Mystery card" expand effect
 * adapted from media/audio/dist and generalized to any track count: cards stack
 * at the stage center with only the featured card visible; hovering the stage
 * expands the rest into a computed grid, collapsing on mouse-leave. Positions
 * (--cx/--cy), the card size, and stagger delays are set by assets/js/audio.js.
 * The player hosts a SoundCloud embed. Titles stay horizontally centered.
 */

:root {
  /* The reference's CustomEase "0.86,0,0.07,1" as a cubic-bezier. */
  --audio-ease: cubic-bezier(0.86, 0, 0.07, 1);
  --audio-dur: 0.64s;
}

.audios {
  --nav-h: 100px;
  position: relative;
  z-index: 10;
  min-height: calc(100vh - var(--nav-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 20px var(--nav-h);
}
.audios-empty {
  text-align: center;
  font-family: var(--font-brand);
  color: var(--color-text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ---- Stage: a relatively-positioned box sized to the full grid ---- */
.audios-stage {
  position: relative;
  margin: 0 auto;
}

/* ---- Card ---- */
.acard {
  position: absolute;
  width: var(--card-size, 220px);
  height: var(--card-size, 220px);
  /* Collapsed: stacked at the stage center, hidden. */
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  visibility: hidden;
  padding: 0;
  border: 1px solid var(--color-border-default);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(160deg, rgba(20, 28, 48, 0.72), rgba(8, 12, 24, 0.82));
  box-shadow:
    0 18px 44px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.02);
  transition:
    left var(--audio-dur) var(--audio-ease),
    top var(--audio-dur) var(--audio-ease),
    transform var(--audio-dur) var(--audio-ease),
    opacity var(--audio-dur) var(--audio-ease),
    border-color 160ms ease,
    box-shadow 160ms ease;
  transition-delay: var(--delay, 0s);
}

/* Featured card: visible at rest, centered in the stage (viewport center).
   When the grid expands it moves to its own cell — the higher-specificity
   .is-expanded / .is-static rule below overrides these left/top. */
.acard.is-featured {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  visibility: visible;
  z-index: 10;
  transition-delay: 0s;
}

/* Expanded (or static): every card flies to its cell and shows. */
.audios-stage.is-expanded .acard,
.audios-stage.is-static .acard {
  left: var(--cx, 50%);
  top: var(--cy, 50%);
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  visibility: visible;
}

.acard:hover,
.acard:focus-visible {
  outline: none;
  border-color: rgba(var(--color-accent-rgb), 0.55);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.55), 0 0 22px rgba(203, 62, 212, 0.22);
}

/* A card whose track has no SoundCloud link yet: dimmed, not clickable. */
.acard--nolink { cursor: default; opacity: 0.55; }
.acard__nolink {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  z-index: 3;
  font-family: var(--font-brand);
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-align: center;
  opacity: 0;
  transition: opacity 220ms ease;
}
.acard--nolink:hover .acard__nolink,
.acard--nolink:focus-visible .acard__nolink { opacity: 1; }

.acard__scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(to top, rgba(4, 8, 16, 0.85) 0%, rgba(4, 8, 16, 0.15) 55%, rgba(4, 8, 16, 0) 100%);
}

/* Title: always horizontally centered. Centered at rest; drops to the
   bottom-center on hover so the play button clears it (never to a corner). */
.acard__name {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  z-index: 3;
  transform: translateY(-50%);
  padding: 0 14px;
  font-family: var(--font-brand);
  font-size: clamp(12px, 1.4vw, 16px);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--color-text-primary);
  text-align: center;
  transition: top 260ms ease, transform 260ms ease;
}
.acard:hover .acard__name,
.acard:focus-visible .acard__name {
  top: auto;
  bottom: 14px;
  transform: none;
}
/* No-link cards keep the title centered (the hint uses the bottom slot). */
.acard--nolink:hover .acard__name,
.acard--nolink:focus-visible .acard__name {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

/* Align the injected nav-fx drawn border to the card edge. */
.acard .nav-fx { top: 0; left: 0; width: 100%; height: 100%; z-index: 2; }
.acard .nav-fx-rect { rx: 12px; ry: 12px; }

/* Morph play button, centered, appears on hover. */
.acard__play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 4;
  width: clamp(52px, 34%, 84px);
  aspect-ratio: 1;
  opacity: 0;
  transition: opacity 220ms ease, transform 220ms ease;
}
.acard:hover .acard__play,
.acard:focus-visible .acard__play {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ---- Equalizer (decorative, card hover only) ---- */
.acard__bars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  height: 42%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  padding: 0 16px 12px;
  opacity: 0;
  transition: opacity 260ms ease;
  pointer-events: none;
}
.acard:not(.acard--nolink):hover .acard__bars,
.acard:not(.acard--nolink):focus-visible .acard__bars { opacity: 0.5; }

.eqbar {
  flex: 0 1 8px;
  min-width: 3px;
  height: 22%;
  border-radius: 3px;
  transform-origin: bottom center;
  background: linear-gradient(to top, #469cf3, #cb3ed4);
  opacity: 0.85;
}
.acard:hover .eqbar,
.acard:focus-visible .eqbar { animation: eqPulse 900ms ease-in-out infinite; }
.eqbar:nth-child(3n)   { animation-duration: 1100ms; }
.eqbar:nth-child(3n+1) { animation-duration: 760ms; }
.eqbar:nth-child(4n)   { animation-delay: -260ms; }
.eqbar:nth-child(4n+2) { animation-delay: -520ms; }
.eqbar:nth-child(5n)   { animation-delay: -140ms; }
.eqbar:nth-child(5n+3) { animation-delay: -700ms; }
@keyframes eqPulse {
  0%, 100% { transform: scaleY(0.28); }
  50%      { transform: scaleY(1); }
}

/* ---- The rings + triangle play button ---- */
.vplay {
  width: 100%;
  height: 100%;
  overflow: visible;
  display: block;
  filter: drop-shadow(0 0 10px rgba(203, 62, 212, 0.35));
}
.vplay__ring {
  fill: none;
  stroke: rgba(203, 62, 212, 0.7);
  stroke-width: 3;
  transform-origin: center;
}
.vplay__ring--2 { stroke: rgba(70, 156, 243, 0.6); }
.vplay__tri {
  fill: none;
  stroke: url(#vplayStroke);
  stroke-width: 6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.acard:hover .vplay__ring--1 { animation: vplaySpin 6s linear infinite; }
.acard:hover .vplay__ring--2 { animation: vplaySpin 8s linear infinite reverse; }
@keyframes vplaySpin { to { transform: rotate(360deg); } }

/* ---- Player (morph open, hosts the SoundCloud embed) ---- */
.aplayer {
  position: fixed;
  inset: 0;
  z-index: 60; /* above the fixed nav (10) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.aplayer[hidden] { display: none !important; }
body.aplayer-open { overflow: hidden; }
.aplayer__backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(4, 8, 16, 0.85) 0%, rgba(4, 8, 16, 0.96) 100%);
  opacity: 0;
  transition: opacity 380ms ease;
}
.aplayer.is-open .aplayer__backdrop { opacity: 1; }

.aplayer__stage {
  position: relative;
  transform: scale(0.55);
  opacity: 0;
  transition: transform 440ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 320ms ease;
}
.aplayer.is-open .aplayer__stage { transform: scale(1); opacity: 1; }

.aplayer__frame {
  position: relative;
  width: min(92vw, 560px);
  border: 1px solid var(--color-border-strong);
  border-radius: 16px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}
.aplayer__embed {
  display: block;
  width: 100%;
  height: min(72vh, 480px);
  border: 0;
}

.aplayer__close {
  position: absolute;
  top: -14px;
  right: -14px;
  z-index: 4;
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border-default);
  border-radius: 999px;
  background: rgba(12, 20, 36, 0.85);
  color: var(--color-text-primary);
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}
.aplayer__close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.aplayer__close:hover,
.aplayer__close:focus-visible {
  outline: none;
  color: #cb3ed4;
  border-color: rgba(var(--color-accent-rgb), 0.55);
  box-shadow: 0 0 0 2px rgba(var(--color-accent-rgb), 0.18), 0 0 18px rgba(203, 62, 212, 0.3);
}

/* Close (X) under the grid — returns to /media with the warp. */
.audios-actions { display: flex; justify-content: center; }
.audios-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  border: 1px solid var(--color-border-default);
  border-radius: 999px;
  background: rgba(12, 20, 36, 0.6);
  color: var(--color-text-primary);
  text-decoration: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}
.audios-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.audios-close:hover,
.audios-close:focus-visible {
  outline: none; color: #cb3ed4;
  border-color: rgba(var(--color-accent-rgb), 0.55);
  box-shadow: 0 0 0 2px rgba(var(--color-accent-rgb), 0.18), 0 0 18px rgba(203, 62, 212, 0.3);
}

@media (prefers-reduced-motion: reduce) {
  .acard { transition: opacity 200ms ease !important; transition-delay: 0s !important; }
  .vplay__ring--1, .vplay__ring--2 { animation: none !important; }
  .eqbar { animation: none !important; transform: scaleY(0.5); }
  .aplayer__stage { transition: opacity 200ms ease; transform: none; }
}

@media (max-width: 768px) {
  .audios { --nav-h: 76px; }
  .aplayer__close { top: 8px; right: 8px; }
}
