/* K3 · «Система живёт»: круговая навигация (шаг 3′, пишет архитектор).

   Три уровня, один набор разметки:
   1. По умолчанию (мобильные, Firefox, Safari, reduced-motion): колонка из пяти
      нумерованных шагов. Колесо скрыто. Всё читается без скриптов.
   2. Chrome/Edge на десктопе без reduced-motion: «прилипшая» сцена внутри высокой
      секции. Скролл страницы крутит колесо (scroll-driven animations,
      `animation-timeline`), шаги сменяют друг друга. Работает без JS.
   3. cycle.js только расставляет aria-current на активный узел.

   Токены берутся из styles.css (--accent, --accent-dark, --border, --pastel, --ink, --grey),
   запасные значения заданы здесь. */

@property --on {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}

.cycle {
  --cy-accent: var(--accent, #E91E63);
  --cy-accent-dark: var(--accent-dark, #C2185B);
  --cy-border: var(--border, #E8E0E0);
  --cy-border-2: var(--border-2, #D8CCCC);
  --cy-ink: var(--ink, #1F1F1F);
  --cy-grey: var(--grey, #666);
  --cy-top: var(--header-h, 72px);
  background: var(--white, #fff);
  padding-bottom: 0;   /* верх даёт .section, низ закрывает сцена */
}

/* ---------- уровень 1: список шагов ---------- */
.cycle__runway { position: relative; }
.cycle__stage {
  width: 100%;
  max-width: var(--container, 1200px);
  margin-inline: auto;
  padding-inline: var(--gutter, 1rem);
  padding-bottom: clamp(3.5rem, 8vw, 6rem);
}
.cycle__wheel,
.cycle__hint,
.cycle__anchor { display: none; }

.cycle__steps { list-style: none; margin: 0; padding: 0; }
.cycle__panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 1.25rem;
  padding-block: 1.5rem;
  border-top: 1px solid var(--cy-border);
}
.cycle__panel:last-child { border-bottom: 1px solid var(--cy-border); }
.cycle__num {
  font-size: clamp(2.25rem, 7vw, 3.25rem);
  font-weight: 800;
  line-height: .95;
  letter-spacing: -.03em;
  color: var(--cy-accent);
  font-variant-numeric: tabular-nums;
}
.cycle__body h3 {
  margin: 0 0 .5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--cy-ink);
}
.cycle__body p { margin: 0 0 .75rem; color: var(--cy-grey); max-width: 38rem; }
.cycle__out { font-size: .875rem; color: var(--cy-ink); }
.cycle__out span {
  display: inline-block;
  margin-right: .5rem;
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--cy-accent-dark);
}
.cycle__steps::after {
  content: "После шага 5 цикл возвращается к шагу 1";
  display: block;
  padding-top: 1rem;
  font-size: .8125rem;
  color: var(--cy-grey);
}

/* ---------- уровень 2: колесо, прокрутка управляет шагами ---------- */
@media (min-width: 60rem) and (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {

    @keyframes cycle-on        { 0% { --on: 0 } 13%, 87% { --on: 1 } 100% { --on: 0 } }
    @keyframes cycle-on-first  { 0%, 87% { --on: 1 } 100% { --on: 0 } }
    @keyframes cycle-on-last   { 0% { --on: 0 } 13%, 100% { --on: 1 } }
    @keyframes cycle-arc {          /* дуга от узла 1 до активного; замыкающий отрезок остаётся пустым */
      0%, 16%   { stroke-dashoffset: 100 }
      24%, 36%  { stroke-dashoffset: 80 }
      44%, 56%  { stroke-dashoffset: 60 }
      64%, 76%  { stroke-dashoffset: 40 }
      84%, 100% { stroke-dashoffset: 20 }
    }
    @keyframes cycle-turn {
      0%, 16%   { rotate: 0deg }
      24%, 36%  { rotate: -72deg }
      44%, 56%  { rotate: -144deg }
      64%, 76%  { rotate: -216deg }
      84%, 100% { rotate: -288deg }
    }
    @keyframes cycle-unturn {
      0%, 16%   { rotate: 0deg }
      24%, 36%  { rotate: 72deg }
      44%, 56%  { rotate: 144deg }
      64%, 76%  { rotate: 216deg }
      84%, 100% { rotate: 288deg }
    }

    /* 500vh = 100vh сцены + 5 шагов по 80vh прокрутки */
    .cycle__runway {
      height: 500vh;
      view-timeline: --cycle block;
    }
    .cycle__stage {
      position: sticky;
      top: var(--cy-top);
      height: calc(100svh - var(--cy-top));
      padding-bottom: 0;
      display: grid;
      grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
      grid-template-rows: minmax(0, 1fr);
      gap: clamp(2rem, 5vw, 5rem);
      align-items: center;
    }
    .cycle__anchor {
      display: block;
      position: absolute;
      left: 0;
      width: 1px;
      height: 1px;
      top: calc(var(--k) * 80vh + 40vh);
    }

    /* колесо */
    .cycle__wheel {
      display: block;
      position: relative;
      container-type: inline-size;
      width: min(100%, 30rem, calc(100svh - var(--cy-top) - 3rem));
      aspect-ratio: 1;
      margin-inline: auto;
    }
    .cycle__svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
    .cycle__track { stroke: var(--cy-border-2); stroke-width: .5; }
    .cycle__arc {
      stroke: var(--cy-accent);
      stroke-width: 1;
      stroke-linecap: round;
      stroke-dasharray: 100;
      stroke-dashoffset: 100;
      animation: cycle-arc linear both;
      animation-timeline: --cycle;
      animation-range: contain 0% contain 100%;
    }
    .cycle__dial {
      position: absolute;
      inset: 0;
      animation: cycle-turn linear both;
      animation-timeline: --cycle;
      animation-range: contain 0% contain 100%;
    }
    .cycle__node {
      --node: clamp(3rem, 14cqw, 4.5rem);
      position: absolute;
      left: 50%;
      top: 50%;
      width: var(--node);
      height: var(--node);
      margin: calc(var(--node) / -2) 0 0 calc(var(--node) / -2);
      transform: rotate(calc(var(--k) * 72deg)) translateX(37.5cqw);
      border-radius: 50%;
      text-decoration: none;
      animation: cycle-on linear both;
      animation-timeline: --cycle;
      animation-range: contain calc(var(--k) * 20% - 3%) contain calc(var(--k) * 20% + 23%);
    }
    .cycle__node.is-first { animation-name: cycle-on-first; animation-range: contain 0% contain 23%; }
    .cycle__node.is-last  { animation-name: cycle-on-last;  animation-range: contain 77% contain 100%; }

    .cycle__face {
      display: grid;
      place-items: center;
      width: 100%;
      height: 100%;
      border-radius: 50%;
      font-size: 1.125rem;
      font-weight: 700;
      font-variant-numeric: tabular-nums;
      background: color-mix(in srgb, var(--cy-accent-dark) calc(var(--on) * 100%), #fff);
      color: color-mix(in srgb, #fff calc(var(--on) * 100%), var(--cy-grey));
      border: 1.5px solid color-mix(in srgb, var(--cy-accent-dark) calc(var(--on) * 100%), var(--cy-border-2));
      scale: calc(1 + var(--on) * .2);
      transform: rotate(calc(var(--k) * -72deg));   /* гасит поворот узла в круге */
      animation: cycle-unturn linear both;          /* гасит поворот колеса */
      animation-timeline: --cycle;
      animation-range: contain 0% contain 100%;
    }
    .cycle__node:focus-visible { outline: 3px solid var(--cy-accent-dark); outline-offset: 4px; }

    /* число в центре */
    .cycle__center {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      pointer-events: none;
    }
    .cycle__count,
    .cycle__of { grid-area: 1 / 1; }
    .cycle__count {
      font-size: clamp(3rem, 22cqw, 6.5rem);
      font-weight: 800;
      letter-spacing: -.04em;
      line-height: 1;
      color: var(--cy-ink);
      font-variant-numeric: tabular-nums;
      opacity: var(--on);
      translate: 0 calc((1 - var(--on)) * .5rem);
      animation: cycle-on linear both;
      animation-timeline: --cycle;
      animation-range: contain calc(var(--k) * 20% - 3%) contain calc(var(--k) * 20% + 23%);
    }
    .cycle__count.is-first { animation-name: cycle-on-first; animation-range: contain 0% contain 23%; }
    .cycle__count.is-last  { animation-name: cycle-on-last;  animation-range: contain 77% contain 100%; }
    .cycle__of {
      align-self: end;
      margin-bottom: 30%;
      font-size: .75rem;
      font-weight: 600;
      letter-spacing: .1em;
      text-transform: uppercase;
      color: var(--cy-grey);
    }

    /* панели шагов накладываются друг на друга */
    .cycle__steps { position: relative; height: 100%; }
    .cycle__steps::after { content: none; }
    .cycle__panel {
      position: absolute;
      inset: 0;
      grid-template-columns: 1fr;
      align-content: center;
      gap: 1rem;
      padding-block: 0;
      border: 0;
      opacity: var(--on);
      translate: 0 calc((1 - var(--on)) * 1.25rem);
      pointer-events: none;
      animation: cycle-on linear both;
      animation-timeline: --cycle;
      animation-range: contain calc(var(--k) * 20% - 3%) contain calc(var(--k) * 20% + 23%);
    }
    .cycle__panel:last-child { border: 0; }
    .cycle__panel.is-first { animation-name: cycle-on-first; animation-range: contain 0% contain 23%; }
    .cycle__panel.is-last  { animation-name: cycle-on-last;  animation-range: contain 77% contain 100%; }
    .cycle__num { font-size: clamp(4rem, 9vw, 7rem); }
    .cycle__body h3 { font-size: clamp(1.5rem, 2.6vw, 2.25rem); letter-spacing: -.01em; }
    .cycle__body p { font-size: 1.0625rem; }

    .cycle__hint {
      display: block;
      position: absolute;
      left: 0;
      bottom: 1rem;
      margin: 0;
      font-size: .75rem;
      font-weight: 600;
      letter-spacing: .1em;
      text-transform: uppercase;
      color: var(--cy-grey);
    }
  }
}
