/* ═══════════════════════════════════════════════════════════════════════════
   Экран 8 («Этапы сотрудничества», вариант «С зазором») — изолированные
   стили для основного лендинга sec2/d1.html: сплит 35/65, 14px-карточки с
   зазором 10px, растущая нить с узлами справа и магнитная стыковка при скролле.
   ═══════════════════════════════════════════════════════════════════════════ */

.stages-chapter {
  --st-paper-deep: #ecebe8;
  --st-paper: #f4f3f0;
  --st-sheet: #f7f6f3;
  --st-navy: #192236;
  --st-navy-glow: #3a526d;
  --st-steel: #355075;
  --st-ivory: #f5f3ea;
  --st-ink: #141821;
  --st-body: #2a2d33;
  --st-muted: #484b52;
  --st-line: #cecdc9;
  --st-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --st-ease-magnet: cubic-bezier(0.16, 1, 0.3, 1);
  --st-pad: clamp(1.25rem, 5vw, 5.5rem);
  --st-maxw: 83.5rem;

  position: relative;
  border-block-start: 1px solid var(--st-line);
  background-color: var(--st-paper-deep);
  background-image:
    radial-gradient(ellipse 56% 52% at 10% 8%, rgb(247 246 243 / 0.9) 0%, transparent 72%),
    radial-gradient(ellipse 40% 48% at 90% 90%, rgb(244 243 240 / 0.72) 0%, transparent 72%);
  color: var(--st-ink);
  font-family: "Jost", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1.125rem;
  line-height: 1.5;
  scroll-margin-top: 0;
}

.stages-chapter *,
.stages-chapter *::before,
.stages-chapter *::after {
  box-sizing: border-box;
}

.stages-chapter h2,
.stages-chapter p,
.stages-chapter ol {
  margin: 0;
  padding: 0;
}

.stages-chapter ::selection {
  background: var(--st-navy);
  color: var(--st-ivory);
}

.stages-chapter :focus-visible {
  outline: 2px solid var(--st-navy);
  outline-offset: 0.25rem;
  border-radius: 0.25rem;
}

.stages-chapter .st-stage {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: clamp(3.5rem, 5.4vw, 5.25rem) clamp(4.75rem, 7.2vw, 7rem);
  padding-inline: var(--st-pad);
}

.stages-chapter .st-dots {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  inset-block-start: 0;
  inset-inline-end: 0;
  inline-size: min(44%, 36.25rem);
  block-size: clamp(12.5rem, 26vw, 21.25rem);
  background: radial-gradient(circle, var(--st-navy-glow) 1.15px, transparent 1.55px) top right / 0.875rem 0.875rem;
  opacity: 0.2;
  mask-image: radial-gradient(ellipse at 100% 6%, #141821 10%, rgb(20 24 33 / 0.55) 40%, transparent 74%);
  -webkit-mask-image: radial-gradient(ellipse at 100% 6%, #141821 10%, rgb(20 24 33 / 0.55) 40%, transparent 74%);
}

.stages-chapter .st-bound {
  position: relative;
  z-index: 1;
  inline-size: min(100%, var(--st-maxw));
  margin-inline: auto;
}

.stages-chapter .st-num {
  font-variant-numeric: tabular-nums;
}

.stages-chapter .st-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.62fr) minmax(0, 1.38fr);
  column-gap: clamp(2rem, 4.4vw, 4.25rem);
  row-gap: 1.75rem;
  align-items: start;
}

.stages-chapter .st-aside {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-block-start: 0.375rem;
}

.stages-chapter .st-title {
  font-weight: 500;
  color: var(--st-navy);
  font-size: clamp(2.125rem, 3.9vw, 3.75rem);
  line-height: 1.06;
  letter-spacing: -0.032em;
  text-wrap: balance;
}

.stages-chapter .st-pips {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.375rem;
  max-inline-size: 16.25rem;
}

.stages-chapter .st-pips span {
  display: block;
  block-size: 0.1875rem;
  border-radius: 999px;
  background: rgb(25 34 54 / 0.14);
  overflow: clip;
}

.stages-chapter .st-pips i {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  background: var(--st-navy);
  transform-origin: left;
  transform: scaleX(1);
}

.stages-chapter .st-note-box {
  margin-block-start: clamp(0.5rem, 1.8vw, 1.5rem);
  padding-block-start: 1.25rem;
  border-block-start: 1px solid var(--st-line);
  max-inline-size: 34ch;
}

.stages-chapter .st-note {
  font-size: 1rem;
  font-weight: 560;
  line-height: 1.48;
  color: var(--st-navy);
  text-wrap: pretty;
}

/* Правая колонка: карточки с зазором 10px + интегрированная справа вертикальная нить и узлы */
.stages-chapter .st-track-wrap {
  --rail-gap: 2.25rem;
  position: relative;
  padding-inline-end: var(--rail-gap);
}

.stages-chapter .st-rail {
  position: absolute;
  inset-inline-end: 0.3125rem;
  inset-block-start: var(--rail-top, 1.875rem);
  inset-block-end: var(--rail-bottom, 2.625rem);
  inline-size: 2px;
  border-radius: 999px;
  background: rgb(25 34 54 / 0.14);
  overflow: clip;
  pointer-events: none;
}

.stages-chapter .st-rail i {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  background: var(--st-navy);
  transform-origin: top;
  transform: scaleY(1);
}

.stages-chapter .st-column {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.stages-chapter .st-step {
  position: relative;
  transition: opacity 0.42s var(--st-ease);
}

.stages-chapter .st-card {
  position: relative;
  overflow: clip;
  display: grid;
  grid-template-columns: 2.625rem minmax(0, 1fr);
  align-items: start;
  gap: 1.125rem;
  padding: 0.9375rem 1.5rem;
  border-radius: 0.875rem;
  background-color: var(--st-sheet);
  box-shadow:
    inset 0 1px 0 rgb(247 246 243 / 0.95),
    0 0.75rem 1.75rem -1.375rem rgb(20 24 33 / 0.2);
  transition:
    transform 0.55s var(--st-ease),
    opacity 0.42s var(--st-ease),
    box-shadow 0.55s var(--st-ease),
    background-color 0.4s var(--st-ease);
}

.stages-chapter .st-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    18.75rem circle at var(--mx, 50%) var(--my, 50%),
    rgb(38 53 84 / 0.06) 0%,
    transparent 68%
  );
  opacity: 0;
  transition: opacity 0.45s var(--st-ease);
}

.stages-chapter .st-card > * {
  position: relative;
  z-index: 1;
}

.stages-chapter .st-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 2.375rem;
  block-size: 1.75rem;
  margin-block-start: 1px;
  border-radius: 999px;
  background-color: var(--st-navy);
  color: var(--st-ivory);
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.04em;
  transition:
    background-color 0.4s var(--st-ease),
    transform 0.5s var(--st-ease);
}

.stages-chapter .st-text {
  font-size: clamp(1rem, 1.08vw, 1.125rem);
  line-height: 1.48;
  color: var(--st-body);
  text-wrap: pretty;
}

.stages-chapter .st-link {
  position: absolute;
  inset-inline-end: calc(-1 * (var(--rail-gap) - 0.375rem));
  inset-block-start: 1.8125rem;
  inline-size: calc(var(--rail-gap) - 0.375rem);
  block-size: 1.5px;
  background: var(--st-line);
  transform-origin: right center;
  transform: scaleX(1);
  pointer-events: none;
  transition:
    transform 0.55s var(--st-ease),
    background-color 0.4s var(--st-ease);
}

.stages-chapter .st-node {
  position: absolute;
  inset-inline-end: calc(-1 * (var(--rail-gap) - 1px));
  inset-block-start: 1.5625rem;
  inline-size: 0.625rem;
  block-size: 0.625rem;
  border-radius: 50%;
  background: var(--st-navy);
  border: 2px solid var(--st-paper-deep);
  pointer-events: none;
  transition:
    transform 0.5s var(--st-ease),
    box-shadow 0.45s var(--st-ease),
    background-color 0.4s var(--st-ease);
}

@media (min-width: 861px) and (hover: hover) and (pointer: fine) {
  .stages-chapter .st-column:has(.st-step:hover) .st-step:not(:hover) .st-card {
    opacity: 0.68;
  }

  .stages-chapter .st-step:hover .st-card {
    transform: translate3d(-0.625rem, 0, 0);
    box-shadow:
      inset 0 1px 0 rgb(247 246 243 / 0.98),
      0 1.25rem 2.375rem -1.5rem rgb(20 24 33 / 0.28);
  }

  .stages-chapter .st-step:hover .st-card::before {
    opacity: 1;
  }

  .stages-chapter .st-step:hover .st-badge {
    background-color: var(--st-steel);
    transform: scale(1.06);
  }

  .stages-chapter .st-step:hover .st-link {
    background: var(--st-navy);
    transform: scaleX(1.334);
  }

  .stages-chapter .st-step:hover .st-node {
    transform: scale(1.35);
    box-shadow: 0 0 0 0.25rem rgb(25 34 54 / 0.12);
  }
}

/* ── Мобильное и не-sticky появление при прокрутке ── */
@media screen and (prefers-reduced-motion: no-preference) {
  .stages-chapter.st-js-ready [data-st-reveal] {
    opacity: 0;
    translate: 0 1.375rem;
    transition:
      opacity 0.72s var(--st-ease) var(--d, 0s),
      translate 0.84s var(--st-ease-magnet) var(--d, 0s);
  }

  .stages-chapter.st-js-ready [data-st-reveal].is-in {
    opacity: 1;
    translate: 0 0;
  }
}

/* ── Залипающая магнитная стыковка на десктопе (>= 960×680) ── */
@media screen and (prefers-reduced-motion: no-preference) and (min-width: 960px) and (min-height: 680px) {
  @supports ((animation-timeline: scroll()) and (animation-range: 0% 100%)) {
    .stages-chapter:not(.st-static) {
      block-size: 340svh;
      view-timeline: --st-chapter-runway block;
    }

    .stages-chapter:not(.st-static) .st-stage {
      position: sticky;
      inset-block-start: 0;
      block-size: 100svh;
      min-block-size: 40rem;
      padding-block: clamp(1.375rem, 2.8svh, 2.5rem) clamp(3.5rem, 5.5svh, 5rem);
      clip-path: inset(-8svh 0 0 0);
    }

    .stages-chapter.st-js-ready:not(.st-static) [data-st-reveal] {
      opacity: 1;
      translate: none;
    }

    .stages-chapter:not(.st-static) .st-rail i {
      animation: stch-spine-grow linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 86%;
    }

    .stages-chapter:not(.st-static) [data-st-step] {
      will-change: translate, opacity, scale;
    }

    .stages-chapter:not(.st-static) [data-st-step="1"] {
      animation: stch-dock-2 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-step="2"] {
      animation: stch-dock-3 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-step="3"] {
      animation: stch-dock-4 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-step="4"] {
      animation: stch-dock-5 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-step="5"] {
      animation: stch-dock-6 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-note] {
      will-change: translate, opacity;
      animation: stch-note-arrive linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-pip="1"] i {
      animation: stch-pip-2 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-pip="2"] i {
      animation: stch-pip-3 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-pip="3"] i {
      animation: stch-pip-4 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-pip="4"] i {
      animation: stch-pip-5 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }

    .stages-chapter:not(.st-static) [data-st-pip="5"] i {
      animation: stch-pip-6 linear both;
      animation-timeline: --st-chapter-runway;
      animation-range: contain 0% contain 100%;
    }
  }
}

@keyframes stch-spine-grow {
  from { transform: scaleY(0.08); }
  to { transform: scaleY(1); }
}

@keyframes stch-dock-2 {
  0%, 2% {
    translate: 0 22svh;
    scale: 0.968;
    opacity: 0;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  7% { opacity: 0.92; }
  20%, 100% {
    translate: 0 0;
    scale: 1;
    opacity: 1;
  }
}

@keyframes stch-dock-3 {
  0%, 18% {
    translate: 0 22svh;
    scale: 0.968;
    opacity: 0;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  23% { opacity: 0.92; }
  37%, 100% {
    translate: 0 0;
    scale: 1;
    opacity: 1;
  }
}

@keyframes stch-dock-4 {
  0%, 35% {
    translate: 0 22svh;
    scale: 0.968;
    opacity: 0;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  40% { opacity: 0.92; }
  53%, 100% {
    translate: 0 0;
    scale: 1;
    opacity: 1;
  }
}

@keyframes stch-dock-5 {
  0%, 51% {
    translate: 0 22svh;
    scale: 0.968;
    opacity: 0;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  56% { opacity: 0.92; }
  69%, 100% {
    translate: 0 0;
    scale: 1;
    opacity: 1;
  }
}

@keyframes stch-dock-6 {
  0%, 67% {
    translate: 0 22svh;
    scale: 0.968;
    opacity: 0;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  }
  72% { opacity: 0.92; }
  85%, 100% {
    translate: 0 0;
    scale: 1;
    opacity: 1;
  }
}

@keyframes stch-note-arrive {
  0%, 76% {
    translate: 0 1.125rem;
    opacity: 0;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  }
  89%, 100% {
    translate: 0 0;
    opacity: 1;
  }
}

@keyframes stch-pip-2 {
  0%, 8% { transform: scaleX(0); }
  20%, 100% { transform: scaleX(1); }
}

@keyframes stch-pip-3 {
  0%, 24% { transform: scaleX(0); }
  37%, 100% { transform: scaleX(1); }
}

@keyframes stch-pip-4 {
  0%, 41% { transform: scaleX(0); }
  53%, 100% { transform: scaleX(1); }
}

@keyframes stch-pip-5 {
  0%, 57% { transform: scaleX(0); }
  69%, 100% { transform: scaleX(1); }
}

@keyframes stch-pip-6 {
  0%, 73% { transform: scaleX(0); }
  85%, 100% { transform: scaleX(1); }
}

/* Резервный JS-фолбэк для браузеров без CSS Scroll-Driven Animations */
@media screen and (prefers-reduced-motion: no-preference) and (min-width: 960px) and (min-height: 680px) {
  .stages-chapter.is-js-fallback {
    block-size: 340svh;
  }

  .stages-chapter.is-js-fallback .st-stage {
    position: sticky;
    inset-block-start: 0;
    block-size: 100svh;
    min-block-size: 40rem;
    padding-block: clamp(1.375rem, 2.8svh, 2.5rem) clamp(3.5rem, 5.5svh, 5rem);
    clip-path: inset(-8svh 0 0 0);
  }

  .stages-chapter.is-js-fallback .st-rail i {
    transform: scaleY(var(--p-spine, 0.08));
  }

  .stages-chapter.is-js-fallback [data-st-step="1"] {
    translate: 0 calc((1 - var(--p-s1, 0)) * 22svh);
    scale: calc(0.968 + var(--p-s1, 0) * 0.032);
    opacity: var(--p-o1, 0);
  }

  .stages-chapter.is-js-fallback [data-st-step="2"] {
    translate: 0 calc((1 - var(--p-s2, 0)) * 22svh);
    scale: calc(0.968 + var(--p-s2, 0) * 0.032);
    opacity: var(--p-o2, 0);
  }

  .stages-chapter.is-js-fallback [data-st-step="3"] {
    translate: 0 calc((1 - var(--p-s3, 0)) * 22svh);
    scale: calc(0.968 + var(--p-s3, 0) * 0.032);
    opacity: var(--p-o3, 0);
  }

  .stages-chapter.is-js-fallback [data-st-step="4"] {
    translate: 0 calc((1 - var(--p-s4, 0)) * 22svh);
    scale: calc(0.968 + var(--p-s4, 0) * 0.032);
    opacity: var(--p-o4, 0);
  }

  .stages-chapter.is-js-fallback [data-st-step="5"] {
    translate: 0 calc((1 - var(--p-s5, 0)) * 22svh);
    scale: calc(0.968 + var(--p-s5, 0) * 0.032);
    opacity: var(--p-o5, 0);
  }

  .stages-chapter.is-js-fallback [data-st-pip="1"] i { transform: scaleX(var(--p-s1, 0)); }
  .stages-chapter.is-js-fallback [data-st-pip="2"] i { transform: scaleX(var(--p-s2, 0)); }
  .stages-chapter.is-js-fallback [data-st-pip="3"] i { transform: scaleX(var(--p-s3, 0)); }
  .stages-chapter.is-js-fallback [data-st-pip="4"] i { transform: scaleX(var(--p-s4, 0)); }
  .stages-chapter.is-js-fallback [data-st-pip="5"] i { transform: scaleX(var(--p-s5, 0)); }

  .stages-chapter.is-js-fallback [data-st-note] {
    translate: 0 calc((1 - var(--p-note, 0)) * 1.125rem);
    opacity: var(--p-note, 0);
  }
}

@media (max-width: 959px) {
  .stages-chapter .st-layout {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 24px;
  }

  .stages-chapter .st-note-box {
    margin-block-start: 0;
  }
}

@media (max-width: 640px) {
  .stages-chapter .st-track-wrap {
    --rail-gap: 24px;
  }

  .stages-chapter .st-card {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 14px;
    padding: 16px 18px;
  }

  .stages-chapter .st-link {
    inset-block-start: 30px;
  }

  .stages-chapter .st-node {
    inset-block-start: 26px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stages-chapter .st-step,
  .stages-chapter .st-card,
  .stages-chapter .st-card::before,
  .stages-chapter .st-badge,
  .stages-chapter .st-link,
  .stages-chapter .st-node {
    transition: none;
  }
}
