.main {
  grid-column: main;
  padding: 1.25rem;
}

/* Photo Gallery */
.gallery {
    margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
  grid-auto-rows: 12.5rem;
  grid-auto-flow: dense;
  gap: 0.75rem;
}

.gallery figure {
  /* container-type: inline-size; */
  container: figure / inline-size;
  overflow: hidden;

  display: grid;
  /* grid-template-columns: 1fr; */
  /* grid-template-rows: 1fr; */

  /*
    Because 1fr = minmax(auto, 1fr),
    to prevent the grid blowout,
    set the minimum to zero.
  */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

.gallery img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;

  /* grid-row: 1 / -1; */
  /* grid-column: 1 / -1; */
  grid-area: 1 / 1 / -1 / -1;

  transition: scale 1s ease-in-out;
}

.gallery figure:hover img {
  scale: 1.125;
}

.gallery figcaption {
  grid-area: 1 / 1 / -1 / -1;
  align-self: end;
  z-index: 1;

  padding: 3em 15% 1em 1em;
  color: #fff;
  font-size: 0.875rem;
  line-height: 1.3;
  background: linear-gradient(transparent 25%, rgb(0 0 0 / 0.75));
  display: none;
}

@container figure (width > 20rem) {
  .gallery figcaption {
    display: block;
  }
}

.gallery figcaption h3 {
  font-size: 1.0625rem;
}

.gallery figcaption p {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media (width > 600px) {
  .gallery figure:nth-child(1) {
    grid-area: span 2 / span 2;
  }

  .gallery figure:nth-child(4n + 1) {
    grid-row: span 2;
  }

  .gallery figure:nth-child(4n + 2) {
    grid-column: span 2;
  }
}
