:root {
    --color-blue-accent: #2563EB;
    --color-blue-dark: #1E40AF
}

.portfolio-section {
    padding: var(--site-pad-y) 0;
    background: #fff;
    position: relative;
    overflow: hidden;
}

/* Ambient Effects */
.portfolio-ambient {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.pf-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    /* Уменьшено со 100px */
    opacity: 0.35;
}

.pf-blob-1 {
    top: -10%;
    right: -5%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #818CF8 0%, rgba(255, 255, 255, 0) 70%);
}

.pf-blob-2 {
    bottom: 10%;
    left: -5%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #6366F1 0%, rgba(255, 255, 255, 0) 70%);
}

.container-fluid {
    position: relative;
    z-index: 2;
}

@media(max-width: 768px) {
    .portfolio-header {
        position: relative;
        z-index: 1000;
        /* Поднимаем весь заголовок с фильтрами выше сетки */
    }
}

.portfolio-header {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
}


@media(min-width:992px) {
    .portfolio-header {
        flex-direction: row;
        align-items: flex-end;
        justify-content: space-between
    }
}

.portfolio-section .section-title {
    font-family: var(--font-primary, sans-serif);
    font-size: 3.5rem;
    font-weight: 800;
    text-transform: uppercase;
    line-height: normal;
    margin: 0;
    letter-spacing: -0.02em;
    color: #000;
}

.portfolio-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    position: relative;
    padding: 6px;
    background: rgba(240, 240, 242, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 100px;
    width: fit-content;
    border: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 10;
    overflow: visible;
}

.capsule-bg {
    position: absolute;
    background: #6366F1;
    /* Primary Accent Color */
    border-radius: 100px;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
    /* Below text */
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    display: block !important;
    opacity: 1 !important;
}

.capsule-bg.moving {
    transform: scaleX(1.1);
    /* Subtle stretch while moving */
}

.filter-btn {
    background: transparent;
    border: none;
    padding: 0.8rem 1.8rem;
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #666;
    cursor: pointer;
    transition: color 0.3s ease;
    text-transform: uppercase;
    font-family: var(--font-mono, monospace);
    position: relative;
    z-index: 2;
    /* Above capsule */
    text-decoration: none;
    display: inline-block;
}

.filter-btn:hover {
    color: #000;
    background: rgba(0, 0, 0, 0.05);
}

@media(min-width: 769px) {
    .filter-btn.active {
        color: #FFFFFF !important;
        font-weight: 800;
    }
}


/* Ensure placeholder is visible if something goes wrong */
.active-marker-fallback {
    position: absolute;
    background: #6366F1;
    z-index: -1;
}

.portfolio-grid.cases-grid-creative {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    padding-bottom: 0;
    max-width: 1600px;
    margin: 0 auto
}

.case-item {
    grid-column: span 1;
    position: relative;
    display: block;
    text-decoration: none;
    cursor: pointer;
    border-radius: 0;
    overflow: hidden;
    transition: transform .6s cubic-bezier(0.16, 1, 0.3, 1);
}

.portfolio-card {
    aspect-ratio: auto;
    background: transparent;
    overflow: visible
}

.case-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 100 / 70;
    overflow: hidden;
    background: #fff;
    border: 3px solid #6366F1;
    border-radius: 24px;
    padding: 6px;
    box-sizing: border-box;
    transition: border-color 0.4s ease, background 0.4s ease;
}


.case-img {
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    object-fit: cover;
    object-position: top center;
    border-radius: 18px;
    transition: all .6s cubic-bezier(0.16, 1, 0.3, 1);
}

.case-item:hover .case-img {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 20px;
    /* Adjust radius to match wrapper inner curvature */
}

.case-info {
    padding-top: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start
}

.case-title {
    font-size: 2rem;
    font-weight: 700;
    color: #000;
    margin: 0;
    line-height: 1.1;
    transition: color .3s ease
}

.case-category-tag {
    position: absolute;
    bottom: 26px;
    left: 26px;
    /* 20 + 6px padding */
    background: #000;
    padding: .6rem 1.2rem;
    font-family: var(--font-mono, monospace);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #fff;
    z-index: 5;
    pointer-events: none;
    border-radius: 100px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.case-item:hover .case-category-tag {
    background: #6366F1;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.card-overlay {
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .8s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 4;
    border-radius: 18px;
    /* Match inner image radius */
}

.case-item:hover .card-overlay {
    opacity: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 20px;
    /* Expands to match border */
}

.overlay-btn {
    background: #fff;
    color: #000;
    padding: 1rem 2rem;
    border-radius: 100px;
    font-family: var(--font-primary, sans-serif);
    font-weight: 600;
    font-size: .9rem;
    text-transform: uppercase;
    transform: translateY(20px);
    transition: transform .3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: none;
    cursor: pointer
}

.case-item:hover .overlay-btn {
    transform: translateY(0)
}

@media(max-width:1200px) {
    .portfolio-grid.cases-grid-creative {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px;
        max-width: 1400px;
    }

    .case-image-wrapper {
        padding: 5px;
    }

    .case-img {
        border-radius: 20px;
    }
}

@media(max-width:1024px) {
    .portfolio-grid.cases-grid-creative {
        grid-template-columns: repeat(2, 1fr);
        gap: 22px;
    }

    .portfolio-section .section-title {
        font-size: 2.5rem;
        line-height: 1.2;
    }


    .portfolio-header {
        margin-bottom: 2.5rem;
        gap: 1.5rem;
    }

    .case-image-wrapper {
        padding: 4px;
        border-radius: 20px;
    }

    .case-img {
        border-radius: 16px;
    }

    .case-title {
        font-size: 1.8rem;
        line-height: 1.2;
    }
}

@media(max-width:900px) {
    .portfolio-grid.cases-grid-creative {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .portfolio-section .section-title {
        font-size: 2.2rem;
    }


    .case-title {
        font-size: 1.7rem;
    }

    .case-category-tag {
        font-size: 0.65rem;
        padding: 0.5rem 1rem;
    }
}

.portfolio-filters-wrapper {
    position: relative;
    z-index: 1001;
    /* Еще выше внутри хедера */
}


.mobile-filter-toggle {
    display: none
}

@media(max-width:768px) {
    .portfolio-section {
        padding: 2rem 0
    }

    .container-fluid {
        padding: 0 1rem
    }

    .portfolio-grid.cases-grid-creative {
        grid-template-columns: 1fr
    }

    .case-item:nth-child(n+5) {
        display: none !important
    }

    .case-title {
        font-size: 1.5rem
    }

    .portfolio-section .section-title {
        font-size: 2.2rem;
        /* Уменьшил с 3.5rem/гигантских размеров */
        line-height: 1.1;
        letter-spacing: -0.01em;
        word-break: normal;
    }

    .portfolio-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 2rem;
        gap: 1rem;
        padding-bottom: 1rem
    }

    .mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: auto;
        min-width: 130px;
        background: #000;
        color: #fff;
        border: 1px solid #000;
        padding: 0.8rem 1.6rem;
        border-radius: 100px;
        font-family: var(--font-mono, monospace);
        font-size: .8rem;
        font-weight: 600;
        text-transform: uppercase;
        cursor: pointer;
        transition: all .3s ease;
        gap: 10px;
    }

    .current-text {
        font-size: 12px;
    }

    .mobile-filter-toggle .arrow-icon {
        display: flex;
        align-items: center;
        transition: transform .3s ease
    }

    .mobile-filter-toggle.active .arrow-icon {
        transform: rotate(180deg)
    }

    .portfolio-filters {
        display: none;
        flex-direction: column;
        position: absolute;
        top: calc(100% + 12px);
        right: 0;
        left: auto;
        width: 220px;
        max-height: 60vh;
        overflow-y: auto;
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 20px;
        padding: 0.8rem;
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
        gap: 4px;
        z-index: 9999;
        /* Поверх всех карточек */
    }


    .portfolio-filters.open {
        display: flex;
        animation: dropdownFadeIn .2s ease forwards
    }

    .filter-btn {
        width: 100%;
        text-align: left;
        border: none;
        border-radius: 8px;
        padding: .8rem 1rem;
        font-size: .9rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #666
    }

    .filter-btn:hover {
        background: #F5F5F5;
        color: #000
    }

    .filter-btn.active {
        background: #f8f8fb;
        color: #000000 !important;
        font-weight: 800;
        border: none;
    }


    .filter-btn.active::after {
        content: '●';
        font-size: .6rem;
        color: #000000 !important;
    }

    .btn-all-cases {
        font-size: 0.95rem;
        padding: 0.8rem 1.6rem;
    }
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

.portfolio-footer {
    display: flex;
    justify-content: center;
    margin-top: 4rem
}

.btn-all-cases {
    display: inline-flex;
    align-items: center;
    gap: 1rem;
    font-family: var(--font-primary, sans-serif);
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    text-decoration: none;
    color: #000;
    background: #fff;
    border: 1px solid #E5E5E5;
    padding: 1rem 2rem;
    border-radius: 100px;
    transition: all .3s ease;
}

.btn-all-cases:hover {
    gap: 1.5rem;
    color: #6366F1;
    border: 3px solid transparent;
    background: linear-gradient(#fff, #fff) padding-box, var(--lava-gradient-base) border-box;
    background-size: auto, 200% 200%;
    animation: lavaLamp 3s infinite ease-in-out alternate;
    box-shadow: 0 5px 25px rgba(99, 102, 241, 0.3);
}

.portfolio-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem
}

.portfolio-modal.open {
    display: flex
}

.portfolio-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 1
}

.portfolio-modal-content {
    position: relative;
    z-index: 2;
    background: #fff;
    width: 96%;
    max-width: 1400px;
    height: 90vh;
    max-height: 850px;
    display: flex;
    box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.2);
    border-radius: 32px;
    overflow: hidden;
    outline: 8px solid rgba(255, 255, 255, 0.2);
    /* Outer glass border effect */
}

.modal-left {
    flex: 1.3;
    background: #F4F4F5;
    /* Light grey matte */
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    padding: 16px;
    /* Frame padding */
}

.modal-gallery-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: #000 #F4F4F5;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

.modal-gallery-scroll::-webkit-scrollbar {
    width: 6px
}

.modal-gallery-scroll::-webkit-scrollbar-track {
    background: transparent
}

.modal-gallery-scroll::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

.modal-gallery-scroll img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    cursor: zoom-in;
    transition: opacity .2s ease;
    position: relative;
    margin-bottom: 0;
}

.modal-gallery-scroll img:first-child {
    border-radius: 20px 20px 0 0;
}

.modal-gallery-scroll img:last-child {
    border-radius: 0 0 20px 20px;
}

.modal-gallery-scroll img:only-child {
    border-radius: 20px;
}

.modal-gallery-scroll img:hover {
    opacity: .98
}

.scroll-hint {
    display: none !important;
    /* Removed as per user request */
}

/* Removed keyframes to clean up */

.modal-right {
    flex: 1;
    background: #fff;
    padding: 3rem;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden
}

.modal-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    background: #F4F4F5;
    border-radius: 50%;
    border: none;
    color: #000;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 20
}

.modal-close:hover {
    background: #000;
    color: #fff;
    transform: rotate(90deg) scale(1.1);
}

.modal-header {
    margin-bottom: 1.5rem;
    padding-right: 4rem;
    margin-top: 1rem;
}

.modal-eyebrow {
    font-family: var(--font-mono, monospace);
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #999;
    margin-bottom: 0.75rem;
    display: block;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.modal-title {
    font-family: var(--font-primary, sans-serif);
    font-size: 2.75rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    margin: 0;
    letter-spacing: -0.03em;
    color: #111;
}

.modal-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #F0F0F0;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: .4rem
}

.meta-label {
    font-family: var(--font-mono, monospace);
    font-size: .65rem;
    text-transform: uppercase;
    color: #999;
    letter-spacing: .05em;
    font-weight: 600;
}

.meta-value {
    font-family: var(--font-primary, sans-serif);
    font-size: 1.1rem;
    color: #000;
    font-weight: 600;
    line-height: 1.2;
}

.modal-tags-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1.5rem
}

.modal-tag {
    font-family: var(--font-mono, monospace);
    font-size: .7rem;
    text-transform: uppercase;
    padding: .5rem 1rem;
    border: 1px solid #E5E5E5;
    border-radius: 100px;
    color: #444;
    letter-spacing: .02em;
    font-weight: 500;
    background: #FAFAFA;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 1rem;
    margin-bottom: 80px;
    scrollbar-width: thin;
    scrollbar-color: #999 #f5f5f5;
    word-break: break-word
}

.modal-body::-webkit-scrollbar {
    width: 6px
}

.modal-body::-webkit-scrollbar-track {
    background: #f5f5f5
}

.modal-body::-webkit-scrollbar-thumb {
    background: #999;
    border-radius: 3px
}

.body-text {
    font-family: var(--font-secondary, sans-serif);
    font-size: .95rem;
    line-height: 1.7;
    color: #333;
    margin: 0
}

.modal-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2rem 3rem;
    background: linear-gradient(to top, #fff 80%, rgba(255, 255, 255, 0));
    z-index: 10
}

.btn-modal-site {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    width: 100%;
    background: #000;
    color: #fff;
    text-align: center;
    padding: 1.2rem;
    font-family: var(--font-mono, monospace);
    text-transform: uppercase;
    font-weight: 700;
    font-size: .9rem;
    text-decoration: none;
    border: none;
    border-radius: 16px;
    /* Rounded modern button */
    transition: all .3s cubic-bezier(0.16, 1, 0.3, 1);
    letter-spacing: .05em;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn-modal-site:hover {
    background: #fff;
    color: #000;
    gap: 1.25rem
}

.btn-modal-site svg {
    transition: transform .3s ease
}

.btn-modal-site:hover svg {
    transform: translateX(5px)
}

@media(max-width:1200px) {
    .modal-title {
        font-size: 2rem
    }

    .modal-right {
        padding: 2rem
    }
}

@media(max-width:992px) {
    .portfolio-modal-content {
        flex-direction: column;
        height: 100%;
        /* Better mobile height handling */
        max-height: 90vh;
        /* Don't cover entire screen, show its a modal */
        max-width: 95vw;
        border-radius: 24px;
        margin: auto;
    }

    .modal-left {
        flex: none;
        height: 40vh;
        /* Fixed height for image area on mobile */
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        padding: 8px;
        /* Smaller frame on mobile */
    }

    .modal-gallery-scroll {
        border-radius: 16px;
    }

    .modal-gallery-scroll img:first-child {
        border-radius: 16px 16px 0 0;
    }

    .modal-gallery-scroll img:last-child {
        border-radius: 0 0 16px 16px;
    }

    .modal-gallery-scroll img:only-child {
        border-radius: 16px;
    }

    .modal-right {
        flex: 1;
        padding: 1.5rem;
        padding-bottom: 0;
        /* No bottom padding on container, handled by body */
        max-height: none;
        overflow: hidden;
        /* STOP overall scroll */
        display: flex;
        flex-direction: column;
        position: relative;
    }

    .modal-right::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }

    .modal-body {
        flex: 1;
        overflow-y: auto;
        /* Scroll ONLY the text area */
        margin-bottom: 0;
        padding-bottom: 100px;
        /* IMPORTANT: Space for the footer so text isn't hidden */
        padding-right: 5px;
        /* Tiny buffer */
    }

    .modal-title {
        font-size: 1.8rem
    }

    .modal-header {
        padding-right: 0;
        margin-top: 0;
    }

    .modal-footer {
        padding: 1.5rem;
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(10px);
        bottom: 0px;
        position: absolute;
        /* Stick to bottom of modal content area */
        border-top: 1px solid rgba(0, 0, 0, 0.05);
    }
}

@media(max-width:576px) {
    .portfolio-modal {
        padding: 0;
        align-items: flex-end;
        /* Sheet style */
    }

    .portfolio-modal-content {
        height: 92vh;
        /* Use almost full height */
        max-height: 92vh;
        max-width: 100%;
        border-radius: 24px 24px 0 0;
        margin: 0;
        outline: none;
    }

    .modal-left {
        height: 30vh;
        /* Reduced height to give more room for text */
        min-height: auto;
        padding: 6px;
    }

    .modal-gallery-scroll {
        border-radius: 18px;
    }

    .modal-right {
        padding: 1.25rem;
        padding-bottom: 0;
        /* Handled by body */
        overflow: hidden;
        /* Ensure consistent flex layout */
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        margin-bottom: 1rem;
        padding-right: 3rem;
        /* Space for close button if needed, but close button is outside/top */
    }

    /* New Close Button Position for Sheet */
    .modal-close {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        background: #fff;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        font-size: 1.2rem;
    }

    .modal-title {
        font-size: 1.5rem;
        line-height: 1.1
    }

    .modal-meta-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        padding-bottom: 1rem;
        margin-bottom: 1rem;
    }

    .modal-tags-row {
        margin-bottom: 1rem
    }

    .btn-modal-site {
        padding: 1rem;
        font-size: .75rem
    }

    .modal-footer {
        padding: 1rem
    }

    .modal-body {
        margin-bottom: 0;
        padding-bottom: 100px;
        /* Ensure huge clearance for mobile footer */
    }
}

.fullscreen-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: none;
    overflow-y: auto;
    overflow-x: hidden;
    backdrop-filter: blur(10px);
    cursor: zoom-out;
    animation: fadeIn .2s ease;
    padding: 60px 0 40px 0
}

.fullscreen-viewer.active {
    display: block
}

.fullscreen-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s ease;
    z-index: 10001;
    backdrop-filter: blur(10px)
}

.fullscreen-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg)
}

#fullscreen-img {
    width: 100%;
    height: auto;
    display: block;
    cursor: default;
    animation: zoomIn .3s cubic-bezier(0.4, 0, 0.2, 1)
}

@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

@keyframes zoomIn {
    from {
        transform: scale(0.95);
        opacity: 0
    }

    to {
        transform: scale(1);
        opacity: 1
    }
}

@media(max-width:768px) {
    .fullscreen-viewer {
        padding: 50px 0 20px 0
    }

    #fullscreen-img {
        width: 100%
    }

    .fullscreen-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 1.5rem
    }
}