/*
 * Artist overlay. Desktop: 50/50 split, the right half is sticky inside the
 * overlay's own scroller, so only the left column moves.
 * The left column uses a 6-column grid that lines up with columns 1–6 of the page.
 */
.overlay {
  --ov-inset: 0.75rem; /* 12px frame around the main image */
  --ov-half: 50vw;
  --ov-cols: 6;
  --ov-col: calc((var(--ov-half) - var(--margin) - var(--gutter) / 2 - (var(--ov-cols) - 1) * var(--gutter)) / var(--ov-cols));
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
}
.overlay[hidden] { display: none; }
.overlay:focus { outline: none; }

.overlay__bg {
  position: absolute;
  inset: 0;
  background: var(--c-bg);
}

.overlay__scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.overlay__inner {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100%;
}

/* ---------- content (left) ---------- */
.overlay__content {
  /* above the right image, so a long artist name can run over it instead of behind it */
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(var(--ov-cols), minmax(0, 1fr));
  column-gap: var(--gutter);
  align-content: start;
  padding: var(--ov-inset) calc(var(--gutter) / 2) max(3rem, calc(70 * var(--u))) var(--margin);
}

/* genre 1: row 1, column 1. Genres 2 and 3 start in row 2, column 2
   (column 2 is pushed right if genre 1 is wider) */
.ov-genres {
  --ov-genre-col: var(--ov-col);
  grid-column: 1 / 5;
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(var(--ov-genre-col), max-content) 1fr;
  column-gap: var(--gutter);
  align-self: start;
  margin-top: calc(120 * var(--u));
}
.ov-genres li { white-space: nowrap; }
.ov-genres li:first-child { grid-column: 1; grid-row: 1; }
.ov-genres li:not(:first-child) { grid-column: 2; }
.ov-genres li:nth-child(2) { grid-row: 2; }
.ov-genres li:nth-child(3) { grid-row: 3; }

.ov-profile {
  grid-column: 5 / 7;
  grid-row: 1;
  aspect-ratio: 251 / 320;
  /* the column ends half a gutter before the main image; shift by the other half
     so the two images sit exactly one gutter (12px) apart, as in the Figma file */
  margin-left: calc(var(--gutter) / -2);
  margin-right: calc(var(--gutter) / 2);
}

.ov-name {
  grid-column: 1 / -1;
  margin-top: calc(53.5 * var(--u));
  font-size: var(--fs-display-xl);
  line-height: var(--lh-display-xl);
}
.ov-name__line { display: block; }
.ov-name__line + .ov-name__line {
  padding-left: calc(var(--ov-col) + var(--gutter));
}

.ov-bio {
  grid-column: 2 / 6;
  margin-top: max(2rem, calc(51 * var(--u)));
}

.ov-section { grid-column: 2 / 6; }
.ov-section--facts { margin-top: max(2rem, calc(38 * var(--u))); }
.ov-section--shows { margin-top: max(2rem, calc(72 * var(--u))); }
.ov-section__label { margin-bottom: max(0.75rem, calc(15.5 * var(--u))); }

.ov-list { display: grid; row-gap: calc(8 * var(--u)); }
.ov-row {
  display: flex;
  align-items: baseline;
  gap: max(0.5rem, calc(14 * var(--u)));
}
.ov-row > :first-child,
.ov-row > :last-child { flex-shrink: 0; }
.ov-row > :last-child { text-align: right; }
.ov-row__leader {
  flex: 1 1 auto;
  min-width: 1.5rem;
  height: 1.5px;
  align-self: baseline; /* an empty box's baseline is its bottom edge: the dashes sit on the text baseline */
  background-image: linear-gradient(to right, var(--c-red) 0 55%, transparent 55% 100%);
  background-size: max(8px, calc(12 * var(--u))) 100%;
  background-repeat: repeat-x;
}

.ov-portrait {
  grid-column: 2 / 6;
  aspect-ratio: 1;
  margin-top: max(2.5rem, calc(98.5 * var(--u)));
}

/* ---------- media (right) ---------- */
.overlay__media {
  position: relative;
  z-index: 1;
  padding: var(--ov-inset) var(--ov-inset) var(--ov-inset) 0;
}
.overlay__frame {
  position: sticky;
  top: var(--ov-inset);
  height: calc(100vh - 2 * var(--ov-inset));
  height: calc(100dvh - 2 * var(--ov-inset));
  overflow: hidden;
}
.overlay__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.overlay.is-flipping .overlay__img { visibility: hidden; }

/* controls float above the sticky media (and stay fixed on mobile) */
.overlay__close {
  position: fixed;
  z-index: 3;
  top: var(--ov-inset);
  right: var(--ov-inset);
  width: max(2.75rem, calc(58 * var(--u)));
  height: max(2.75rem, calc(58 * var(--u)));
  display: grid;
  place-items: center;
  background: var(--c-bg);
}
.overlay__close svg {
  width: 42%;
  height: 42%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: square;
  transition: transform var(--dur-btn) var(--ease-out-expo);
}
@media (hover: hover) {
  .overlay__close:hover svg { transform: rotate(90deg); }
}

.overlay__book {
  position: fixed;
  z-index: 3;
  right: calc(2 * var(--ov-inset));
  bottom: calc(2 * var(--ov-inset));
  width: max(9rem, calc(218 * var(--u)));
  height: max(3.25rem, calc(71 * var(--u)));
}

/* FLIP clone */
.flip-clone {
  position: fixed;
  z-index: var(--z-flip);
  top: 0;
  left: 0;
  overflow: hidden;
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform, width, height;
}
.flip-clone img {
  position: absolute;
  max-width: none;
  object-fit: cover;
}

/* ---------- tablet portrait: stacked, image first ---------- */
@media (max-width: 991px) {
  .overlay { --ov-cols: 12; }
  .overlay__inner {
    grid-template-columns: 1fr;
  }
  .overlay__media {
    order: -1;
    padding: var(--ov-inset) var(--ov-inset) 0;
  }
  .overlay__frame {
    position: relative;
    top: 0;
    height: auto;
    aspect-ratio: 4 / 5;
    max-height: calc(100svh - 2 * var(--ov-inset));
    width: 100%;
  }
  .overlay__content {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    padding: 3rem var(--margin) 8rem;
  }
  .ov-genres { --ov-genre-col: calc(2 * var(--col) + var(--gutter)); grid-column: 1 / 9; margin-top: 0; }
  .ov-profile { grid-column: 9 / 13; margin-inline: 0; }
  .ov-name { margin-top: 3rem; }
  .ov-name__line + .ov-name__line { padding-left: calc(2 * (var(--col) + var(--gutter))); }
  .ov-bio,
  .ov-section,
  .ov-portrait { grid-column: 3 / 12; }
  .overlay__book { right: var(--ov-inset); bottom: var(--ov-inset); }
}

/* mobile order: image → name + bio → genres | small image → facts → shows → final image */
@media (max-width: 767px) {
  .overlay__frame { aspect-ratio: 3 / 4; }
  .ov-name { order: 1; margin-top: 0; font-size: clamp(3.5rem, 20vw, 9rem); }
  .ov-name__line + .ov-name__line { padding-left: calc(var(--col) + var(--gutter)); }
  .ov-bio { order: 2; max-width: 32rem; margin-top: 1.5rem; }
  .ov-genres { order: 3; grid-row: auto; margin-top: 3rem; --ov-genre-col: calc(3 * var(--col) + 2 * var(--gutter)); grid-column: 1 / 8; }
  .ov-profile { order: 3; grid-row: auto; margin-top: 3rem; grid-column: 8 / 13; }
  .ov-section--facts { order: 4; margin-top: 3rem; }
  .ov-section--shows { order: 5; }
  .ov-portrait { order: 6; }
  .ov-bio,
  .ov-section,
  .ov-portrait { grid-column: 1 / -1; }
}

/* landscape phones: a short viewport, so keep the image beside the text */
@media (max-width: 991px) and (orientation: landscape) and (max-height: 560px) {
  .overlay__inner { grid-template-columns: 1fr 1fr; }
  .overlay__media { order: 1; padding: var(--ov-inset) var(--ov-inset) var(--ov-inset) 0; }
  .overlay__frame {
    position: sticky;
    top: var(--ov-inset);
    aspect-ratio: auto;
    height: calc(100dvh - 2 * var(--ov-inset));
  }
  .overlay__content { grid-template-columns: repeat(6, minmax(0, 1fr)); padding: 1.5rem calc(var(--gutter) / 2) 5rem var(--margin); }
  .ov-genres { --ov-genre-col: 0px; grid-column: 1 / 4; grid-template-columns: 1fr; }
  .ov-genres li:nth-child(n) { grid-column: 1; grid-row: auto; margin-top: 0; }
  .ov-profile { grid-column: 4 / 7; margin-left: calc(var(--gutter) / -2); margin-right: calc(var(--gutter) / 2); }
  .ov-bio,
  .ov-section,
  .ov-portrait { grid-column: 1 / -1; }
  .ov-name { font-size: 11vw; }
  .ov-name__line + .ov-name__line { padding-left: calc(var(--col) * 1.6); }
}

@media (max-width: 479px) {
  .overlay__content { padding: 2.25rem var(--margin) 7rem; }
  .overlay__book {
    left: var(--ov-inset);
    right: var(--ov-inset);
    width: auto;
    height: 3.5rem;
  }
}

.genres__hover.is-flipping { visibility: hidden; }
