/**
 * GalleryKit – the galleries on the site.
 * @copyright (C) 2026 Thrane.nu
 * @license   GNU General Public License version 2 or later; see LICENSE.txt
 *
 * Every size comes from CSS variables set on .gk by the gallery's settings. A template (T4, Cassiopeia …) can set its
 * own, e.g. `.gk { --gk-gap: 1rem; --gk-radius: var(--border-radius); }` – values from the template win when they are
 * set on a more specific selector or with !important. Columns follow the gallery's own width (container queries),
 * so a gallery in a narrow column or module gets the phone or tablet columns by itself.
 */

.gk {
    --gk-cols: 4;
    --gk-cols-t: 3;
    --gk-cols-m: 2;
    --gk-gap: 8px;
    --gk-radius: 0px;
    --gk-row: 240px;
    --gk-ratio: 1/1;
    --gk-placeholder: rgba(127, 127, 127, .15);
    --gk-overlay-bg: linear-gradient(to top, rgba(0, 0, 0, .72), rgba(0, 0, 0, 0));
    --gk-overlay-color: #fff;
    --gk-focus: currentColor;
    container-type: inline-size;
    margin-block: 0 1.5rem;
}

.gk-items {
    --gk-c: var(--gk-cols);
    --gk-r: var(--gk-row);
}

@container (max-width: 767px) {
    .gk-items {
        --gk-c: var(--gk-cols-t);
        --gk-r: calc(var(--gk-row) * .85);
    }
}

@container (max-width: 479px) {
    .gk-items {
        --gk-c: var(--gk-cols-m);
        --gk-r: calc(var(--gk-row) * .75);
    }
}

.gk-item {
    position: relative;
    margin: 0;
    min-width: 0;
}

.gk-item[hidden] {
    display: none !important;
}

.gk-link {
    display: block;
    position: relative;
    color: inherit;
    text-decoration: none;
    border-radius: var(--gk-radius);
}

.gk-link:focus-visible {
    outline: 3px solid var(--gk-focus);
    outline-offset: 2px;
}

/* Back from the lightbox after a click or a tap: the picture has the focus, but no ring (gallerykit.js). */
.gk .gk-link.gk-quiet:focus,
.gk .gk-link.gk-quiet:focus-visible {
    outline: none;
    box-shadow: none;
}

.gk-media {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: var(--gk-radius);
    background-color: var(--gk-placeholder);
    background-size: cover;
    background-position: center;
}

/* The picture fills the box exactly: placed absolutely, so its size never depends on a percentage height against a box
   that only has an aspect-ratio (every .gk-media has one: the grid's crop or the picture's own shape). `.gk` in front
   so a template's content rule such as `.content img { height: auto }` (same weight, loaded later) cannot win – that gave
   a 167×598 picture in a 222×222 box on a live site. */
.gk .gk-media img {
    display: block;
    position: absolute;
    inset: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    transition: transform .4s ease, opacity .3s ease;
}

/* Grid: the same crop for every picture; the focus point (object-position) decides what stays in view. */
.gk--grid .gk-items {
    display: grid;
    grid-template-columns: repeat(var(--gk-c), minmax(0, 1fr));
    gap: var(--gk-gap);
}

.gk--grid .gk-media {
    aspect-ratio: var(--gk-ratio);
}

/* Masonry: CSS columns, every picture in its own shape. */
.gk--masonry .gk-items {
    column-count: var(--gk-c);
    column-gap: var(--gk-gap);
}

.gk--masonry .gk-item {
    break-inside: avoid;
    margin-bottom: var(--gk-gap);
}

/* Justified: rows of the same height that fill the width. Each picture grows by its own width/height ratio (--gk-ar),
   so all pictures in a row get the same height; the last row keeps the row height. No script needed. */
.gk--justified .gk-items {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gk-gap);
}

.gk--justified .gk-items::after {
    content: "";
    flex-grow: 999999;
}

.gk--justified .gk-item {
    flex: var(--gk-ar, 1.5) 1 calc(var(--gk-ar, 1.5) * var(--gk-r));
    max-width: 100%;
}

/* Picture fit "whole picture" (product pictures): nothing is cut off. The picture sits inside the box with the chosen
   inner space (--gk-fit-pad, % of the box's width or px) on the chosen background (--gk-fit-bg; none = the page shows through).
   A template can set its own, e.g. `.gk--fit-contain { --gk-fit-bg: #fff; }`. */
.gk--fit-contain .gk-media {
    background-color: var(--gk-fit-bg, transparent);
    background-image: none;
}

/* The inner space is padding on the picture itself: object-fit draws the picture inside the padding, and a % padding
   is measured on the box's width. */
.gk--fit-contain .gk-media img {
    padding: var(--gk-fit-pad, 0);
    object-fit: contain;
}

/* Hover */
@media (hover: hover) {
    .gk--hover-zoom .gk-link:hover .gk-media img {
        transform: scale(1.05);
    }

    .gk--hover-fade .gk-link:hover .gk-media img {
        opacity: .8;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gk .gk-media img {
        transition: none;
    }

    .gk--hover-zoom .gk-link:hover .gk-media img {
        transform: none;
    }
}

/* A gallery in Joomla's list of custom fields: no bullet in front of it. */
.field-entry:has(> .field-value > .gk) {
    list-style: none;
}

/* Captions */
/* Reset what templates give every figcaption (T4: dark band, capitals) – the caption follows the page's text. */
.gk .gk-caption {
    margin: .35em 0 0;
    padding: 0;
    background: none;
    color: inherit;
    font-size: .875em;
    line-height: 1.35;
    letter-spacing: normal;
    text-align: start;
    text-transform: none;
    text-shadow: none;
}

.gk-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 2em .75em .6em;
    font-size: .875em;
    line-height: 1.35;
    color: var(--gk-overlay-color);
    background: var(--gk-overlay-bg);
    border-radius: 0 0 var(--gk-radius) var(--gk-radius);
    pointer-events: none;
    overflow-wrap: anywhere;
}

/* Show more */
.gk-more-wrap {
    display: flex;
    justify-content: center;
    margin-top: calc(var(--gk-gap) + 1rem);
}

.gk-more:not(.btn) {
    padding: .5em 1.25em;
    border: 1px solid currentColor;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

/* Lightbox: caption and credit at the bottom (PhotoSwipe draws the rest). */
.pswp__gk-caption {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 100%;
    max-width: 52rem;
    padding: 1.5rem 1rem 1rem;
    color: #fff;
    font-size: .95rem;
    line-height: 1.4;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
    pointer-events: none;
}

.pswp__gk-caption:empty {
    display: none;
}

.pswp__gk-caption strong {
    display: block;
}

.pswp__gk-caption small {
    display: block;
    margin-top: .25rem;
    opacity: .8;
}

/* The category page: galleries as cards with their cover. */
/*
 * Cards (category page, module "Latest galleries"). The columns follow the width of the space the cards are in.
 * Two styles: .gk-cards--below (text under the picture) and .gk-cards--overlay (text on the picture over a dark fade).
 * --gk-card-ratio is a minimum: a card grows when its text needs more room.
 */
.gk-cards {
    --gk-card-cols: 3;
    --gk-card-cols-t: 2;
    --gk-card-cols-m: 1;
    --gk-card-ratio: 4/3;
    --gk-card-gap: 1.5rem;
    --gk-card-radius: var(--gk-radius, 0px);
    --gk-card-placeholder: rgba(127, 127, 127, .15);
    --gk-card-overlay-bg: linear-gradient(to top, rgba(0, 0, 0, .78) 0%, rgba(0, 0, 0, .45) 45%, rgba(0, 0, 0, 0) 75%);
    --gk-card-overlay-color: #fff;
    --gk-card-focus: currentColor;
    container-type: inline-size;
    margin-block: 0 1.5rem;
}

.gk-cards__list {
    --gk-c: var(--gk-card-cols);
    display: grid;
    grid-template-columns: repeat(var(--gk-c), minmax(0, 1fr));
    gap: var(--gk-card-gap);
}

@container (max-width: 767px) {
    .gk-cards__list {
        --gk-c: var(--gk-card-cols-t);
    }
}

@container (max-width: 479px) {
    .gk-cards__list {
        --gk-c: var(--gk-card-cols-m);
    }
}

.gk-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-radius: var(--gk-card-radius);
}

.gk-card__media {
    display: block;
    position: relative;
    overflow: hidden;
    aspect-ratio: var(--gk-card-ratio);
    border-radius: var(--gk-card-radius);
    background-color: var(--gk-card-placeholder);
    background-size: cover;
    background-position: center;
}

/* Placed absolutely like .gk-media img, and with `.gk-cards` in front so a template's `img { height: auto }` rule cannot win. */
.gk-cards .gk-card__media img {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .4s ease;
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .gk-card:hover .gk-card__media img {
        transform: scale(1.04);
    }
}

/* The title's own look: the template's heading font, size and capitals are not used. */
.gk-cards .gk-card__title {
    margin: .6rem 0 .15rem;
    padding: 0;
    font-family: inherit;
    font-size: 1.125rem;
    font-weight: 600;
    font-style: normal;
    line-height: 1.3;
    letter-spacing: normal;
    text-transform: none;
    color: inherit;
}

.gk-cards .gk-card__link {
    color: inherit;
    text-decoration: none;
}

/* The whole card is the link. */
.gk-cards .gk-card__link::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--gk-card-radius);
}

/* No ring or shadow on the link itself (also not from the template), and nothing moves when it is clicked. */
.gk-cards .gk-card__link:focus,
.gk-cards .gk-card__link:active {
    outline: 0;
    box-shadow: none;
}

/* The ring is on the card – only for the keyboard (:focus-visible), never after a mouse click. */
.gk-card:has(.gk-card__link:focus-visible) {
    outline: 3px solid var(--gk-card-focus);
    outline-offset: 4px;
}

@media (hover: hover) {
    .gk-cards--below .gk-card:hover .gk-card__link {
        text-decoration: underline;
        text-underline-offset: .15em;
    }
}

.gk-card__count {
    margin: 0;
    font-size: .875em;
    opacity: .75;
}

.gk-card__desc {
    margin: .35rem 0 0;
    font-size: .9375em;
}

/* Overlay: the picture fills the card, the text sits at the bottom. */
.gk-cards--overlay .gk-card {
    display: grid;
    grid-template-areas: "card";
    align-items: end;
    /* Every card in a row as tall as the tallest (a long title makes one grow), never lower than the ratio. */
    align-self: stretch;
    justify-self: stretch;
    aspect-ratio: var(--gk-card-ratio);
    color: var(--gk-card-overlay-color);
}

.gk-cards--overlay .gk-card__media {
    grid-area: card;
    align-self: stretch;
    justify-self: stretch;
    aspect-ratio: auto;
    height: 100%;
    min-height: 0;
}

.gk-cards--overlay .gk-card__body {
    grid-area: card;
    /* Not positioned: the title link's ::after must cover the whole card, not only the text. */
    padding: 3rem 1rem .9rem;
    background: var(--gk-card-overlay-bg);
    border-radius: 0 0 var(--gk-card-radius) var(--gk-card-radius);
}

.gk-cards--overlay .gk-card__title {
    margin-top: 0;
}

.gk-cards--overlay .gk-card__count {
    opacity: .85;
}

.gk-cards--overlay .gk-card:has(.gk-card__link:focus-visible) {
    outline-color: var(--gk-card-focus);
}

.gk-subcats {
    margin-block: 0 1.5rem;
}
