/* ═══════════════════════════════════════════════════════════
   Gallery — Premium Translucent Editorial Design
   Elegant, modern, expensive-feeling infinite canvas
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-deep: #08080c;
    --bg-surface: rgba(255, 255, 255, 0.025);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #f5f5f5;
    --text-muted: rgba(255, 255, 255, 0.45);
    --accent: #8b6cef;
    --accent-glow: rgba(139, 108, 239, 0.15);
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset & Base ── */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Ambient atmosphere ── */
body::before {
    content: '';
    position: fixed;
    top: -20%;
    left: -10%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(139, 108, 239, 0.08) 0%, transparent 70%);
    filter: blur(80px);
    z-index: 0;
    pointer-events: none;
    animation: ambient-1 30s ease-in-out infinite alternate;
}

body::after {
    content: '';
    position: fixed;
    bottom: -15%;
    right: -8%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(99, 155, 255, 0.06) 0%, transparent 70%);
    filter: blur(100px);
    z-index: 0;
    pointer-events: none;
    animation: ambient-2 25s ease-in-out infinite alternate;
}

@keyframes ambient-1 {
    0%   { transform: translate(0, 0) scale(1); opacity: 0.6; }
    50%  { transform: translate(40px, 30px) scale(1.1); opacity: 0.8; }
    100% { transform: translate(-20px, 50px) scale(0.95); opacity: 0.5; }
}

@keyframes ambient-2 {
    0%   { transform: translate(0, 0); opacity: 0.5; }
    100% { transform: translate(-50px, -30px); opacity: 0.7; }
}

/* ── Noise texture overlay for depth ── */
.noise-layer {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px;
}

/* ── Back Button — frosted pill ── */
.back-btn {
    position: fixed;
    top: 28px;
    left: 28px;
    z-index: 100;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 44px;
    min-height: 44px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border: 1px solid var(--border-subtle);
    padding: 10px 18px;
    border-radius: 100px;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    letter-spacing: 0.5px;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--border-hover);
    transform: translateX(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    text-decoration: none;
}

/* ── Floating title ── */
.gallery-title {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    margin: 0;
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: var(--text-muted);
    pointer-events: none;
    animation: title-reveal 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.3s both;
}

@keyframes title-reveal {
    from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Scroll hint ── */
.scroll-hint {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    font-size: 0.6rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.15);
    transition: opacity 0.8s ease;
    pointer-events: none;
}

.scroll-hint::after {
    content: '';
    display: block;
    width: 1px;
    height: 20px;
    background: linear-gradient(to bottom, rgba(255,255,255,0.15), transparent);
    margin: 8px auto 0;
    animation: scroll-line 2s ease-in-out infinite;
}

@keyframes scroll-line {
    0%, 100% { opacity: 0.3; transform: scaleY(0.6); }
    50%      { opacity: 0.8; transform: scaleY(1); }
}

/* ── Viewport ── */
.gallery-viewport {
    width: 100vw;
    height: 100vh;
    overflow: auto;
    cursor: grab;
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: relative;
    z-index: 1;
}

.gallery-viewport::-webkit-scrollbar { display: none; }
.gallery-viewport:active { cursor: grabbing; }

.gallery-viewport:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ── Canvas ── */
.gallery-canvas {
    font-size: 0;
    min-width: 300vw;
    min-height: 300vh;
    display: block;
    box-sizing: border-box;
    padding: 60px;
}

/* ── Grid ── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: 280px;
    grid-auto-flow: dense;
    gap: 8px;
    width: 100%;
    height: 100%;
}

/* ── Gallery Tile ── */
.gallery-item {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    overflow: hidden;
    opacity: 0;
    animation: tile-enter 0.7s ease-out forwards;
    transition:
        transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        border-color 0.5s ease;
}

/* Size variants */
.w-2 { grid-column: span 2; }
.h-2 { grid-row: span 2; }
.w-3 { grid-column: span 3; }

.gallery-item:hover {
    transform: scale(1.015);
    z-index: 10;
    border-color: rgba(139, 108, 239, 0.2);
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(139, 108, 239, 0.1),
        inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

/* ── Image ── */
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    filter: brightness(0.78) contrast(1.05) saturate(0.9);
    transition: filter 0.6s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.gallery-item:hover img {
    filter: brightness(0.95) contrast(1.02) saturate(1.05);
    transform: scale(1.04);
}

/* ── Overlay — editorial gradient ── */
.overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        transparent 40%,
        rgba(0, 0, 0, 0.15) 60%,
        rgba(0, 0, 0, 0.65) 85%,
        rgba(0, 0, 0, 0.8) 100%
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 28px;
}

.gallery-item:hover .overlay {
    opacity: 1;
}

.overlay h3 {
    margin: 0 0 3px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    transform: translateY(10px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.overlay p {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.3px;
    line-height: 1.4;
    transform: translateY(10px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.05s;
}

.gallery-item:hover .overlay h3,
.gallery-item:hover .overlay p {
    transform: translateY(0);
}

/* ── Entrance Animation ── */
@keyframes tile-enter {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Staggered reveals */
.gallery-item:nth-child(1)  { animation-delay: 0.05s; }
.gallery-item:nth-child(2)  { animation-delay: 0.08s; }
.gallery-item:nth-child(3)  { animation-delay: 0.11s; }
.gallery-item:nth-child(4)  { animation-delay: 0.14s; }
.gallery-item:nth-child(5)  { animation-delay: 0.17s; }
.gallery-item:nth-child(6)  { animation-delay: 0.20s; }
.gallery-item:nth-child(7)  { animation-delay: 0.23s; }
.gallery-item:nth-child(8)  { animation-delay: 0.26s; }
.gallery-item:nth-child(9)  { animation-delay: 0.29s; }
.gallery-item:nth-child(10) { animation-delay: 0.32s; }
.gallery-item:nth-child(n+11) { animation-delay: 0.35s; }

/* ── Touch devices: no hover, so captions stay readable persistently
      with a lighter gradient that lifts the text without hiding the photo ── */
@media (hover: none) {
    .gallery-item .overlay {
        opacity: 1;
        background: linear-gradient(
            180deg,
            transparent 55%,
            rgba(0, 0, 0, 0.2) 72%,
            rgba(0, 0, 0, 0.65) 100%
        );
    }

    .overlay h3,
    .overlay p {
        transform: none;
    }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        grid-auto-rows: 150px;
        gap: 6px;
    }

    .gallery-canvas {
        padding: 16px;
    }

    .back-btn {
        top: 16px;
        left: 16px;
        padding: 8px 14px;
        font-size: 0.8rem;
        /* min-width/min-height: 44px from the base rule still apply */
    }

    .gallery-title {
        top: 18px;
        font-size: 0.55rem;
        letter-spacing: 3px;
    }

    .overlay {
        padding: 16px;
    }

    .overlay h3 { font-size: 0.75rem; }
    .overlay p  { font-size: 0.65rem; }
}

/* ── Reduced motion: kill ambient loops, entrance stagger and hover
      transitions; states appear instantly in their final form ── */
@media (prefers-reduced-motion: reduce) {
    body::before,
    body::after,
    .scroll-hint::after,
    .gallery-title,
    .gallery-item {
        animation: none;
    }

    .gallery-item {
        opacity: 1;
    }

    .gallery-item,
    .gallery-item img,
    .overlay,
    .overlay h3,
    .overlay p,
    .back-btn,
    .scroll-hint {
        transition: none;
    }

    .gallery-item:hover {
        transform: none;
        box-shadow: none;
    }

    .gallery-item:hover img {
        transform: none;
    }
}
