/* =========================================
   Homepage Category Carousel
   Optimized for Performance, CLS & LCP
========================================= */

.carousel-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    /* Lock layout height to prevent collapse before image loads */
    min-height: 250px;
    contain: layout style;
}

/* Horizontal scrolling handled natively by browser */
.carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    gap: 30px;
    padding: 10px;
    scrollbar-width: none;
    /* Tells browser to optimize rendering for off-screen items */
    content-visibility: auto;
    contain-intrinsic-size: 1000px 250px;
}

.carousel::-webkit-scrollbar {
    display: none;
}

/* Individual category card */
.carousel-slide {
    flex: 0 0 196px; /* Lock both basis and max-width */
    width: 196px;
    scroll-snap-align: start;
    text-align: center;
    border-radius: 10px;
    overflow: hidden;
    background: linear-gradient(
        180deg,
        rgba(0,0,0,0) 30%,
        #fff 0%
    );
}

/* Category image */
.carousel-slide img {
    width: 196px;
    height: 196px;
    /* Reserve precise space instantly even before image bytes arrive */
    aspect-ratio: 1 / 1; 
    object-fit: cover;
    display: block;
    border-radius: 10px;
    transition: transform .6s ease;
    will-change: transform;
}

.carousel-slide img:hover {
    transform: scale(1.25);
}

/* Category title button */
.carousel-slide a:nth-child(2) {
    color: #fff;
    background-color: #5440fa;
    display: block;
    padding: 6px 5px;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 600;
    transition: transform .4s ease;
    margin-top: 5px;
    position: relative;
    text-decoration: none;
}

/* Optimized arrow icon */
.carousel-slide a:nth-child(2)::after {
    content: "";
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 8px;
    vertical-align: middle;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Ccircle cx='256' cy='256' r='248' fill='white'/%3E%3Cpath fill='%235440fa' d='M227.1 151.6l75.5 72.4H120c-13.3 0-24 10.7-24 24v16c0 13.3 10.7 24 24 24h182.6l-75.5 72.4c-9.7 9.3-9.9 24.8-.4 34.3l11 10.9c9.4 9.4 24.6 9.4 33.9 0L404.3 273c9.4-9.4 9.4-24.6 0-33.9L271.6 106.3c-9.4-9.4-24.6-9.4-33.9 0l-11 10.9c-9.5 9.6-9.3 25.1.4 34.4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    border-radius: 50%;
}

.carousel-slide a:hover {
    transform: scale(1.1);
}

/* Navigation arrows */
.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    border: none;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel-btn.prev {
    left: 10px;
}

.carousel-btn.next {
    right: 10px;
}

.carousel-btn:hover {
    background: #5440fa;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .carousel-wrapper {
        min-height: 200px;
    }

    .carousel {
        gap: 15px;
        contain-intrinsic-size: 1000px 200px;
    }

    .carousel-slide {
        flex: 0 0 150px; /* Synchronized flex-basis for mobile */
        width: 150px;
    }

    .carousel-slide img {
        width: 150px;
        height: 150px;
    }

    .carousel-btn {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
}