.portfolio-page {
    width: min(100% - 2rem, var(--site-container));
    margin-inline: auto;
    padding-inline: max(0px, env(safe-area-inset-left)) max(0px, env(safe-area-inset-right));
}

.portfolio-hero {
    text-align: center;
    padding: clamp(1.75rem, 5vw, 2.5rem) clamp(0.5rem, 3vw, 1rem) clamp(1.5rem, 4vw, 2rem);
}

.portfolio-hero__title {
    margin: 0;
    font-size: clamp(1.75rem, 5vw, 2.75rem);
    font-weight: 700;
    line-height: 1.15;
    color: var(--site-accent-deep);
}

.portfolio-hero__subtitle {
    margin: 0.75rem auto clamp(1rem, 3vw, 1.5rem);
    max-width: 36rem;
    color: var(--site-muted);
    font-size: clamp(0.95rem, 2.5vw, 1.05rem);
    line-height: 1.55;
}

.portfolio-hero .site-btn {
    min-height: 2.75rem;
    padding-inline: clamp(1rem, 4vw, 1.5rem);
}

.portfolio-hero__btn {
    width: min(100%, 22rem);
}

.portfolio-category {
    margin-bottom: clamp(2rem, 5vw, 2.75rem);
}

.portfolio-category__title {
    margin: 0 0 clamp(0.875rem, 2.5vw, 1.25rem);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e8d5c0;
    font-size: clamp(1.2rem, 3.5vw, 1.5rem);
    color: var(--site-accent-deep);
}

.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    gap: clamp(0.875rem, 2.5vw, 1.25rem);
}

.portfolio-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--site-surface);
    border: none;
    border-radius: var(--site-radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    box-shadow:
        0 4px 8px rgba(44, 36, 25, 0.2),
        0 12px 22px rgba(44, 36, 25, 0.16);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.portfolio-card:hover {
    transform: translateY(-3px);
    box-shadow:
        0 8px 14px rgba(44, 36, 25, 0.22),
        0 18px 32px rgba(44, 36, 25, 0.16);
}

.portfolio-card:active {
    transform: translateY(-1px);
}

.portfolio-card__image {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.portfolio-card__body {
    min-width: 0;
    padding: clamp(0.75rem, 2.5vw, 1rem) clamp(0.8rem, 2.5vw, 1.1rem) clamp(0.85rem, 2.5vw, 1.15rem);
}

.portfolio-card__title {
    margin: 0 0 0.35rem;
    font-size: clamp(0.9rem, 2.5vw, 1.05rem);
    line-height: 1.3;
    color: var(--site-accent-deep);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.portfolio-card__text {
    margin: 0;
    color: var(--site-muted);
    font-size: clamp(0.78rem, 2vw, 0.9rem);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}

.portfolio-empty {
    text-align: center;
    padding: clamp(2rem, 6vw, 3rem) 1rem;
    color: var(--site-muted);
}

.portfolio-alert {
    margin-bottom: 1.25rem;
    padding: 0.875rem 1rem;
    border-radius: var(--site-radius);
    font-weight: 500;
}

.portfolio-alert--error {
    background: #fdf0ee;
    border: 1px solid #e8b8b0;
    color: #a33b2a;
}

.portfolio-detail__nav {
    margin-bottom: clamp(0.875rem, 2.5vw, 1.25rem);
}

.portfolio-back-link {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    color: var(--site-accent);
    text-decoration: none;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
}

.portfolio-back-link:hover {
    color: var(--site-accent-deep);
}

.portfolio-detail__title {
    margin: 0 0 clamp(1rem, 3vw, 1.5rem);
    font-size: clamp(1.5rem, 5vw, 2.25rem);
    line-height: 1.2;
    color: var(--site-accent-deep);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.portfolio-detail-page {
    padding-bottom: clamp(2rem, 5vw, 2.75rem);
}

.portfolio-detail__header {
    margin-bottom: 0.25rem;
}

.portfolio-detail__layout {
    display: grid;
    gap: clamp(1.5rem, 4vw, 2.5rem);
}

.portfolio-detail__gallery {
    display: flex;
    flex-direction: column;
    gap: clamp(0.875rem, 2.5vw, 1.25rem);
    min-width: 0;
}

.portfolio-detail__viewer {
    position: relative;
}

.portfolio-detail__slides {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    aspect-ratio: 4 / 3;
    background: #111;
    border-radius: var(--site-radius);
    scrollbar-width: none;
    touch-action: pan-x;
}

.portfolio-detail__slides::-webkit-scrollbar {
    display: none;
}

.portfolio-detail__slides:focus-visible {
    outline: 2px solid var(--site-accent);
    outline-offset: 3px;
}

.portfolio-detail__slide {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    scroll-snap-align: center;
    scroll-snap-stop: always;
}

.portfolio-detail__main-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
}

.portfolio-detail__arrow {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 248, 240, 0.92);
    color: var(--site-accent-deep);
    font-size: 1.75rem;
    line-height: 1;
    box-shadow: 0 4px 16px rgba(44, 36, 25, 0.14);
    cursor: pointer;
    transform: translateY(-50%);
    transition: background 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.portfolio-detail__arrow:hover {
    background: #fff;
    box-shadow: 0 6px 20px rgba(44, 36, 25, 0.18);
}

.portfolio-detail__arrow--prev {
    left: 0.75rem;
}

.portfolio-detail__arrow--next {
    right: 0.75rem;
}

.portfolio-detail__counter {
    position: absolute;
    right: 0.75rem;
    bottom: 0.75rem;
    z-index: 2;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    background: rgba(51, 38, 28, 0.72);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    pointer-events: none;
}

.portfolio-detail__swipe-hint {
    margin: 0.5rem 0 0;
    text-align: center;
    color: var(--site-muted);
    font-size: 0.78rem;
}

.portfolio-detail__thumbs {
    display: flex;
    gap: 0.625rem;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding: 0.25rem 0 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: #d9cfc0 transparent;
}

.portfolio-detail__thumbs::-webkit-scrollbar {
    height: 0.35rem;
}

.portfolio-detail__thumbs::-webkit-scrollbar-thumb {
    background: #d9cfc0;
    border-radius: 999px;
}

.portfolio-detail__thumb-btn {
    flex: 0 0 auto;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 0.5rem;
    background: none;
    cursor: pointer;
    scroll-snap-align: start;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.portfolio-detail__thumb-btn.is-active {
    border-color: var(--site-accent);
    box-shadow: 0 2px 10px rgba(176, 125, 74, 0.22);
}

.portfolio-detail__thumb {
    display: block;
    width: clamp(4.25rem, 14vw, 5.5rem);
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 0.375rem;
    pointer-events: none;
}

.portfolio-detail__description {
    background: var(--site-surface);
    border: 1px solid #d9cfc0;
    border-radius: var(--site-radius);
    padding: clamp(1.15rem, 3.5vw, 1.75rem);
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.portfolio-detail__description img {
    max-width: 100%;
    height: auto;
}

.portfolio-cta {
    margin-top: clamp(1.75rem, 5vw, 2.5rem);
    padding: clamp(1.35rem, 4vw, 2rem);
    text-align: center;
    background: var(--site-surface);
    border: 1px solid #d9cfc0;
    border-radius: var(--site-radius);
    box-shadow: var(--site-shadow);
}

.portfolio-cta__title {
    margin: 0 0 0.5rem;
    font-size: clamp(1.15rem, 3.5vw, 1.35rem);
    color: var(--site-accent-deep);
}

.portfolio-cta__text {
    margin: 0 0 1.25rem;
    color: var(--site-muted);
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    line-height: 1.55;
}

.portfolio-cta__btn {
    width: min(100%, 20rem);
}

@media (min-width: 900px) {
    .portfolio-detail__layout {
        grid-template-columns: 1.1fr 0.9fr;
        align-items: start;
    }

    .portfolio-detail__swipe-hint {
        display: none;
    }
}

@media (max-width: 991.98px) {
    .portfolio-grid {
        grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    }
}

@media (max-width: 767.98px) {
    .portfolio-page {
        width: min(100% - 1.25rem, var(--site-container));
    }

    .portfolio-grid {
        grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
        gap: 0.875rem;
    }

    .portfolio-detail__arrow {
        display: none;
    }

    .portfolio-detail__thumbs {
        display: none;
    }

    .portfolio-detail__viewer {
        margin-inline: -0.125rem;
    }

    .portfolio-detail__slides {
        border-radius: 0.625rem;
    }
}

@media (max-width: 575.98px) {
    .portfolio-page {
        width: min(100% - 1rem, var(--site-container));
    }

    .portfolio-hero .site-btn {
        width: 100%;
        max-width: 22rem;
    }

    .portfolio-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }

    .portfolio-card__text {
        -webkit-line-clamp: 2;
    }

    .portfolio-detail__layout {
        gap: 1.5rem;
    }

    .portfolio-detail__counter {
        right: 0.5rem;
        bottom: 0.5rem;
    }
}

@media (max-width: 400px) {
    .portfolio-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.625rem;
    }

    .portfolio-card__body {
        padding: 0.6rem 0.65rem 0.7rem;
    }

    .portfolio-card__title {
        font-size: 0.82rem;
    }

    .portfolio-card__text {
        font-size: 0.74rem;
        line-height: 1.3;
    }

    .portfolio-detail__thumb {
        width: 3.75rem;
    }
}

@media (max-width: 359.98px) {
    .portfolio-page {
        width: min(100% - 0.75rem, var(--site-container));
    }

    .portfolio-hero__title {
        font-size: 1.55rem;
    }

    .portfolio-grid {
        gap: 0.5rem;
    }
}

@media (hover: none) {
    .portfolio-card:hover {
        transform: none;
        box-shadow:
            0 4px 8px rgba(44, 36, 25, 0.2),
            0 12px 22px rgba(44, 36, 25, 0.16);
    }
}

@media (prefers-reduced-motion: reduce) {
    .portfolio-card,
    .portfolio-detail__arrow,
    .portfolio-detail__thumb-btn,
    .portfolio-detail__slides {
        transition: none;
        scroll-behavior: auto;
    }
}
