/* ═══════════════════════════════════════════════════════════
   gallery.css — SPIDER-VERSE
   Glitching Display Monitors in Spidey world
═══════════════════════════════════════════════════════════ */

.section--gallery {
    position: relative;
    background: url('../assets/gallery_background.jpg') center bottom no-repeat;
    background-size: cover;
    overflow: hidden;
    padding: var(--sp-xl) 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.gallery__bg-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(17, 17, 17, 0.7) 0%, rgba(17, 17, 17, 0.55) 30%, rgba(17, 17, 17, 0.7) 100%);
    z-index: 1;
}

.gallery-main-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
}

.gallery-swiper {
    width: 100%;
    margin-top: 2rem;
    overflow: hidden;
    padding: 2rem 0; /* space for drop shadows and scaling */
    position: relative;
}

/* Cinematic edge fade on both sides */
.gallery-swiper::before,
.gallery-swiper::after {
    content: '';
    position: absolute;
    top: 0;
    width: 10%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

.gallery-swiper::before {
    left: 0;
    background: linear-gradient(to right, rgba(17,17,17,1) 0%, rgba(17,17,17,0.6) 40%, transparent 100%);
}

.gallery-swiper::after {
    right: 0;
    background: linear-gradient(to left, rgba(17,17,17,1) 0%, rgba(17,17,17,0.6) 40%, transparent 100%);
}

/* Linear continuous slide configuration */
.gallery-swiper .swiper-wrapper {
    transition-timing-function: linear !important;
}

/* Spiderverse Monitor Display Styles */
.gallery-display {
    position: relative;
    /* width is now controlled by Swiper's slidesPerView, we just set the aspect ratio */
    aspect-ratio: 3/2;
    background-color: #000;
    border: 3px solid var(--c-cyan);
    box-shadow: 
      4px 4px 0 var(--c-magenta),
      -4px -4px 0 var(--c-yellow),
      0 0 15px rgba(0, 240, 255, 0.4);
    transform: perspective(800px) rotateY(-5deg) rotateX(5deg);
    transition: transform 0.4s ease, box-shadow 0.4s ease;
    cursor: pointer;
}

.gallery-display:nth-child(even) {
    transform: perspective(800px) rotateY(5deg) rotateX(-2deg);
    border-color: var(--c-yellow);
    box-shadow: 
      4px 4px 0 var(--c-cyan),
      -4px -4px 0 var(--c-magenta),
      0 0 15px rgba(255, 230, 0, 0.4);
}

.gallery-display:hover {
    transform: perspective(800px) rotateY(0deg) rotateX(0deg) scale(1.05); /* Slight pop out on hover, NO shaking of the box */
    z-index: 10;
}

.gallery-img-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    background: #000;
}

.gallery-img-main {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    position: relative;
    z-index: 1;
    transition: filter 0.3s ease;
    transform: scale(1.02); /* base scale to prevent edge bleeding on shake */
}

/* Base Comic Filter when hovered */
.gallery-display:hover .gallery-img-main {
    filter: drop-shadow(0 0 5px rgba(0,0,0,0.5));
    /* Jitters for 1s (0.25 * 4), then strictly applies a cartoon/comic filter */
    animation: 
      main-jitter 0.25s 4 steps(3) forwards,
      become-cartoon 1s forwards;
}

@keyframes become-cartoon {
    0%, 85% { filter: drop-shadow(0 0 5px rgba(0,0,0,0.5)); }
    100% { filter: contrast(130%) saturate(180%) brightness(130%) drop-shadow(0 0 6px rgba(0,0,0,0.6)); }
}

@keyframes main-jitter {
    0% { transform: scale(1.02) translate(0, 0); }
    33% { transform: scale(1.03) translate(-1px, 1px); }
    66% { transform: scale(1.02) translate(1px, -1px); }
    100% { transform: scale(1.02) translate(0, 0); }
}

/* Chromatic Aberration & Glitch Layers */
.gallery-img-cyan, .gallery-img-red {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    mix-blend-mode: screen;
    opacity: 0;
    pointer-events: none;
    z-index: 2;
    transform: scale(1.02);
}

.gallery-display:hover .gallery-img-cyan {
    filter: sepia(100%) hue-rotate(180deg) saturate(300%) contrast(150%);
    /* Glitches aggressively then fades out over exactly 1 second */
    animation: glitch-cyan-anim 0.2s 5 linear alternate forwards, ghost-drift 1s forwards, fade-out-glitch 1s forwards;
}

.gallery-display:hover .gallery-img-red {
    filter: sepia(100%) hue-rotate(330deg) saturate(300%) contrast(150%);
    /* Glitches aggressively then fades out over exactly 1 second */
    animation: glitch-red-anim 0.25s 4 linear alternate forwards, ghost-drift-rev 1s forwards, fade-out-glitch 1s forwards;
}

@keyframes fade-out-glitch {
    0%, 75% { opacity: 0.20; }
    100% { opacity: 0; }
}

@keyframes glitch-cyan-anim {
    0%, 100% { clip-path: inset(0 0 0 0); transform: scale(1.05) translate(-3px, 2px); }
    10% { clip-path: inset(10% 0 80% 0); transform: scale(1.05) translate(8px, -4px); }
    20% { clip-path: inset(80% 0 10% 0); transform: scale(1.05) translate(-8px, 2px); }
    30%, 70% { clip-path: inset(0 0 0 0); transform: scale(1.05) translate(2px, 0); }
    80% { clip-path: inset(40% 0 40% 0); transform: scale(1.05) translate(-4px, 4px); }
}

@keyframes glitch-red-anim {
    0%, 100% { clip-path: inset(0 0 0 0); transform: scale(1.05) translate(3px, -2px); }
    15% { clip-path: inset(60% 0 20% 0); transform: scale(1.05) translate(-6px, 3px); }
    35% { clip-path: inset(20% 0 60% 0); transform: scale(1.05) translate(6px, -3px); }
    50%, 80% { clip-path: inset(0 0 0 0); transform: scale(1.05) translate(-2px, 0); }
    90% { clip-path: inset(30% 0 50% 0); transform: scale(1.05) translate(4px, -4px); }
}

@keyframes ghost-drift {
    0% { transform: translateX(0); }
    100% { transform: translateX(-4px); }
}
@keyframes ghost-drift-rev {
    0% { transform: translateX(0); }
    100% { transform: translateX(4px); }
}

/* Halftone/Grain Overlay */
.gallery-img-wrapper::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    mix-blend-mode: multiply;
    /* Softened and spread out the "pores" to reduce quality degradation */
    background: radial-gradient(circle, rgba(0,0,0,0.3) 1px, transparent 1px) 0 0 / 6px 6px;
    opacity: 0.05; 
    transition: all 0.3s ease;
}

.gallery-display:hover .gallery-img-wrapper::after {
    opacity: 0.15;
    mix-blend-mode: overlay;
    background: radial-gradient(circle, rgba(0,0,0,0.4) 1px, transparent 1px) 0 0 / 6px 6px;
    /* Halftone shifts 10 times (exactly 1 second) then stops */
    animation: halftone-jitter 0.1s 10 steps(2) forwards;
}

@keyframes halftone-jitter {
    0% { background-position: 0 0, 0 0; }
    100% { background-position: 2px 2px, 0 0; }
}

/* Comic Panel Flash / Ink Stroke */
.comic-flash {
    position: absolute;
    inset: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(135deg, transparent 45%, rgba(255,255,255,0.6) 48%, rgba(255,255,255,0.9) 50%, rgba(255,255,255,0.6) 52%, transparent 55%);
    z-index: 6;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-100%) rotate(15deg);
}

.gallery-display:hover .comic-flash {
    /* Flash twice over 1 second then stop */
    animation: comic-slash 0.5s 2 forwards;
}

@keyframes comic-slash {
    0%, 90% { opacity: 0; transform: translateX(-100%) rotate(15deg); }
    94% { opacity: 1; transform: translateX(0) rotate(15deg); }
    98%, 100% { opacity: 0; transform: translateX(100%) rotate(15deg); }
}