/* Story timeline motion. Everything here only applies while motion/story.js runs (html.story-motion). */

/* Thread tip: a bead that leads the line. */
html.story-motion .sm-tip {
  transition: opacity .3s ease;
}

html.story-motion .sm-tip.is-hidden {
  opacity: 0;
}

html.story-motion .sm-tip circle {
  fill: var(--foreground);
  stroke: none;
}

html.story-motion .sm-tip-halo {
  opacity: .16;
}

/* Markers A-D: a small white bead until the thread arrives, then a pop with overshoot. */
html.story-motion .history-marker {
  transform: translate(-50%, -50%) scale(.3);
  transition: transform .62s cubic-bezier(.34, 1.75, .5, 1), color 0s linear .16s;
}

html.story-motion .history-marker::before,
html.story-motion .history-marker::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  bottom: -2px;
  left: -2px;
  border-radius: 50%;
  pointer-events: none;
}

html.story-motion .history-marker::before {
  z-index: -1;
  background: var(--foreground);
  transition: transform .42s cubic-bezier(.2, .7, .2, 1);
}

html.story-motion .history-marker::after {
  border: 1px solid var(--foreground);
  opacity: 0;
}

html.story-motion .history-marker.is-lit {
  transform: translate(-50%, -50%) scale(1);
}

html.story-motion .history-marker.is-lit:not(.is-current)::before {
  transform: scale(0);
}

html.story-motion .history-marker.is-lit.is-current {
  color: var(--background);
  transition: transform .62s cubic-bezier(.34, 1.75, .5, 1), color 0s linear .06s;
}

html.story-motion .history-marker.is-lit::after {
  animation: sm-ring .9s cubic-bezier(.2, .7, .2, 1) 1;
}

/* End star: spins in, pulses once, stays lit while the thread is complete. */
html.story-motion .history-marker-star::before {
  display: none;
}

html.story-motion .history-marker-star {
  transform: translate(-50%, -50%) scale(.28);
}

html.story-motion .history-marker-star::after {
  top: 8%;
  right: 8%;
  bottom: 8%;
  left: 8%;
}

html.story-motion .history-marker-star svg {
  fill: var(--foreground);
}

html.story-motion .history-marker-star.is-lit svg {
  animation: sm-star 1.1s cubic-bezier(.2, .8, .2, 1) both;
}

html.story-motion .history-marker-star.is-lit:not(.is-current) svg {
  fill: var(--background);
}

html.story-motion .history-marker-star.is-lit.is-current > span {
  color: var(--background);
}

/* Connectors grow out of the marker towards the text (desktop only, hidden on phones by story.css). */
html.story-motion .history-item:not(.history-item-end)::after {
  transform: scaleX(0);
  transform-origin: right center;
  transition: transform .7s cubic-bezier(.2, .8, .2, 1) .12s;
}

html.story-motion .history-item:nth-child(even)::after {
  transform-origin: left center;
}

html.story-motion .history-item.is-reached::after {
  transform: scaleX(1);
}

/* Text blocks slide in from their side, line by line. */
html.story-motion .history-body > * {
  opacity: 0;
  translate: -56px 0;
  transition:
    opacity .7s ease calc(var(--sm-i, 0) * 75ms),
    translate 1s cubic-bezier(.16, 1, .3, 1) calc(var(--sm-i, 0) * 75ms),
    clip-path 1s cubic-bezier(.7, 0, .2, 1) calc(var(--sm-i, 0) * 75ms);
}

html.story-motion .history-item:nth-child(even) .history-body > * {
  translate: 56px 0;
}

html.story-motion .history-item-end .history-body > * {
  translate: 0 36px;
}

html.story-motion .history-body > .history-date {
  clip-path: polygon(-4% -40%, -4% -40%, -4% 140%, -4% 140%);
}

html.story-motion .history-item-end .history-body > .history-date {
  clip-path: polygon(50% -40%, 50% -40%, 50% 140%, 50% 140%);
}

html.story-motion .history-item .history-body.is-in > * {
  opacity: 1;
  translate: 0 0;
}

html.story-motion .history-body.is-in > .history-date,
html.story-motion .history-item-end .history-body.is-in > .history-date {
  clip-path: polygon(-4% -40%, 104% -40%, 104% 140%, -4% 140%);
}

@media (max-width: 700px) {
  html.story-motion .history-item:not(.history-item-end) .history-body > * {
    translate: 32px 0;
  }

  html.story-motion .history-item:not(.history-item-end) .history-body.is-in > * {
    translate: 0 0;
  }
}

/* The text waiting off to the right must not widen the page (phones could drag it sideways).
   clip only cuts sideways overflow: no scroll container, the thread and the rings stay as they are. */
html.story-motion #story {
  overflow-x: clip;
}

/* Safari before 16 has no overflow: clip: there the text rises instead of sliding in from the side. */
@supports not (overflow: clip) {
  html.story-motion .history-item:not(.history-item-end) .history-body > * {
    translate: 0 24px;
  }

  html.story-motion .history-item:not(.history-item-end) .history-body.is-in > * {
    translate: 0 0;
  }
}

/* "Это - моя логика": the rule draws from the centre, heading lines wipe in, the rest rises. */
html.story-motion .story-logic {
  position: relative;
  border-top-color: transparent;
}

html.story-motion .story-logic::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  border-top: 1px solid var(--line);
  transform: scaleX(0);
  transition: transform 1.2s cubic-bezier(.7, 0, .2, 1);
}

html.story-motion .story-logic .sm-line {
  display: inline-block;
  opacity: 0;
  translate: 0 .5em;
  clip-path: polygon(-4% -40%, -4% -40%, -4% 140%, -4% 140%);
  transition:
    clip-path .9s cubic-bezier(.7, 0, .2, 1) calc(.2s + var(--sm-i, 0) * 140ms),
    translate .9s cubic-bezier(.16, 1, .3, 1) calc(.2s + var(--sm-i, 0) * 140ms),
    opacity .4s ease calc(.2s + var(--sm-i, 0) * 140ms);
}

html.story-motion .story-logic-content > :not(h3) {
  opacity: 0;
  translate: 0 28px;
  /* scale stays quick: motion/sections.css uses it for the button press. */
  transition:
    opacity .8s ease calc(.25s + var(--sm-i, 0) * 110ms),
    translate .8s cubic-bezier(.16, 1, .3, 1) calc(.25s + var(--sm-i, 0) * 110ms),
    scale .12s ease-out;
}

html.story-motion .story-logic.is-in::before {
  transform: scaleX(1);
}

html.story-motion .story-logic.is-in .sm-line {
  opacity: 1;
  translate: 0 0;
  clip-path: polygon(-4% -40%, 104% -40%, 104% 140%, -4% 140%);
}

html.story-motion .story-logic.is-in .story-logic-content > :not(h3) {
  opacity: 1;
  translate: 0 0;
}

/* Reached with Tab: the focused button shows at once, so its focus ring is never invisible. */
html.story-motion .story-logic.is-in .story-logic-content > :focus-visible {
  transition: scale .12s ease-out;
}

@keyframes sm-ring {
  from {
    opacity: .8;
    transform: scale(1);
  }

  to {
    opacity: 0;
    transform: scale(2.4);
  }
}

@keyframes sm-star {
  0% {
    transform: rotate(-200deg) scale(.6);
  }

  55% {
    transform: rotate(12deg) scale(1.04);
  }

  70% {
    transform: rotate(0deg) scale(1);
  }

  84% {
    transform: scale(1.18);
  }

  100% {
    transform: none;
  }
}

/* First frames after start and the test hook (?storyprogress=0.5): no transitions.
   .ms-word is the "Моя история" title, animated by motion/sections.js: leave it alone. */
html.story-motion.sm-boot #story *:not(.ms-word),
html.story-motion.sm-boot #story *::before,
html.story-motion.sm-boot #story *::after,
html.story-motion.sm-instant #story *:not(.ms-word),
html.story-motion.sm-instant #story *::before,
html.story-motion.sm-instant #story *::after {
  transition: none !important;
  animation: none !important;
}

/* Safety and print: the script never starts with reduced motion, but if the class is there anyway
   (or the page is printed mid-scroll) show the original static design. */
@media (prefers-reduced-motion: reduce), print {
  html.story-motion #story .history-marker {
    transform: translate(-50%, -50%) !important;
    color: var(--foreground) !important;
  }

  html.story-motion #story .history-marker::before,
  html.story-motion #story .history-marker::after,
  html.story-motion #story .sm-tip {
    display: none !important;
  }

  html.story-motion #story .history-marker-star svg {
    fill: var(--background) !important;
  }

  html.story-motion #story .history-marker-star > span {
    color: var(--foreground) !important;
  }

  html.story-motion #story .history-knot path,
  html.story-motion #story .history-thread path {
    stroke-dasharray: none !important;
    stroke-dashoffset: 0 !important;
  }

  html.story-motion #story .history-item::after,
  html.story-motion #story .story-logic::before {
    transform: none !important;
  }

  html.story-motion #story .history-body > *,
  html.story-motion #story .story-logic .sm-line,
  html.story-motion #story .story-logic-content > * {
    opacity: 1 !important;
    translate: none !important;
    clip-path: none !important;
  }

  html.story-motion #story *,
  html.story-motion #story *::before,
  html.story-motion #story *::after {
    transition: none !important;
    animation: none !important;
  }
}
