/* Плавная прокрутка */
html {
    scroll-behavior: smooth;
}

/* Секция работ - соответствие общему стилю */
.works {
    padding: var(--section-pad) 0;
    background-color: var(--bg-alt);
}

/* ===========================================
   СЕТКА ПОРТФОЛИО
   Используем CSS Grid с auto-fill и minmax
   для автоматической адаптации под разные экраны
   =========================================== */
.portfolio__grid {
    display: grid;
    /* 
     * auto-fill: автоматически заполняет строку колонками
     * minmax(340px, 1fr): минимум 340px, максимум — равная доля
     * Сетка сама перестраивается без media-запросов
     */
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 32px;
    align-items: stretch;
}

/* Размеры карточек — теперь все одинаковые для grid auto-fill */
.portfolio__item {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    transition: var(--transition);
    overflow: hidden;
    border-radius: 24px;
    /* Начальное состояние для анимации */
    opacity: 0;
    transform: translateY(30px);
}

/* Анимация появления карточек */
.portfolio__item.active {
    opacity: 1;
    transform: translateY(0);
}

/* Hover-эффект с учётом анимации появления */
.portfolio__item.active:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
}

/* Изображение */
.portfolio__image {
    position: relative;
    width: 100%;
    overflow: hidden;
    background-color: #f0f0f0;
    border-radius: 24px;
    /* Единый aspect-ratio для всех карточек */
    aspect-ratio: 16/10;
}

.portfolio__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 1.8s;
}

.portfolio__item:hover .portfolio__image img {
    transform: scale(1.06);
}

/* Оверлей */
.portfolio__overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.6s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.portfolio__item:hover .portfolio__overlay {
    opacity: 1;
}

.portfolio__arrow {
    width: 60px;
    height: 60px;
    background: var(--bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    transform: scale(0.8) rotate(-45deg);
    transition: var(--transition);
}

.portfolio__item:hover .portfolio__arrow {
    transform: scale(1) rotate(0deg);
    background: var(--accent);
    color: var(--bg);
}

/* Контент карточки */
.portfolio__content {
    padding: 32px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.portfolio__tag {
    display: inline-block;
    color: var(--accent);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3em;
    margin-bottom: 12px;
    width: fit-content;
    background: rgba(255, 77, 0, 0.1);
    padding: 6px 16px;
    border-radius: 50px;
}

.portfolio__name {
    font-family: var(--font-head);
    font-size: 1.6rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text);
    margin-bottom: 16px;
    line-height: 0.92;
    letter-spacing: -0.05em;
}

.portfolio__description {
    font-size: 0.95rem;
    font-weight: 300;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ===========================================
   ПАГИНАЦИЯ
   =========================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 60px;
    flex-wrap: wrap;
}

/* Контейнер для номеров страниц */
.pagination__numbers {
    display: flex;
    gap: 8px;
}

/* Кнопки навигации (стрелки) */
.pagination__btn {
    width: 48px;
    height: 48px;
    border: 2px solid var(--text);
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text);
}

.pagination__btn:hover:not(.pagination__btn--disabled) {
    background: var(--text);
    color: var(--bg);
}

.pagination__btn--disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Кнопки номеров страниц */
.pagination__number {
    min-width: 48px;
    height: 48px;
    border: 2px solid transparent;
    background: transparent;
    border-radius: 50%;
    font-family: var(--font-head);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
}

.pagination__number:hover {
    border-color: var(--text);
    color: var(--text);
}

/* Активная страница — визуально выделена */
.pagination__number--active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

.pagination__number--active:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

/* ===========================================
   АДАПТИВНОСТЬ
   Благодаря auto-fill + minmax сетка сама
   перестраивается, но дополнительные правила
   для мелких экранов всё же нужны
   =========================================== */

/* Для очень маленьких экранов уменьшаем минимальную ширину */
@media (max-width: 400px) {
    .portfolio__grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .works {
        padding: 60px 0;
    }
    
    .portfolio__grid {
        gap: 24px;
    }
    
    .portfolio__content {
        padding: 20px;
    }
    
    .portfolio__name {
        font-size: 1.4rem;
    }

    .portfolio__description {
        font-size: 0.9rem;
    }

    .portfolio__tag {
        font-size: 0.6rem;
        padding: 5px 12px;
    }
    
    /* Пагинация на мобильных */
    .pagination {
        margin-top: 40px;
        gap: 8px;
    }
    
    .pagination__btn,
    .pagination__number {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .works {
        padding: 48px 0;
    }

    .portfolio__grid {
        gap: 20px;
    }

    .portfolio__content {
        padding: 16px;
    }

    .portfolio__name {
        font-size: 1.2rem;
    }

    .portfolio__description {
        font-size: 0.85rem;
        line-height: 1.4;
    }

    .portfolio__tag {
        font-size: 0.55rem;
        padding: 4px 10px;
    }
}

/* ===========================================
   СТРАНИЦА КЕЙСА (Compact Layout)
   =========================================== */
.case-study {
    padding-top: 140px;
    padding-bottom: var(--section-pad);
    min-height: 80vh;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 40px;
    transition: var(--transition);
}

.back-link svg {
    transition: transform 0.3s;
}

.back-link:hover {
    color: var(--text);
}

.back-link:hover svg {
    transform: translateX(-4px);
}

.case-header {
    margin-bottom: 60px;
    max-width: 800px;
}

.case-header h1 {
    font-size: clamp(2.5rem, 5vw, 4rem);
    margin-top: 16px;
}

.case-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 60px;
    align-items: start;
}

.case-media {
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.05);
    background: #f5f5f5;
}

.case-img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 1.5s;
}

.case-media:hover .case-img {
    transform: scale(1.02);
}

.case-info {
    position: sticky;
    top: 120px;
    padding-top: 20px;
}

.case-info h3 {
    font-family: var(--font-head);
    font-size: 1.5rem;
    text-transform: uppercase;
    margin-bottom: 24px;
}

.case-info p {
    font-size: 1.1rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 40px;
}

.case-actions {
    display: flex;
    gap: 20px;
}

@media (max-width: 1024px) {
    .case-grid {
        grid-template-columns: 1fr;
        gap: 40px;
    }
    
    .case-info {
        position: static;
        padding-top: 0;
    }

    .case-header h1 {
        font-size: clamp(2rem, 8vw, 3rem);
    }
}

/* ===========================================
   DETAILED CASE STUDY TEMPLATE
   =========================================== */

/* Global Case Variables */
:root {
    --case-text-max-width: 800px;
    --case-section-gap: 60px;
}

.case-template {
    background: #fff;
    color: #1a1a1a;
}

/* 1. Hero Section - Обновленный дизайн */
.case-hero {
    position: relative;
    height: 90vh;
    min-height: 650px;
    display: flex;
    align-items: center;
    color: #fff;
    overflow: hidden;
}

.case-hero__bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 1;
    transform: scale(1.05);
    transition: transform 8s ease-out;
}

.case-hero:hover .case-hero__bg {
    transform: scale(1);
}

.case-hero__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.75) 0%, rgba(255, 77, 0, 0.3) 100%);
    backdrop-filter: blur(3px);
    z-index: 2;
    display: flex;
    align-items: center;
}

.case-hero__content {
    max-width: 900px;
    animation: fadeInUp 1s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.case-hero__title {
    font-size: clamp(2.5rem, 6vw, 5.5rem);
    font-weight: 900;
    margin-bottom: 24px;
    line-height: 1.05;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.case-hero__desc {
    font-size: clamp(1.1rem, 2vw, 1.6rem);
    font-weight: 300;
    opacity: 0.95;
    margin-bottom: 40px;
    max-width: 700px;
    line-height: 1.6;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.case-hero__stack {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.stack-badge {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 10px 20px;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.stack-badge:hover {
    background: rgba(255, 77, 0, 0.9);
    border-color: rgba(255, 77, 0, 1);
    transform: translateY(-2px);
}

.back-link.white {
    color: #fff;
    border-bottom: 2px solid rgba(255, 77, 0, 0.5);
    display: inline-flex;
    margin-bottom: 32px;
    padding-bottom: 6px;
    transition: all 0.3s ease;
}
.back-link.white:hover {
    border-color: var(--accent);
    transform: translateX(-4px);
}

/* Common Section Styles - Обновленные */
.case-section {
    padding: var(--case-section-gap) 0;
    position: relative;
}

.case-section.bg-alt {
    background: linear-gradient(180deg, #fafafa 0%, #f5f5f5 100%);
}

.case-section.no-pad-bottom {
    padding-bottom: 0;
}

.section-label {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--accent);
    margin-bottom: 20px;
    font-weight: 700;
    background: rgba(255, 77, 0, 0.1);
    padding: 8px 20px;
    border-radius: 50px;
    border: 1px solid rgba(255, 77, 0, 0.2);
}

.case-section__title {
    font-size: clamp(2rem, 4vw, 3.2rem);
    margin-bottom: 60px;
    font-weight: 900;
    color: #000;
    position: relative;
    display: inline-block;
}

.case-section__title::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 0;
    width: 60px;
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
}

/* 2. Overview - Улучшенный */
.case-grid-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 80px;
}

.case-text {
    font-size: 1.25rem;
    line-height: 1.8;
    font-weight: 300;
    color: #2a2a2a;
}

.case-text.max-width {
    max-width: var(--case-text-max-width);
}

.case-meta {
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 32px;
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    border-radius: 16px;
    border: 1px solid #eee;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

.meta-item span {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 8px;
    letter-spacing: 0.15em;
    font-weight: 700;
}

.meta-item {
    font-size: 1.15rem;
    font-weight: 600;
    color: #000;
}

/* 3. Tasks & Constraints - Улучшенный */
.case-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 60px;
}

.case-col {
    background: #fff;
    padding: 40px;
    border-radius: 16px;
    border: 1px solid #eee;
    transition: all 0.3s ease;
}

.case-col:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.06);
    border-color: rgba(255, 77, 0, 0.3);
}

.case-col h3 {
    font-size: 1.6rem;
    margin-bottom: 32px;
    font-weight: 800;
    color: #000;
}

.case-list {
    list-style: none;
    padding: 0;
}

.case-list li {
    position: relative;
    padding-left: 32px;
    margin-bottom: 20px;
    font-size: 1.1rem;
    line-height: 1.6;
    color: #333;
}

.case-list li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 700;
    font-size: 1.2rem;
}

/* 5. Tech Grid - Улучшенный */
.tech-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
}

.tech-item {
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    padding: 36px 32px;
    border-radius: 20px;
    border: 2px solid #f0f0f0;
    transition: all 0.4s ease;
    position: relative;
    overflow: hidden;
}

.tech-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 0;
    background: var(--accent);
    transition: height 0.4s ease;
}

.tech-item:hover {
    transform: translateY(-6px);
    border-color: rgba(255, 77, 0, 0.3);
    box-shadow: 0 12px 40px rgba(255, 77, 0, 0.1);
}

.tech-item:hover::before {
    height: 100%;
}

.tech-item h4 {
    margin-bottom: 12px;
    font-size: 1.2rem;
    font-weight: 800;
    color: #000;
}

.tech-item p {
    font-size: 0.95rem;
    color: #555;
    line-height: 1.6;
}

/* 6. Results - Улучшенный */
.result-list {
    list-style: none;
    max-width: 800px;
    margin-bottom: 40px;
}

.result-list li {
    padding: 28px 32px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    border-left: 4px solid var(--accent);
    border-radius: 12px;
    font-size: 1.3rem;
    font-weight: 500;
    color: #1a1a1a;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.result-list li:hover {
    transform: translateX(8px);
    box-shadow: 0 4px 20px rgba(255, 77, 0, 0.1);
}

.case-actions.big-margin {
    margin-top: 60px;
}

/* 7. Screenshots - Улучшенный */
.screenshots-gallery {
    display: flex;
    flex-direction: column;
    gap: 100px;
    padding: 100px 0;
    background: linear-gradient(180deg, #f8f8f8 0%, #f0f0f0 50%, #f8f8f8 100%);
    min-height: 200px;
}

/* Скриншоты всегда видимы (контент подставляется JS, не скрывать reveal'ом) */
#case-screenshots,
#case-screenshots img,
.screenshots-gallery img {
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    display: block !important;
}

.screenshots-gallery img {
    max-width: 100%;
    margin: 0 auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.15);
    border-radius: 16px;
    transition: all 0.5s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.screenshots-gallery img:hover {
    transform: translateY(-10px) scale(1.02);
    box-shadow: 0 40px 100px rgba(255, 77, 0, 0.2);
}

.screen-desktop { width: 90%; max-width: 1200px; }
.screen-tablet { width: 70%; max-width: 800px; }
.screen-mobile { width: 30%; max-width: 375px; }

/* 9. Summary - Улучшенный */
.summary-text {
    font-size: 1.6rem;
    font-weight: 400;
    line-height: 1.7;
    color: #2a2a2a;
    padding: 40px;
    background: linear-gradient(135deg, rgba(255, 77, 0, 0.05) 0%, rgba(255, 77, 0, 0.02) 100%);
    border-radius: 20px;
    border-left: 4px solid var(--accent);
}

/* 10. CTA Button Section - Улучшенный */
.case-cta {
    padding: 80px 0 0 0;
    text-align: center;
    position: relative;
}

.case-cta .btn {
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.case-cta::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    border-radius: 2px;
    pointer-events: none;
}

.scroll-to-top-wrapper {
    margin-top: 60px;
    padding-bottom: 40px;
}

.scroll-to-top {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    border: 2px solid var(--text);
    color: var(--text);
    padding: 16px 32px;
    border-radius: 50px;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.4s ease;
    position: relative;
    overflow: hidden;
}

.scroll-to-top::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--accent);
    transform: translateY(100%);
    transition: transform 0.4s ease;
    z-index: -1;
}

.scroll-to-top:hover {
    border-color: var(--accent);
    color: #fff;
    transform: translateY(-4px);
}

.scroll-to-top:hover::before {
    transform: translateY(0);
}

.scroll-to-top svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

.scroll-to-top:hover svg {
    transform: translateY(-4px);
    animation: bounce 0.6s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(-4px); }
    50% { transform: translateY(-8px); }
}

/* Responsive */
@media (max-width: 1024px) {
    :root { --case-section-gap: 40px; }
    .case-grid-content, .case-columns { grid-template-columns: 1fr; gap: 40px; }
    .case-meta { border-left: none; padding-left: 0; border-top: 1px solid #eee; padding-top: 32px; flex-direction: row; flex-wrap: wrap; }
    .screen-desktop, .screen-tablet, .screen-mobile { width: 90%; max-width: 100%; }
}

@media (max-width: 768px) {
    .case-hero__title { font-size: 2.5rem; }
    .case-section__title { font-size: 2rem; margin-bottom: 40px; }
    .result-list li { font-size: 1.1rem; }
    
    .scroll-to-top {
        padding: 14px 28px;
        font-size: 0.8rem;
        gap: 10px;
    }
    
    .scroll-to-top svg {
        width: 18px;
        height: 18px;
    }
    
    .scroll-to-top-wrapper {
        margin-top: 40px;
        padding-bottom: 30px;
    }
}
