/* The gallery's mosaic view (the Mosaic button of /media), loaded through
   the layout.head hook after the features' stylesheets. See viewer.py.

   splent_feature_media draws it with CSS columns: every photo one column
   wide, ordered down each column (not the order the viewer walks through)
   and reshuffled between columns whenever infinite scroll adds a page.
   Here it is a grid where some photos take two columns and two rows, or
   two columns, on a fixed pattern by position. The pattern tiles the grid
   with no gaps, so the photos read left to right, row by row, in the same
   order as the viewer, and a new page carries the pattern on. Fixed rather
   than random: the page looks the same on every visit.

   4 columns, 16 photos per round:   3 columns, 12 per round:
     A A 2 3                           A A 2
     A A 4 5                           A A 3
     B B 7 8                           4 5 6
     9 10 C C                          7 B B
     12 13 C C                         9 B B
     14 15 D D                         10 11 12
   2 columns: one photo across the whole width, then four in pairs. */

.gallery-grid.gallery-grid--mosaic {
    display: grid;
    column-count: auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-flow: row dense;
    gap: .75rem;
}

.gallery-grid--mosaic .gallery-grid__item {
    position: relative;
    margin: 0;
    aspect-ratio: 4 / 3;
    height: auto;
}

/* Out of the flow, the photo sets no height of its own: the tile's
   proportions (or, for a spanning tile, its rows) do. That also drops the
   strip an inline image leaves under itself for the text baseline. */
.gallery-grid--mosaic .gallery-grid__item img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* A tile that spans drops its own proportions and takes the height of
   the rows the other photos set. */
@media (min-width: 901px) {
    .gallery-grid--mosaic .gallery-grid__item:nth-child(16n + 1),
    .gallery-grid--mosaic .gallery-grid__item:nth-child(16n + 11) {
        grid-column: span 2;
        grid-row: span 2;
        aspect-ratio: auto;
    }
    .gallery-grid--mosaic .gallery-grid__item:nth-child(16n + 6),
    .gallery-grid--mosaic .gallery-grid__item:nth-child(16n + 16) {
        grid-column: span 2;
        aspect-ratio: auto;
    }
}

@media (min-width: 521px) and (max-width: 900px) {
    .gallery-grid.gallery-grid--mosaic { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .gallery-grid--mosaic .gallery-grid__item:nth-child(12n + 1),
    .gallery-grid--mosaic .gallery-grid__item:nth-child(12n + 8) {
        grid-column: span 2;
        grid-row: span 2;
        aspect-ratio: auto;
    }
}

@media (max-width: 520px) {
    .gallery-grid.gallery-grid--mosaic {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .5rem;
    }
    .gallery-grid--mosaic .gallery-grid__item:nth-child(5n + 1) {
        grid-column: 1 / -1;
        aspect-ratio: 16 / 9;
    }
}
