/**
 * Portfolio Projects Stylesheet
 * Styles for project cards, filters, infinite carousel, and drag/swipe interactions
 * Integrated with CMS data and supports both light/dark themes
 */

/**
 * Portfolio Filter Buttons
 * Pill-shaped buttons with glassmorphism effects in dark mode
 */
.portfolio-filters {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 3rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.8rem 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.4rem;
    font-weight: 500;
}

.filter-btn:hover {
    background: rgba(42, 93, 168, 0.2);
    border-color: rgba(42, 93, 168, 0.4);
    color: #4a9eff;
}

.filter-btn.active {
    background: rgba(42, 93, 168, 0.3);
    border-color: rgba(42, 93, 168, 0.6);
    color: #4a9eff;
}

html[data-theme='dark'] .filter-btn {
    background: linear-gradient(145deg, rgba(59, 130, 246, 0.24) 0%, rgba(14, 165, 233, 0.22) 100%);
    border: 1px solid rgba(96, 165, 250, 0.45);
    color: #e2f2ff;
    box-shadow: 0 14px 32px rgba(12, 74, 110, 0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

html[data-theme='dark'] .filter-btn:hover {
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.45) 0%, rgba(56, 189, 248, 0.42) 100%);
    border-color: rgba(129, 140, 248, 0.75);
    color: #f5fbff;
    box-shadow: 0 18px 38px rgba(30, 64, 175, 0.42);
}

html[data-theme='dark'] .filter-btn.active {
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.55) 0%, rgba(59, 130, 246, 0.5) 50%, rgba(56, 189, 248, 0.48) 100%);
    border-color: rgba(129, 140, 248, 0.85);
    color: #ffffff;
    box-shadow: 0 22px 42px rgba(30, 64, 175, 0.5);
}

/**
 * Portfolio Container
 * Main wrapper for carousel with overflow control and drag cursor
 */
.portfolio-container {
    position: relative;
    overflow: hidden;
    margin-bottom: 2rem;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/**
 * Carousel Track
 * Flexbox layout with GPU-accelerated transforms for smooth infinite scrolling
 */
.portfolio-carousel {
    display: flex;
    gap: 2rem;
    will-change: transform;
    cursor: grab;
    transition: none;
}

/**
 * Dragging State
 * Changes cursor and disables transitions during user interaction
 */
.portfolio-carousel.dragging {
    cursor: grabbing;
    transition: none !important;
    animation: none !important;
}

/**
 * Auto-scrolling Animation
 * Continuous smooth scroll with pause-on-hover functionality
 */
.portfolio-carousel.auto-scrolling {
    animation: smoothScroll 15s linear infinite;
    cursor: grab;
}

.portfolio-carousel.auto-scrolling:hover {
    animation-play-state: paused;
}

@keyframes smoothScroll {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-50%);
    }
}

/**
 * Carousel Card Styles
 * Two-column layout cards with glassmorphism effects
 */
.carousel-card {
    flex: 0 0 auto;
    width: calc(50% - 1rem);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.carousel-card:hover {
    box-shadow: 0 20px 40px rgba(42, 93, 168, 0.2);
    border-color: rgba(42, 93, 168, 0.4);
}

.card-image {
    position: relative;
    width: 100%;
    /* Responsive aspect ratio to avoid "gepeng" look on tablet */
    height: auto;
    aspect-ratio: 16 / 9; /* default desktop */
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.card-image img {
    width: 100%;
    height: 100%;
    /* Show the whole image (no crop). OK to stretch to fill the frame */
    object-fit: fill;
    transition: transform 0.4s ease;
    cursor: pointer;
}

.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Bottom-only gradient to keep most of the image clear and highlighted */
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.70) 0%,
        rgba(0, 0, 0, 0.55) 22%,
        rgba(0, 0, 0, 0.30) 42%,
        rgba(0, 0, 0, 0.12) 60%,
        rgba(0, 0, 0, 0.00) 75%
    );
    display: flex;
    flex-direction: column;
    cursor: pointer;
    /* Keep bottom area (title/desc) anchored to bottom */
    justify-content: flex-start;
    padding: 1rem;
    /* Always show overlay so title is on top of image */
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Subtle image highlight on hover */
.carousel-card:hover .card-image img {
    transform: scale(1.03);
}

/* Make image taller on tablet for better balance */
@media (min-width: 641px) and (max-width: 1024px) {
    .card-image { aspect-ratio: 3 / 2; }
}

/* Slightly taller on mobile for readability */
@media (max-width: 640px) {
    .card-image { aspect-ratio: 4 / 3; }
}

/* Overlay is visible by default for title-on-image design */

/**
 * Overlay Layout Sections
 * Top section contains category badge and link button
 * Bottom section contains project description
 */
.overlay-top {
    /* Hidden by default; shown on hover or when active */
    display: none;
    justify-content: space-between;
    align-items: flex-start;
    cursor: pointer;
}

.overlay-bottom {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    cursor: pointer;
    /* Push bottom block to the bottom even when overlay-top is hidden */
    margin-top: auto;
}

/* Show category badge and link on hover (desktop) or when active (mobile) */
.carousel-card:hover .overlay-top,
.carousel-card.active .overlay-top {
    display: flex;
}

/**
 * Category Badge
 * Pill-shaped indicator for project type
 */
.card-category {
    background: rgba(42, 93, 168, 0.9);
    color: #fff;
    padding: 0.4rem 0.9rem;
    border-radius: 15px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
}

/**
 * External Link Button
 * Circular button with icon for project links
 */
.card-link {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s ease;
}

.card-link:hover {
    background: #fff;
    transform: scale(1.1);
}

/**
 * Overlay Title
 * Visible inside image overlay, positioned above description
 */
.overlay-title {
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

/**
 * Overlay Description
 * Truncated text with text-shadow for readability over images
 */
.overlay-description {
    font-size: 1.4rem;
    color: rgba(255, 255, 255, 0.95);
    line-height: 1.6;
    /* hidden by default, shown on hover/tap */
    display: none;
    line-clamp: 4;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

/* Show description on hover (desktop) */
.carousel-card:hover .overlay-description {
    display: -webkit-box;
}

/* Show description when card is activated (mobile tap) */
.carousel-card.active .overlay-description {
    display: -webkit-box;
}

/* Light theme: ensure strong contrast for overlay text */
html[data-theme='light'] .card-overlay {
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.80) 0%,
        rgba(0, 0, 0, 0.60) 28%,
        rgba(0, 0, 0, 0.32) 52%,
        rgba(0, 0, 0, 0.12) 70%,
        rgba(0, 0, 0, 0.00) 82%
    );
}

html[data-theme='light'] .overlay-title,
html[data-theme='light'] .overlay-description {
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7), 0 1px 3px rgba(0, 0, 0, 0.45);
}

/* Hide bottom content area to avoid extra space below image */
.card-content {
    display: none;
}

.card-title {
    font-size: 1.6rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 0;
    line-height: 1.3;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-description {
    display: none;
}

/* Dot Navigation */
.carousel-nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
    align-items: center;
}

.carousel-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    margin: 0;
}

.carousel-dot:hover {
    background: rgba(42, 93, 168, 0.5);
    border-color: rgba(42, 93, 168, 0.7);
    transform: scale(1.2);
}

.carousel-dot.active {
    background: #4a9eff;
    border-color: #4a9eff;
    transform: scale(1.3);
}

.carousel-dot:focus {
    outline: 2px solid rgba(42, 93, 168, 0.8);
    outline-offset: 2px;
}

/* Legacy Project Styling (for backward compatibility) */
.project {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    padding: 2rem;
    transition: all 0.3s ease;
    overflow: hidden;
    margin-bottom: 2rem;
}

.project:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(42, 93, 168, 0.1);
    border-color: rgba(42, 93, 168, 0.3);
}

.project-image {
    width: 100%;
    height: 200px;
    overflow: hidden;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.project-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.project:hover .project-image img {
    transform: scale(1.05);
}

.project-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-size: var(--fs-small);
    opacity: 0.8;
}

.project-category {
    background: rgba(42, 93, 168, 0.2);
    color: #4a9eff;
    padding: 0.3rem 0.8rem;
    border-radius: 15px;
    font-weight: 500;
    font-size: 1.2rem;
}

.project-date {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.2rem;
}

.project-content h3 {
    margin-bottom: 1rem;
    color: #fff;
    line-height: 1.3;
    font-size: 1.8rem;
}

.project-content p {
    margin-bottom: 1.5rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.4rem;
}

.project-tech {
    margin-bottom: 1.5rem;
}

.project-tech strong {
    color: #4a9eff;
    margin-bottom: 0.5rem;
    display: block;
    font-size: 1.4rem;
}

.tech-tag {
    display: inline-block;
    background: rgba(74, 158, 255, 0.1);
    color: #4a9eff;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 1.1rem;
    margin: 0.2rem 0.3rem 0.2rem 0;
    border: 1px solid rgba(74, 158, 255, 0.2);
}

.project-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.project-links .btn {
    font-size: 1.4rem;
    padding: 1rem 1.5rem;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.project-links .btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.project-links .btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

/* Light Theme */
html[data-theme='light'] .project {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme='light'] .project:hover {
    box-shadow: 0 10px 30px rgba(42, 93, 168, 0.15);
}

html[data-theme='light'] .project-content h3 {
    color: #0f172a;
}

html[data-theme='light'] .project-content p {
    color: rgba(0, 0, 0, 0.7);
}

html[data-theme='light'] .project-date {
    color: rgba(0, 0, 0, 0.6);
}

html[data-theme='light'] .project-links .btn.secondary {
    background: rgba(0, 0, 0, 0.05);
    color: #0f172a;
    border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme='light'] .project-links .btn.secondary:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Light Theme */
html[data-theme='light'] .filter-btn {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.7);
}

html[data-theme='light'] .filter-btn:hover,
html[data-theme='light'] .filter-btn.active {
    background: rgba(42, 93, 168, 0.1);
    border-color: rgba(42, 93, 168, 0.3);
    color: #2a5da8;
}

html[data-theme='light'] .carousel-card {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme='light'] .carousel-card:hover {
    box-shadow: 0 20px 40px rgba(42, 93, 168, 0.1);
}

html[data-theme='light'] .card-title {
    color: #0f172a;
}

html[data-theme='light'] .card-description {
    color: rgba(0, 0, 0, 0.7);
}

html[data-theme='light'] .carousel-dot {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(0, 0, 0, 0.3);
}

html[data-theme='light'] .carousel-dot:hover {
    background: rgba(42, 93, 168, 0.3);
    border-color: rgba(42, 93, 168, 0.5);
}

html[data-theme='light'] .carousel-dot.active {
    background: #2a5da8;
    border-color: #2a5da8;
}

html[data-theme='light'] .card-image,
html[data-theme='light'] .project-image {
    background: rgba(0, 0, 0, 0.05);
}

/* Responsive Carousel */
@media (max-width: 1024px) {
    .carousel-card {
        width: calc(50% - 1rem);
    }
}

@media (max-width: 768px) {
    .carousel-card {
        width: 100%;
    }
    
    .portfolio-filters {
        gap: 0.5rem;
        margin-bottom: 2rem;
    }
    
    .filter-btn {
        padding: 0.6rem 1.2rem;
        font-size: 1.3rem;
    }
    
    /* Make mobile images fit to frame like desktop */
    .card-image {
        height: 250px;
    }
    .card-image img {
        object-fit: fill; /* fit to frame, allow stretch */
    }
    
    .card-content {
        padding: 1.2rem;
    }
    
    .card-title {
        font-size: 1.5rem;
    }
    
    .card-description {
        font-size: 1.2rem;
    }
    
    .carousel-nav {
        gap: 0.8rem;
    }
    
    .carousel-dot {
        width: 10px;
        height: 10px;
    }
}

@media (max-width: 480px) {
    .portfolio-carousel {
        gap: 1rem;
    }
    
    .card-image {
        height: 200px; /* fixed height on small mobile */
    }
    
    .card-image img {
        object-fit: fill; /* fit to frame */
    }
    
    .filter-btn {
        padding: 0.5rem 1rem;
        font-size: 1.2rem;
    }
}

/* Legacy Responsive (for backward compatibility) */
@media (max-width: 768px) {
    .project {
        padding: 1.5rem;
    }
    /* Legacy list: match carousel behavior */
    .project-image {
        height: auto;
        aspect-ratio: 16 / 9;
    }
    .project-image img {
        object-fit: contain; /* don't crop image on mobile */
    }
    
    .project-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .project-links {
        flex-direction: column;
    }
    
    .project-links .btn {
        width: 100%;
        text-align: center;
        justify-content: center;
    }
}