/* The album grid: rows, frames and width: from album.yaml. The site links
   this next to style.css, and Arrange loads it from /album-layout/album.css
   to draw its preview, so it holds only the album and nothing else of the
   page. */

.album {
  display: grid;
  gap: 0.75rem;
  margin: 1.5rem 0 2rem;
}

/* One row per album.yaml entry. album.liquid sets --cols to the number of
   photos in the row, and they split its width evenly. */
.album-row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  gap: 0.75rem;
}

.album-photo {
  margin: 0;
}

.album-photo img {
  display: block;
  width: 100%;
  height: auto;
  /* border-radius: 0.4rem; */
}

@media (max-width: 32rem) {
  .album-row {
    grid-template-columns: 1fr;
  }
}

/* frame: in album.yaml. Every photo gets the same --frame-w × --frame-h inch
   frame, however many share its row, with 1/8" between photos in a row and
   1/4" between rows. album.liquid sets both, plus --widest, the most photos
   in any row. These are real inches on a MacBook Pro screen, which shows
   127px to the inch (CSS's own in unit is 96px, so on a Mac it measures about
   3/4 size). The widest row can outgrow the site's usual 42rem page (style.css
   lets main go wider), so the album is capped at that row instead. Each row
   works out its own frame size, so when the space can't fit a row at full
   size, only that row's frames shrink and a lone photo keeps its true size. */
.album-frame {
  --mac-inch: 127px;
  --frame-gap: calc(0.125 * var(--mac-inch));
  --frame-full: calc(var(--frame-w) * var(--mac-inch));
  max-width: calc(var(--widest) * var(--frame-full) + (var(--widest) - 1) * var(--frame-gap));
  gap: calc(0.25 * var(--mac-inch));
}

.album-frame .album-row {
  --frame: min(var(--frame-full), (100% - (var(--cols) - 1) * var(--frame-gap)) / var(--cols));
  grid-template-columns: repeat(var(--cols, 1), var(--frame));
  justify-content: center;
  gap: calc(0.25 * var(--mac-inch)) var(--frame-gap);
}

/* A photo well off the frame's shape shrinks to fit inside it, uncropped: a
   landscape in a portrait frame is as wide as the frame, a portrait in a
   square frame as tall. The img box stays as wide as the frame, and contain
   centres the photo in it. The figure is a container so cqw can measure the
   frame's width here, where 100% would mean the figure's height instead. */
.album-frame .album-photo {
  container-type: inline-size;
}

.album-frame .album-photo img {
  max-height: calc(100cqw * var(--frame-h) / var(--frame-w));
  object-fit: contain;
}

/* A near miss (trim.js, within 5%) fills the frame exactly, losing a sliver
   off two edges, so its edges line up with its neighbours'. */
.album-frame .album-photo-trim img {
  aspect-ratio: var(--frame-w) / var(--frame-h);
  object-fit: cover;
}

/* width: in album.yaml. Every row is exactly --across frames wide (plus the
   gaps between them), and its photos split that width evenly, near misses at
   the frame's shape and the rest at their own, so the edges of every row line
   up: a lone landscape is as wide as a pair of portraits, or a pair shares
   one frame's width. Photos can come out taller than the frame. */
.album-fill {
  max-width: calc(var(--across) * var(--frame-full) + (var(--across) - 1) * var(--frame-gap));
}

.album-fill .album-row {
  grid-template-columns: repeat(var(--cols, 1), 1fr);
}

.album-fill .album-photo img {
  max-height: none;
}

@media (max-width: 32rem) {
  .album-frame .album-row {
    --frame: min(var(--frame-full), 100%);
    grid-template-columns: var(--frame);
  }
}
