/* ============================================
   PROJECTS PAGE STYLES
   ============================================ */
.projects-page {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    scroll-snap-type: none;
    scroll-behavior: auto;
}

/* Единственный вертикальный скролл — у viewport (html), не у body и не у блоков */
html:has(body.page-projects) {
    overflow-x: hidden;
    overflow-y: auto;
    scroll-snap-type: none;
    scroll-padding-top: calc(var(--header-height, 70px) + 12px);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

html:has(body.page-projects)::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

body.page-projects {
    overflow: visible !important;
    height: auto;
    min-height: 100%;
    touch-action: pan-y pinch-zoom;
    scroll-snap-type: none;
}

.page-main--projects,
.projects-page,
#projects-root,
body.page-projects .project-block,
body.page-projects .project-block__inner,
body.page-projects .project-review,
body.page-projects .review-text,
body.page-projects .review-footer {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow-x: visible;
    overflow-y: visible;
}

/* Анимации */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

.d1 { transition-delay: 0.1s; }
.d2 { transition-delay: 0.2s; }
.d3 { transition-delay: 0.3s; }

/* Блок проекта */
.project-block {
    min-height: 100vh;
    height: auto;
    scroll-snap-align: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    overflow: visible;
    position: relative;
    scroll-margin-top: calc(var(--header-height, 70px) + 12px);
}

.project-block:last-child {
    border-bottom: none;
}

.project-block__inner {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 90px clamp(20px, 5vw, 60px) 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
    gap: 15px;
}

.project-title {
    flex-shrink: 0;
    font-family: var(--font-display);
    font-size: clamp(24px, 3vw, 34px);
    font-weight: normal;
    letter-spacing: 2px;
    margin-bottom: 5px;
    text-align: center;
    background: linear-gradient(135deg, var(--white) 0%, var(--gray-300) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.project-description {
    flex-shrink: 0;
    text-align: center;
    color: var(--gray-400);
    font-size: 14px;
    line-height: 1.4;
    max-width: 600px;
    margin: 0 auto 15px auto;
}

/* Галерея проекта */
.project-gallery {
    background: #111;
    border-radius: 16px;
    overflow: hidden;
    flex-shrink: 0;
    flex-grow: 0;
    padding: 8px;
    box-sizing: border-box;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-auto-rows: 56px;
    gap: 0;
    width: 100%;
    height: 100%;
    transition: opacity 0.4s ease;
    box-sizing: border-box;
}

@media (min-width: 769px) {
    .project-block__inner {
        justify-content: flex-start;
        gap: 8px;
    }

    .project-description {
        margin-bottom: 6px;
    }

    .project-gallery {
        margin-bottom: 2px;
        flex: 0 0 600px;
        width: 100%;
        height: 600px;
        min-height: 600px;
        max-height: 600px;
    }

    .project-review {
        margin-top: 0;
    }

    .gallery-grid.gallery-grid--desktop-mosaic {
        height: 100%;
        max-height: 100%;
        grid-template-rows: repeat(3, minmax(0, 1fr));
        grid-auto-rows: minmax(0, 1fr);
        align-content: stretch;
    }
}

.gallery-item {
    position: relative;
    cursor: pointer;
    overflow: hidden;
    border-radius: 8px;
    min-width: 0;
    min-height: 0;
}

.gallery-item.is-invisible {
    cursor: default;
    opacity: 0;
    pointer-events: none;
}

.gallery-inner {
    position: relative;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.gallery-item:hover .gallery-inner {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(0,0,0,0.6);
}

.gallery-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    background: #000;
    display: block;
}

@media (min-width: 769px) {
    .gallery-grid.gallery-grid--desktop-mosaic .gallery-item.is-horiz .gallery-inner img {
        object-position: top center;
    }

    .gallery-grid.gallery-grid--desktop-mosaic .gallery-item.is-vert .gallery-inner img {
        object-position: top center;
    }
}

.gallery-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 36px;
    height: 36px;
    border: 2px solid rgba(255,255,255,0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2;
}

.gallery-play::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 5px 0 5px 8px;
    border-color: transparent transparent transparent #fff;
    margin-left: 2px;
}

.gallery-item:hover .gallery-play {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    background: rgba(0,0,0,0.3);
}

.gallery-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.7) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.gallery-item:hover .gallery-overlay {
    opacity: 1;
}

.gallery-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-family: var(--font-display);
    font-size: 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #fff;
    z-index: 2;
    opacity: 0;
    transform: translateY(4px);
    transition: all 0.3s ease;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.gallery-item.is-video:hover .gallery-label {
    opacity: 1;
    transform: translateY(0);
}

/* Отзыв */
.project-review {
    flex-shrink: 0;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 24px;
    padding: 25px 30px;
    text-align: center;
    max-width: 550px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.review-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(135deg, var(--gray-700), var(--gray-500));
    margin-bottom: 15px;
}

.review-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.review-avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    color: #fff;
}

.review-author {
    font-size: 18px;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 2px;
}

.review-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-300);
    font-style: italic;
    max-width: 90%;
    margin-bottom: 12px;
}

.review-footer {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 10px;
    margin-top: 8px;
}

.review-date {
    font-size: 12px;
    color: var(--gray-500);
}

/* Навигационные точки */
.project-nav {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.project-nav-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.project-nav-dot.active {
    background: #fff;
    transform: scale(1.3);
}

.project-nav-dot:hover {
    background: rgba(255,255,255,0.8);
}

/* Навигационные кнопки в модальных окнах */
.modal-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(0,0,0,0.6);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 50%;
    color: white;
    font-size: 30px;
    cursor: pointer;
    z-index: 2003;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    user-select: none;
}

.modal-nav-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.8);
}

.modal-prev {
    left: 20px;
}

.modal-next {
    right: 20px;
}

/* Адаптив */
@media (max-width: 768px) {
    html:has(body.page-projects) {
        scroll-padding-top: calc(var(--header-height, 70px) + 8px);
    }

    .project-block {
        height: auto;
        min-height: 0 !important;
        max-height: none;
        scroll-snap-align: none;
        scroll-snap-stop: normal;
        scroll-margin-top: calc(var(--header-height, 70px) + 8px);
        overflow: visible;
    }

    .project-block__inner {
        padding: 24px 20px 32px;
        min-height: 0 !important;
        justify-content: flex-start;
        gap: 12px;
    }

    .project-block:first-child .project-block__inner {
        padding-top: calc(var(--header-height, 70px) + env(safe-area-inset-top, 0px) + 16px);
    }

    .project-title {
        font-size: 24px;
        margin-bottom: 4px;
    }
    
    .project-description {
        font-size: 13px;
        margin-bottom: 8px;
    }
    
    .project-gallery {
        flex: 0 0 214px;
        width: 100%;
        height: 214px;
        min-height: 214px;
        max-height: 214px;
        padding: 0;
        background: transparent;
        box-sizing: border-box;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pinch-zoom;
        overscroll-behavior-x: contain;
        overscroll-behavior-y: none;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .project-gallery::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }

    .project-gallery.project-gallery--mobile-x {
        padding: 0 clamp(16px, 4vw, 24px) 4px;
    }

    .project-gallery:not(.project-gallery--mobile-x) {
        overflow: hidden;
    }
    
    .gallery-grid.gallery-grid--mobile {
        --gallery-mobile-horiz-w: 183px;
        --gallery-mobile-horiz-h: 103px;
        --gallery-mobile-vert-w: 120px;
        --gallery-mobile-vert-h: 214px;
        --gallery-mobile-row-gap: 8px;
        --gallery-mobile-col-gap: 6px;
        --gallery-mobile-brick-shift: 92px;
        --gallery-mobile-height: 214px;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: var(--gallery-mobile-col-gap);
        width: max-content;
        min-width: 100%;
        height: var(--gallery-mobile-height);
        min-height: var(--gallery-mobile-height);
        max-height: var(--gallery-mobile-height);
        padding: 0;
        margin: 0;
        overflow: visible;
        box-sizing: border-box;
        touch-action: pan-x pinch-zoom;
    }

    .gallery-grid.gallery-grid--mobile > .gallery-mobile-col.is-stack {
        --gallery-mobile-stack-w: calc(
            var(--gallery-mobile-horiz-w) + var(--gallery-mobile-brick-shift)
        );
        flex: 0 0 var(--gallery-mobile-stack-w);
        width: var(--gallery-mobile-stack-w);
        min-width: var(--gallery-mobile-stack-w);
        max-width: var(--gallery-mobile-stack-w);
        height: var(--gallery-mobile-height);
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: var(--gallery-mobile-row-gap);
        overflow: hidden;
        box-sizing: border-box;
        scroll-snap-align: start;
        position: relative;
    }

    .gallery-grid.gallery-grid--mobile > .gallery-mobile-col.is-stack.is-pack-left {
        margin-left: calc(-1 * var(--gallery-mobile-brick-shift));
        z-index: 1;
    }

    .gallery-grid.gallery-grid--mobile > .gallery-mobile-col.is-vert {
        flex: 0 0 var(--gallery-mobile-vert-w);
        width: var(--gallery-mobile-vert-w);
        min-width: var(--gallery-mobile-vert-w);
        max-width: var(--gallery-mobile-vert-w);
        height: var(--gallery-mobile-height);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        overflow: hidden;
        box-sizing: border-box;
        scroll-snap-align: start;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-slot {
        flex: 0 0 var(--gallery-mobile-horiz-h);
        width: var(--gallery-mobile-horiz-w);
        max-width: var(--gallery-mobile-horiz-w);
        height: var(--gallery-mobile-horiz-h);
        min-height: var(--gallery-mobile-horiz-h);
        max-height: var(--gallery-mobile-horiz-h);
        aspect-ratio: 16 / 9;
        overflow: hidden;
        border-radius: 8px;
        box-sizing: border-box;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-col.is-stack .gallery-mobile-slot--top {
        align-self: flex-start;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-col.is-stack .gallery-mobile-slot--bottom {
        align-self: flex-start;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-slot.gallery-mobile-slot--vert {
        flex: 0 0 var(--gallery-mobile-vert-h);
        width: var(--gallery-mobile-vert-w);
        height: var(--gallery-mobile-vert-h);
        min-width: var(--gallery-mobile-vert-w);
        min-height: var(--gallery-mobile-vert-h);
        max-width: var(--gallery-mobile-vert-w);
        max-height: var(--gallery-mobile-vert-h);
        aspect-ratio: 9 / 16;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-col.is-stack .gallery-mobile-slot--bottom {
        margin-left: var(--gallery-mobile-brick-shift);
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-slot.is-empty {
        visibility: hidden;
        pointer-events: none;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-slot .gallery-item {
        display: block;
        width: 100%;
        height: 100%;
        min-height: 0;
        min-width: 0;
        border-radius: 8px;
        overflow: hidden;
    }

    .gallery-grid.gallery-grid--mobile .gallery-item .gallery-inner {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.06);
    }

    .gallery-grid.gallery-grid--mobile .gallery-item .gallery-inner {
        background: #141414 !important;
    }

    .gallery-grid.gallery-grid--mobile .gallery-item .gallery-inner img {
        background-color: transparent !important;
        background-image: none !important;
    }

    .gallery-grid.gallery-grid--mobile .gallery-mobile-slot .gallery-item {
        position: relative;
    }

    .gallery-grid.gallery-grid--mobile .gallery-item .gallery-inner img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center center;
        display: block;
        opacity: 0;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    .gallery-grid.gallery-grid--mobile .gallery-item .gallery-inner img.is-ready {
        opacity: 1;
        transition: opacity 0.4s ease;
    }


    .gallery-grid.gallery-grid--mobile .gallery-item:hover .gallery-inner,
    .gallery-grid.gallery-grid--mobile .gallery-item .gallery-inner {
        transform: none;
        box-shadow: none;
    }

    .gallery-grid.gallery-grid--mobile .gallery-item.is-video .gallery-play {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
        background: rgba(0, 0, 0, 0.35);
    }

    .gallery-grid.gallery-grid--mobile .gallery-item.is-video .gallery-overlay {
        opacity: 0.45;
    }

    .gallery-grid.gallery-grid--mobile .gallery-item.is-video .gallery-label {
        opacity: 1;
        transform: translateY(0);
    }
    
    .project-review {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        align-self: stretch;
        width: 100%;
        height: auto;
        min-height: 0;
        max-height: none;
        padding: 12px 16px 10px;
        max-width: 100%;
        margin-top: 4px;
        overflow: visible;
        touch-action: auto;
        box-sizing: border-box;
    }

    .project-review .review-avatar {
        width: 64px;
        height: 64px;
        margin: 0 auto 6px;
    }
    
    .project-review .review-avatar-placeholder {
        font-size: 26px;
    }
    
    .project-review .review-author {
        font-size: 14px;
        margin-bottom: 4px;
    }
    
    .project-review .review-text {
        font-size: 13px;
        max-width: 100%;
        margin: 0 auto 8px;
        line-height: 1.45;
        width: 100%;
        overflow: visible;
        touch-action: auto;
    }

    .project-review .review-footer {
        flex: 0 0 auto;
        margin-top: 0;
        padding-top: 8px;
    }
    
    .modal-nav-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 24px;
    }
    
    .modal-prev {
        left: 10px;
    }
    
    .modal-next {
        right: 10px;
    }
    
    .project-nav {
        display: none;
    }
}