/* 
 * Flipping Cards Scroll Effect 
 * Inspired by Evatto Webflow Template
 */

:root {
    --card-primary: #e7f2e7;
    --card-secondary: #f1eae2;
    --card-border-radius: 24px;
    --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.flip-scroll-section {
    position: relative;
    height: 110vh;
    /* Much shorter scroll distance for a faster, snappier feel */
    background-color: #0d1117;
    margin: 0;
    padding-top: 12px;
}

.flip-sticky-wrapper {
    position: relative;
    /* CHANGED FROM STICKY TO RELATIVE: 
       GSAP 'pin: true' already handles the pinning. 
       Double pinning (CSS sticky + GSAP pin spacer) caused the "Double Title" ghosting 
       and the massive layout gaps. This allows GSAP to control the flow naturally. */
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: 100px;
    /* Space for header + Title breathing room */
    overflow: hidden;
    perspective: 2000px;
}

.flip-section-title {
    margin-bottom: 2rem;
    text-align: center;
    z-index: 100;
}

.flip-section-title h2 {
    font-family: 'Cinzel', serif;
    font-size: 3.5rem;
    color: white;
    /* Matches church theme */
}

.flip-cards-container {
    position: relative;
    width: 100%;
    max-width: 1200px;
    height: 500px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    /* Ensure centering */
}

/* Fallback when GSAP/ScrollTrigger fails */
html.gsap-disabled .flip-cards-container {
    height: auto;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

html.gsap-disabled .flip-card {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    opacity: 1;
    margin: 0 auto 1.5rem;
}

.flip-card {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 280px;
    height: 420px;
    transform-style: preserve-3d;
    cursor: pointer;
    /* Initial state: small and centered */
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 0;
    z-index: 10;
    /* Base z-index */
}

/* Reverse stacking order so first card is on top */
.flip-card:nth-child(1) {
    z-index: 40;
}

.flip-card:nth-child(2) {
    z-index: 30;
}

.flip-card:nth-child(3) {
    z-index: 20;
}

.flip-card:nth-child(4) {
    z-index: 10;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    /* Rotation will be handled by GSAP */
    transform-style: preserve-3d;
}

/* We will control the rotation via GSAP */
/* .flip-card:hover .flip-card-inner { transform: rotateY(180deg); } */

.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: var(--card-border-radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--card-shadow);
}

.flip-card-front {
    background-color: var(--card-primary);
    color: #0f172a !important;
    /* Force dark navy even in dark mode */
}

.flip-card-back {
    background-color: var(--card-secondary);
    color: #334155 !important;
    /* Force dark gray even in dark mode */
    transform: rotateY(180deg);
}

.card-icon {
    font-size: 4rem;
    margin: auto;
}

.card-category {
    font-size: 1.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #2d4a3e;
}

.card-image-wrap {
    width: 100%;
    height: 200px;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.card-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-back-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: left;
    color: #0f172a !important;
    margin-bottom: 0.5rem;
}

.flip-card-back p {
    color: #334155 !important;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.6;
    margin-top: 0;
}

/* Explicit Dark Mode Overrides for these specific light cards */
body.dark .card-category,
body.dark .card-back-title,
body.dark .flip-card-back p,
body[data-theme="dark"] .card-category,
body[data-theme="dark"] .card-back-title,
body[data-theme="dark"] .flip-card-back p {
    color: #0f172a !important;
}

.card-button {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background: #090b0f;
    color: white;
    border-radius: 50px;
    font-size: 0.9rem;
    align-self: flex-start;
}

@media (max-width: 1024px) {
    .flip-section-title h2 {
        font-size: 2.5rem;
    }

    .flip-cards-container {
        height: 460px;
    }

    .flip-scroll-section {
        height: 100vh;
    }
}

@media (max-width: 768px) {
    .flip-section-title h2 {
        font-size: 2rem;
    }

    .flip-sticky-wrapper {
        padding: 80px 1rem 0;
        /* Tighter for mobile but still clearing header */
    }

    .flip-cards-container {
        height: 420px;
    }

    .flip-card {
        width: 260px;
        height: 380px;
    }

    .flip-scroll-section {
        height: 110vh;
        /* Extra scroll room for mobile stacking sequence */
    }
}

@media (max-width: 480px) {
    .flip-section-title h2 {
        font-size: 1.75rem;
    }

    .flip-card {
        width: 240px;
        height: 350px;
    }
}
