/* FAME: движение программы, тарифов, набора и кнопок.
   Прячем что-либо только под html.ms-on (его ставит motion/sections.js).
   Без JS и при prefers-reduced-motion: reduce страница как раньше. */

/* ---------- Служебные обёртки (ставит JS, на вид ничего не меняют) ---------- */

.ms-word,
.ms-digit {
  display: inline-block;
}

#countdown .countdown-unit {
  position: relative;
}

.ms-digit-old {
  position: absolute;
  margin: 0;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

#tariffs .plan-price.ms-counting {
  position: relative;
  color: transparent;
}

.ms-count {
  position: absolute;
  top: 0;
  left: 0;
  color: var(--foreground);
  white-space: nowrap;
  pointer-events: none;
}

/* Строка программы сворачивается: стрелка и цифра сразу как у закрытой (яркость цифры - как в styles.css). */
.program-row.ms-closing .program-title::after {
  transform: translateY(-20%) rotate(45deg);
}

.program-row.ms-closing .program-number {
  opacity: .32;
}

.program-row.ms-closing:nth-child(n + 3) .program-number {
  opacity: .53;
}

.program-row.ms-closing:nth-child(n + 5) .program-number {
  opacity: .78;
}

.program-row.ms-closing:nth-child(7) .program-number {
  opacity: 1;
}

/* ---------- Появление при прокрутке ---------- */

html.ms-on .ms-reveal:not(.ms-in) {
  opacity: 0;
}

@keyframes ms-mask-rise {
  from {
    translate: 0 105%;
    clip-path: inset(-30% -10% 105% -10%);
  }
  to {
    translate: 0 0;
    clip-path: inset(-30% -10% 0 -10%);
  }
}

@keyframes ms-wipe {
  from {
    translate: -28px 0;
    clip-path: inset(0 100% 0 0);
  }
  to {
    translate: 0 0;
    clip-path: inset(0 0 0 0);
  }
}

@keyframes ms-rise {
  from {
    opacity: 0;
    translate: 0 48px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

@keyframes ms-rise-sm {
  from {
    opacity: 0;
    translate: 0 24px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

@keyframes ms-dialog-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(.985);
  }
}

@keyframes ms-fade {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .ms-in.ms-k-title:not(.ms-instant, .ms-done),
  .ms-in.ms-k-unit:not(.ms-instant, .ms-done) {
    animation: ms-mask-rise 1s cubic-bezier(.16, 1, .3, 1) var(--ms-delay, 0ms) backwards;
  }

  /* Вторая строка «Набор»: поднимается чуть позже первой. */
  #sales-title.ms-in:not(.ms-instant, .ms-done) .sales-period {
    animation: ms-mask-rise 1s cubic-bezier(.16, 1, .3, 1) calc(var(--ms-delay, 0ms) + 160ms) backwards;
  }

  .ms-in.ms-k-row:not(.ms-instant, .ms-done) {
    animation: ms-wipe .9s cubic-bezier(.7, 0, .2, 1) var(--ms-delay, 0ms) backwards;
  }

  .ms-in.ms-k-plan:not(.ms-instant, .ms-done) {
    animation: ms-rise .9s cubic-bezier(.16, 1, .3, 1) var(--ms-delay, 0ms) backwards;
  }

  .ms-in.ms-k-cta:not(.ms-instant, .ms-done) {
    animation: ms-rise-sm .8s cubic-bezier(.16, 1, .3, 1) var(--ms-delay, 0ms) backwards;
  }

  /* Окно заказа: мягкое открытие. Закрывается как раньше. */
  .order[open] {
    animation: ms-dialog-in .22s cubic-bezier(.16, 1, .3, 1);
  }

  .order[open]::backdrop {
    animation: ms-fade .22s ease-out;
  }

  /* ---------- Кнопки: нажатие (и на телефоне) ---------- */

  .button {
    transition: scale .12s ease-out;
  }

  a.button[href]:active,
  button.order-submit:not([disabled]):active {
    scale: .98;
  }
}

/* ---------- Кнопки и тарифы: наведение мышью ---------- */

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .button {
    isolation: isolate;
  }

  /* Заливка едет слоем difference: под ним белое становится чёрным, чёрное белым. */
  .button[href]::before,
  button.order-submit::before {
    content: "";
    position: absolute;
    z-index: 1;
    inset: 0;
    background: #fff;
    mix-blend-mode: difference;
    pointer-events: none;
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform .5s cubic-bezier(.7, 0, .2, 1);
  }

  /* Старая мгновенная инверсия отключена: её делает заливка. */
  html .button[href]:hover,
  html .order-submit:hover:not([disabled]) {
    background: var(--foreground);
    color: var(--background);
  }

  .button[href]:hover::before,
  .button[href]:focus-visible::before,
  button.order-submit:not([disabled]):hover::before,
  button.order-submit:not([disabled]):focus-visible::before {
    transform: scaleX(1);
    transform-origin: left center;
  }

  .button::after {
    transition: transform .35s cubic-bezier(.16, 1, .3, 1);
  }

  .button[href]:hover::after,
  .button[href]:focus-visible::after,
  button.order-submit:not([disabled]):hover::after,
  button.order-submit:not([disabled]):focus-visible::after {
    transform: translateX(5px);
  }

  /* Карточка тарифа приподнимается и получает рамку. */
  #tariffs .plan {
    position: relative;
    transition: transform .45s cubic-bezier(.16, 1, .3, 1);
  }

  #tariffs .plan::after {
    content: "";
    position: absolute;
    inset: -1px;
    border: 1px solid var(--foreground);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
  }

  /* Невидимый запас снизу: курсор у нижнего края не дёргает карточку. */
  #tariffs .plan::before {
    content: "";
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    height: 8px;
  }

  #tariffs .plan:hover {
    z-index: 1;
    background: var(--background);
    transform: translateY(-6px);
  }

  #tariffs .plan:hover::after {
    opacity: 1;
  }

  /* Плашка названия тарифа переворачивается в чёрную. */
  #tariffs .plan-name {
    position: relative;
    isolation: isolate;
  }

  /* inset 1px: по краю остаётся белая рамка самой плашки. */
  #tariffs .plan-name::before {
    content: "";
    position: absolute;
    z-index: 1;
    inset: 1px;
    background: #fff;
    mix-blend-mode: difference;
    pointer-events: none;
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform .45s cubic-bezier(.7, 0, .2, 1);
  }

  #tariffs .plan:hover .plan-name::before {
    transform: scaleX(1);
    transform-origin: left center;
  }
}

@media print {
  html.ms-on .ms-reveal,
  html.ms-on .sales-period {
    opacity: 1 !important;
    translate: none !important;
    clip-path: none !important;
    animation: none !important;
  }

  .ms-count,
  .ms-digit-old {
    display: none !important;
  }

  #tariffs .plan-price.ms-counting {
    color: inherit;
  }
}
