/* ==========================================================================
   animations.css — 키프레임 + 헬퍼 클래스
   모든 지속시간/이징은 tokens.css 모션 토큰을 사용.
   cascade-fall(승리 연출)은 JS rAF 구동이라 여기 없음.

   위치 계약: 레이아웃 엔진은 카드를 left/top으로 배치한다(components.css 헤더
   참조). transform·translate는 애니메이션/상태 전용으로 예약 —
   이동 계열(shake)은 개별 속성(translate)을 써서 selected 등과
   합성되고, 회전 계열(card-flip)은 transform(rotateY+perspective)을 쓴다.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. card-flip — 3D 카드 뒤집기
      JS 계약: .flipping 부여 → 50% 시점(rotateY 90°)에 face-down 클래스 토글
      → 종료 후 .flipping 제거. (animation 절반 시점 = var(--t-med)/2)
   -------------------------------------------------------------------------- */
@keyframes card-flip {
  0%   { transform: perspective(700px) rotateY(0deg); }
  50%  { transform: perspective(700px) rotateY(90deg); }
  100% { transform: perspective(700px) rotateY(0deg); }
}

.flipping {
  /* 단일 면 클래스 토글 방식 — 양면 동시 렌더가 없으므로 backface-visibility는 효과 없음 */
  animation: card-flip var(--t-med) var(--ease-out) both;
}

/* --------------------------------------------------------------------------
   2. shake — 잘못된 이동 (x축 3사이클)
   -------------------------------------------------------------------------- */
@keyframes shake {
  0%, 100% { translate: 0 0; }
  15%      { translate: -6px 0; }
  30%      { translate:  5px 0; }
  45%      { translate: -4px 0; }
  60%      { translate:  3px 0; }
  80%      { translate: -2px 0; }
}

.shake {
  animation: shake calc(var(--t-med) * 1.25) linear both;
}

/* --------------------------------------------------------------------------
   3. pulse-hint — 힌트 글로우 맥동 (components의 .card.hint-glow가 사용)
   -------------------------------------------------------------------------- */
@keyframes pulse-hint {
  0%, 100% {
    box-shadow:
      inset 0 0 0 1.5px rgba(255, 255, 255, .85),
      0 0 0 2px color-mix(in srgb, var(--ac, var(--coral)) 70%, white),
      0 0 10px 2px color-mix(in srgb, var(--ac, var(--coral)) 35%, transparent),
      var(--sh-1);
  }
  50% {
    box-shadow:
      inset 0 0 0 1.5px rgba(255, 255, 255, .85),
      0 0 0 3px color-mix(in srgb, var(--ac, var(--coral)) 95%, white),
      0 0 22px 6px color-mix(in srgb, var(--ac, var(--coral)) 65%, transparent),
      var(--sh-2);
  }
}

/* --------------------------------------------------------------------------
   4. combo-pop — 콤보 배지 오버슈트 팝
   -------------------------------------------------------------------------- */
@keyframes combo-pop {
  0%   { transform: scale(.4);  opacity: 0; }
  55%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   4b. slot-pop — 파운데이션 안착 링 펄스 (sol-v85)
       테두리/그림자만 번지게 한다 — transform을 쓰면 슬롯 위 카드와 어긋난다.
   -------------------------------------------------------------------------- */
@keyframes slot-pop {
  0%   { border-color: var(--ac, var(--gold)); box-shadow: 0 0 0 0 rgba(255, 209, 102, .55); }
  100% { border-color: rgba(244, 247, 251, .22); box-shadow: 0 0 0 14px rgba(255, 209, 102, 0); }
}

/* 5. shine-sweep — 보상 배너와 함께 제거 (sol-v86) */

/* --------------------------------------------------------------------------
   6. fade-in / modal-in — 딤 페이드 + 모달 스프링 스케일 진입
      (components의 .modal-dim / .modal-in이 사용)
   -------------------------------------------------------------------------- */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-in {
  from { transform: scale(.86); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* --------------------------------------------------------------------------
   7. toast-in-out — 등장 → 대기 → 퇴장 (총 2.4s, components의 .toast가 사용)
   -------------------------------------------------------------------------- */
@keyframes toast-in-out {
  0%       { opacity: 0; transform: translateY(14px) scale(.96); }
  10%, 86% { opacity: 1; transform: translateY(0)    scale(1); }
  100%     { opacity: 0; transform: translateY(10px) scale(.98); }
}

/* 8. coin-fly — 상점과 함께 제거 (sol-v86) */

/* Landing changes only the shadow: render-owned transforms remain untouched. */
@keyframes card-settle {
  from {box-shadow:0 8px 12px -3px rgba(3,8,18,.42),0 2px 3px rgba(3,8,18,.28);}
  to {box-shadow:var(--sh-1);}
}
@keyframes move-accent-life {
  0% {opacity:.35;}
  18%,65% {opacity:.95;}
  100% {opacity:0;}
}
/* Static marks must survive a preference change during their JS-owned lifetime. */
.board .move-accent--static,
:root[data-motion="reduced"] .board .move-accent {animation:none!important;opacity:.9;}
:root[data-motion="reduced"] .card.card-settle {animation:none!important;}
:root[data-motion="reduced"] .card.selected {translate:0 0;}

/* --------------------------------------------------------------------------
   9. prefers-reduced-motion
      base.css가 모든 duration을 1ms로 강제하지만:
      - 무한 루프(pulse-hint)는 명시적으로 끈다
      - 토스트는 fill:both 1ms 재생 시 마지막 프레임(투명)에 고정되므로
        애니메이션을 제거해 보이는 상태로 유지 (제거는 JS 타이머 책임)
      - flip/shake는 base.css의 1ms 강제로 충분: 즉시 무동작 종료
        (100% 프레임 = 원위치)하면서 animationend가 정상 발화해 JS 클래스
        제거 로직이 깨지지 않는다 → 별도 오버라이드 금지
      - 모달은 단순 페이드로 대체
   -------------------------------------------------------------------------- */
.win-confetti {
  position:fixed;inset:0;overflow:hidden;pointer-events:none;
  z-index:var(--z-win,700);contain:strict;
}
.win-confetti-piece {
  position:absolute;top:-18px;display:block;pointer-events:none;opacity:0;
  animation:win-confetti-fall var(--confetti-time) linear var(--confetti-delay) both;
}
@keyframes win-confetti-fall {
  0% {transform:translate3d(0,0,0) rotate(0deg);opacity:0;}
  5% {opacity:.95;}
  82% {opacity:.95;}
  100% {transform:translate3d(var(--confetti-drift),calc(100dvh + 40px),0) rotate(var(--confetti-turn));opacity:0;}
}
:root[data-motion="reduced"] .win-confetti {display:none;}
@media (prefers-reduced-motion: reduce) {
  .win-confetti {display:none;}
  .board .move-accent {animation:none!important;opacity:.9;}
  .card.card-settle {animation:none!important;}
  .card.selected {translate:0 0;}
  .card.hint-glow {
    animation: none;
  }

  .toast {
    animation: none;
    opacity: 1;
  }

  .modal.modal-in,
  .combo-badge {
    animation: fade-in 1ms linear both;
  }

  /* slot-pop은 JS가 animationsReduced()로 아예 안 붙이지만, 클래스가 남은 상태로
     설정이 바뀌는 경우를 대비해 여기서도 끈다 (base.css 1ms 강제와 이중 방어). */
  .pile-slot.slot-pop {
    animation: none;
  }
}
