/*
 * Витрина главной (modules/home-showcase.php): плитки категорий, лента товаров, зёрна граната и движение.
 * Скрытые до появления состояния действуют только с классом pg-home-motion на <html> — его ставит
 * home-showcase.js, разметив блоки. Без скрипта всё видно сразу.
 */

/* Тема красит каждый элемент (* { color; font-weight }) — внутри блоков возвращаем наследование,
   иначе цена и подписи в ссылках берут цвет темы, а не свой. */
.pg-home-cats *,
.pg-home-rail * {
    color: inherit;
    font-weight: inherit;
    letter-spacing: normal;
}

body.home ::selection {
    background: var(--pg-wine);
    color: var(--pg-home-cream);
}

body.home .storefront-discover {
    padding-bottom: 28px;
}

/* ---------- Плитки категорий ---------- */

.pg-home-cats {
    display: grid;
    box-sizing: border-box;
    max-width: 1440px;
    margin: 0 auto clamp(48px, 6vw, 96px);
    padding: 0 20px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, clamp(180px, 17vw, 250px)) clamp(92px, 8vw, 120px);
    grid-template-areas:
        "soki soki sladosti sladosti"
        "soki soki sousy maslo"
        "chai chai all all";
    gap: 14px;
}

.pg-home-cats__tile--soki { grid-area: soki; }
.pg-home-cats__tile--sladosti { grid-area: sladosti; }
.pg-home-cats__tile--sousy { grid-area: sousy; }
.pg-home-cats__tile--maslo { grid-area: maslo; }
.pg-home-cats__tile--chai-i-tsvety { grid-area: chai; }
.pg-home-cats__tile--all { grid-area: all; }

.entry-content .pg-home-cats a.pg-home-cats__tile {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: flex-end;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--pg-home-line);
    border-radius: 14px;
    background: var(--pg-home-panel);
    color: var(--pg-home-cream);
    text-decoration: none;
    transition: border-color 200ms ease;
}

.pg-home-cats__media {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--pg-home-photo-bg);
}

/* Подпись читается на любом фото: снизу тень, сверху фото как есть. */
.pg-home-cats__media::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(12, 11, 10, .9) 0%, rgba(12, 11, 10, .45) 38%, rgba(12, 11, 10, 0) 68%);
}

.entry-content .pg-home-cats img.pg-home-cats__image {
    display: block;
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
    border-radius: 0;
    object-fit: cover;
    transition: transform 300ms ease;
}

.entry-content .pg-home-cats__tile--soki img.pg-home-cats__image {
    object-position: 50% 35%;
}

.pg-home-cats__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: clamp(14px, 1.6vw, 22px);
}

.pg-home-cats__name {
    font-size: clamp(18px, 1.6vw, 24px);
    font-weight: 600;
    line-height: 1.25;
}

.pg-home-cats__tile--soki .pg-home-cats__name {
    font-size: clamp(26px, 2.6vw, 38px);
}

.pg-home-cats__price {
    color: var(--pg-home-muted);
    font-size: 15px;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
}

.entry-content .pg-home-cats a.pg-home-cats__tile--all {
    align-items: center;
    justify-content: space-between;
    border-color: var(--pg-home-gold);
    background: var(--pg-home-gold);
    color: var(--pg-home-on-gold);
    transition: background-color 200ms ease, border-color 200ms ease;
}

.pg-home-cats__tile--all .pg-home-cats__price {
    color: var(--pg-home-on-gold);
}

.pg-home-cats__arrow {
    padding-right: clamp(16px, 2vw, 28px);
    font-size: 28px;
    line-height: 1;
    transition: transform 200ms var(--pg-ease-out);
}

.entry-content .pg-home-cats a.pg-home-cats__tile:focus-visible {
    outline: 3px solid var(--pg-home-cream);
    outline-offset: 3px;
}

@media (hover: hover) and (pointer: fine) {
    .entry-content .pg-home-cats a.pg-home-cats__tile:hover {
        border-color: var(--pg-home-gold);
    }

    .entry-content .pg-home-cats a.pg-home-cats__tile:hover img.pg-home-cats__image {
        transform: scale(1.04);
    }

    .entry-content .pg-home-cats a.pg-home-cats__tile--all:hover {
        border-color: var(--pg-gold-hover);
        background: var(--pg-gold-hover);
    }

    .pg-home-cats__tile--all:hover .pg-home-cats__arrow {
        transform: translateX(4px);
    }
}

/* Узкий экран: полосы из квадратных фото не читаются, а подпись ложится на товар. Здесь плитка — карточка:
   квадратное фото целиком (снимки товаров квадратные, сок по центру виден от крышки до дна), подпись под ним. */
@media (max-width: 1023px) {
    .pg-home-cats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: none;
        grid-template-areas:
            "soki sladosti sousy"
            "maslo chai all";
        gap: 12px;
    }

    .entry-content .pg-home-cats a.pg-home-cats__tile {
        flex-direction: column;
        align-items: stretch;
    }

    .pg-home-cats__media {
        position: relative;
        inset: auto;
        z-index: auto;
        display: block;
        aspect-ratio: 1;
        overflow: hidden;
    }

    .pg-home-cats__media::after {
        content: none;
    }

    .entry-content .pg-home-cats__tile--soki img.pg-home-cats__image {
        object-position: 50% 50%;
    }

    .pg-home-cats__text {
        padding: 12px 14px 14px;
    }

    .pg-home-cats__name,
    .pg-home-cats__tile--soki .pg-home-cats__name {
        font-size: 18px;
    }

    .entry-content .pg-home-cats a.pg-home-cats__tile--all {
        flex-direction: column;
        align-items: flex-start;
        justify-content: space-between;
    }

    .pg-home-cats__tile--all .pg-home-cats__arrow {
        padding: 0 14px 14px;
        font-size: 32px;
    }
}

@media (max-width: 767px) {
    .pg-home-cats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas:
            "soki sladosti"
            "sousy maslo"
            "chai all";
        gap: 10px;
    }

    .pg-home-cats__text {
        padding: 10px 12px 12px;
    }

    .pg-home-cats__name,
    .pg-home-cats__tile--soki .pg-home-cats__name {
        font-size: 17px;
    }

    .pg-home-cats__price {
        font-size: 14px;
    }
}

/* ---------- Лента товаров с ценами ---------- */

.pg-home-rail {
    box-sizing: border-box;
    max-width: 1440px;
    margin: 0 auto clamp(48px, 6vw, 96px);
    padding: 0 20px;
    color: var(--pg-home-cream);
}

.pg-home-rail__head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.entry-content .pg-home-rail h2 {
    margin: 0;
    color: var(--pg-home-cream);
    font-family: inherit;
    font-size: clamp(28px, 3vw, 42px);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: normal;
    text-transform: none;
}

.pg-home-rail__controls {
    display: flex;
    gap: 8px;
}

.pg-home-rail__nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 1px solid var(--pg-home-line);
    border-radius: 50%;
    background: transparent;
    color: var(--pg-home-cream);
    font: inherit;
    font-size: 18px;
    cursor: pointer;
    transition: border-color 200ms ease, color 200ms ease, opacity 200ms ease;
}

.pg-home-rail__nav:disabled {
    opacity: .35;
    cursor: default;
}

.pg-home-rail__nav:focus-visible {
    outline: 3px solid var(--pg-home-cream);
    outline-offset: 3px;
}

.entry-content ul.pg-home-rail__list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: clamp(220px, 20vw, 280px);
    gap: 16px;
    margin: 0;
    padding: 4px 0 18px;
    list-style: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: var(--pg-home-line) transparent;
}

.entry-content .pg-home-rail__list li.pg-home-rail__item {
    margin: 0;
    padding: 0;
    scroll-snap-align: start;
}

.entry-content .pg-home-rail__list li.pg-home-rail__item::before {
    content: none;
}

.entry-content .pg-home-rail a.pg-home-rail__card {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    border: 1px solid var(--pg-home-line);
    border-radius: 14px;
    background: var(--pg-home-panel);
    color: var(--pg-home-cream);
    text-decoration: none;
    transition: border-color 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}

.pg-home-rail__media {
    display: block;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--pg-home-photo-bg);
}

.entry-content .pg-home-rail img.pg-home-rail__image {
    display: block;
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
    border-radius: 0;
    object-fit: cover;
    transition: transform 300ms ease;
}

.pg-home-rail__name {
    padding: 14px 16px 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
}

.pg-home-rail__label {
    padding: 4px 16px 0;
    color: var(--pg-home-muted);
    font-size: 14px;
    line-height: 1.4;
}

.pg-home-rail__price {
    margin-top: auto;
    padding: 12px 16px 16px;
    color: var(--pg-home-gold);
    font-size: 19px;
    font-weight: 700;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

.is-out .pg-home-rail__price {
    color: var(--pg-home-muted);
    font-size: 15px;
    font-weight: 500;
}

.entry-content .pg-home-rail .is-out img.pg-home-rail__image {
    opacity: .5;
}

.entry-content .pg-home-rail a.pg-home-rail__card:focus-visible {
    outline: 3px solid var(--pg-home-cream);
    outline-offset: 3px;
}

@media (hover: hover) and (pointer: fine) {
    .pg-home-rail__nav:not(:disabled):hover {
        border-color: var(--pg-home-gold);
        color: var(--pg-home-gold);
    }

    .entry-content .pg-home-rail a.pg-home-rail__card:hover {
        border-color: var(--pg-home-gold);
        box-shadow: 0 18px 36px -18px var(--pg-home-glow);
        transform: translateY(-3px);
    }

    .entry-content .pg-home-rail a.pg-home-rail__card:hover img.pg-home-rail__image {
        transform: scale(1.04);
    }
}

@media (max-width: 767px) {
    .pg-home-rail__controls {
        display: none;
    }

    .entry-content ul.pg-home-rail__list {
        grid-auto-columns: 64vw;
        gap: 12px;
    }
}

/* ---------- Атмосфера: зерно на фоне и зёрна граната ---------- */

/* Зерно — только на фоне страницы: под блоками со своим фоном его не видно, текст не шумит. */
body.home::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: .09;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body.home .storefront-discover,
.entry-content .progranat-home-shopping__order,
.pg-home-rail,
.entry-content .progranat-guides--home {
    position: relative;
}

body.home .storefront-discover::after,
.entry-content .progranat-home-shopping__order::after,
.pg-home-rail::after,
.entry-content .progranat-guides--home::after {
    content: "";
    position: absolute;
    z-index: 0;
    pointer-events: none;
    background: no-repeat center / contain;
}

/* Россыпь зёрен справа от заголовка витрины — там, где строка заканчивается. */
body.home .storefront-discover::after {
    top: clamp(8px, 2vw, 32px);
    right: clamp(8px, 4vw, 72px);
    width: clamp(110px, 13vw, 200px);
    aspect-ratio: 560 / 512;
    background-image: url("home/seeds-cluster.webp");
    rotate: -12deg;
}

/* Одно зерно на углу «Как заказать» — заходит за рамку. */
.entry-content .progranat-home-shopping__order::after {
    top: -34px;
    right: clamp(18px, 6vw, 90px);
    width: 76px;
    aspect-ratio: 184 / 188;
    background-image: url("home/seed-c.webp");
    rotate: 24deg;
}

/* Зерно не в фокусе у кнопок ленты — глубина без лишней резкости. */
.pg-home-rail::after {
    top: -34px;
    right: 128px;
    width: 54px;
    aspect-ratio: 197 / 183;
    background-image: url("home/seed-a.webp");
    filter: blur(2px);
    opacity: .7;
    rotate: -30deg;
}

.entry-content .progranat-guides--home::after {
    top: -10px;
    right: 6%;
    width: 64px;
    aspect-ratio: 175 / 195;
    background-image: url("home/seed-b.webp");
    rotate: 14deg;
}

@media (max-width: 767px) {
    /* Над строками заголовка справа: короткие строки туда не доходят. */
    body.home .storefront-discover::after {
        top: 4px;
        right: -8px;
        width: 84px;
    }

    .pg-home-rail::after,
    .entry-content .progranat-guides--home::after {
        content: none;
    }
}

/* Содержимое — над зёрнами. */
body.home .storefront-discover > *,
.entry-content .progranat-home-shopping__order > *,
.pg-home-rail > *,
.entry-content .progranat-guides--home > * {
    position: relative;
    z-index: 1;
}

/* Параллакс: зёрна чуть отстают от прокрутки. Только браузеры с прокруточной анимацией, на потоке
   композитора; в остальных зёрна просто лежат на месте. */
@supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
        body.home .storefront-discover { view-timeline: --pg-home-v1 block; }
        .entry-content .progranat-home-shopping__order { view-timeline: --pg-home-v2 block; }
        .pg-home-rail { view-timeline: --pg-home-v3 block; }
        .entry-content .progranat-guides--home { view-timeline: --pg-home-v4 block; }

        body.home .storefront-discover::after { animation: pg-home-drift linear both; animation-timeline: --pg-home-v1; }
        .entry-content .progranat-home-shopping__order::after { animation: pg-home-drift linear both; animation-timeline: --pg-home-v2; }
        .pg-home-rail::after { animation: pg-home-drift-far linear both; animation-timeline: --pg-home-v3; }
        .entry-content .progranat-guides--home::after { animation: pg-home-drift linear both; animation-timeline: --pg-home-v4; }
    }
}

@keyframes pg-home-drift {
    from { transform: translateY(40px); }
    to { transform: translateY(-40px); }
}

@keyframes pg-home-drift-far {
    from { transform: translateY(80px); }
    to { transform: translateY(-80px); }
}

/* ---------- Появление при прокрутке ---------- */

/* Разные блоки входят по-разному: текст поднимается, плитки проявляются из чуть меньшего размера,
   карточки ленты въезжают сбоку. Один раз; уже видимое при загрузке не прячется. */
@media (prefers-reduced-motion: no-preference) {
    html.pg-home-motion body.home [data-home-reveal] {
        transition: opacity 700ms var(--pg-ease-out), transform 700ms var(--pg-ease-out);
        transition-delay: var(--pg-home-delay, 0ms);
    }

    html.pg-home-motion body.home [data-home-reveal="up"]:not(.is-in) {
        opacity: 0;
        transform: translateY(20px);
    }

    html.pg-home-motion body.home [data-home-reveal="tile"]:not(.is-in) {
        opacity: 0;
        transform: scale(.96);
    }

    html.pg-home-motion body.home [data-home-reveal="side"]:not(.is-in) {
        opacity: 0;
        transform: translateX(32px);
    }

    /* Линия шагов прорисовывается, кружки загораются по очереди за ней. */
    html.pg-home-motion .entry-content .progranat-home-shopping__steps:not(.is-drawn)::before {
        transform: scaleX(0);
    }

    html.pg-home-motion .entry-content .progranat-home-shopping__steps::before {
        transition: transform 1100ms var(--pg-ease-in-out);
    }

    html.pg-home-motion .entry-content .progranat-home-shopping__steps:not(.is-drawn) .progranat-home-shopping__step-number {
        border-color: var(--pg-home-line);
        color: var(--pg-home-muted);
        box-shadow: none;
    }

    html.pg-home-motion .entry-content .progranat-home-shopping__step-number {
        transition: border-color 300ms ease, color 300ms ease, box-shadow 300ms ease;
    }

    html.pg-home-motion .entry-content .is-drawn li:nth-child(2) .progranat-home-shopping__step-number {
        transition-delay: 500ms;
    }

    html.pg-home-motion .entry-content .is-drawn li:nth-child(3) .progranat-home-shopping__step-number {
        transition-delay: 1000ms;
    }

    @media (max-width: 767px) {
        html.pg-home-motion .entry-content .progranat-home-shopping__steps:not(.is-drawn) li::after {
            transform: scaleY(0);
        }

        html.pg-home-motion .entry-content .progranat-home-shopping__steps li::after {
            transition: transform 500ms var(--pg-ease-in-out);
        }

        html.pg-home-motion .entry-content .is-drawn li:nth-child(2)::after {
            transition-delay: 500ms;
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    html.pg-home-motion body.home [data-home-reveal] {
        transition: opacity 400ms ease;
        transition-delay: var(--pg-home-delay, 0ms);
    }

    html.pg-home-motion body.home [data-home-reveal]:not(.is-in) {
        opacity: 0;
    }
}

/* ---------- Плавный переход «фото карточки → фото товара» (пара — в modules/home-showcase.php) ---------- */

@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }

    ::view-transition-group(pg-photo) {
        animation-duration: .45s;
        animation-timing-function: cubic-bezier(0.77, 0, 0.175, 1);
    }

    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: .25s;
    }
}
