/* Theme variables */
:root {
    --bg: #f9f9fb;
    --text: #1a1a1f;
    --border: #d0d4dc;
    --accent: #3b82f6;
    --accent-rgb: 59, 130, 246;
    --shadow: 0 4px 12px rgba(0, 0, 0, .08);
    --radius: 10px;
    --item-bg: #fff;
}

:root.dark {
    --bg: #15171a;
    --text: #e5e7eb;
    --border: #2a2d33;
    --accent: #60a5fa;
    --accent-rgb: 96, 165, 250;
    --shadow: 0 4px 16px rgba(0, 0, 0, .6);
    --item-bg: #1f2329;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(0.5rem, 2vw, 1rem) clamp(0.75rem, 2vw, 1.25rem);
}

header h1 {
    margin: 0;
    font-size: clamp(1.2rem, 4vw, 2rem);
    font-weight: 600;
}

.controls {
    display: flex;
    gap: .5rem;
}

#themeToggle {
    cursor: pointer;
    background: var(--item-bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font-size: 1rem;
    line-height: 1;
    box-shadow: var(--shadow);
    transition: background .25s, border-color .25s, transform .25s;
}

#themeToggle:hover,
#themeToggle:focus {
    outline: none;
    transform: translateY(-2px);
    border-color: var(--accent);
}

/* Masonry responsive layout using columns */
#gallery {
    column-gap: 1rem;
    padding: 0 1rem 2rem;
    width: 100%;
    box-sizing: border-box;
}

@media (min-width:600px) {
    #gallery {
        column-count: 2;
    }
}

@media (min-width:900px) {
    #gallery {
        column-count: 3;
    }
}

@media (min-width:1300px) {
    #gallery {
        column-count: 4;
    }
}

.gallery-item {
    break-inside: avoid;
    position: relative;
    margin: 0 0 1rem;
    background: var(--item-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow .3s, transform .3s;
}

.gallery-item:focus-within,
.gallery-item:hover {
    box-shadow: 0 6px 20px rgba(var(--accent-rgb), .35);
    transform: translateY(-3px);
}

.gallery-item img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    object-fit: cover;
    /* irregular shapes supported */
    transition: filter .3s, transform .3s;
}

.gallery-item:hover img {
    filter: brightness(.85);
}

/* Subtle loading animation */
.gallery-item img[data-loading="true"] {
    opacity: 0;
}

.gallery-item img[data-loading="false"] {
    opacity: 1;
    transition: opacity .4s ease;
}

/* Lightbox */
#lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .7);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 2rem 1.5rem 3rem;
    z-index: 999;
}

#lightbox.active {
    display: flex;
    animation: fadeIn .25s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#lightboxImg {
    max-width: min(90vw, 1400px);
    max-height: 75vh;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
    object-fit: contain;
    background: #000;
}

#lightboxCaption {
    margin-top: 1rem;
    font-size: .9rem;
    text-align: center;
    max-width: 80ch;
    line-height: 1.4;
}

#lightbox button#lightboxClose {
    position: absolute;
    top: .75rem;
    right: .75rem;
    background: var(--item-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.25rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

#lightbox button.nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, .15);
    color: #fff;
    border: none;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background .3s;
}

#lightbox button.nav.prev {
    left: 1rem;
}

#lightbox button.nav.next {
    right: 1rem;
}

#lightbox button.nav:hover {
    background: rgba(255, 255, 255, .35);
}

#lightbox button:focus {
    outline: 2px solid var(--accent);
}

footer {
    text-align: center;
    padding: 1.5rem .75rem;
    font-size: .8rem;
    opacity: .8;
}

/* Scrollbar theming */
body::-webkit-scrollbar {
    width: 10px;
}

body::-webkit-scrollbar-track {
    background: var(--bg);
}

body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 99px;
}

body::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Dark mode prefers-color-scheme */
@media (prefers-color-scheme: dark) {
    :root:not(.dark) {
        /* allow manual override */
    }
}

/* Accessibility hidden utility */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    border: 0;
}

ul {
    width: 100%;
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333333;
}

ul li {
    float: left;
}

ul li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

ul li a:hover {
    background-color: #2b99d0;
}

ul li a.active {
    background-color: #28db99;
}