:root {
    --primary: #2563eb;
    --accent: #1d4ed8;
    --text-main: #0f172a;
    --text-muted: #475569;
    --bg-body: #edf2f9;
    --card-bg: rgba(255, 255, 255, 0.65);
    --card-border: rgba(15, 23, 42, 0.14);
    --focus-ring: rgba(37, 99, 235, 0.4);
    --gallery-bg: #edf2f9;
    --gallery-panel: rgba(255, 255, 255, 0.72);
    --gallery-border: rgba(15, 23, 42, 0.13);
    --gallery-caption-bg: rgba(237, 242, 249, 0.9);
    --terminal-font: Consolas, "SFMono-Regular", "Liberation Mono", Menlo, monospace;
}

[data-bs-theme="dark"] {
    --primary: #7ba2ff;
    --accent: #a4c0ff;
    --text-main: #e5ecf6;
    --text-muted: #9fb0cb;
    --bg-body: #0b1220;
    --card-bg: rgba(20, 31, 53, 0.55);
    --card-border: rgba(255, 255, 255, 0.08);
    --focus-ring: rgba(123, 162, 255, 0.4);
    --gallery-bg: #0b1220;
    --gallery-panel: #0f172a;
    --gallery-border: rgba(255, 255, 255, 0.08);
    --gallery-caption-bg: rgba(5, 10, 18, 0.88);
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

html[data-bs-theme="dark"] {
    color-scheme: dark;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--gallery-bg);
    color: var(--text-main);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body.lightbox-open {
    overflow: hidden;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.gallery-page {
    min-height: 100vh;
    padding: clamp(1rem, 3vw, 2rem) 0 3rem;
}

.gallery-shell {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
}

.gallery-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0 1.25rem;
    border-bottom: 1px solid var(--gallery-border);
}

.gallery-kicker,
.gallery-subtitle,
.gallery-back,
.gallery-caption,
.lightbox-path,
.lightbox-close,
.lightbox-nav,
.lightbox-counter {
    font-family: var(--terminal-font);
}

.gallery-kicker {
    margin: 0 0 0.4rem;
    color: var(--primary);
    font-size: 0.82rem;
}

.gallery-title {
    margin: 0;
    color: var(--text-main);
    font-family: var(--terminal-font);
    font-size: clamp(2.2rem, 7vw, 4.8rem);
    font-weight: 700;
    letter-spacing: 0;
    line-height: 0.95;
}

.gallery-subtitle {
    max-width: 36rem;
    margin: 0.8rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.gallery-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gallery-border);
    border-radius: 6px;
    background: var(--gallery-panel);
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}

.gallery-back:hover,
.gallery-back:focus-visible {
    border-color: var(--primary);
    color: var(--text-main);
}

.gallery-back:focus-visible,
.gallery-thumb:focus-visible,
.lightbox button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.gallery-grid {
    column-count: 3;
    column-gap: 1rem;
    padding-top: 1rem;
}

.gallery-item {
    break-inside: avoid;
    margin: 0 0 1rem;
    overflow: hidden;
    border: 1px solid var(--gallery-border);
    border-radius: 8px;
    background: var(--gallery-panel);
    transition: border-color 0.25s ease;
}

.gallery-item:focus-within {
    border-color: var(--primary);
}

.gallery-thumb {
    position: relative;
    display: block;
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 7px;
    background:
        linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent),
        var(--gallery-panel);
    color: inherit;
    cursor: zoom-in;
    text-align: left;
}

.gallery-thumb img {
    display: block;
    width: 100%;
    height: auto;
    opacity: 1;
    transition: opacity 0.25s ease, transform 0.25s ease;
    transform-origin: center;
}

.js-ready .gallery-thumb img {
    opacity: 0;
}

.js-ready .gallery-thumb img.is-loaded {
    opacity: 1;
}

.gallery-caption {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 0.45rem 0.6rem;
    border-top: 1px solid var(--gallery-border);
    background: var(--gallery-caption-bg);
    color: var(--text-main);
    font-size: 0.78rem;
    line-height: 1.2;
    opacity: 0;
    transform: translateY(100%);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.gallery-thumb:focus-visible .gallery-caption {
    opacity: 1;
    transform: translateY(0);
}

.lightbox[hidden] {
    display: none;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: grid;
    padding: clamp(0.75rem, 2vw, 1.5rem);
    background: rgba(0, 0, 0, 0.9);
    color: #e5ecf6;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.lightbox.is-open {
    opacity: 1;
}

.lightbox-shell {
    position: relative;
    display: grid;
    min-height: 100%;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(5, 10, 18, 0.78);
    grid-template-rows: auto 1fr;
}

.lightbox-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 52px;
    padding: 0.35rem 0.5rem 0.35rem 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(5, 10, 18, 0.94);
}

.lightbox-path {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: #cbd5e1;
    font-size: 0.85rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lightbox-close,
.lightbox-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.82);
    color: #e5ecf6;
}

.lightbox-close:hover,
.lightbox-nav:hover {
    border-color: var(--primary);
    color: #fff;
}

.lightbox-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: clamp(0.75rem, 3vw, 2rem);
}

.lightbox-image {
    display: block;
    width: auto;
    max-width: 90vw;
    height: auto;
    max-height: calc(90vh - 58px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #050a12;
    opacity: 0;
    transition: opacity 0.18s ease;
}

.lightbox-image.is-loaded {
    opacity: 1;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    width: 44px;
    height: 56px;
    font-size: 1.4rem;
    transform: translateY(-50%);
}

.lightbox-prev {
    left: clamp(0.5rem, 2vw, 1.25rem);
}

.lightbox-next {
    right: clamp(0.5rem, 2vw, 1.25rem);
}

.lightbox-counter {
    position: absolute;
    right: clamp(0.75rem, 2vw, 1.5rem);
    bottom: clamp(0.75rem, 2vw, 1.5rem);
    min-width: 4.2rem;
    margin: 0;
    padding: 0.35rem 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    background: rgba(5, 10, 18, 0.82);
    color: #cbd5e1;
    font-size: 0.82rem;
    text-align: center;
}

@media (hover: hover) and (pointer: fine) {
    .gallery-item:hover {
        border-color: var(--primary);
    }

    .gallery-thumb:hover img.is-loaded {
        transform: scale(1.03);
    }

    .gallery-thumb:hover .gallery-caption {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (hover: none), (pointer: coarse) {
    .lightbox-nav {
        display: none;
    }
}

@media (max-width: 900px) {
    .gallery-grid {
        column-count: 2;
    }
}

@media (max-width: 560px) {
    .gallery-shell {
        width: min(100% - 1rem, 1120px);
    }

    .gallery-header {
        display: block;
        padding-top: 0.25rem;
    }

    .gallery-back {
        margin-top: 1rem;
    }

    .gallery-grid {
        column-count: 1;
    }

    .lightbox {
        padding: 0;
    }

    .lightbox-shell {
        border: 0;
        border-radius: 0;
    }

    .lightbox-stage {
        padding: 0.75rem;
    }

    .lightbox-image {
        max-width: 96vw;
        max-height: calc(92vh - 56px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }

    .gallery-thumb:hover img,
    .gallery-thumb img {
        transform: none !important;
    }
}
