/* animations.css – Shared keyframes, utility animation classes, and motion helpers */

/* ==================================================================
   Keyframes
   ================================================================== */

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

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

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

@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

@keyframes slide-in-left {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

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

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

/* ==================================================================
   Utility animation classes
   ================================================================== */

.animate-fade-in {
  animation: fade-in var(--duration-normal) var(--ease-out);
}

.animate-fade-up {
  animation: fade-up var(--duration-normal) var(--ease-out);
}

.animate-fade-down {
  animation: fade-down var(--duration-normal) var(--ease-out);
}

.animate-scale-in {
  animation: scale-in var(--duration-normal) var(--ease-spring);
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ==================================================================
   Stagger utilities (for lists / grids)
   ================================================================== */

.stagger > * {
  animation-fill-mode: both;
}

.stagger > *:nth-child(1)  { animation-delay: 0ms; }
.stagger > *:nth-child(2)  { animation-delay: 50ms; }
.stagger > *:nth-child(3)  { animation-delay: 100ms; }
.stagger > *:nth-child(4)  { animation-delay: 150ms; }
.stagger > *:nth-child(5)  { animation-delay: 200ms; }
.stagger > *:nth-child(6)  { animation-delay: 250ms; }
.stagger > *:nth-child(7)  { animation-delay: 300ms; }
.stagger > *:nth-child(8)  { animation-delay: 350ms; }
.stagger > *:nth-child(9)  { animation-delay: 400ms; }
.stagger > *:nth-child(10) { animation-delay: 450ms; }

/* ==================================================================
   Turbo page transitions
   ================================================================== */

[data-turbo-animate="true"] main {
  animation: fade-up var(--duration-normal) var(--ease-out);
}

/* ==================================================================
   Loading spinners
   ================================================================== */

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

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

/* ==================================================================
   View Transitions (same-origin navigation)
   ================================================================== */

::view-transition-old(root) {
  animation: fade-out var(--duration-fast) var(--ease-in);
}

::view-transition-new(root) {
  animation: fade-in var(--duration-fast) var(--ease-out);
}

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

/* Editor panel transitions – crossfade without layout shift */
::view-transition-old(step-editor) {
  animation: fade-out var(--duration-fast) var(--ease-in);
}

::view-transition-new(step-editor) {
  animation: fade-in var(--duration-normal) var(--ease-out);
}

/* Assign view-transition-name to the editor turbo-frame */
#step_editor {
  view-transition-name: step-editor;
}

/* ==================================================================
   Reduced motion – respect user preference
   ================================================================== */

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