.scene {
  cursor: grab; /* The sliders can be dragged */
  perspective: 900px;
  position: relative;
  height: 100svh;
  overflow: clip;
  display: flex;
  justify-content: center;
  align-items: center;
}

.scene__title {
  position: relative;
  z-index: 10;
  margin: 0;
}

.scene__title a {
  display: block;
}

.scene__title span {
  display: inline-block;
}

.scene__title .char {
  display: inline-block;
  transform-style: preserve-3d;
  transform-origin: 50% 0%;
}

.carousel {
  width: 400px;
  height: 500px;
  top: 50%;
  left: 50%;
  margin: -250px 0 0 -200px;
  position: absolute;
  transform-style: preserve-3d;
  will-change: transform;
  transform: translateZ(-550px) rotateY(0deg);
}

@media screen and (max-width: 53em) {
  .carousel {
    scale: 0.7 0.7 0.7;
  }
}

.carousel__cell {
  position: absolute;
  width: 350px;
  height: 420px;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  rotate: y calc(var(--lean, 0deg) + var(--spin-lean, 0deg)); /* Leans against the scroll and the drag (set from their speed), on top of GSAP's transform */
}

.card__face {
  width: 100%;
  height: 100%;
  position: absolute;
  backface-visibility: hidden;
  background-image: var(--img);
  background-size: cover;
}

.card__face--back {
  transform: rotateY(180deg);
}

.preview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: var(--preview-padding);
  display: grid;
  grid-template-rows: auto 1fr; /* The title and close at the top, the grid centered below */
  align-items: center;
  justify-items: center;
  grid-row-gap: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preview__header {
  align-self: start;
  display: flex;
  width: 100%;
  align-items: flex-end;
  justify-content: space-between;
  line-height: 1;
}

.preview__title {
  margin: 0;
}

.preview__close {
  background: none;
  text-transform: inherit;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
  color: var(--color-link);
  &:hover {
    color: var(--color-link-hover);
  }
  &:focus-visible {
    outline: 2px solid red;
  }
}

.grid {
  padding: 1rem 0;
  display: grid;
  grid-template-columns: repeat(var(--column-count), var(--column-width, minmax(var(--column), 1fr)));
  justify-content: center;
  grid-column-gap: var(--c-gap);
  grid-row-gap: var(--r-gap);
  width: 100%;
}

.grid__item {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow: hidden;
  position: relative;
}

.grid__item-image {
  width: 100%;
  aspect-ratio: var(--aspect);
  background-size: 100%;
  background-position: 50% 50%;
  transition: opacity 0.15s cubic-bezier(0.2, 0, 0.2, 1);
}

.grid__item:hover .grid__item-image {
  opacity: 0.7;
}

/* Hidden while the WebGL canvas draws it */
.grid__item-image.is-drawn {
  visibility: hidden;
}

/* While a slider is dragged */
.is-dragging,
.is-dragging * {
  cursor: grabbing !important;
  user-select: none;
}

/* First in the page and without a z-index: below the carousel and the previews' text */
.grid-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.grid__item-caption h3 {
  font-size: 1rem;
  font-weight: 400;
  margin: 0;
}

@media screen and (min-width: 53em) {
  .selected-works {
    --column-count: 5;
    --c-gap: 4rem;
    --r-gap: 2.5rem;
    /* The 15 images in 5 columns and 3 rows, as big as fits: 3 rows in the screen's height
       (minus the padding, the title, the gaps and the captions) or 5 columns in its width */
    --column-width: min(
      calc((100vw - 2 * var(--preview-padding) - 4 * var(--c-gap)) / 5),
      calc((100svh - 2 * var(--preview-padding) - 5rem - 2 * var(--r-gap) - 3 * 1.6rem) / 3 * 0.8)
    );
  }
}

.selected-works { --aspect:4/5; --preview-padding:1.5rem; --column:55px; --column-count:3; --r-gap:1rem; --c-gap:1rem; background:#18191b; color:#faf9f6; padding-block:clamp(3rem,6vw,6rem); }
.works-heading,.works-end { max-width:1240px; margin:auto; padding-inline:5vw; }
.works-heading { font-size:clamp(2.6rem,6vw,6rem); font-weight:500; letter-spacing:-.06em; }
.selected-works .scene { height:clamp(28rem,80svh,54rem); touch-action:pan-y; }
.scene__title a { color:white; text-decoration:none; font-size:clamp(2rem,5vw,5rem); letter-spacing:-.055em; text-shadow:0 2px 18px #000; }
.works-end a { color:#fff; }
.work-preview-open { overflow:hidden; }
.selected-works .preview { z-index:1001; background:#18191b; }
.grid-canvas { z-index:1002; }
.preview__header { position:sticky; top:0; z-index:1; background:#18191b; padding:.75rem; }
.preview__close { color:#fff; }
@media(min-width:53em){ .selected-works { --column-count:5; } }
@media(prefers-reduced-motion:reduce){.scene__title .char {transform:none;} }

/* Size the ring cards from the featured image's native proportions. */
.selected-works .carousel {
  width: 400px;
  height: auto;
  aspect-ratio: var(--work-ratio, 1.6);
  margin: calc(-200px / var(--work-ratio, 1.6)) 0 0 -200px;
}
.selected-works .carousel__cell {
  width: 100%;
  height: 100%;
}
.selected-works .card__face {
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.selected-works .preview { grid-template-rows:auto minmax(0,1fr); }
.homepage-project-gallery { width:min(1100px,100%); min-height:0; overflow-y:auto; padding:1rem; }
.homepage-project-gallery .grid { display:block; padding:0; }
.homepage-project-gallery .portfolio-gallery-main {
  display:block; width:100%; height: min(60svh,650px); aspect-ratio:auto; object-fit:contain;
}
.homepage-project-gallery .portfolio-gallery-thumbs { display:flex;flex-wrap:wrap;gap:.75rem;margin-top:1rem; }
.homepage-project-gallery button { width:100px;aspect-ratio:3/2;padding:0;border:2px solid transparent;background:none;cursor:pointer; }
.homepage-project-gallery button[aria-pressed="true"] { border-color:#fff; }
.homepage-project-gallery button:hover { border-color:white; }
.homepage-project-gallery .gallery-case-study { display:inline-block;margin-top:1.5rem;color:#fff;text-decoration:none; }
