#post-categories {
    background-color: #F7F9FC;
    position:relative;
    padding-top:200px;
    padding-bottom: 200px;
}

.post-categories-title {
    font-family: 'Geologica', sans-serif;
    font-weight: 700;
    font-size: 24px;
    color: #013877;
    margin-bottom: 40px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#post-categories .bg-img{
    position: absolute;
    top:0;
    right:0;
}
.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 50px;
}

.category-card {
    position: relative;
    background-color: #ffffff;
    border-radius: 30px;
    height: 280px;
    overflow: hidden;
    text-decoration: none;
    display: block;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

/* ── CACHE-SAFE CARD HIDING LOGIC ── */

/* Desktop default: Hide from the 9th category card onwards */
.category-grid .category-card:nth-child(n+9) {
    display: none;
}

/* Force elements back to block layout when revealed by JavaScript */
.category-grid .category-card.is-animating {
    display: block !important;
    animation: revealCard 0.5s ease forwards;
    opacity: 0;
}

@keyframes revealCard {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.category-card__news-icon {
    position: absolute;
    bottom: 25px;
    left: 25px;
    z-index: 1;
    width: 48px;
    height: 48px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.category-card:hover .category-card__news-icon {
    opacity: 1;
    transform: translateY(0);
}

.category-card__title-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #BFD4E8;
    z-index: 2;
    padding: 30px;
    box-sizing: border-box;
    transition: height 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

.category-card:hover .category-card__title-bg {
    height: 110px;
}

.category-card__name {
    font-family: 'Geologica';
    font-weight: 700;
    font-size: 24px;
    line-height: 32px;
    letter-spacing: 0%;
    color:#013877;
}

.category-card__desc-wrapper {
    position: absolute;
    top: 115px;
    left: 30px;
    right: 30px;
    z-index: 3;
    pointer-events: none;
}

.category-card__description {
    font-family: 'Geologica';
    font-weight: 100;
    font-size: 18px;
    line-height: 24px;
    letter-spacing: 0%;
    color:#013877;
}

.category-card__icon {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: transparent;
    border: 1px solid rgba(1, 56, 119, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #013877;
    z-index: 3;
    transition: all 0.4s ease;
}

.category-card:hover .category-card__icon {
    background-color: #ffffff;
    border-color: #e0e6ed;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.category-card__icon svg {
    width: 20px;
    height: 20px;
}


/* ── CACHE-SAFE BUTTON VISIBILITY LOGIC ── */
.category-load-more-wrapper {
    display: none; /* Hidden by default */
    justify-content: end;
    margin-top: 40px;
}

#post-categories button.sliding-btn-link {
    appearance: none;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
}

/* Desktop: Show button ONLY if a 9th card exists in the HTML */
#post-categories:has(.category-card:nth-child(n+9)) .category-load-more-wrapper {
    display: flex;
}


/* ── MEDIA QUERIES ── */

@media (max-width: 1100px) {
    .category-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 850px) {
    .category-grid { grid-template-columns: repeat(2, 1fr); }

    .category-load-more-wrapper{
        justify-content: center;
    }
}

@media screen and (max-width:768px){

    #post-categories{
        padding-top:40px;
        padding-bottom: 40px;
    }
    .category-card__name{
        font-size:18px;
    }

    .category-card__description{
        font-size:16px;
    }

    #post-categories .bg-img{
        width: 100px;
    }

    /* Mobile Cutoff: Override hiding rule to cut off after the 4th item */
    .category-grid .category-card:nth-child(n+5) {
        display: none;
    }

    /* Mobile Button Control: Reset desktop conditions and apply mobile thresholds */
    #post-categories:has(.category-card:nth-child(n+9)) .category-load-more-wrapper {
        display: none;
    }
    #post-categories:has(.category-card:nth-child(n+5)) .category-load-more-wrapper {
        display: flex;
    }
}

@media (max-width: 520px) {
    .category-grid { grid-template-columns: 1fr; }
}