@import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,600,600italic|Playfair+Display:400,700");
@import url("animations.css");
@import url("context_menu.css");

/* ============================================
   RESET & BASE
   ============================================ */

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

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a0a;
    color: #fff;
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: #667eea;
}

/* ============================================
   WRAPPER
   ============================================ */

#wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   HEADER
   ============================================ */

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 2.5em; /* Compact height */
    padding: 0 1.5em;
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #fff;
    z-index: 100;
    position: sticky;
    top: 0;
    transition: all 0.3s ease;
}

#header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.1em;
    font-weight: 400;
    margin: 0;
    letter-spacing: 0.02em;
    text-transform: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#header h1 a {
    text-decoration: none;
    background: linear-gradient(90deg, #fff, #aaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: opacity 0.3s ease;
}

#header h1 a:hover {
    opacity: 0.8;
}

#header nav {
    display: flex;
    gap: 2em;
}

#header nav a {
    font-size: 0.85em;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: color 0.3s ease, transform 0.3s ease;
    position: relative;
}

#header nav a::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 1px;
    background: #fff;
    transition: width 0.3s ease;
}

#header nav a:hover {
    color: #fff;
    transform: translateY(-1px);
}

#header nav a:hover::after {
    width: 100%;
}

/* Responsive Header */
@media screen and (max-width: 768px) {
    #header {
        padding: 0 1em;
    }
    
    #header h1 {
        font-size: 1em;
    }

    #header nav {
        gap: 1em;
    }
}

@media screen and (max-width: 480px) {
    #header h1 {
        font-size: 0.9em;
        max-width: 60%;
    }
    
    #header nav a {
        font-size: 0.8em;
    }
}

/* ============================================
   RESPONSIVE GRID (~500x500 on 4K)
   ============================================ */

#main {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 0;
    background: #0a0a0a;
    width: 100%;
    padding: 0;
}

/* 4K screens - larger images */
@media screen and (min-width: 2560px) {
    #main {
        grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    }
}

@media screen and (min-width: 3840px) {
    #main {
        grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
    }
}

/* Tablet */
@media screen and (max-width: 1280px) {
    #main {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
}

/* Mobile */
@media screen and (max-width: 768px) {
    #main {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media screen and (max-width: 480px) {
    #main {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   IMAGE THUMBNAILS
   ============================================ */

.thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    width: 100%;
    background: #1a1a1a;
}

.image-link {
    display: block;05);
    transition: filter 0.8s cubic-bezier(0.2, 0.8, 0.2, 1),
                opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1),
                transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: var(--delay, 0s); /* Staggered delay */

.image-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 0.3s ease;
    pointer-events: none;
}

/* ============================================
   BLUR-TO-SHARP LOAD ANIMATION
   ============================================ */

.blur-load {
    filter: blur(20px);
    opacity: 0;
    transform: scale(1.1);
    transition: filter 0.6s ease-out,
                opacity 0.6s ease-out,
                transform 0.6s ease-out;
}

.blur-load.loaded {
    filter: blur(0);
    opacity: 1;
    transform: scale(1);
}

/* ============================================
   HOVER MICRO-INTERACTIONS
   ============================================ */

.thumb:hover .image-overlay {
    background: rgba(0, 0, 0, 0.15);
}

.thumb:hover img {
    transform: scale(1.08);
}

/* Click/tap feedback */
.thumb:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

.thumb:active img {
    transform: scale(1.02);
}

/* Title overlay */
.image-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    margin: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: #fff;
    font-size: 0.9rem;
    text-align: center;
}

/* ============================================
   MODAL
   ============================================ */

#modal:empty, #admin-modal:empty {
    display: none;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    pointer-events: all;
    opacity: 0;
    animation: modalFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-overlay.closing {
    animation: modalFadeOut 0.3s ease-out forwards;
}

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

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

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    animation: modalSlideIn 0.5s cubic-bezier(0.19, 1, 0.22, 1) 0.1s forwards; /* Swift UI spring-like */
}

.modal-overlay.closing .modal-content {
    animation: modalSlideOut 0.25s ease-in forwards;
}

@keyframes modalSlideIn {
    from {
        transform: scale(0.92) translateY(30px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes modalSlideOut {
    from {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    to {
        transform: scale(0.95) translateY(10px);
        opacity: 0;
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.main-image-link {
    display: block;
}

.modal-image {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
    margin: 0 auto;
    transition: opacity 0.2s ease;
}

.modal-image.switching {
    opacity: 0.5;
}

/* ============================================
   VERSIONS GALLERY IN MODAL
   ============================================ */

.versions-gallery {
    display: flex;
    gap: 8px;
    padding: 16px;
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.3);
    scrollbar-width: thin;
    scrollbar-color: #666 transparent;
}

.versions-gallery::-webkit-scrollbar {
    height: 6px;
}

.versions-gallery::-webkit-scrollbar-track {
    background: transparent;
}

.versions-gallery::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 3px;
}

.version-thumb {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border: 2px solid transparent;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
    background: none;
    padding: 0;
}

.version-thumb:hover {
    transform: scale(1.05);
}

.version-thumb.active {
    border-color: #fff;
}

.version-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================
   MODAL INFO
   ============================================ */

.modal-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #111;
    gap: 1rem;
}

.modal-info-text h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0 0 0.25rem 0;
}

.modal-info-text p {
    color: #888;
    margin: 0;
    font-size: 0.9rem;
}

.modal-actions {
    flex-shrink: 0;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    color: #111;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s ease, transform 0.2s ease;
}

.download-btn:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
    color: #111;
}

.download-btn svg {
    flex-shrink: 0;
}

/* ============================================
   EMPTY STATE
   ============================================ */

.empty-gallery {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    color: #666;
    font-size: 1.2rem;
}

/* ============================================
   RESPONSIVE MODAL
   ============================================ */

@media screen and (max-width: 768px) {
    .modal-content {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .modal-image {
        max-height: 60vh;
    }

    .modal-info {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
    }

    .modal-actions {
        width: 100%;
    }

    .download-btn {
        width: 100%;
        justify-content: center;
    }

    .version-thumb {
        width: 60px;
        height: 60px;
    }
}

/* ============================================
   CONTEXT MENU
   OVERLAY DOWNLOAD BUTTON
   ============================================ */

.modal-image-container {
    position: relative;
    display: inline-block;
    margin: 0 auto;
}

.overlay-download {
    position: absolute;
    top: 1rem;
    left: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    transition: all 0.2s ease;
    z-index: 20;
    padding: 0;
}

.overlay-download:hover {
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    transform: scale(1.1);
}

.overlay-download svg {
    width: 18px;
    height: 18px
}

.floating-download {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    z-index: 10;
}

.floating-download:hover {
    background: #fff;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    transform: scale(1.05);
}

.floating-download svg {
    stroke: #0a0a0a;
}
