/* ==========================================
   1. IMAGE UTILITY ATOMS
   ========================================== */
.round, .round75, .round50 {
    border-radius: 50%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    max-width: var(--max-width, 100%);
}
.round75 { --max-width: 75%; }
.round50 { --max-width: 50%; }

.roundedcorners {
    border-radius: 15px;
}

/* Shared oval image base */
.oval-wide,
.oval-tall,
.oval-wide-4-3,
.oval-tall-3-4 {
    border-radius: 50%;
    object-fit: cover;
    object-position: center 20%; /* Keeps faces/heads from being cropped at the top */
}

/* Aspect ratio modifiers */
.oval-wide     { aspect-ratio: 3 / 2; }
.oval-tall     { aspect-ratio: 2 / 3; }
.oval-wide-4-3 { aspect-ratio: 4 / 3; }
.oval-tall-3-4 { aspect-ratio: 3 / 4; }


/* ==========================================
   2. CORE CONTAINER VARIABLES & ENGINES
   ========================================== */
:root {
    --main-scale: 1; /* Decreases from 1 down to 0.2 */
}

.gallery-item, 
.gallery-item-f, 
.gallery-item-s, 
.gallery-item-l,
.gallery-item-ls {
    position: relative;
    display: block;
    height: auto;
    margin-inline: auto;
    width: var(--item-width, 100%);
}

.gallery-item, 
.gallery-item-l,
.gallery-item-ls {
    cursor: pointer;
    transition: transform 0.35s ease, box-shadow 0.35s ease;
    /* Removed z-index: 0 to prevent unnecessary stacking contexts */
}

.gallery-item {
    transform: scale(var(--main-scale, 1));
}

/* Default item widths (for standalone use outside grids) */
.gallery-item-f  { --item-width: calc(90% - 10px); }
.gallery-item-s  { --item-width: calc(50% - 10px); }
.gallery-item-ls { --item-width: calc(50% - 10px); }

/* Let grid containers control image width cleanly */
.Cards2 img, .Cards3 img, .Cards4 img, .Cards5 img {
    --item-width: 100%;
    margin: 0;
}

/* Ensure popouts aren't clipped by ANY grid container */
.Cards2, .Cards3, .Cards4, .Cards5 {
    overflow: visible;
}
/* Center popout display properties */
.popout {
    position: fixed;
    top: 50%;
    left: 40%;
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
    visibility: hidden; /* Guarantees it is hidden on load */
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    z-index: 9999;
    /* Force the popout to respect the image's natural portrait or landscape shape */
    width: auto !important;
    height: auto !important;
    aspect-ratio: auto !important;
    object-fit: contain;

    /* Limit size to 2x thumbnail width while keeping tall portrait images on-screen */
    max-width: min(90vw, calc(var(--thumb-width, 300px) * 2));
    max-height: 85vh;

    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border-radius: 8px;
}

@media (hover: hover) {
    .gallery-item:hover + .popout,
    .gallery-item-ls:hover + .popout {
        opacity: 1;
        visibility: visible;
        transform: translate(-50%, -50%) scale(1);
    }
}


/* ==========================================
   3. HOVER ACTIONS & CENTER POPOUT SYSTEMS
   ========================================== */
@media (hover: hover) {
    .gallery-item:hover {
        transform: scale(calc(2 - var(--main-scale, 1)));
        z-index: 10;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    }

    .gallery-item-l:hover,
    .gallery-item-ls:hover {
        transform: scale(1.45);
        z-index: 10;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    }
}

/* Combined media queries: prevents tablet touch leak & avoids CSS nesting */
@media (hover: hover) and (min-width: 768px) {
    .gallery-item-ls:hover { 
        transform: scale(1.75); 
    }
}

@media (hover: hover) and (min-width: 1200px) {
    .gallery-item-ls:hover { 
        transform: scale(1.5); 
    }

    /* Apply 4-col edge protection ONLY when the grid is actually 4 columns wide */
    .Cards4 > *:nth-child(4n + 1) .gallery-item-ls:hover,
    .Cards4 > .gallery-item-ls:nth-child(4n + 1):hover {
        transform-origin: left center;
    }

    .Cards4 > *:nth-child(4n) .gallery-item-ls:hover,
    .Cards4 > .gallery-item-ls:nth-child(4n):hover {
        transform-origin: right center;
    }
}

/* ==========================================
   5. BREAKPOINT RESPONSIVENESS
   ========================================== */
@media screen and (max-width: 768px) {
    .gallery-item { --item-width: calc(50% - 20px); }
}

@media screen and (max-width: 480px) {
    .gallery-item { --item-width: calc(100% - 20px); }
}
