/* The Hip Hop Lab — the video opening on Home. Revision 0.4, sections 6 and 7.
   Owner: stage lane. Behaviour: assets/hero.js. Colours, sizes and timings: tokens.css.

   One slide per artist (data/hero.json), stacked. Each shows its poster with a slow push-in
   or, once the owner's clip is in, plays it muted and inline. Over the footage: the current
   artist and title with Listen Now, the track list, and Pause. Text sits on dark
   shading strong enough that every text node holds 4.5:1 against the lightest pixel behind
   it on every slide (measured; see the stage lane's handback). */

.hero {
  position: relative;
  isolation: isolate;
  height: calc(100svh - var(--masthead-h));
  min-height: 34rem;
  overflow: clip;
  background: var(--ink-0);
  color: var(--text);
}

/* ---------- Footage ---------- */

.hero__media,
.hero__slide,
.hero__poster,
.hero__video {
  position: absolute;
  inset: 0;
}

.hero__slide {
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  /* The outgoing slide fades out in 0.5 s; the incoming one fades in over 1.2 s after it. */
  transition: opacity var(--dur-slide-out) var(--ease-in), visibility 0s linear var(--dur-slide-out);
}

.hero__slide.is-current {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-slide-in) var(--ease-stage) var(--dur-slide-out), visibility 0s;
}

/* Only the current slide and the next one render their poster, so lazy posters load just
   ahead of their turn (section 6: only the first loads eagerly). */
.hero__slide:not(.is-near) .hero__poster {
  display: none;
}

.hero__poster,
.hero__video {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: var(--focal, 50% 50%);
}

.hero__poster {
  transform-origin: var(--focal, 50% 50%);
}

/* The push-in: only where the script runs, so Pause can always stop it. */
.js .hero__slide.is-current .hero__poster {
  animation: hero-push calc(var(--slide-time) + var(--dur-slide-in)) linear both;
}

.js .hero.is-paused .hero__poster,
.js .hero.is-held .hero__poster,
.js .hero__slide.is-playing .hero__poster {
  animation-play-state: paused;
}

@keyframes hero-push {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.07);
  }
}

.hero__video {
  opacity: 0;
  transition: opacity var(--dur-fade) var(--ease-out);
}

.hero__slide.is-playing .hero__video {
  opacity: 1;
}

/* Shading: dark at the very top (under the controls and against the header) and a
   bottom-weighted gradient (the reference's, deepened); the text blocks add their own. */
.hero__shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    transparent 48%,
    color-mix(in srgb, var(--ink-0) 30%, transparent) 64%,
    color-mix(in srgb, var(--ink-0) 70%, transparent) 86%,
    color-mix(in srgb, var(--ink-0) 85%, transparent) 100%
  );
}

/* ---------- Layout over the footage ---------- */

.hero__ui {
  position: absolute;
  inset: 0;
  z-index: var(--z-hero-ui);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    ". controls"
    ". ."
    "now tracks";
  gap: 1.5rem clamp(1.5rem, 4vw, 4rem);
  padding: clamp(1rem, 2.4vh, 1.75rem) var(--gutter) clamp(1.75rem, 5vh, 3.5rem);
  pointer-events: none;
}

.hero__ui > * {
  pointer-events: auto;
}

.hero__controls {
  grid-area: controls;
  position: relative;
  display: flex;
  justify-content: flex-end;
  gap: 0.625rem;
}

.hero__now {
  grid-area: now;
  position: relative;
  align-self: end;
  min-width: 0;
}

.hero__tracks {
  grid-area: tracks;
  position: relative;
  align-self: end;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
  width: min(25rem, 34vw);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Local shading behind each text block: a dark field larger than the block, blurred so
   it is even across the text and has no edge on the footage. */
.hero__controls::before,
.hero__now::before,
.hero__tracks::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -2.5rem -3rem;
  pointer-events: none;
  background: var(--scrim);
  filter: blur(2rem);
}

.hero__now::before {
  inset: -3rem -4rem -2rem;
}

:root:not(.js) .hero__controls,
:root:not(.js) .hero__tracks {
  display: none;
}

/* ---------- The current release ---------- */

.hero__info {
  display: grid;
  justify-items: start;
  gap: 0.5rem;
}

.js .hero__info:not([hidden]) {
  animation: hero-info-in var(--dur-fade) var(--ease-stage) both;
}

@keyframes hero-info-in {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

.hero__artist {
  font-size: clamp(1.125rem, 1.5vw, 1.375rem);
  font-weight: 700;
  line-height: 1.2;
}

.hero__artist a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  text-decoration: none;
}

.hero__artist a:hover {
  text-decoration: underline;
  text-decoration-color: var(--signal);
  text-decoration-thickness: 2px;
}

.hero__title {
  max-width: 13ch;
  margin-top: -0.375rem;
  font-family: var(--font-display);
  font-stretch: var(--display-stretch);
  font-weight: var(--display-weight);
  font-size: clamp(2.5rem, 6.2vw, 6rem);
  line-height: 0.92;
  letter-spacing: var(--display-tracking);
  text-transform: uppercase;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.hero__meta {
  font-size: var(--fs-lead);
  font-weight: 500;
}

.hero__upcoming {
  font-weight: 700;
}

/* ---------- Listen Now: a native disclosure, so it works without JavaScript ---------- */

.hero__listen {
  position: relative;
  margin-top: 0.75rem;
}

.hero__listen > summary {
  list-style: none;
}

.hero__listen > summary::-webkit-details-marker {
  display: none;
}

.btn__chevron {
  transition: transform var(--dur-ui) var(--ease-out);
}

.hero__listen[open] .btn__chevron {
  transform: rotate(180deg);
}

/* The platforms open beside Listen Now, on its row, so they never cover the title. */
.hero__listen {
  display: inline-block;
}

.hero__platforms {
  position: absolute;
  left: calc(100% + 0.625rem);
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 0.625rem;
  margin: 0;
  padding: 0;
  list-style: none;
  animation: listen-in var(--dur-ui) var(--ease-out);
}

@keyframes listen-in {
  from {
    opacity: 0;
    transform: translateX(-0.5rem);
  }
}

/* ---------- Track list ---------- */

.hero__track {
  width: 100%;
  min-height: 3.25rem;
  justify-content: space-between;
  gap: 1rem;
  font-size: 1.125rem;
  overflow: hidden;
  text-align: left;
}

.hero__track-artist {
  flex: none;
  font-weight: 700;
}

.hero__track-title {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 500;
}

/* Time left on the current slide, a hairline along the bottom of its button. */
.hero__track-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--signal);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

.js .hero__track[aria-pressed="true"] .hero__track-bar {
  animation: hero-progress var(--track-time, var(--slide-time)) linear both;
}

.js .hero.is-paused .hero__track-bar,
.js .hero.is-held .hero__track-bar {
  animation-play-state: paused;
}

[data-buttons="a"] .hero__track-bar {
  left: 1.5rem;
  right: 1.5rem;
  bottom: 6px;
  border-radius: 2px;
}

@keyframes hero-progress {
  to {
    transform: scaleX(1);
  }
}

.hero__control .btn__icon {
  flex: none;
}

.hero__control [data-icon-play],
.hero.is-paused .hero__control [data-icon-pause] {
  display: none;
}

.hero.is-paused .hero__control [data-icon-play] {
  display: block;
}

/* ---------- Phone: everything thumb-reachable at the bottom ---------- */

@media (max-width: 47.99em) {
  .hero {
    min-height: 32rem;
  }

  .hero__ui {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas:
      ". ."
      "now controls"
      "tracks tracks";
    gap: 0.875rem;
    padding: 1rem var(--gutter) 1.25rem;
  }

  /* Pause sits at the end of the Listen Now row, as an icon with a hidden label. On a phone
     each clip is framed where its artist is (--focal-phone, from tools/prep_video.py). */
  .hero__video,
  .hero__poster {
    object-position: var(--focal-phone, var(--focal, 50% 50%));
  }

  .hero__controls {
    align-self: end;
    justify-content: flex-end;
  }

  [data-buttons] .hero__control {
    width: var(--btn-h);
    min-width: var(--btn-h);
    padding: 0;
  }

  .hero__control > span {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
  }

  .hero__track {
    min-height: var(--btn-h);
    font-size: var(--fs-button);
  }

  .hero__controls::before {
    display: none;
  }

  .hero__now::before,
  .hero__tracks::before {
    inset: -4rem -4rem -1rem;
  }

  .hero__tracks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: auto;
  }


  .hero__track {
    justify-content: center;
    padding-inline: 0.75rem;
    white-space: normal;
    text-align: center;
  }

  .hero__track-artist {
    flex: 0 1 auto;
    min-width: 0;
  }

  [data-buttons="b"] .hero__track {
    font-size: 0.8125rem;
  }

  /* On a phone the platforms open in the stack, under Listen Now; the stack grows upwards. */
  .hero__listen {
    display: block;
  }

  .hero__platforms {
    position: static;
    flex-wrap: wrap;
    margin-top: 0.625rem;
  }

  .hero__platforms li {
    flex: 1 1 auto;
  }

  .hero__platforms .btn {
    width: 100%;
    padding-inline: 1rem;
  }

  .hero__track-title {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
  }

  [data-buttons="a"] .hero__track-bar {
    left: 1rem;
    right: 1rem;
  }

  /* Sized so the longest single word ("SOMEBODY") fits 358 px without breaking. */
  .hero__title {
    max-width: none;
    font-size: clamp(1.875rem, 9.2vw, 3.5rem);
    overflow-wrap: normal;
  }

}

/* Short desktop windows: a smaller title so the stack still fits. */
@media (min-width: 48em) and (max-height: 46em) {
  .hero__title {
    font-size: clamp(2.25rem, 4.6vw, 4.25rem);
  }
}

/* ---------- Reduced motion: posters only, nothing drifts or fades ---------- */

@media (prefers-reduced-motion: reduce) {
  .hero__slide,
  .hero__slide.is-current {
    transition: none;
  }
}
