:root {
    --gallery-left-outline: calc(100vw * 208 / 1920); /* 13rem @1920 */
    --gallery-spacing: calc(100vw * 48 / 1920); /* 3rem @1920 */
}

.portfolioGallerySection {
    padding-bottom: var(--gallery-left-outline);

    .row {
        text-align: center;
        padding: 0 var(--gallery-left-outline);

        /* Shared: every image keeps its own ratio, no cropping */
        .photo {
            display: block;
            min-width: 0;
            height: auto;
        }

        /* Equal-height rows: flex-grow = ratio */
        .image-row.default {
            display: flex;
            flex-direction: row;
            align-items: flex-start;
            gap: var(--gallery-spacing);

            .photo {
                flex: var(--ar, 1) 1 0;
            }
        }

        .image-row.split.rows-and-grid {
            align-items: stretch; /* needs to be a loose thing to ovverride the other css rule, applied in split */
        }

        .rows-and-grid {
            .horizontal-stack {
                flex: 1 1 0;
                min-width: 0;
                display: flex;
                flex-direction: column;
                gap: var(--gallery-spacing);

                .photo {
                    width: 100%;
                }
            }

            .grid-vertical {
                flex: var(--k, 1) 1 calc(var(--gallery-spacing) * (1 + var(--ar, 1)));
                min-width: 0;
                display: grid;
                grid-template-columns: 1fr 1fr;
                align-items: start; /* images keep their own height */
                align-content: space-between; /* extra height goes between the rows */
                column-gap: var(--gallery-spacing);
                row-gap: var(--gallery-spacing); /* minimum row gap */

                .photo {
                    width: 100%;
                }
            }
        }

        .image-row.split {
            display: flex;
            flex-direction: row;
            align-items: flex-start;
            gap: var(--gallery-spacing);

            /* wrappers vanish so images become direct flex children */
            .row-2,
            .vertical,
            .horizontal-photo {
                display: contents;
            }

            .row-2 .photo,
            .vertical .photo,
            .horizontal-photo .photo {
                flex: var(--ar, 1) 1 0;
            }

            /* 2x2 grid + large photo */
            .grid-2x2 {
                /* basis = the gap's share, so grid height equals large photo height */
                flex: var(--ar, 1) 1
                calc(var(--gallery-spacing) * (1 - var(--ar, 1)));
                min-width: 0;
                display: grid;
                grid-template-columns: 1fr 1fr;
                align-items: start;
                gap: var(--gallery-spacing);

                .photo {
                width: 100%;
                }
            }

            .single-photo {
                flex: var(--ar, 1) 1 0;
                min-width: 0;

                .photo {
                width: 100%;
                }
            }
        }

        .image-row.split.flipped {
        flex-direction: row-reverse;
        }

        .image-row:not(:last-child) {
        padding-bottom: var(--gallery-spacing);
        }
    }

    .row.text-container.head {
        padding: 2rem 0;
    }

    .row.text-container.middle {
        padding: var(--gallery-left-outline) 0 0 0;
    }
}

#main > section.portfolioGallerySection.no-bottom-margins {
    margin-bottom: 0;
}

#main > section.portfolioGallerySection.no-top-margins {
    margin-top: 0;
}