.categories-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: minmax(130px, auto);
    grid-auto-flow: dense;
    gap: 22px;
    width: 100%;
    padding: 16px;
}

.category-card {
    position: relative;
    text-decoration: none;
    color: var(--color-text-main);
    align-items: center;
    text-align: center;
    justify-content: center;
    grid-column: span 1;
    grid-row: span 1;
    transform: rotate(0deg);
}

    .category-card:hover {
        transform: rotate(0deg) translateY(-4px) scale(1.02);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
        z-index: 2;
    }

    .category-card .card-content {
        align-items: center;
        justify-content: center;
        gap: 8px;
        flex: 1;
    }

    .category-card h3 {
        margin: 0;
    }

    .category-card p {
        margin: 0;
        padding: 3px 14px;
        border-radius: var(--radius-pill);
        background-color: rgba(255, 255, 255, 0.6);
        font-size: var(--font-size-sm);
        color: var(--color-text-sub);
    }

.category-bubbles {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 42px;
}

.category-bubble {
    border-radius: 50%;
    object-fit: cover;
    background-color: var(--color-white);
    border: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-play-state: running;
    transition: margin .45s ease;
}

.category-card:hover .category-bubble {
    animation-play-state: paused;
}

    .category-bubble:not(:first-child) {
        margin-inline-start: -12px;
    }

    .category-card:hover .category-bubble:not(:first-child) {
        margin-inline-start: -2px;
    }

    .category-card:hover .category-bubble:nth-child(2) {
        margin-bottom: 6px;
    }

    .category-bubble:nth-child(1) {
        width: 30px;
        height: 30px;
        z-index: 1;
        animation-name: bubble-float-a;
        animation-duration: 4.2s;
        animation-delay: -0.6s;
    }

    .category-bubble:nth-child(2) {
        width: 42px;
        height: 42px;
        z-index: 2;
        animation-name: bubble-float-b;
        animation-duration: 5.4s;
        animation-delay: -2.1s;
    }

    .category-bubble:nth-child(3) {
        width: 35px;
        height: 35px;
        z-index: 1;
        animation-name: bubble-float-c;
        animation-duration: 4.8s;
        animation-delay: -3.4s;
    }

@keyframes bubble-float-a {
    0%, 100% { transform: translate(0, 3px) rotate(-3deg); }
    50% { transform: translate(3px, -6px) rotate(-7deg); }
}

@keyframes bubble-float-b {
    0%, 100% { transform: translate(0, -4px) rotate(3deg); }
    50% { transform: translate(-4px, 5px) rotate(6deg); }
}

@keyframes bubble-float-c {
    0%, 100% { transform: translate(0, 3px) rotate(-2deg); }
    50% { transform: translate(3px, -5px) rotate(4deg); }
}

/* -- irregular bento sizing -- */
.categories-grid .category-card:nth-child(8n+1) {
    grid-column: span 2;
    grid-row: span 2;
    background-color: var(--color-primary-light);
    padding: 28px;
    transform: rotate(-1.5deg);
}

.categories-grid .category-card:nth-child(8n+2) {
    transform: rotate(2deg);
}

.categories-grid .category-card:nth-child(8n+3) {
    grid-row: span 2;
    background-color: var(--color-accent);
    color: var(--color-white);
    padding: 22px;
    transform: rotate(1deg);
}

    .categories-grid .category-card:nth-child(8n+3) p {
        color: var(--color-white);
        background-color: rgba(0, 0, 0, 0.15);
    }

.categories-grid .category-card:nth-child(8n+4) {
    transform: rotate(-2deg);
}

.categories-grid .category-card:nth-child(8n+5) {
    grid-column: span 2;
    background-color: var(--gray);
    transform: rotate(1.5deg);
}

.categories-grid .category-card:nth-child(8n+6) {
    transform: rotate(-1deg);
}

.categories-grid .category-card:nth-child(8n+7) {
    grid-row: span 2;
    background-color: var(--color-secondary-light);
    color: var(--color-white);
    padding: 22px;
    transform: rotate(2deg);
}

    .categories-grid .category-card:nth-child(8n+7) p {
        color: var(--color-white);
        background-color: rgba(0, 0, 0, 0.15);
    }

.categories-grid .category-card:nth-child(8n) {
    grid-column: span 2;
    transform: rotate(-1.5deg);
}

.category-card:nth-child(8n+1) h3 {
    font-size: var(--font-size-2xl);
}

.categories-grid .category-card:nth-child(8n+1) .category-bubbles {
    height: 68px;
}

.categories-grid .category-card:nth-child(8n+1) .category-bubble:nth-child(1) {
    width: 52px;
    height: 52px;
}

.categories-grid .category-card:nth-child(8n+1) .category-bubble:nth-child(2) {
    width: 68px;
    height: 68px;
}

.categories-grid .category-card:nth-child(8n+1) .category-bubble:nth-child(3) {
    width: 58px;
    height: 58px;
}

.categories-grid .category-card:nth-child(8n+3) .category-bubbles,
.categories-grid .category-card:nth-child(8n+7) .category-bubbles {
    height: 52px;
}

.categories-grid .category-card:nth-child(8n+3) .category-bubble:nth-child(1),
.categories-grid .category-card:nth-child(8n+7) .category-bubble:nth-child(1) {
    width: 36px;
    height: 36px;
}

.categories-grid .category-card:nth-child(8n+3) .category-bubble:nth-child(2),
.categories-grid .category-card:nth-child(8n+7) .category-bubble:nth-child(2) {
    width: 48px;
    height: 48px;
}

.categories-grid .category-card:nth-child(8n+3) .category-bubble:nth-child(3),
.categories-grid .category-card:nth-child(8n+7) .category-bubble:nth-child(3) {
    width: 40px;
    height: 40px;
}

.category-card:nth-child(8n+3) h3,
.category-card:nth-child(8n+5) h3,
.category-card:nth-child(8n+7) h3,
.category-card:nth-child(8n) h3 {
    font-size: var(--font-size-xl);
}

/* -- wide, short-height cards: flank the text with bubbles instead of stacking above it -- */
.categories-grid .category-card:nth-child(8n+5) .card-content,
.categories-grid .category-card:nth-child(8n) .card-content {
    padding-inline: 90px;
}

.categories-grid .category-card:nth-child(8n+5) .category-bubbles,
.categories-grid .category-card:nth-child(8n) .category-bubbles {
    display: contents;
}

.categories-grid .category-card:nth-child(8n+5) .category-bubble,
.categories-grid .category-card:nth-child(8n) .category-bubble {
    position: absolute;
    top: 50%;
    margin: 0;
}

.categories-grid .category-card:nth-child(8n+5) .category-bubble:nth-child(1),
.categories-grid .category-card:nth-child(8n) .category-bubble:nth-child(1) {
    left: 30px;
    margin-top: -15px;
}

.categories-grid .category-card:nth-child(8n+5) .category-bubble:nth-child(2),
.categories-grid .category-card:nth-child(8n) .category-bubble:nth-child(2) {
    right: 42px;
    margin-top: -21px;
}

.categories-grid .category-card:nth-child(8n+5) .category-bubble:nth-child(3),
.categories-grid .category-card:nth-child(8n) .category-bubble:nth-child(3) {
    right: 20px;
    margin-top: -17px;
}


@media (max-width: 992px) {
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: minmax(110px, auto);
    }

    .categories-grid .category-card:nth-child(8n+1),
    .categories-grid .category-card:nth-child(8n+5),
    .categories-grid .category-card:nth-child(8n+7),
    .categories-grid .category-card:nth-child(8n) {
        grid-column: span 2;
    }
}

@media (max-width: 578px) {
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: minmax(100px, auto);
        gap: 12px;
        padding: 10px;
    }

    .category-card {
        transform: rotate(0deg) !important;
    }

        .category-card:hover {
            transform: translateY(-4px) !important;
        }
}
