/* ============================================
   ANIMATIONS
   Keyframes and transition definitions
   ============================================ */

/* Fade in */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Slide down */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide in */
@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Spin (loading spinners) */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Highlight flash for deck entries */
@keyframes highlight-flash {
    0% {
        box-shadow: 0 0 20px 5px rgba(139, 92, 246, 0.8), inset 0 0 15px rgba(139, 92, 246, 0.5);
        background: rgba(139, 92, 246, 0.3);
        z-index: 1000;
    }

    100% {
        box-shadow: 0 0 0 0 transparent, inset 0 0 0 transparent;
        background: transparent;
    }
}

/* Standardized flash-highlight class for any element */
.highlight-flash {
    animation: highlight-flash 1.5s ease-out forwards;
}

/* Salt update animation */
@keyframes salt-update {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.salt-value.updated {
    animation: salt-update 0.3s ease-out;
}

/* Spinner (`.spinner-small` is in loading_spinner.css) */
.spin {
    animation: spin 1s linear infinite;
}

/* ============================================
   STAGGERED REVEAL
   A tab that opens on a set of small widgets — the Library's decks, the
   Stats widgets, search results, a binder page — reveals them in order
   rather than all at once.

   The whole set is in place inside about a second however many there are:
   the first sixteen step 36 ms apart and everything after arrives with the
   sixteenth, so a long grid never crawls. A panel that is not showing is
   `display: none` (see tabs.css), and an animation restarts when its
   element is displayed again, so this plays whenever a tab or a view is
   opened, not only the first time.

   `backwards` rather than `both`: the item is hidden while it waits its
   turn, and once it has arrived the animation stops overriding it, so a
   widget's own hover transform still works.
   ============================================ */

@keyframes widget-reveal {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stagger-reveal > * {
    animation: widget-reveal 320ms cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
}

.stagger-reveal > :nth-child(2) { animation-delay: 36ms; }
.stagger-reveal > :nth-child(3) { animation-delay: 72ms; }
.stagger-reveal > :nth-child(4) { animation-delay: 108ms; }
.stagger-reveal > :nth-child(5) { animation-delay: 144ms; }
.stagger-reveal > :nth-child(6) { animation-delay: 180ms; }
.stagger-reveal > :nth-child(7) { animation-delay: 216ms; }
.stagger-reveal > :nth-child(8) { animation-delay: 252ms; }
.stagger-reveal > :nth-child(9) { animation-delay: 288ms; }
.stagger-reveal > :nth-child(10) { animation-delay: 324ms; }
.stagger-reveal > :nth-child(11) { animation-delay: 360ms; }
.stagger-reveal > :nth-child(12) { animation-delay: 396ms; }
.stagger-reveal > :nth-child(13) { animation-delay: 432ms; }
.stagger-reveal > :nth-child(14) { animation-delay: 468ms; }
.stagger-reveal > :nth-child(15) { animation-delay: 504ms; }
/* Past the fifteenth child there is nothing left to stagger: a grid that
   grows by a page at a time (the collection's infinite scroll) held every
   appended tile invisible for half a second and then popped the lot in. */
.stagger-reveal > :nth-child(n + 16) { animation: none; }
/* A grid shown a page at a time (the Library's decks) appends nothing, so the
   rest of the page arrives together one step after the fifteenth rather than
   sitting still under tiles that faded in. */
.stagger-reveal--paged > :nth-child(n + 16) {
    animation: widget-reveal 320ms cubic-bezier(0.2, 0.7, 0.3, 1) 540ms backwards;
}

/* A view that has played its opening reveal and then re-renders parts of
   itself (the deck grid rebuilds a group when a card moves) shows the new
   parts at once: the reveal is the view's opening, not every change's. */
.reveal-settled .stagger-reveal > * { animation: none; }

/* Content that arrives after its view is shown (style rule 4): the box opens
   from what stood in for it (a loading line) to the size of the answer, then
   its entries fade in on the stagger above. `SizeReveal`
   (`ui/components/motion.rs`) animates the outer box's height inline while a
   ResizeObserver watches the inner one; `flow-root` keeps the first and last
   children's margins inside what it measures. With reduced motion the box
   simply takes its new size. */
.size-reveal-content {
    display: flow-root;
}

@media (prefers-reduced-motion: reduce) {
    .stagger-reveal > * {
        animation: none;
    }

    .stagger-reveal--paged > :nth-child(n + 16) {
        animation: none;
    }
}
