/* ==========================================================================
   Stand alone gallery (single projects)
   Sizes itself from its own width (container queries), so it works inside
   any column or container the template puts it in.
   ========================================================================== */

.csg {
    /* Same gaps and side padding as the existing project gallery */
    --csg-gap: 60px;
    container-type: inline-size;
    padding: 0 var(--xm, 8%) var(--ym, 4%);
}

@media (max-width: 1200px) {
    .csg { --csg-gap: 40px; }
}

@media (max-width: 767.98px) {
    .csg { --csg-gap: 20px; }
}

.csg__grid {
    display: grid;
    gap: var(--csg-gap);
}

.csg__item {
    display: block;
    position: relative;
    overflow: hidden;
}

.csg__img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    transition: transform 0.6s ease;
}

a.csg__item:hover .csg__img,
a.csg__item:focus-visible .csg__img {
    transform: scale(1.04);
}

a.csg__item:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* ---------- Square grid ---------- */

.csg--square .csg__item       { aspect-ratio: 1 / 1; }
.csg--cols-2 .csg__grid       { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.csg--cols-3 .csg__grid       { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.csg--cols-4 .csg__grid       { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@container (max-width: 900px) {
    .csg--cols-4 .csg__grid   { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@container (max-width: 600px) {
    .csg--cols-3 .csg__grid,
    .csg--cols-4 .csg__grid   { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Mosaic ----------
   Rows are exactly one column wide, so small tiles are square and
   big tiles (2x2) are square too. */

.csg--mosaic .csg__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: calc((100cqw - 3 * var(--csg-gap)) / 4);
    grid-auto-flow: dense;
}

.csg--mosaic .csg__item--big       { grid-column: span 2; grid-row: span 2; }
.csg--mosaic .csg__item--big-right { grid-column: 3 / span 2; grid-row: span 2; }
.csg--mosaic .csg__item--wide      { grid-column: span 2; }
.csg--mosaic .csg__item--pano      { grid-column: span 4; grid-row: span 2; }

@container (max-width: 600px) {
    .csg--mosaic .csg__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: calc((100cqw - var(--csg-gap)) / 2);
    }
    .csg--mosaic .csg__item--big-right { grid-column: span 2; }
    .csg--mosaic .csg__item--pano      { grid-column: span 2; grid-row: span 1; }
}

/* ---------- Lightbox ---------- */

.csg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 70px;
    background: rgba(0, 0, 0, 0.92);
    opacity: 0;
    visibility: hidden;
    /* Hide only after the fade-out finishes... */
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}

.csg-lightbox.is-open {
    opacity: 1;
    visibility: visible;
    /* ...but become visible (and focusable) straight away when opening. */
    transition: opacity 0.25s ease, visibility 0s;
}

.csg-lightbox__figure {
    margin: 0;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.csg-lightbox__img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 160px);
    width: auto;
    height: auto;
    object-fit: contain;
}

.csg-lightbox__caption {
    margin-top: 12px;
    color: #ddd;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
}

.csg-lightbox__counter {
    position: absolute;
    top: 20px;
    left: 24px;
    color: #aaa;
    font-size: 13px;
    letter-spacing: 0.05em;
}

.csg-lightbox__btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease;
}

.csg-lightbox__btn:hover,
.csg-lightbox__btn:focus-visible {
    background: rgba(255, 255, 255, 0.2);
}

.csg-lightbox__btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.csg-lightbox__btn svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.csg-lightbox__close { top: 12px; right: 12px; }
.csg-lightbox__prev  { left: 12px; top: 50%; transform: translateY(-50%); }
.csg-lightbox__next  { right: 12px; top: 50%; transform: translateY(-50%); }

.csg-lightbox--single .csg-lightbox__prev,
.csg-lightbox--single .csg-lightbox__next,
.csg-lightbox--single .csg-lightbox__counter {
    display: none;
}

body.csg-lightbox-open {
    overflow: hidden;
}

@media (max-width: 600px) {
    .csg-lightbox          { padding: 60px 10px; }
    .csg-lightbox__prev,
    .csg-lightbox__next    { top: auto; bottom: 12px; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .csg__img,
    .csg-lightbox          { transition: none; }
}
