.project-grid,
.gallery {
  --gallery-gap: clamp(5px, .75vw, 14px);
  gap: var(--gallery-gap);
}

.project-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.project-grid .tile { min-width: 0 }
.project-grid .tile:focus-visible,
.gallery .film-poster:focus-visible { outline-offset: -4px }

.film-poster--play { position: relative }
.film-embed { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0 }

.film-play-symbol {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max(44px, 13.16%);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgb(0 0 0 / .75);
  pointer-events: none;
}

.film-play-symbol::after {
  content: "";
  position: absolute;
  inset: 27% auto auto 34%;
  width: 41%;
  height: 46%;
  background: #fff;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.project-grid img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.project-grid .tile--banner { grid-column: 1 / -1 }
.project-grid .tile--banner img { height: auto }

.gallery {
  --gallery-columns: 1;
  --gallery-column: calc((100% - (var(--gallery-columns) - 1) * var(--gallery-gap)) / var(--gallery-columns));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.gallery > * { min-width: 0 }
.gallery > :is(.tile--banner, .film, .project-intro, .editions, .gallery-square) { flex: 0 0 100% }
.gallery :is(img, video) { width: 100% }

.gallery-photo {
  flex: 0 0 var(--gallery-column);
  aspect-ratio: 3 / 4;
}

.gallery-photo img {
  height: 100%;
  object-fit: cover;
}

.gallery-landscape { aspect-ratio: 3 / 2 }
.gallery-square img { margin-inline: auto }

@media (min-width: 540px) {
  .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .project-grid .tile:not(.tile--banner) { aspect-ratio: 3 / 4 }
  .gallery { --gallery-columns: 2 }
  .gallery-landscape { flex-basis: calc(2 * var(--gallery-column) + var(--gallery-gap)) }
}

@media (min-width: 1200px) {
  .project-grid { grid-template-columns: repeat(4, minmax(0, 1fr)) }
  .gallery { --gallery-columns: 4 }
  .gallery-photo {
    /* Portraits and landscapes are the same height on shared rows. */
    height: calc((100cqi - 3 * var(--gallery-gap)) / 3);
  }
  .gallery-square img { width: calc(50% - var(--gallery-gap) / 2) }
}

.gallery-photo-viewable { position: relative }

.gallery-photo-trigger {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.gallery-photo-trigger:focus-visible {
  outline: 2px solid #383433;
  outline-offset: -4px;
}

html:has(.gallery) { scrollbar-gutter: stable }
html:has(.photo-viewer[open]) { overflow: hidden }

.photo-viewer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  background: transparent;
}

.photo-viewer::backdrop { background: rgb(0 0 0 / .75) }

.photo-viewer__close {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-out;
}

.photo-viewer__close img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery--justified { justify-content: flex-start }

.gallery--justified > :is(.gallery-photo, .gallery-square) {
  /* Leave room for subpixel rounding, then let the row grow flush to both edges. */
  flex: 1 0 calc(var(--justified-width) - .5px);
  height: var(--justified-height);
  aspect-ratio: auto;
}

.gallery--justified > :is(.gallery-photo, .gallery-square) > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery--logotypes {
  --logo-columns: 2;
  display: grid;
  grid-template-columns: repeat(var(--logo-columns), minmax(0, 1fr));
}

.gallery--logotypes > :is(.project-intro, .logotype-feature, .logotype-row) {
  grid-column: 1 / -1;
}

.logotype-feature img {
  width: 100%;
  height: auto;
}

.logotype-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gallery-gap);
}

.logotype-row > .gallery-photo {
  flex: 0 0 calc((100% - (var(--logo-columns) - 1) * var(--gallery-gap)) / var(--logo-columns));
  min-width: 0;
  aspect-ratio: 1;
  height: auto;
  background: #fff;
}

.logotype-row > .gallery-photo > img { object-fit: contain }

@media (min-width: 680px) {
  .gallery--logotypes { --logo-columns: 3 }
}

@media (min-width: 960px) {
  .gallery--logotypes { --logo-columns: 4 }
}

@media (min-width: 1200px) {
  .gallery--logotypes { --logo-columns: 5 }
}
