/* Flip Card Styles */
.portfolio-card {
    width: 100%;
    height: 100%;
    perspective: 1000px;
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    /* Clip content at card boundary - essential for preventing overflow */
    overflow: hidden;
    border-radius: 12px;
    /* Force clipping of 3D transformed children - use isolation instead of transform-style */
    isolation: isolate;
}

/* Desktop: Constrain card width to match video width, prevent stretching to grid column */
@media (min-width: 769px) {
    /* Section A: Match video max-width (402px) */
    .section-a-video .portfolio-card {
        width: min(402px, 25.125vw);
        max-width: min(402px, 25.125vw);
        margin-inline: auto;
        height: 100%;
    }
    
    /* Section B and C: Match video max-width (382px) */
    .section-b-video .portfolio-card,
    .section-c-video .portfolio-card {
        width: min(382px, 24.12vw);
        max-width: min(382px, 24.12vw);
        margin-inline: auto;
        height: 100%;
    }
    
    /* Ensure video-wrapper and both faces use full width/height of card */
    .portfolio-card .video-wrapper,
    .portfolio-card .card-front,
    .portfolio-card .card-back {
        width: 100%;
        height: 100%;
    }
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    /* overflow: visible needed for 3D transforms, but parent clips */
    overflow: visible;
    border-radius: 12px;
    /* Ensure inner doesn't exceed card bounds */
    max-width: 100%;
    max-height: 100%;
}

/* Mobile: Fixed aspect ratio for card container */
@media (max-width: 768px) {
    .portfolio-card {
        aspect-ratio: 9 / 16;
        height: auto;
        min-height: 497px; /* Ensure minimum height for video visibility */
    }
    
    .card-inner {
        aspect-ratio: 9 / 16;
        height: 100%;
        min-height: 497px; /* Match parent min-height */
    }
    
    .card-front,
    .card-back {
        min-height: 497px; /* Ensure absolute positioned elements have height */
    }
}

.portfolio-card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
    /* overflow: hidden on faces to clip content */
    overflow: hidden;
    /* Ensure content is clipped to card bounds */
    box-sizing: border-box;
}


.card-front {
    z-index: 2;
    pointer-events: auto;
}

@media (max-width: 768px) {
    .card-front {
        z-index: 1;
    }
}

.card-back {
    transform: rotateY(180deg);
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    /* Fully constrained within card bounds - inset:0 already set in shared rule above */
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    /* Ensure clipping works with 3D transforms */
    contain: layout style paint;
    /* Force strict clipping - overflow hidden on card-back to clip text-shadow */
    overflow: hidden;
    border-radius: 12px;
    /* Additional containment to prevent visual overflow */
    max-width: 100%;
    max-height: 100%;
    box-sizing: border-box;
}

.card-back-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.15;
    transition: opacity 0.3s ease;
}

.card-back-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Desktop: Ensure card-back-video matches card-front video dimensions exactly */
@media (min-width: 769px) {
    .card-back-video {
        /* Match the video-item dimensions from card-front */
        aspect-ratio: 9 / 16;
    }
    
    /* Match specific section video sizes */
    .section-a-video .card-back-video {
        max-width: 402px;
        max-height: 80vh;
    }
    
    /* Section A specific text containment - same as Section B */
    .section-a-video .card-back-content {
        padding: clamp(20px, 2.5vw, 30px) clamp(25px, 3vw, 40px) clamp(80px, 8vw, 100px) clamp(25px, 3vw, 40px); /* Increased side padding to ensure text-shadow stays within bounds */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        overflow: hidden;
        overflow-y: auto;
        min-height: 0;
    }
    
    .section-a-video .card-back-content h3 {
        font-size: clamp(1rem, 1.2vw, 1.4rem);
        margin-bottom: clamp(10px, 1.2vw, 15px);
        margin-top: 0;
        /* Strict width containment - account for text-shadow extension (25px each side = 50px total) */
        width: calc(100% - 50px);
        max-width: calc(100% - 50px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        overflow-wrap: break-word;
        word-break: break-word;
        letter-spacing: 0.1em;
        /* Force clipping of visual overflow */
        clip-path: inset(0);
        /* Minimal text-shadow to prevent visual overflow */
        text-shadow: 
            0 0 5px rgba(220, 170, 255, 0.3),
            0 0 10px rgba(200, 150, 255, 0.2);
    }
    
    .section-a-video .card-back-content p {
        font-size: clamp(0.7rem, 0.8vw, 0.8rem);
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 12px;
        box-sizing: border-box;
        line-height: 1.5;
        overflow: hidden;
        word-break: break-word;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
    }
    
    .section-a-video .card-back-content .card-info {
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        overflow: hidden;
        margin-top: 12px;
        gap: 6px;
    }
    
    /* Section B specific text containment - same as Section C */
    .section-b-video .card-back-content {
        padding: clamp(20px, 2.5vw, 30px) clamp(25px, 3vw, 40px) clamp(80px, 8vw, 100px) clamp(25px, 3vw, 40px); /* Increased side padding to ensure text-shadow stays within bounds */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        overflow: hidden;
        overflow-y: auto;
        min-height: 0;
    }
    
    .section-b-video .card-back-content h3 {
        font-size: clamp(1rem, 1.2vw, 1.4rem);
        margin-bottom: clamp(10px, 1.2vw, 15px);
        margin-top: 0;
        /* Strict width containment - account for text-shadow extension (25px each side = 50px total) */
        width: calc(100% - 50px);
        max-width: calc(100% - 50px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        overflow-wrap: break-word;
        word-break: break-word;
        letter-spacing: 0.1em;
        /* Force clipping of visual overflow */
        clip-path: inset(0);
        /* Minimal text-shadow to prevent visual overflow */
        text-shadow: 
            0 0 5px rgba(220, 170, 255, 0.3),
            0 0 10px rgba(200, 150, 255, 0.2);
    }
    
    .section-b-video .card-back-content p {
        font-size: clamp(0.7rem, 0.8vw, 0.8rem);
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 12px;
        box-sizing: border-box;
        line-height: 1.5;
        overflow: hidden;
        word-break: break-word;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
    }
    
    .section-b-video .card-back-content .card-info {
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        overflow: hidden;
        margin-top: 12px;
        gap: 6px;
    }
    
    /* Section B now uses same sizes as Section C */
    .section-b-video .card-back-video {
        max-width: min(382px, 24.12vw);
        max-height: 75vh;
    }
    
    .video-small .card-back-video,
    .video-medium .card-back-video,
    .video-large .card-back-video {
        max-width: min(382px, 24.12vw); /* All equal now */
        max-height: 75vh;
    }
    
    .section-c-video .card-back-video {
        max-width: min(382px, 24.12vw);
        max-height: 75vh;
    }
    
    /* Section C specific text containment - same as Section B */
    .section-c-video .card-back-content {
        padding: clamp(20px, 2.5vw, 30px) clamp(25px, 3vw, 40px) clamp(80px, 8vw, 100px) clamp(25px, 3vw, 40px); /* Increased side padding to ensure text-shadow stays within bounds */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        overflow: hidden;
        overflow-y: auto;
        min-height: 0;
    }
    
    .section-c-video .card-back-content h3 {
        font-size: clamp(1rem, 1.2vw, 1.4rem);
        margin-bottom: clamp(10px, 1.2vw, 15px);
        margin-top: 0;
        /* Strict width containment - account for text-shadow extension (25px each side = 50px total) */
        width: calc(100% - 50px);
        max-width: calc(100% - 50px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        overflow-wrap: break-word;
        word-break: break-word;
        letter-spacing: 0.1em;
        /* Force clipping of visual overflow */
        clip-path: inset(0);
        /* Minimal text-shadow to prevent visual overflow */
        text-shadow: 
            0 0 5px rgba(220, 170, 255, 0.3),
            0 0 10px rgba(200, 150, 255, 0.2);
    }
    
    .section-c-video .card-back-content p {
        font-size: clamp(0.7rem, 0.8vw, 0.8rem);
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 12px;
        box-sizing: border-box;
        line-height: 1.5;
        overflow: hidden;
        word-break: break-word;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
    }
    
    .section-c-video .card-back-content .card-info {
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        overflow: hidden;
        margin-top: 12px;
        gap: 6px;
    }
}

.card-back-content {
    position: relative;
    z-index: 2;
    /* Increased side padding to account for text-shadow clipping (25px buffer each side for h3 text-shadow max 10px blur) */
    padding: clamp(20px, 2.5vw, 30px) clamp(25px, 3vw, 40px) clamp(80px, 8vw, 100px) clamp(25px, 3vw, 40px); /* Increased side padding to ensure text-shadow stays within bounds */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    height: 100%;
    color: #fff;
    text-align: center;
    box-sizing: border-box;
    /* Strict containment - must not exceed card bounds */
    width: 100%;
    max-width: 100%;
    min-width: 0; /* Allow flex shrinking */
    /* Overflow clipping to prevent text from going outside card */
    overflow: hidden;
    /* Prevent text from overflowing */
    word-break: break-word;
    /* Ensure content is contained within parent */
    min-height: 0;
    overflow-y: auto; /* Allow scrolling if needed */
}

.card-back-content h3 {
    font-size: clamp(1.1rem, 1.3vw, 1.5rem);
    font-weight: 300;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: transparent;
    -webkit-text-stroke: 1px rgba(220, 170, 255, 0.9);
    text-stroke: 1px rgba(220, 170, 255, 0.9);
    /* Minimal text-shadow to prevent visual overflow - keep glow very subtle */
    text-shadow: 
        0 0 5px rgba(220, 170, 255, 0.3),
        0 0 10px rgba(200, 150, 255, 0.2);
    margin-bottom: clamp(15px, 1.8vw, 20px);
    margin-top: 0;
    /* Strict width containment - account for text-shadow extension (25px each side = 50px total) */
    width: calc(100% - 50px);
    max-width: calc(100% - 50px);
    min-width: 0;
    padding: 0 5px; /* Minimal padding to ensure fit */
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    /* Clamp to max 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    /* Force clipping of visual overflow */
    clip-path: inset(0);
}

.card-back-content p {
    font-size: clamp(0.75rem, 0.9vw, 0.85rem);
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: clamp(12px, 1.2vw, 15px);
    /* Strict width containment - account for own padding (5px each side = 10px total) */
    width: calc(100% - 10px);
    max-width: calc(100% - 10px);
    min-width: 0;
    padding: 0 5px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    overflow: hidden;
    /* Limit to 4-5 lines max */
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    /* Ensure text doesn't visually overflow */
    text-align: center;
}

.card-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 15px;
    /* Strict width containment - account for own padding (5px each side = 10px total) */
    width: calc(100% - 10px);
    max-width: calc(100% - 10px);
    min-width: 0;
    padding: 0 5px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    overflow: hidden;
}

.card-info span {
    font-size: clamp(0.75rem, 0.9vw, 0.9rem);
    color: rgba(220, 170, 255, 0.8);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Play Button */
.play-button {
    position: absolute;
    bottom: clamp(20px, 2.5vw, 30px);
    left: 50%;
    transform: translateX(-50%);
    width: clamp(50px, 5vw, 70px);
    height: clamp(50px, 5vw, 70px);
    background: rgba(220, 170, 255, 0.2);
    border: 2px solid rgba(220, 170, 255, 0.6);
    border-radius: 50%;
    color: rgba(220, 170, 255, 0.9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.play-button:hover {
    background: rgba(220, 170, 255, 0.3);
    border-color: rgba(220, 170, 255, 0.9);
    color: rgba(220, 170, 255, 1);
    transform: translateX(-50%) scale(1.1);
    box-shadow: 0 0 30px rgba(220, 170, 255, 0.5);
}

.play-button svg {
    width: 24px;
    height: 24px;
    margin-left: 3px;
}

/* Desktop: Better text positioning within video */
@media (min-width: 769px) {
    /* Global card-back-content padding - sections A, B, C override this with their own padding */
    .card-back-content {
        padding: clamp(20px, 2.5vw, 30px) clamp(25px, 3vw, 40px) clamp(80px, 8vw, 100px) clamp(25px, 3vw, 40px); /* Increased side padding to ensure text-shadow stays within bounds */
        /* Strict containment - must not exceed card bounds */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        /* Prevent any overflow - clip text to container */
        overflow: hidden;
        overflow-y: auto;
        /* Contain content */
        min-height: 0;
    }
    
    .card-back-content h3 {
        font-size: clamp(1rem, 1.2vw, 1.4rem);
        margin-bottom: clamp(10px, 1.2vw, 15px);
        margin-top: 0;
        /* Strict width containment - account for text-shadow extension (25px each side = 50px total) */
        width: calc(100% - 50px);
        max-width: calc(100% - 50px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        /* Force clipping of visual overflow */
        clip-path: inset(0);
        /* Minimal text-shadow to prevent visual overflow */
        text-shadow: 
            0 0 5px rgba(220, 170, 255, 0.3),
            0 0 10px rgba(200, 150, 255, 0.2);
        text-overflow: ellipsis;
        overflow-wrap: break-word;
        word-break: break-word;
        letter-spacing: 0.1em;
    }
    
    .card-back-content p {
        font-size: clamp(0.7rem, 0.8vw, 0.8rem);
        /* Strict width containment - account for own padding (5px each side = 10px total) */
        width: calc(100% - 10px);
        max-width: calc(100% - 10px);
        min-width: 0;
        padding: 0 5px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 12px;
        box-sizing: border-box;
        line-height: 1.5;
        overflow: hidden;
        word-break: break-word;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
    }
    
    .card-info {
        /* Strict width containment */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 0 5px;
        box-sizing: border-box;
        overflow: hidden;
        margin-top: 12px;
        gap: 6px;
    }
    
    /* Adjust for smaller videos */
    .video-small .card-back-content {
        padding: clamp(18px, 2vw, 25px) clamp(12px, 1.5vw, 15px) clamp(70px, 7vw, 90px) clamp(12px, 1.5vw, 15px);
    }
    
    .video-small .card-back-content h3 {
        font-size: clamp(0.9rem, 1vw, 1.2rem);
        line-height: 1.3;
        /* Reduced letter-spacing on narrow cards to prevent stroke/glow overflow */
        letter-spacing: 0.1em;
    }
    
    .video-small .card-back-content p {
        font-size: clamp(0.65rem, 0.75vw, 0.75rem);
        line-height: 1.4;
        -webkit-line-clamp: 3; /* Fewer lines for small videos */
    }
}

/* Responsive */
@media (max-width: 768px) {
    .card-back-content {
        padding: 25px 15px 90px 15px; /* Bottom padding for play button */
    }
    
    .card-back-content h3 {
        font-size: 1.2rem;
        margin-bottom: 15px;
        margin-top: 0;
        /* Strict width containment */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 0 5px;
        letter-spacing: 0.08em;
        overflow-wrap: break-word;
        word-break: break-word;
        box-sizing: border-box;
    }
    
    .card-back-content p {
        font-size: 0.75rem;
        margin-bottom: 12px;
        /* Strict width containment */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 0 5px;
        overflow-wrap: break-word;
        word-break: break-word;
        overflow: hidden;
        box-sizing: border-box;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
        line-height: 1.4;
    }
    
    .card-info {
        /* Strict width containment */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 0 5px;
        overflow: hidden;
        box-sizing: border-box;
        margin-top: 10px;
        gap: 5px;
    }
    
    .play-button {
        width: 60px;
        height: 60px;
        bottom: 20px;
    }
}

