/* Pictures typed into a page (slms/utils/image_grids.py): photo grids that open full size,
   logo tiles, and album cards. Loaded by public/custom_page.html only when the page has one.
   The photo viewer is page-gallery.js. */

.cp-content .cp-gallery {
    display: grid;
    gap: 0.5rem;
    margin: 1.25rem 0 1.75rem;
}

/* Photos: square thumbnails, as many a row as fit (three on a phone). */
.cp-content .cp-gallery--photos {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 7rem), 1fr));
}

.cp-content .cp-gallery__item {
    position: relative;
    display: block;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: calc(var(--cp-r) * 0.6);
    background: color-mix(in srgb, var(--cp-primary) 6%, var(--cp-surface));
}

.cp-content .cp-gallery--photos .cp-gallery__item {
    aspect-ratio: 1;
    cursor: zoom-in;
}

.cp-content .cp-gallery__item img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    border-radius: 0;
}

.cp-content .cp-gallery--photos .cp-gallery__item img {
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cp-content .cp-gallery--photos .cp-gallery__item:hover img { transform: scale(1.04); }
.cp-content .cp-gallery--photos .cp-gallery__item:focus-visible {
    outline: 3px solid var(--cp-accent);
    outline-offset: 2px;
}

/* Logos: even tiles, each logo shown whole. */
.cp-content .cp-gallery--logos {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr));
    gap: 0.75rem;
}

.cp-content .cp-gallery--logos .cp-gallery__item {
    aspect-ratio: 5 / 3;
    padding: 0.6rem;
    border: 1px solid var(--cp-border);
    background: var(--cp-surface);
}

.cp-content .cp-gallery--logos .cp-gallery__item img { object-fit: contain; }

.cp-content .cp-gallery__item--link > a {
    display: block;
    width: 100%;
    height: 100%;
}

.cp-content .cp-gallery__item--link {
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.cp-content .cp-gallery__item--link:hover,
.cp-content .cp-gallery__item--link:focus-within {
    border-color: color-mix(in srgb, var(--cp-accent) 50%, var(--cp-border));
    transform: translateY(-1px);
}

/* Albums: a cover and the album's name, the whole card one link. */
.cp-content .cp-albums {
    list-style: none;
    margin: 1.25rem 0 1.75rem;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
    gap: 1rem;
}

.cp-content .cp-album {
    position: relative;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--cp-border);
    border-radius: var(--slms-card-radius, var(--cp-r));
    background: var(--cp-surface);
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.cp-content .cp-album:hover,
.cp-content .cp-album:focus-within {
    border-color: color-mix(in srgb, var(--cp-accent) 50%, var(--cp-border));
    transform: translateY(-2px);
}

.cp-content .cp-album__photo {
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: color-mix(in srgb, var(--cp-primary) 6%, var(--cp-surface));
}

.cp-content .cp-album__photo a { display: block; width: 100%; height: 100%; }

.cp-content .cp-album__photo img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    border-radius: 0;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cp-content .cp-album:hover .cp-album__photo img { transform: scale(1.04); }

.cp-content .cp-album > :is(h2, h3, h4, h5, h6) {
    margin: 0;
    padding: 0.8rem 1rem 0.95rem;
    font-size: 1.05rem;
    line-height: 1.3;
}

.cp-content .cp-album > :is(h2, h3, h4, h5, h6) a {
    color: var(--cp-heading);
    text-decoration: none;
}

/* The album's name stretches over the whole card, so the card is one target. */
.cp-content .cp-album > :is(h2, h3, h4, h5, h6) a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.cp-content .cp-album > :is(h2, h3, h4, h5, h6) a:focus-visible {
    outline: none;
}

.cp-content .cp-album > :is(h2, h3, h4, h5, h6) a:focus-visible::after {
    border-radius: inherit;
    box-shadow: inset 0 0 0 3px var(--cp-accent);
}

@media (max-width: 575.98px) {
    .cp-content .cp-gallery--photos { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.35rem; }
    .cp-content .cp-gallery--logos { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
    .cp-content .cp-albums { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
    .cp-content .cp-album > :is(h2, h3, h4, h5, h6) { padding: 0.6rem 0.7rem 0.75rem; font-size: 0.92rem; }
}

/* The photo viewer. */
.cp-lightbox {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    /* Near black whatever the league's colours, as a photo needs. */
    background: color-mix(in srgb, var(--slms-heading) 30%, black);
    color: white;
}

.cp-lightbox::backdrop { background: transparent; }

.cp-lightbox__frame {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
}

.cp-lightbox__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.9rem;
}

.cp-lightbox__stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    touch-action: pan-y;
}

.cp-lightbox__stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.cp-lightbox__caption {
    margin: 0.5rem 0 0;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.85;
}

.cp-lightbox button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
    border-radius: 50%;
    background: color-mix(in srgb, currentColor 10%, transparent);
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
}

.cp-lightbox button:hover,
.cp-lightbox button:focus-visible { background: color-mix(in srgb, currentColor 22%, transparent); }

.cp-lightbox__prev,
.cp-lightbox__next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.cp-lightbox__prev { left: 0.25rem; }
.cp-lightbox__next { right: 0.25rem; }

@media (prefers-reduced-motion: reduce) {
    .cp-content .cp-gallery__item img,
    .cp-content .cp-album__photo img,
    .cp-content .cp-album,
    .cp-content .cp-gallery__item--link { transition: none; }
}
