/* Music collage: glass tiles with 3D tilt */
.collage {
  --cols: 2;
  --gap: 10px;
  position: relative;
  perspective: 1200px; /* gives the scroll tilt real depth */
  display: flex;
  flex-wrap: wrap;
  justify-content: center; /* a short last row sits centred */
  gap: var(--gap);
  margin-bottom: clamp(48px, 7vw, 88px); /* space before the playlist */
}
@media (min-width: 640px) {
  .collage {
    --cols: 3;
    --gap: 12px;
  }
}
@media (min-width: 1100px) {
  .collage {
    --cols: 5;
    --gap: 14px;
  }
}

.tile {
  --sx: 0deg;
  --ax: 1;
  --ay: 0;
  --rx: 0deg;
  --ry: 0deg;
  --mx: 50%;
  --my: 50%;
  --px: 0;
  --py: 0;
  --s: 1;
  position: relative;
  display: block;
  flex: 0 0 calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols) - 0.5px);
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
  isolation: isolate;
  background: #141414;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.1);
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry))
    scale(var(--s));
  transition:
    transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1),
    box-shadow 0.5s,
    opacity 0.4s,
    filter 0.4s;
  rotate: var(--ax) var(--ay) 0 var(--sx); /* scroll tilt: separate from the hover tilt, so it follows the scroll instantly */
  will-change: transform;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  transform: scale(1.1)
    translate(calc(var(--px) * -2.2%), calc(var(--py) * -2.2%));
  transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* light that follows the pointer */
.tile .glare {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(
    circle at var(--mx) var(--my),
    rgba(255, 255, 255, 0.32),
    rgba(255, 255, 255, 0) 55%
  );
  transition: opacity 0.4s;
}

/* glass edge and sheen */
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 255, 255, 0) 32%,
    rgba(255, 255, 255, 0) 68%,
    rgba(255, 255, 255, 0.08) 100%
  );
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -24px 40px -24px rgba(255, 255, 255, 0.1);
}

/* frosted title bar */
.tile .label {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.88rem;
  background: rgba(12, 12, 12, 0.38);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.35s,
    transform 0.35s;
}
.tile .label b {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .label i {
  font-size: 18px;
  flex-shrink: 0;
}

.tile:hover .label,
.tile:focus-visible .label,
.tile.is-active .label {
  opacity: 1;
  transform: none;
}
.tile:hover .glare,
.tile.is-active .glare {
  opacity: 1;
}
.tile.is-active {
  --s: 1.035;
  box-shadow:
    0 28px 60px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.2);
  transition:
    transform 0.12s ease-out,
    box-shadow 0.4s,
    opacity 0.4s,
    filter 0.4s;
}
.tile.is-active img {
  transition: transform 0.12s ease-out;
}

/* the others step back */
.collage:has(.tile.is-active) .tile:not(.is-active) {
  opacity: 0.5;
  filter: saturate(0.7);
}

/* image missing: still looks intentional */
.tile.noimg {
  background: linear-gradient(135deg, #232323, #0d0d0d);
}
.tile.noimg img {
  display: none;
}
.tile.noimg .label {
  opacity: 1;
  transform: none;
}

@media (hover: none) {
  .tile .label {
    opacity: 1;
    transform: none;
  }
}

/* entrance: tiles rise in one after another */
.collage.js .tile {
  animation: tileIn 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 90ms);
  animation-play-state: paused;
}
.collage.js.in .tile {
  animation-play-state: running;
}
@keyframes tileIn {
  from {
    opacity: 0;
    translate: 0 28px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile img {
    transition: none;
  }
  .collage.js .tile {
    animation: none;
  }
}
