/* ==========================================================================
   Этапы изготовления: схема с кружками и раскрывающаяся панель этапа
   ========================================================================== */

.stage-section {
    position: relative;
}

/* --------------------------------------------------------------------------
   Схема: цветная лента со стрелкой направления и кружками этапов
   -------------------------------------------------------------------------- */

.stage-section__hint {
    color: var(--ink-soft);
    font-size: 0.92rem;
}

/* при большом числе этапов схема не сжимается до наложения кружков,
   а прокручивается по горизонтали. Прокрутка включается только когда схема
   не помещается (класс is-scrollable ставит stages.js): overflow обрезает
   тени кружков, поэтому в обычном случае контейнер ничего не обрезает,
   а в прокручиваемом — даёт теням поля */
.stage-flow-scroll.is-scrollable {
    /* снизу запас не компенсируем отрицательным отступом: полоса прокрутки
       рисуется по нижнему краю и иначе ложится на панель этапа */
    margin: -28px -8px 0;
    padding: 28px 8px 40px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
}

/* край, за которым схема продолжается, мягко гаснет */
.stage-flow-scroll.has-more-right {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 56px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 56px), transparent);
}

.stage-flow-scroll.has-more-left {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 56px), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 56px), transparent);
}

.stage-flow-scroll.has-more-left.has-more-right {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 56px, #000 calc(100% - 56px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 56px, #000 calc(100% - 56px), transparent);
}

.stage-flow {
    /* высота половины схемы = ножка + кружок + отступ + две строки подписи */
    --stage-disc: clamp(74px, 7.4vw, 104px);
    /* кружки чередуются сверху/снизу, поэтому соседям по одной стороне
       хватает двух колонок: колонка — чуть больше половины кружка */
    --stage-col: calc(var(--stage-disc) / 2 + 14px);
    --stage-stem: 22px;
    --stage-gap: 16px;
    --stage-caption: 2.7em;
    --stage-track: 12px;
    --stage-half: calc(var(--stage-stem) + var(--stage-disc) + var(--stage-gap) + var(--stage-caption));
    position: relative;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(var(--stage-col), 1fr);
    min-width: min-content;
    margin: 0;
    /* слева запас: в плотной схеме первый кружок шире своей колонки */
    padding: 0 44px 0 20px;
    list-style: none;
}

.stage-flow__item {
    position: relative;
    height: calc(var(--stage-half) * 2);
    min-width: 0;
    --stage-color: var(--wood);
}

.stage-flow__item:nth-child(6n + 2) { --stage-color: var(--resin-deep); }
.stage-flow__item:nth-child(6n + 3) { --stage-color: var(--success); }
.stage-flow__item:nth-child(6n + 4) { --stage-color: var(--wood-dark); }
.stage-flow__item:nth-child(6n + 5) { --stage-color: var(--danger); }
.stage-flow__item:nth-child(6n + 6) { --stage-color: var(--warning); }

/* каждый этап рисует свой отрезок ленты — цвета стыкуются в одну полосу */
.stage-flow__item::before {
    content: "";
    position: absolute;
    top: 50%;
    left: -1px;
    right: -1px;
    height: var(--stage-track);
    background: var(--stage-color);
    transform: translateY(-50%);
}

.stage-flow__item:first-child::before {
    left: 0;
    border-radius: var(--stage-track) 0 0 var(--stage-track);
}

/* остриё в конце ленты — показывает направление процесса */
.stage-flow__item:last-child::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 100%;
    width: 0;
    height: 0;
    border-top: calc(var(--stage-track) / 2 + 8px) solid transparent;
    border-bottom: calc(var(--stage-track) / 2 + 8px) solid transparent;
    border-left: 26px solid var(--stage-color);
    transform: translateY(-50%);
}

.stage-flow__node {
    position: absolute;
    left: 50%;
    z-index: 2;
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    transform: translateX(-50%);
    cursor: pointer;
}

.stage-flow__item:nth-child(odd) .stage-flow__node {
    bottom: calc(50% + var(--stage-stem));
}

.stage-flow__item:nth-child(even) .stage-flow__node {
    top: calc(50% + var(--stage-stem));
}

/* ножка от кружка к ленте */
.stage-flow__node::after {
    content: "";
    position: absolute;
    left: 50%;
    width: 4px;
    height: calc(var(--stage-stem) + 4px);
    border-radius: 4px;
    background: var(--stage-color);
    transform: translateX(-50%);
}

.stage-flow__item:nth-child(odd) .stage-flow__node::after {
    top: 100%;
}

.stage-flow__item:nth-child(even) .stage-flow__node::after {
    bottom: 100%;
}

.stage-flow__disc {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    overflow: hidden;
    width: var(--stage-disc);
    aspect-ratio: 1;
    border-radius: 50%;
    border: 4px solid var(--surface-strong);
    background: var(--stage-color);
    color: #fff;
    box-shadow: 0 0 0 2px var(--stage-color), 0 16px 32px rgba(32, 23, 16, 0.2);
    transition: box-shadow 0.24s ease, filter 0.24s ease;
}

.stage-flow__disc img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stage-flow__fallback {
    font-family: var(--display-font);
    font-size: 1.5rem;
    line-height: 1;
}

/* номер этапа — бейдж на самой ленте, поэтому никогда не липнет к кружку */
.stage-flow__num {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 3;
    display: grid;
    place-items: center;
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    border-radius: 999px;
    border: 2px solid var(--stage-color);
    background: var(--surface-strong);
    color: var(--stage-color);
    font-family: var(--display-font);
    font-size: 0.94rem;
    line-height: 1;
    transform: translate(-50%, -50%);
    cursor: pointer;
}

/* подпись шире своей колонки: соседняя подпись на той же стороне — через колонку */
.stage-flow__caption {
    position: absolute;
    left: calc(-50% + 6px);
    right: calc(-50% + 6px);
    display: -webkit-box;
    overflow: hidden;
    max-height: var(--stage-caption);
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    text-align: center;
    /* длинное слово в узкой колонке переносится, а не обрезается */
    overflow-wrap: anywhere;
    hyphens: auto;
    cursor: pointer;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.stage-flow__caption:hover {
    color: var(--wood-dark);
}

/* выбранный этап читается не только по кольцу: подпись в его цвете и жирнее */
.stage-flow__item:has(.stage-flow__node[aria-selected="true"]) .stage-flow__caption {
    color: var(--stage-color);
    font-weight: 600;
}

.stage-flow__item:nth-child(odd) .stage-flow__caption {
    bottom: calc(50% + var(--stage-stem) + var(--stage-disc) + var(--stage-gap));
}

.stage-flow__item:nth-child(even) .stage-flow__caption {
    top: calc(50% + var(--stage-stem) + var(--stage-disc) + var(--stage-gap));
}

/* состояния — без transform: размер кружка не меняется,
   иначе отступ до подписи у активного этапа отличался бы от остальных */
.stage-flow__node:hover .stage-flow__disc {
    box-shadow: 0 0 0 3px var(--stage-color), 0 20px 38px rgba(32, 23, 16, 0.26);
    filter: brightness(1.04);
}

.stage-flow__node:focus-visible {
    outline: none;
}

.stage-flow__node:focus-visible .stage-flow__disc {
    outline: 2px solid var(--stage-color);
    outline-offset: 6px;
}

/* фокус пришёл от клика по подписи или номеру — рамка не нужна */
.stage-flow__node.is-pointer-focus:focus-visible .stage-flow__disc {
    outline: none;
}

/* неактивный этап приглушаем цветом, а не прозрачностью:
   прозрачный кружок просвечивал ленту насквозь */
.stage-flow__node[aria-selected="false"] .stage-flow__disc {
    filter: saturate(0.55) brightness(1.06);
}

.stage-flow__node[aria-selected="false"]:hover .stage-flow__disc {
    filter: saturate(0.9) brightness(1.04);
}

.stage-flow__node[aria-selected="true"] .stage-flow__disc {
    box-shadow: 0 0 0 3px var(--stage-color), 0 0 0 8px color-mix(in srgb, var(--stage-color) 16%, transparent),
        0 22px 40px rgba(32, 23, 16, 0.28);
}

.stage-flow__item:has(.stage-flow__node[aria-selected="true"]) .stage-flow__num {
    background: var(--stage-color);
    color: #fff;
}

/* --------------------------------------------------------------------------
   Итоговый результат: кружок в конце ленты, по центру, вместо стрелки
   -------------------------------------------------------------------------- */

.stage-flow--final {
    --stage-final-disc: calc(var(--stage-disc) * 1.18);
    padding-right: 0;
}

.stage-flow__item.stage-flow__item--final {
    --stage-color: var(--resin-deep);
}

/* лента доходит только до центра итогового кружка */
.stage-flow__item--final::before {
    right: 50%;
}

.stage-flow__item--final:last-child::after {
    content: none;
}

.stage-flow__item--final .stage-flow__disc {
    border-color: var(--surface-strong);
    background: linear-gradient(145deg, var(--resin) 0%, var(--resin-deep) 70%);
    box-shadow: 0 0 0 3px var(--stage-color), 0 0 0 7px var(--surface-strong),
        0 0 0 9px color-mix(in srgb, var(--wood) 70%, transparent), 0 18px 36px rgba(32, 23, 16, 0.24);
}

/* на тач-экранах :hover «залипает» после тапа — там подсветку не включаем */
@media (hover: hover) {
    .stage-flow__item--final .stage-flow__node:hover .stage-flow__disc {
        box-shadow: 0 0 0 3px var(--stage-color), 0 0 0 7px var(--surface-strong),
            0 0 0 9px var(--wood), 0 22px 40px rgba(32, 23, 16, 0.3);
    }
}

.stage-flow__item--final .stage-flow__node[aria-selected="true"] .stage-flow__disc {
    box-shadow: 0 0 0 3px var(--stage-color), 0 0 0 7px var(--surface-strong),
        0 0 0 9px var(--wood), 0 0 0 16px color-mix(in srgb, var(--stage-color) 14%, transparent),
        0 22px 40px rgba(32, 23, 16, 0.3);
}

.stage-flow__check {
    width: 46%;
    height: 46%;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* бейдж «Итог» — пара к номерам этапов */
.stage-flow__badge {
    position: absolute;
    left: 50%;
    z-index: 3;
    display: grid;
    place-items: center;
    height: 26px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--stage-color);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
    transform: translateX(-50%);
    cursor: pointer;
}

/* точное дополнение к max-width: 760px — без «щели» при дробной ширине окна */
@media not all and (max-width: 760px) {
    /* колонка итога в 1,5 раза шире обычной: круг крупнее и стоит на самой ленте,
       и без запаса отрезок до него выходил на треть короче, чем между этапами */
    .stage-flow--final {
        /* этап занимает две колонки — минимальная колонка вдвое уже */
        --stage-col: calc(var(--stage-disc) / 4 + 2px);
        /* итоговый кружок крупнее своей колонки — запас справа */
        padding-right: calc(var(--stage-disc) * 0.25);
    }

    .stage-flow--final > .stage-flow__item {
        grid-column: span 2;
    }

    .stage-flow--final > .stage-flow__item--final {
        grid-column: span 3;
    }

    .stage-flow .stage-flow__item--final .stage-flow__node {
        top: 50%;
        bottom: auto;
        transform: translate(-50%, -50%);
    }

    .stage-flow__item--final .stage-flow__node::after {
        display: none;
    }

    .stage-flow__item--final .stage-flow__disc {
        width: var(--stage-final-disc);
    }

    .stage-flow__item--final .stage-flow__fallback {
        font-size: 1.8rem;
    }

    .stage-flow__item--final .stage-flow__badge {
        bottom: calc(50% + var(--stage-final-disc) / 2 + 18px);
    }

    .stage-flow .stage-flow__item--final .stage-flow__caption {
        top: calc(50% + var(--stage-final-disc) / 2 + 18px);
        bottom: auto;
        left: -8px;
        right: -8px;
        font-weight: 600;
    }
}

.stage-panel--final .stage-panel__index {
    color: var(--wood-deep);
}

/* --------------------------------------------------------------------------
   Панель этапа
   -------------------------------------------------------------------------- */

.stage-panels {
    margin-top: clamp(28px, 4vw, 44px);
}

.stage-panels.is-enhanced .stage-panel {
    display: none;
}

.stage-panels.is-enhanced .stage-panel.is-active {
    display: block;
}

.stage-panel {
    padding: clamp(22px, 3vw, 34px);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: rgba(255, 252, 247, 0.9);
    box-shadow: var(--shadow-card);
}

.stage-panel + .stage-panel {
    margin-top: 18px;
}

/* с фото панель делится пополам: слева заголовок и текст, справа медиа —
   одна строка текста больше не висит над огромным пустым полем */
@media (min-width: 901px) {
    .stage-panels.is-enhanced .stage-panel.is-active:has(.stage-media),
    .stage-panels:not(.is-enhanced) .stage-panel:has(.stage-media) {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: auto 1fr;
        column-gap: clamp(24px, 3.4vw, 44px);
    }

    .stage-panel:has(.stage-media) .stage-panel__head,
    .stage-panel:has(.stage-media) .stage-panel__text {
        grid-column: 1;
    }

    .stage-panel:has(.stage-media) .stage-media {
        grid-column: 2;
        grid-row: 1 / span 2;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-content: start;
        margin-top: 0;
    }

    .stage-panel:has(.stage-media) .stage-media__item:only-child {
        grid-column: 1 / -1;
    }
}

.stage-panel__head {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
}

.stage-panel__index {
    color: var(--resin-deep);
    font-size: 0.76rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.stage-panel__title {
    font-family: var(--display-font);
    font-size: clamp(1.3rem, 1.1rem + 0.8vw, 1.7rem);
    font-weight: 500;
    line-height: 1.2;
}

.stage-panel__text {
    max-width: 74ch;
    color: var(--ink-muted);
    line-height: 1.6;
}

.stage-panel__text p + p {
    margin-top: 10px;
}

/* --------------------------------------------------------------------------
   Медиа этапа
   -------------------------------------------------------------------------- */

.stage-media {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.stage-media__item {
    display: grid;
    gap: 8px;
    margin: 0;
    min-width: 0;
}

/* кликабельное фото этапа — открывается во всплывающем просмотре */
.stage-media__link {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: 16px;
    cursor: zoom-in;
}

.stage-media__item img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 16px;
    border: 0;
    background: transparent;
    transition: transform 0.3s ease;
}

.stage-media__link:hover img,
.stage-media__link:focus-visible img {
    transform: scale(1.03);
}

.stage-media__link:focus-visible {
    outline: 2px solid var(--resin-deep);
    outline-offset: 3px;
}

/* значок увеличения — подсказывает, что фото открывается крупно */
.stage-media__zoom {
    position: absolute;
    right: 10px;
    bottom: 10px;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(17, 13, 12, 0.55);
    color: #fff;
    opacity: 0;
    transition: opacity 0.24s ease;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.stage-media__zoom svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.stage-media__link:hover .stage-media__zoom,
.stage-media__link:focus-visible .stage-media__zoom {
    opacity: 1;
}

@media (hover: none) {
    .stage-media__zoom {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .stage-media__link:hover img,
    .stage-media__link:focus-visible img {
        transform: none;
    }
}

.stage-media__item--video {
    grid-column: span 2;
}

.stage-media__frame {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #1d1513;
}

.stage-media__frame iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.stage-media__item figcaption {
    color: var(--ink-soft);
    font-size: 0.86rem;
    line-height: 1.35;
}

/* --------------------------------------------------------------------------
   Адаптив: на узких экранах схема становится вертикальной
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .stage-media {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stage-media__item--video {
        grid-column: 1 / -1;
    }
}

@media (max-width: 760px) {
    /* вертикальная лента: кружок слева, подпись справа, стрелка вниз */
    .stage-flow {
        --stage-disc: 64px;
        grid-auto-flow: row;
        grid-auto-columns: auto;
        gap: 0;
        padding: 0 0 34px 18px;
    }

    .stage-flow__item {
        display: flex;
        align-items: center;
        gap: 14px;
        height: auto;
        min-height: calc(var(--stage-disc) + 16px);
        padding: 6px 0;
    }

    .stage-flow__item::before {
        top: -1px;
        bottom: -1px;
        left: calc(var(--stage-disc) / 2 - var(--stage-track) / 2);
        right: auto;
        width: var(--stage-track);
        height: auto;
        border-radius: 0;
        transform: none;
    }

    .stage-flow__item:first-child::before {
        /* лента стартует от центра первого кружка, а не от верха блока,
           иначе над ним торчит обрезок полосы */
        top: 50%;
        /* left обязателен: иначе побеждает десктопное правило left: 0
           и лента первого этапа уезжает к левому краю */
        left: calc(var(--stage-disc) / 2 - var(--stage-track) / 2);
        border-radius: 0;
    }

    .stage-flow__item:last-child::after {
        top: 100%;
        left: calc(var(--stage-disc) / 2);
        border-top: 26px solid var(--stage-color);
        border-right: calc(var(--stage-track) / 2 + 8px) solid transparent;
        border-bottom: 0;
        border-left: calc(var(--stage-track) / 2 + 8px) solid transparent;
        transform: translateX(-50%);
    }

    .stage-flow__node {
        position: static;
        flex: 0 0 auto;
        transform: none;
    }

    .stage-flow__node::after {
        display: none;
    }

    .stage-flow__disc {
        border-width: 3px;
    }

    .stage-flow__fallback {
        font-size: 1.15rem;
    }

    .stage-flow__num {
        position: static;
        flex: 0 0 auto;
        min-width: 26px;
        height: 26px;
        font-size: 0.82rem;
        transform: none;
    }

    .stage-flow__caption {
        position: static;
        flex: 1 1 auto;
        max-height: none;
        text-align: left;
        -webkit-line-clamp: 3;
    }

    .stage-media {
        grid-template-columns: minmax(0, 1fr);
    }

    /* итоговый этап: лента заканчивается на кружке, стрелки нет */
    .stage-flow--final {
        padding-bottom: 0;
    }

    /* кольца итогового кружка шире — чуть отодвигаем его от предыдущего этапа */
    .stage-flow__item--final {
        margin-top: 8px;
    }

    .stage-flow__item--final::before {
        top: -9px;
        bottom: 50%;
    }

    .stage-flow__item--final:last-child::after {
        content: none;
    }

    .stage-flow__item--final .stage-flow__disc {
        box-shadow: 0 0 0 2px var(--stage-color), 0 0 0 5px var(--surface-strong),
            0 0 0 7px color-mix(in srgb, var(--wood) 70%, transparent), 0 12px 24px rgba(32, 23, 16, 0.2);
    }

    .stage-flow__item--final .stage-flow__node[aria-selected="true"] .stage-flow__disc {
        box-shadow: 0 0 0 2px var(--stage-color), 0 0 0 5px var(--surface-strong),
            0 0 0 7px var(--wood), 0 0 0 12px color-mix(in srgb, var(--stage-color) 14%, transparent);
    }

    .stage-flow__badge {
        position: static;
        flex: 0 0 auto;
        height: 24px;
        padding: 0 10px;
        font-size: 0.66rem;
        transform: none;
    }

    .stage-flow__item--final .stage-flow__caption {
        font-weight: 600;
    }
}
