/* Apple Bar project page: every poster on one screen, growing on rollover. */

.apple-bar-page {
  --case-accent: #00ddee;
  --case-bg-deep: #000;
  --ink: #fff;
  --paper: #000;
  background: #000;
  color: #fff;
  height: 100dvh;
  overflow: hidden;
}

.apple-stage {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.6dvh, 32px);
  height: 100dvh;
  padding: clamp(16px, 3dvh, 32px) clamp(16px, 1.8vw, 32px);
  transition: opacity .45s ease, transform .55s cubic-bezier(.2, .8, .2, 1);
}

.apple-bar-page.is-closing .apple-stage {
  opacity: 0;
  transform: scale(.985);
}

.apple-bar-page.is-closing .case-study-close {
  opacity: 0;
}

/* ---- Heading ---- */

.apple-head {
  flex: none;
  padding-right: 84px;
}

.apple-kicker {
  color: #00ddee;
  display: block;
  font-size: clamp(11px, .9vw, 13px);
  margin-bottom: clamp(6px, 1.2dvh, 14px);
  text-transform: uppercase;
}

.apple-head h1 {
  font-size: clamp(38px, min(7.4vw, 13dvh), 148px);
  font-weight: 800;
  line-height: .95;
  margin: 0;
}

/* Sits under the posters: the line on the left, the description beside it. */
.apple-copy {
  align-items: baseline;
  display: grid;
  flex: none;
  gap: clamp(16px, 3vw, 56px);
  grid-template-columns: auto minmax(0, 1fr);
}

.apple-copy h2 {
  color: #00ddee;
  font-size: clamp(16px, min(1.7vw, 3dvh), 28px);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

.apple-copy p {
  font-size: clamp(12px, min(1.05vw, 1.9dvh), 17px);
  font-weight: 400;
  line-height: 1.5;
  margin: 0;
  max-width: 96ch;
}

/* ---- Poster wall: 8 x 2, sized to whichever of width or height runs out first ---- */

.apple-wall {
  container-type: size;
  flex: 1;
  min-height: 0;
}

.apple-grid {
  --gap: clamp(6px, .7vw, 12px);
  --poster-w: min(
    calc((100cqw - 7 * var(--gap)) / 8),
    calc((100cqh - var(--gap)) / 2 * .7068)
  );
  align-content: center;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(8, var(--poster-w));
  height: 100%;
  justify-content: center;
}

/* The button stays put and takes the hover; only the image scales. That way
   the cursor can sweep straight across the wall, even over a grown neighbor. */
.apple-poster {
  --ox: 50%;
  --oy: 0%;
  animation: apple-in .6s cubic-bezier(.2, .8, .2, 1) backwards;
  animation-delay: calc(var(--i) * 35ms);
  appearance: none;
  aspect-ratio: 540 / 764;
  background: none;
  border: 0;
  cursor: default;
  display: block;
  outline: none;
  padding: 0;
  position: relative;
  transition: z-index 0s .45s;
  width: 100%;
  z-index: 1;
}

.apple-poster img {
  display: block;
  height: 100%;
  pointer-events: none;
  transform-origin: var(--ox) var(--oy);
  transition: transform .45s cubic-bezier(.2, .8, .2, 1), opacity .3s ease;
  width: 100%;
}

/* Grow toward the middle of the wall, so nothing leaves the screen. */
.apple-poster:nth-child(n+9) { --oy: 100%; }
.apple-poster:nth-child(8n+1) { --ox: 0%; }
.apple-poster:nth-child(8n) { --ox: 100%; }

@keyframes apple-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.apple-poster:focus-visible,
.apple-poster.is-grown {
  transition-delay: 0s;
  z-index: 3;
}

.apple-poster:focus-visible img,
.apple-poster.is-grown img {
  transform: scale(2.04);
}

.apple-poster:focus-visible img {
  outline: 1px solid #00ddee;
}

.apple-grid:has(.apple-poster:focus-visible) .apple-poster:not(:focus-visible) img,
.apple-grid:has(.apple-poster.is-grown) .apple-poster:not(.is-grown) img {
  opacity: .3;
}

@media (hover: hover) {
  .apple-poster:hover {
    transition-delay: 0s;
    z-index: 3;
  }

  .apple-poster:hover img {
    transform: scale(2.04);
  }

  .apple-grid:has(.apple-poster:hover) .apple-poster:not(:hover) img {
    opacity: .3;
  }
}

/* ---- Very short screens, like a phone on its side ---- */

@media (max-height: 520px) and (min-width: 821px) {
  .apple-kicker {
    display: none;
  }

  .apple-copy p {
    line-height: 1.35;
  }
}

/* ---- Phones and portrait tablets: 4 x 4, tap to grow ---- */

@media (max-width: 820px) {
  .apple-bar-page {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .apple-stage {
    gap: 24px;
    height: auto;
    min-height: 100dvh;
    overflow-x: clip;
    padding: 24px 16px 32px;
  }

  .apple-head {
    padding-right: 72px;
  }

  .apple-head h1 {
    font-size: clamp(38px, 12vw, 84px);
  }

  .apple-copy {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr);
  }

  .apple-copy h2 {
    font-size: 20px;
  }

  .apple-copy p {
    font-size: 15px;
  }

  .apple-wall {
    container-type: normal;
    flex: none;
  }

  .apple-grid {
    --gap: 8px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    height: auto;
  }

  .apple-poster {
    cursor: pointer;
  }

  /* Each poster grows over the whole 4 x 4 wall, anchored by its place in it. */
  .apple-poster:nth-child(4n+1) { --ox: 0%; }
  .apple-poster:nth-child(4n+2) { --ox: 33.33%; }
  .apple-poster:nth-child(4n+3) { --ox: 66.67%; }
  .apple-poster:nth-child(4n) { --ox: 100%; }
  .apple-poster:nth-child(n+1) { --oy: 0%; }
  .apple-poster:nth-child(n+5) { --oy: 33.33%; }
  .apple-poster:nth-child(n+9) { --oy: 66.67%; }
  .apple-poster:nth-child(n+13) { --oy: 100%; }

  .apple-poster:focus-visible img,
  .apple-poster.is-grown img {
    transform: scale(4);
  }
}

@media (max-width: 820px) and (hover: hover) {
  .apple-poster:hover img {
    transform: scale(4);
  }
}

@media (prefers-reduced-motion: reduce) {
  .apple-poster {
    animation: none;
  }

  .apple-poster img {
    transition: opacity .2s ease;
  }
}
