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

.stage-section {
    position: relative;
}

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

.stage-flow {
    /* высота половины схемы = ножка + кружок + отступ + две строки подписи */
    --stage-disc: clamp(74px, 7.4vw, 104px);
    --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(0, 1fr);
    margin: 0;
    padding: 0 44px 0 0;
    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: 6px;
    right: 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;
    cursor: pointer;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

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

.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.92) brightness(0.98);
}

.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-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;
}

.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);
    }
}
