/**
 * animations.css
 * MyMoim 인터랙티브 애니메이션 시스템
 */

/* ===== CSS Variables (Timing & Easing) ===== */
:root {
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
  --duration-slower: 600ms;
}

/* ===== Page Load — Staggered fadeInUp ===== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.anim-fade-in-up {
  opacity: 0;
  animation: fadeInUp var(--duration-slow) var(--ease-out) forwards;
}

/* Stagger children: add .anim-stagger to parent */
.anim-stagger > * {
  opacity: 0;
  animation: fadeInUp var(--duration-slow) var(--ease-out) forwards;
}
.anim-stagger > *:nth-child(1) { animation-delay: 0ms; }
.anim-stagger > *:nth-child(2) { animation-delay: 60ms; }
.anim-stagger > *:nth-child(3) { animation-delay: 120ms; }
.anim-stagger > *:nth-child(4) { animation-delay: 180ms; }
.anim-stagger > *:nth-child(5) { animation-delay: 240ms; }
.anim-stagger > *:nth-child(6) { animation-delay: 300ms; }
.anim-stagger > *:nth-child(7) { animation-delay: 360ms; }
.anim-stagger > *:nth-child(8) { animation-delay: 420ms; }

/* ===== Button Ripple ===== */
.btn-ripple {
  position: relative;
  overflow: hidden;
}

.btn-ripple .ripple-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0);
  animation: rippleExpand 500ms ease-out forwards;
  pointer-events: none;
}

@keyframes rippleExpand {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* ===== Button Scale on Active ===== */
.btn-scale {
  transition: transform 60ms ease;
}
.btn-scale:active:not(:disabled) {
  transform: scale(0.96);
}

/* ===== Button Shimmer ===== */
.btn-shimmer {
  position: relative;
  overflow: hidden;
}
.btn-shimmer::after {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: none;
}
.btn-shimmer:hover::after {
  animation: shimmerSlide 700ms ease forwards;
}

@keyframes shimmerSlide {
  from { left: -100%; }
  to   { left: 100%; }
}

/* ===== Button Loading Spinner ===== */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spinLoader 600ms linear infinite;
}

@keyframes spinLoader {
  to { transform: rotate(360deg); }
}

/* ===== Card Hover Lift + Shadow Depth ===== */
.card-hover {
  transition: transform var(--duration-normal) var(--ease-smooth),
              box-shadow var(--duration-normal) var(--ease-smooth);
}
.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 40px rgba(0,0,0,0.12);
}

/* ===== Skeleton Loading Shimmer ===== */
.skeleton {
  background: #e5e7eb;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
  animation: skeletonShimmer 1.5s ease-in-out infinite;
}

@keyframes skeletonShimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-line {
  height: 14px;
  margin-bottom: 10px;
}
.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }
.skeleton-line.long { width: 100%; }

.skeleton-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* ===== Toast Notification ===== */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: 12px;
  background: #323232;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  pointer-events: auto;
  animation: toastSlideIn 300ms var(--ease-spring) forwards;
  will-change: transform, opacity;
}

.toast.toast-out {
  animation: toastSlideOut 250ms var(--ease-in) forwards;
}

.toast-icon {
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
}

.toast-message {
  flex: 1;
  line-height: 1.4;
}

/* Toast variants */
.toast.success { background: #065f46; }
.toast.error   { background: #991b1b; }
.toast.warning { background: #92400e; }
.toast.info    { background: #1e40af; }

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastSlideOut {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-12px) scale(0.95);
  }
}

/* ===== Modal Slide-Up + Backdrop Blur ===== */
.modal-backdrop.anim-modal {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

.modal-backdrop.anim-modal.is-active {
  opacity: 1;
}

.modal-backdrop.anim-modal .modal {
  transform: translateY(24px) scale(0.97);
  opacity: 0;
  transition: transform var(--duration-slow) var(--ease-spring),
              opacity var(--duration-normal) var(--ease-smooth);
}

.modal-backdrop.anim-modal.is-active .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Mobile bottom-sheet style */
@media (max-width: 480px) {
  .modal-backdrop.anim-modal {
    align-items: flex-end;
  }
  .modal-backdrop.anim-modal .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    margin: 0;
    transform: translateY(100%);
    opacity: 1;
  }
  .modal-backdrop.anim-modal.is-active .modal {
    transform: translateY(0);
  }
}

/* ===== Queue — Radar Pulse ===== */
.radar-pulse-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.radar-pulse-wrap::before,
.radar-pulse-wrap::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: radarPulse 2s var(--ease-out) infinite;
}

.radar-pulse-wrap::after {
  animation-delay: 1s;
}

@keyframes radarPulse {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* ===== Progress Ring SVG ===== */
.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring__bg {
  fill: none;
  stroke: #e5e7eb;
}

.progress-ring__fill {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s var(--ease-smooth);
}

/* ===== Flip Countdown ===== */
.flip-countdown {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.flip-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.flip-card {
  position: relative;
  width: 56px;
  height: 68px;
  perspective: 300px;
}

.flip-card .flip-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: #1e293b;
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.flip-card.flip .flip-face {
  animation: flipDown 500ms var(--ease-spring);
}

@keyframes flipDown {
  0%   { transform: rotateX(0deg); }
  50%  { transform: rotateX(-90deg); }
  100% { transform: rotateX(0deg); }
}

.flip-label {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.flip-separator {
  font-size: 28px;
  font-weight: 700;
  color: #374151;
  margin-top: -18px;
}

/* ===== Success Checkmark SVG Draw ===== */
.checkmark-wrap {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

.checkmark-svg {
  width: 80px;
  height: 80px;
}

.checkmark-circle {
  fill: none;
  stroke: var(--ok);
  stroke-width: 3;
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: checkCircleDraw 600ms var(--ease-smooth) forwards;
}

.checkmark-check {
  fill: none;
  stroke: var(--ok);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: checkDraw 300ms var(--ease-smooth) 400ms forwards;
}

@keyframes checkCircleDraw {
  to { stroke-dashoffset: 0; }
}

@keyframes checkDraw {
  to { stroke-dashoffset: 0; }
}

/* ===== Floating Label System ===== */
.float-label {
  position: relative;
}

.float-label .control {
  position: relative;
}

.float-label .float-text {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: #9ca3af;
  pointer-events: none;
  transition: all var(--duration-normal) var(--ease-smooth);
  background: #fff;
  padding: 0 4px;
}

.float-label .control:focus-within .float-text,
.float-label .control.has-value .float-text {
  top: 0;
  font-size: 11px;
  color: var(--accent);
}

/* ===== Validation Shake ===== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

.anim-shake {
  animation: shake 400ms ease;
}

/* ===== Validation Pop ===== */
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.anim-pop {
  animation: pop 250ms var(--ease-bounce);
}

/* ===== Multi-Step Stepper UI ===== */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 24px;
  padding: 0 8px;
}

.stepper-step {
  display: flex;
  align-items: center;
  gap: 0;
}

.stepper-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  background: #e5e7eb;
  color: #9ca3af;
  transition: all var(--duration-normal) var(--ease-smooth);
  flex-shrink: 0;
}

.stepper-dot.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 4px rgba(26,115,232,0.18);
}

.stepper-dot.done {
  background: var(--ok);
  color: #fff;
}

.stepper-line {
  width: 40px;
  height: 2px;
  background: #e5e7eb;
  transition: background var(--duration-normal) var(--ease-smooth);
  flex-shrink: 0;
}

.stepper-line.done {
  background: var(--ok);
}

.stepper-label {
  display: none; /* Hidden on mobile for space */
}

@media (min-width: 480px) {
  .stepper-label {
    display: block;
    font-size: 10px;
    color: #9ca3af;
    margin-top: 4px;
    text-align: center;
    white-space: nowrap;
  }
  .stepper-dot.active + .stepper-label,
  .stepper-step.current .stepper-label {
    color: var(--accent);
    font-weight: 600;
  }
  .stepper-step {
    flex-direction: column;
    align-items: center;
  }
  .stepper-line {
    align-self: center;
    margin-top: -18px;
  }
}

/* ===== Digit Box Input (Verification Code) ===== */
.digit-boxes {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.digit-box {
  width: 44px;
  height: 52px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  border: 2px solid #d1d5db;
  border-radius: 10px;
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-smooth),
              box-shadow var(--duration-fast) var(--ease-smooth);
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
}

.digit-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(26,115,232,0.15);
}

.digit-box.filled {
  border-color: var(--accent);
  background: #f0f7ff;
}

.digit-box.error {
  border-color: var(--error);
  animation: shake 400ms ease;
}

/* ===== Number Transition ===== */
.anim-number {
  display: inline-block;
  transition: transform var(--duration-normal) var(--ease-bounce),
              opacity var(--duration-fast) ease;
}

.anim-number.changing {
  transform: scale(1.15);
  color: var(--accent);
}

/* ===== Scroll Reveal ===== */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== prefers-reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .anim-stagger > * {
    opacity: 1;
    animation: none;
  }

  .anim-fade-in-up {
    opacity: 1;
    animation: none;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }

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

  .toast.toast-out {
    display: none;
  }

  .modal-backdrop.anim-modal .modal {
    transform: none;
    opacity: 1;
  }

  .flip-card.flip .flip-face {
    animation: none;
  }

  .skeleton::after {
    animation: none;
  }
}
