/*
 * Анимация блока «Подарки без угадываний» на главной (index.html,
 * .template-teaser-wishlist → .ftw-live). Запускает scripts/wishlist-live.js.
 *
 * Сценарий (цикл 16 с):
 *  1. Ане приходит напоминание: скоро день рождения, обнови список желаний.
 *  2. Аня открывает список и добавляет два желания: 1 → 2 → 3,
 *     «Список обновлён сегодня».
 *  3. Через 2 недели кроссовки из списка подарены: «Желание исполнено».
 *
 * Базовые стили ниже — итоговый кадр (без JS и при prefers-reduced-motion).
 */

.ftw-stage {
  display: grid;
  width: 100%;
  justify-items: center;
}

/* Два тоста в одной ячейке: место под них зарезервировано, высота не скачет */
.ftw-toasts {
  display: grid;
  justify-self: start;
  margin: 0 0 14px;
}

.ftw-live .ftw-toast {
  position: relative;
  inset: auto;
  grid-area: 1 / 1;
  align-self: start;
  margin: 0;
}

.ftw-toast-remind {
  opacity: 0;
}

.ftw-tap {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.95) 0 14%,
    rgba(111, 206, 255, 0.85) 28%,
    rgba(47, 107, 255, 0) 70%
  );
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* Переключатели состояний: все варианты в одной ячейке, виден последний */
.ftw-swap {
  display: inline-grid;
}

.ftw-swap > * {
  grid-area: 1 / 1;
}

.ftw-count-1,
.ftw-count-2,
.ftw-sub-before,
.ftw-upd-before {
  opacity: 0;
}

.ft-pill.ftw-swap {
  font-weight: 700;
}

.ft-pill.ftw-swap b {
  font-weight: inherit;
}

/* Новые желания: строка раскрывается на месте */
.ftw-slot {
  max-height: 90px;
  overflow: hidden;
}

.ftw-slot > .ft-row {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(21, 23, 28, 0.06);
}

.ftw-row-gifted strong {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--muted);
}

.ftw-row-old strong,
.ftw-row-old .ft-gift-thumb {
  opacity: 0.72;
}

.ftw-row-body-swap {
  min-height: 22px;
}

.ftw-sub-before {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}

.ftw-foot {
  display: grid;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(21, 23, 28, 0.06);
  font-size: 12px;
}

.ftw-upd-before {
  color: var(--muted);
}

.ftw-upd-after {
  color: #3d6b50;
  font-weight: 650;
}

/* Конфетти над кроссовками */
.ftw-confetti {
  position: absolute;
  z-index: 4;
  top: 80px;
  left: 44px;
  pointer-events: none;
}

.ftw-confetti i {
  position: absolute;
  top: -4px;
  left: -3px;
  width: 6px;
  height: 9px;
  border-radius: 2px;
  background: #ffcf4a;
  opacity: 0;
}

.ftw-confetti i:nth-child(1)  { --x: -46px; --y: -52px; --r: -140deg; }
.ftw-confetti i:nth-child(2)  { --x: -12px; --y: -66px; --r: 90deg;  background: #2f6bff; }
.ftw-confetti i:nth-child(3)  { --x: 26px;  --y: -58px; --r: 200deg; background: #88a995; }
.ftw-confetti i:nth-child(4)  { --x: 58px;  --y: -34px; --r: -80deg; background: #ff7a8a; }
.ftw-confetti i:nth-child(5)  { --x: 70px;  --y: 6px;   --r: 160deg; }
.ftw-confetti i:nth-child(6)  { --x: -60px; --y: -14px; --r: 120deg; background: #ff7a8a; }
.ftw-confetti i:nth-child(7)  { --x: -40px; --y: 30px;  --r: -200deg; background: #2f6bff; }
.ftw-confetti i:nth-child(8)  { --x: 40px;  --y: 34px;  --r: 70deg;  background: #88a995; }
.ftw-confetti i:nth-child(9)  { --x: 4px;   --y: -84px; --r: -60deg; background: #ff7a8a; width: 5px; height: 5px; border-radius: 50%; }
.ftw-confetti i:nth-child(10) { --x: 88px;  --y: -22px; --r: 30deg;  background: #2f6bff; width: 5px; height: 5px; border-radius: 50%; }

@media (max-width: 760px) {
  .ftw-toasts {
    justify-self: center;
    width: min(380px, 100%);
  }

  .ftw-live .ftw-toast {
    width: 100%;
    max-width: none;
    margin: 0;
  }

  .ftw-confetti {
    top: 75px;
    left: 41px;
  }
}

/* — Анимация — */

@media (prefers-reduced-motion: no-preference) {
  /* Высота и отступ сверху зафиксированы скриптом по итоговому кадру:
     строки раскрываются вниз, карточка и страница не двигаются */
  .ftw-live.is-playing {
    align-content: start;
  }

  .ftw-live.is-playing .ftw-stage {
    margin-top: var(--ftw-top, 0px);
  }

  .ftw-live.is-playing .ftw-stage,
  .ftw-live.is-playing .ftw-stage *,
  .ftw-live.is-playing .ftw-gift {
    animation-duration: 16s;
    animation-iteration-count: infinite;
    animation-fill-mode: both;
    animation-timing-function: ease;
  }

  .ftw-live.is-paused .ftw-stage,
  .ftw-live.is-paused .ftw-stage *,
  .ftw-live.is-paused .ftw-gift {
    animation-play-state: paused !important;
  }

  .ftw-live.is-playing .ftw-stage { animation-name: ftw-stage; }
  .ftw-live.is-playing .ftw-toast-remind { animation-name: ftw-toast-remind; }
  .ftw-live.is-playing .ftw-tap { animation-name: ftw-tap; }
  .ftw-live.is-playing .ftw-card { animation-name: ftw-card-focus; }
  .ftw-live.is-playing .ftw-slot-1 { animation-name: ftw-slot-1; }
  .ftw-live.is-playing .ftw-slot-2 { animation-name: ftw-slot-2; }
  .ftw-live.is-playing .ftw-count-1 { animation-name: ftw-count-1; }
  .ftw-live.is-playing .ftw-count-2 { animation-name: ftw-count-2; }
  .ftw-live.is-playing .ftw-count-3 { animation-name: ftw-count-3; }
  .ftw-live.is-playing .ftw-upd-before { animation-name: ftw-upd-before; }
  .ftw-live.is-playing .ftw-upd-after { animation-name: ftw-upd-after; }
  .ftw-live.is-playing .ftw-toast-gift { animation-name: ftw-toast-gift; }
  .ftw-live.is-playing .ftw-row-gifted strong { animation-name: ftw-strike; }
  .ftw-live.is-playing .ftw-sub-before { animation-name: ftw-sub-before; }
  .ftw-live.is-playing .ftw-sub-after { animation-name: ftw-sub-after; }
  .ftw-live.is-playing .ftw-confetti i { animation-name: ftw-confetti; animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  .ftw-live.is-playing .ftw-gift { animation-name: ftw-gift; }
}

/* 1% = 0,16 с */

@keyframes ftw-stage {
  0% { opacity: 0; }
  2%, 95% { opacity: 1; }
  98%, 100% { opacity: 0; }
}

/* 1. Напоминание перед днём рождения + касание */
@keyframes ftw-toast-remind {
  0%, 4% { opacity: 0; transform: translateY(-16px) scale(0.96); }
  7%, 14.5% { opacity: 1; transform: none; }
  15.5% { opacity: 1; transform: scale(0.97); }
  17%, 19% { opacity: 1; transform: none; }
  22%, 100% { opacity: 0; transform: translateY(-10px) scale(0.97); }
}

@keyframes ftw-tap {
  0%, 14.5% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  15.5% { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
  19%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(2.8); }
}

@keyframes ftw-card-focus {
  0%, 21% { box-shadow: 0 22px 54px rgba(28, 39, 70, 0.12); }
  24% { box-shadow: 0 22px 54px rgba(28, 39, 70, 0.12), 0 0 0 4px rgba(47, 107, 255, 0.28); }
  32%, 100% { box-shadow: 0 22px 54px rgba(28, 39, 70, 0.12); }
}

/* 2. Аня добавляет желания */
@keyframes ftw-slot-1 {
  0%, 26% { max-height: 0; opacity: 0; transform: translateY(-6px); }
  30%, 100% { max-height: 90px; opacity: 1; transform: none; }
}

@keyframes ftw-slot-2 {
  0%, 35% { max-height: 0; opacity: 0; transform: translateY(-6px); }
  39%, 100% { max-height: 90px; opacity: 1; transform: none; }
}

@keyframes ftw-count-1 {
  0%, 28% { opacity: 1; }
  29.5%, 100% { opacity: 0; }
}

@keyframes ftw-count-2 {
  0%, 28% { opacity: 0; }
  29.5%, 37% { opacity: 1; }
  38.5%, 100% { opacity: 0; }
}

@keyframes ftw-count-3 {
  0%, 37% { opacity: 0; transform: none; }
  38.5% { opacity: 1; transform: scale(1.12); }
  40%, 100% { opacity: 1; transform: none; }
}

@keyframes ftw-upd-before {
  0%, 41% { opacity: 1; }
  43%, 100% { opacity: 0; }
}

@keyframes ftw-upd-after {
  0%, 41% { opacity: 0; transform: translateY(4px); }
  43%, 100% { opacity: 1; transform: none; }
}

/* 3. Через 2 недели — подарок из списка */
@keyframes ftw-toast-gift {
  0%, 51% { opacity: 0; transform: translateY(-16px) scale(0.96); }
  55%, 100% { opacity: 1; transform: none; }
}

@keyframes ftw-strike {
  0%, 56% { color: var(--ink); text-decoration-color: transparent; }
  59%, 100% { color: var(--muted); text-decoration-color: var(--muted); }
}

@keyframes ftw-sub-before {
  0%, 56% { opacity: 1; }
  57.5%, 100% { opacity: 0; }
}

@keyframes ftw-sub-after {
  0%, 56.5% { opacity: 0; transform: scale(0.8); }
  59% { opacity: 1; transform: scale(1.08); }
  61%, 100% { opacity: 1; transform: none; }
}

@keyframes ftw-confetti {
  0%, 56.5% { opacity: 0; transform: translate(0, 0) rotate(0); }
  57.5% { opacity: 1; transform: translate(0, 0) rotate(0); }
  64% { opacity: 1; }
  69%, 100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); }
}

/* scale, а не transform: transform занят hover-эффектом .ft-float */
@keyframes ftw-gift {
  0%, 55.5% { opacity: 0; scale: 0.4; }
  59% { opacity: 1; scale: 1.14; }
  62%, 94% { opacity: 1; scale: 1; }
  98%, 100% { opacity: 0; scale: 0.9; }
}
