@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;700&family=Plus+Jakarta+Sans:wght@300;400;500;600&display=swap');

:root {
    color-scheme: dark;
    --bg-hue: 0;
    --bg-saturation: 15%;
    --bg-lightness: 6%;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.35);
    
    /* Theme color driven by selected values */
    --theme-saturation: 85%;
    --theme-lightness: 65%;
    --theme-color: hsl(var(--bg-hue), var(--theme-saturation), var(--theme-lightness));
    --theme-color-glow: hsla(var(--bg-hue), var(--theme-saturation), var(--theme-lightness), 0.15);
    --glass-bg: rgba(10, 10, 10, 0.55);
    --glass-border: rgba(255, 255, 255, 0.07);
    --glass-border-focus: rgba(255, 255, 255, 0.18);

    /* Row height for justified layout */
    --row-height: 280px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: hsl(var(--bg-hue), var(--bg-saturation), var(--bg-lightness));
    color: var(--text-primary);
    font-family: 'Plus Jakarta Sans', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    transition: background-color 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

/* Dynamic ambient glow behind the site */
body::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle at 50% 50%, hsla(var(--bg-hue), var(--bg-saturation), var(--bg-lightness), 0.65) 0%, hsla(var(--bg-hue), var(--bg-saturation), var(--bg-lightness), 0.35) 60%, rgba(5, 5, 5, 0.9) 100%);
    pointer-events: none;
    z-index: 2; /* Sits in front of backdrops to blend them */
    transition: background-image 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Main page dynamic blurred backdrop layers */
.main-ambient-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-size: cover;
    background-position: center;
    filter: blur(80px) brightness(0.38) saturate(1.25);
    transform: scale(1.15);
    opacity: 0;
    z-index: 1; /* Sits behind #gallery (z-index: 2) */
    pointer-events: none;
    transition: opacity 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.main-ambient-backdrop.active {
    opacity: 0.85;
}

/* Header & Logo */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(5, 5, 5, 0.8) 0%, rgba(5, 5, 5, 0.4) 50%, rgba(5, 5, 5, 0) 100%);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    pointer-events: none;
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.4rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--text-primary);
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    transition: color 0.4s ease, text-shadow 0.4s ease;
}

.logo span {
    color: var(--dot-color, var(--theme-color));
    transition: color 0.4s ease;
}

/* Main Gallery justified container */
#gallery {
    height: 100vh;
    width: 100vw;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 110px 40px 150px 40px;
    z-index: 5; /* Ensure gallery photos sit strictly on top of ambient backdrops and vignettes */
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

#gallery::-webkit-scrollbar {
    width: 6px;
}

#gallery::-webkit-scrollbar-track {
    background: transparent;
}

#gallery::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
}

#gallery::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Flexbox justified gallery spacer to align last row left */
#gallery::after {
    content: '';
    flex-grow: 999999999;
    height: 0;
    min-width: 300px;
}

/* Gallery Empty State */
.gallery-empty {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100px 20px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    text-align: center;
}

/* Image Card Styling */
.img-card {
    flex: 0 0 auto;
    height: var(--row-height);
    width: calc(var(--row-height) * var(--aspect-ratio, 1.5));
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid var(--glass-border);
    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;
    transform-origin: center;
    opacity: 0;
    transform: translateY(30px) scale(0.95);
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.img-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    pointer-events: none;
    z-index: 2;
}

.img-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--card-glow, var(--glass-border-focus));
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65), 0 0 30px var(--card-shadow, rgba(0,0,0,0));
    z-index: 3;
}

.img-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1), filter 0.5s ease;
    filter: brightness(0.9) contrast(1.02);
}

.img-card:hover img {
    transform: scale(1.06);
    filter: brightness(1.05) contrast(1.02);
}

/* Card Metadata Overlay - Disabled */
.img-info {
    display: none !important;
}

/* Floating Controls (HUD) */
#controls {
    position: fixed;
    bottom: 35px; /* Floating clearance from bottom screen edge */
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    background: rgba(12, 12, 12, 0.5); /* 50% transparent dark glass background */
    border: 1px solid rgba(235, 235, 235, 0.48); /* Bright silver glass outline */
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    padding: 16px 28px; /* Breathing room padding */
    border-radius: 30px; /* Capsule rounded corners */
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5), 
                0 0 25px var(--theme-color-glow), /* Dynamic glow matching the active hue */
                inset 0 1px 0 rgba(255, 255, 255, 0.08);
    width: 480px; /* Pill width */
    max-width: 92vw; /* Stays inside viewport on smartphones */
    height: auto;
    overflow: visible;
    opacity: 0;
    transform: translate(-50%, 150%); /* Start lower for slide-up entrance */
    animation: slide-up-controls 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; /* Smooth entrance */
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

#controls:hover {
    border-color: rgba(255, 255, 255, 0.75);
}

@keyframes slide-up-controls {
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.slider-container {
    width: 100%;
    position: relative;
    height: 24px; /* Sizing container */
    display: flex;
    align-items: center;
}

/* Spectrum Slider Stylings */
#color-picker {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 28px; /* Invisibly taller to make dragging much easier */
    background: transparent; /* Invisible slider body */
    outline: none;
    margin: 0;
    padding: 0;
    border: none;
    cursor: pointer;
}

#color-picker:focus,
#color-picker:focus-visible {
    outline: none !important;
}

#color-picker::-webkit-slider-runnable-track {
    height: 4px; /* Slim visible track */
    border-radius: 2px;
    background: linear-gradient(
        to right,
        hsl(0, 100%, 50%) 0%,
        hsl(60, 100%, 50%) 15%,
        hsl(120, 100%, 50%) 30%,
        hsl(180, 100%, 50%) 45%,
        hsl(240, 100%, 50%) 60%,
        hsl(300, 100%, 50%) 75%,
        hsl(360, 100%, 50%) 90%,
        #555555 90.1%,
        #ffffff 100%
    ); /* Vivid spectrum track slot */
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8), 
                0 1px 0 rgba(255, 255, 255, 0.05); /* Highlight to define the track slot */
    border: none;
}

#color-picker::-moz-range-track {
    height: 4px; /* Slim visible track */
    border-radius: 2px;
    background: linear-gradient(
        to right,
        hsl(0, 100%, 50%) 0%,
        hsl(60, 100%, 50%) 15%,
        hsl(120, 100%, 50%) 30%,
        hsl(180, 100%, 50%) 45%,
        hsl(240, 100%, 50%) 60%,
        hsl(300, 100%, 50%) 75%,
        hsl(360, 100%, 50%) 90%,
        #555555 90.1%,
        #ffffff 100%
    );
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8), 
                0 1px 0 rgba(255, 255, 255, 0.05);
    border: none;
}

/* Chrome/Safari Slider Thumb */
#color-picker::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px !important; /* Circular, clean thumb */
    height: 14px !important;
    border-radius: 50% !important;
    background: var(--theme-color) !important; /* Color center matching active selected hue */
    border: 2px solid #ffffff !important; /* High-contrast white border ring */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6) !important;
    cursor: pointer;
    margin-top: -5px !important; /* Centered relative to the 4px track: (4 - 14) / 2 = -5px */
    transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), 
                box-shadow 0.15s cubic-bezier(0.16, 1, 0.3, 1), 
                border-color 0.15s ease !important;
}

#color-picker:hover::-webkit-slider-thumb {
    transform: scale(1.22) !important;
    border-color: #ffffff !important;
    box-shadow: 0 0 12px var(--theme-color), 0 2px 6px rgba(0, 0, 0, 0.6) !important; /* Subtle colored glow on hover */
}

#color-picker:active::-webkit-slider-thumb {
    transform: scale(1.1) !important;
    border-color: #e0e0e0 !important; /* Snappy tactile border change when active */
    box-shadow: 0 0 18px var(--theme-color), 0 1px 4px rgba(0, 0, 0, 0.7) !important; /* Intense glow when active */
}

/* Firefox Slider Thumb */
#color-picker::-moz-range-thumb {
    width: 14px !important;
    height: 14px !important;
    border-radius: 50% !important;
    background: var(--theme-color) !important;
    border: 2px solid #ffffff !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6) !important;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), 
                box-shadow 0.15s cubic-bezier(0.16, 1, 0.3, 1), 
                border-color 0.15s ease !important;
}

#color-picker:hover::-moz-range-thumb {
    transform: scale(1.22) !important;
    border-color: #ffffff !important;
    box-shadow: 0 0 12px var(--theme-color), 0 2px 6px rgba(0, 0, 0, 0.6) !important;
}

#color-picker:active::-moz-range-thumb {
    transform: scale(1.1) !important;
    border-color: #e0e0e0 !important;
    box-shadow: 0 0 18px var(--theme-color), 0 1px 4px rgba(0, 0, 0, 0.7) !important;
}

/* Immersive Overlay Modal */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(5, 5, 5, 0.82);
    display: flex;
    z-index: 100;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: auto; /* Controlled entirely by visibility transition to block click-throughs */
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.5s step-end;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    flex-direction: column;
    overflow: hidden;
}

#overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0s;
}

.overlay-ambient-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    filter: blur(50px) brightness(0.42) saturate(1.3);
    transform: scale(1.12);
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
    pointer-events: none;
}

#overlay.active .overlay-ambient-backdrop {
    opacity: 0.8;
}

/* Overlay Navigation Area */
.overlay-viewport {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    z-index: 2;
}

.overlay-img-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

#full-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 0;
    box-shadow: none;
    transform: scale(0.97);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), 
                opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
}

#overlay.active #full-img {
    transform: scale(1);
    opacity: 1;
}

/* Hide navigation, close buttons, swatches and textual panels */
#overlay-prev,
#overlay-next,
#overlay-close,
.overlay-info-panel,
.keyboard-hint {
    display: none !important;
}

/* Keyboard Hints */
.keyboard-hint {
    position: absolute;
    bottom: 12px;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    pointer-events: none;
}

@media (max-width: 768px) {
    :root {
        --row-height: 160px; /* Scaling down row height for tablets */
    }
    
    header {
        height: 75px;
    }
    
    #gallery {
        padding: 90px 16px 140px 16px;
        gap: 12px;
    }
    
    #controls {
        padding: 12px 20px;
        bottom: 25px;
    }
    
    #overlay-prev {
        left: 15px;
    }
    
    #overlay-next {
        right: 15px;
    }
    
    .overlay-nav-btn {
        width: 46px;
        height: 46px;
    }
    
    #overlay-close {
        top: 20px;
        right: 20px;
    }
    
    .palette-swatch {
        width: 28px;
        height: 28px;
    }
    
    .logo {
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    :root {
        --row-height: 125px; /* Even smaller rows for smartphones to show at least 3 rows */
    }
    
    header {
        height: 60px;
    }
    
    #gallery {
        padding: 75px 10px 120px 10px;
        gap: 8px;
    }
    
    #controls {
        padding: 10px 16px;
        bottom: 20px;
    }
    
    .img-info {
        padding: 12px 10px 10px 10px;
    }
    
    .img-title {
        font-size: 0.78rem;
    }
    
    .img-meta, .img-dimensions {
        display: none;
    }

    .controls-stats {
        font-size: 0.7rem;
    }
    
    .overlay-nav-btn {
        display: none; /* Swipe or tap on image side to navigate on mobile */
    }
}
