/* CSS Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light mode colors (default) */
    --bg-color: #f5f5f5;
    --text-color: #1a1a1a;
    --header-color: #2c2c2c;
    --card-bg: #ffffff;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --overlay-bg: rgba(0, 0, 0, 0.9);
    --button-bg: rgba(255, 255, 255, 0.1);
    --button-hover: rgba(255, 255, 255, 0.2);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #e5e5e5;
        --header-color: #f5f5f5;
        --card-bg: #2c2c2c;
        --card-shadow: rgba(0, 0, 0, 0.5);
        --overlay-bg: rgba(0, 0, 0, 0.95);
        --button-bg: rgba(255, 255, 255, 0.15);
        --button-hover: rgba(255, 255, 255, 0.25);
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

header {
    text-align: center;
    padding: 3rem 1rem 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.1em;
    color: var(--header-color);
}

main {
    padding: 2rem 0 4rem;
}

/* Gallery Masonry Layout */
.gallery-grid {
    column-count: 1;
    column-gap: 1.5rem;
    padding: 0 1rem;
    max-width: 100%;
    margin: 0 auto;
}

/* 2 columns when each column is at least 300px wide */
@media (min-width: 650px) {
    .gallery-grid {
        column-count: 2;
        column-gap: 2rem;
        padding: 0 2rem;
    }
}

/* 3 columns when each column is at least 320px wide */
@media (min-width: 1060px) {
    .gallery-grid {
        column-count: 3;
        column-gap: 2.5rem;
        padding: 0 3rem;
    }
}

/* On very wide screens, constrain width but keep images visible */
@media (min-width: 1600px) {
    .gallery-grid {
        max-width: 1400px;
        padding: 0 2rem;
    }
}

/* Gallery Item */
.gallery-item {
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px var(--card-shadow);
    cursor: pointer;
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 2rem;
    display: inline-block;
    width: 100%;
    position: relative;
}

.gallery-item:hover {
    opacity: 0.95;
}

.gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    aspect-ratio: 3 / 4;
}

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-bg);
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.lightbox.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
}

/* Lightbox Controls */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: fixed;
    background: var(--button-bg);
    color: white;
    border: none;
    font-size: 2.5rem;
    cursor: pointer;
    padding: 1rem;
    transition: background-color 0.2s ease;
    z-index: 1001;
    backdrop-filter: blur(10px);
    border-radius: 4px;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    background: var(--button-hover);
}

.lightbox-close {
    top: 1rem;
    right: 1rem;
    font-size: 3rem;
    line-height: 1;
    width: 3rem;
    height: 3rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-prev {
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-next {
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-counter {
    color: white;
    font-size: 1rem;
    margin-top: 1rem;
    text-align: center;
    background: var(--button-bg);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

/* Keyboard Navigation Hint (screen readers only) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Loading State */
.gallery-item img[loading="lazy"] {
    background: var(--card-bg);
}

/* Mobile Adjustments */
@media (max-width: 767px) {
    header h1 {
        font-size: 2rem;
    }

    .gallery-item {
        margin-bottom: 1.5rem;
    }

    .lightbox-prev,
    .lightbox-next {
        font-size: 2rem;
        padding: 0.75rem;
    }

    .lightbox-close {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 2.5rem;
    }
}
