/* ============================================================
   grid-gallery / style.css
   All gallery-specific styles. Assumes ../../assets/theme.css
   is loaded first (or that its CSS custom properties exist).
   ============================================================ */

/* ----------------------------------------------------------
   Grid container
   ---------------------------------------------------------- */

.gg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    padding: 0 20px 60px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ----------------------------------------------------------
   Cell — the slot that stays in the grid flow always.
   position:relative is the anchor for the popped image.
   The aspect ratio box trick: inner div with padding-bottom.
   ---------------------------------------------------------- */

.gg-cell {
    position: relative;
    aspect-ratio: 4 / 3;
    border-radius: var(--fc-radius-md);
    /* Keeps the slot visible as a ghost when image is popped */
    background: var(--fc-surface-2);
    overflow: visible; /* allow child to escape */
}

/* ----------------------------------------------------------
   Image wrapper — sits inside the cell, normally fills it.
   On hover it escapes via absolute positioning tricks:
   we leave it in-flow by using position:absolute relative
   to the cell, but we expand its size and z-index upward.
   The wrapper IS the thing that pops and tilts.
   ---------------------------------------------------------- */

.gg-img-wrap {
    position: absolute;
    inset: 0;
    border-radius: var(--fc-radius-md);
    overflow: hidden;
    cursor: pointer;
    will-change: transform;

    /* Smooth snap-back when mouse leaves */
    transition:
        transform 0.45s cubic-bezier(0.23, 1, 0.32, 1),
        box-shadow 0.45s cubic-bezier(0.23, 1, 0.32, 1),
        border-radius 0.3s ease;

    z-index: 0;
}

.gg-img-wrap img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Slight zoom-in on hover via img scale, independent of wrap transform */
    transition: transform 0.45s cubic-bezier(0.23, 1, 0.32, 1),
                filter 0.3s ease;
    transform-origin: center center;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* ----------------------------------------------------------
   Popped state — applied via JS when mouse enters cell.
   The wrapper expands beyond the cell boundary using negative
   margins and a larger size. The cell ghost remains in flow.
   ---------------------------------------------------------- */

.gg-img-wrap.is-popped {
    position: absolute;
    inset: -15%;
    border-radius: 10px;
    overflow: hidden;
    z-index: 100;
    clip-path: none; /* let border-radius + overflow handle clipping */

    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 0 0 1px var(--fc-green-border),
        0 0 40px rgba(74, 222, 128, 0.08);
}

.gg-img-wrap.is-popped img {
    width: 100%;
    height: 100%;
    border-radius: 10px;
    transform: scale(1);
}

/* ----------------------------------------------------------
   Caption overlay — fades in when popped
   ---------------------------------------------------------- */

.gg-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 14px 12px;
    background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
    border-radius: 0 0 10px 10px;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.gg-img-wrap.is-popped .gg-caption {
    opacity: 1;
}

.gg-caption-title {
    display: block;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    color: var(--fc-text);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gg-caption-cat {
    display: block;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.65rem;
    color: var(--fc-green-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 3px;
}

/* ----------------------------------------------------------
   Page header area
   ---------------------------------------------------------- */

.gg-header {
    padding: 48px 20px 36px;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: baseline;
    gap: 24px;
    flex-wrap: wrap;
}

.gg-count {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    color: var(--fc-text-muted);
    letter-spacing: 0.05em;
}

/* ----------------------------------------------------------
   Loading / error states
   ---------------------------------------------------------- */

.gg-state {
    padding: 80px 20px;
    text-align: center;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.85rem;
    color: var(--fc-text-muted);
    letter-spacing: 0.05em;
}

.gg-state-err {
    color: #f87171;
}

/* ----------------------------------------------------------
   Skeleton pulse while loading
   ---------------------------------------------------------- */

.gg-cell-skeleton {
    background: linear-gradient(
        90deg,
        var(--fc-surface-2) 25%,
        var(--fc-surface-3) 50%,
        var(--fc-surface-2) 75%
    );
    background-size: 200% 100%;
    animation: gg-pulse 1.6s ease-in-out infinite;
    border-radius: var(--fc-radius-md);
    aspect-ratio: 4 / 3;
}

@keyframes gg-pulse {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Stagger the skeleton cells slightly */
.gg-cell-skeleton:nth-child(2) { animation-delay: 0.1s; }
.gg-cell-skeleton:nth-child(3) { animation-delay: 0.2s; }
.gg-cell-skeleton:nth-child(4) { animation-delay: 0.3s; }
.gg-cell-skeleton:nth-child(5) { animation-delay: 0.4s; }
.gg-cell-skeleton:nth-child(6) { animation-delay: 0.5s; }

/* ----------------------------------------------------------
   Responsive — tighter columns on small screens
   ---------------------------------------------------------- */

@media (max-width: 600px) {
    .gg-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
        padding: 0 12px 40px;
    }

    .gg-header {
        padding: 32px 12px 24px;
    }

    /* No popout on touch — just show caption on tap */
    .gg-img-wrap {
        overflow: hidden;
    }

    .gg-img-wrap.is-popped {
        inset: 0;
        box-shadow: none;
        z-index: 0;
    }
}
