/* ==========================================================================
   Animations — keyframes + motion utilities
   All durations/distances reference tokens from main.css.
   Every animation is disabled under prefers-reduced-motion (global rule
   in main.css). Keep motion purposeful: enter, attention, feedback.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes skeleton-sweep {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

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

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(8px) scale(0.97); }
}

@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 var(--accent-soft); }
  70%  { box-shadow: 0 0 0 8px rgba(192, 230, 253, 0); }
  100% { box-shadow: 0 0 0 0 rgba(192, 230, 253, 0); }
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}

@keyframes check-draw {
  from { stroke-dashoffset: 24; }
  to   { stroke-dashoffset: 0; }
}

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

/* --------------------------------------------------------------------------
   Enter utilities
   -------------------------------------------------------------------------- */

.anim-fade    { animation: fade-in var(--dur-slow) var(--ease-out) both; }
.anim-up      { animation: slide-up var(--dur-slow) var(--ease-out) both; }
.anim-down    { animation: slide-down var(--dur) var(--ease-out) both; }
.anim-scale   { animation: scale-in var(--dur) var(--ease-out) both; }

/* Staggered list/grid reveal — children cascade instead of popping together */
.stagger > * { animation: slide-up var(--dur-slow) var(--ease-out) both; }
.stagger > *:nth-child(1)  { animation-delay: 0ms; }
.stagger > *:nth-child(2)  { animation-delay: 40ms; }
.stagger > *:nth-child(3)  { animation-delay: 80ms; }
.stagger > *:nth-child(4)  { animation-delay: 120ms; }
.stagger > *:nth-child(5)  { animation-delay: 160ms; }
.stagger > *:nth-child(6)  { animation-delay: 200ms; }
.stagger > *:nth-child(7)  { animation-delay: 240ms; }
.stagger > *:nth-child(8)  { animation-delay: 280ms; }
.stagger > *:nth-child(n + 9) { animation-delay: 320ms; }

/* --------------------------------------------------------------------------
   Modal — animation only while mounted
   -------------------------------------------------------------------------- */

.modal-backdrop.is-open { animation: backdrop-in var(--dur) var(--ease) both; }
.modal-backdrop.is-open .modal {
  animation: modal-in var(--dur-slow) var(--ease-out) both;
}

.toast.is-entering { animation: toast-in var(--dur) var(--ease-out) both; }
.toast.is-leaving  { animation: toast-out var(--dur-fast) var(--ease) both; }

/* --------------------------------------------------------------------------
   Interaction feedback
   -------------------------------------------------------------------------- */

/* Subtle lift on hover — 1.01 not 1.02, to stay editorial rather than bouncy */
.lift {
  transition: transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}

.lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.press:active { transform: scale(0.97); }

.is-shaking { animation: shake 400ms var(--ease); }

/* Attention pulse for a newly created item */
.is-new { animation: pulse-ring 1.4s var(--ease) 1; }

/* --------------------------------------------------------------------------
   Loading
   -------------------------------------------------------------------------- */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: var(--radius-pill);
  animation: spin 700ms linear infinite;
  flex: none;
}

.spinner--invert {
  border-color: var(--border-invert);
  border-top-color: var(--fg-invert);
}

.spinner--lg { width: 28px; height: 28px; border-width: 3px; }

/* Indeterminate bar — used when total work is unknown */
.progress--indeterminate .progress__bar {
  width: 25%;
  animation: indeterminate 1.2s var(--ease) infinite;
}

/* Success checkmark that draws itself */
.check-draw {
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 24;
  animation: check-draw var(--dur-slow) var(--ease-out) both;
}

/* --------------------------------------------------------------------------
   Route / view transition
   -------------------------------------------------------------------------- */

.view-enter { animation: fade-in var(--dur) var(--ease-out) both; }

/* --------------------------------------------------------------------------
   Reduced motion — belt and braces on top of the global kill-switch
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .anim-fade,
  .anim-up,
  .anim-down,
  .anim-scale,
  .stagger > *,
  .view-enter,
  .modal-backdrop.is-open .modal,
  .toast.is-entering,
  .toast.is-leaving {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .lift:hover { transform: none; }
  .spinner { animation-duration: 3s; }
  .progress--indeterminate .progress__bar { animation: none; width: 100%; }
}
