/* --- Masonry Grid --- */
.container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    grid-auto-rows: 4px; /* base row height for masonry math */
    gap: 16px;
    align-items: start;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.35s ease;
    max-width: 1400px;
    margin: 0 auto;
}

.container.is-ready {
    opacity: 1;
}

figure {
    margin: 0;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.container.is-ready figure {
    opacity: 1;
    transform: translateY(0);
}

.container img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
    cursor: pointer;
}

figcaption {
    padding-top: 8px;
    font-size: 14px;
    word-wrap: anywhere;
    color: var(--text-main);
}

figcaption a {
    color: inherit;
    text-decoration: none;
    opacity: 0.8;
    transition: opacity 0.2s;
}

figcaption a:hover {
    opacity: 1;
    text-decoration: underline;
}

@media screen and (max-width: 1100px) {
    .container { grid-template-columns: repeat(2, 1fr); }
}

@media screen and (max-width: 750px) {
    .container { grid-template-columns: repeat(1, 1fr); padding: 10px; }
}

/* --- Lightbox --- */
#fullpage {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: #000;
    z-index: 99;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

@media screen and (max-width: 750px) {
    #fullpage { height: 100dvh; }
}

#lightbox-img {
    max-width: 95%;
    max-height: 100vh;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#lightbox-loader {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #ffffff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    position: absolute;
    z-index: -1;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Lightbox Controls */
#fullpage button {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 10000;
}

#fullpage button:hover {
    background: rgba(255, 255, 255, 0.3);
}

#close-btn { top: 20px; right: 20px; width: 40px; height: 40px; }
#prev-btn { left: 15px; top: 0; bottom: 0; margin: auto 0; width: 40px; height: 40px; border-radius: 8px;}
#next-btn { right: 20px; top: 0; bottom: 0; margin: auto 0; width: 40px; height: 40px; border-radius: 8px;}

#lightbox-counter {
    position: absolute;
    top: 30px;
    right: 70px;
    color: #eee;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    pointer-events: none;
}