/* Shared motion layer. No content depends on an animation to become usable. */
:root {
    --tc-motion-fast: 140ms;
    --tc-motion-normal: 240ms;
    --tc-motion-enter: 360ms;
    --tc-motion-ease: cubic-bezier(.2, .8, .2, 1);
}

@keyframes tc-surface-enter {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes tc-content-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes tc-ripple-expand {
    from { opacity: .2; transform: scale(0); }
    to { opacity: 0; transform: scale(1); }
}

/* Only the inner overlay clips the ripple; dropdowns and focus rings stay free. */
body .tc-ripple-anchor { position: relative; }
body .tc-ripple-surface {
    position: absolute;
    inset: 0;
    display: block;
    margin: 0;
    padding: 0;
    border-radius: inherit;
    overflow: hidden;
    pointer-events: none;
    color: inherit;
}
body .tc-ripple-ink {
    position: absolute;
    display: block;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    background: currentColor;
    pointer-events: none;
    opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
    body :is(.btn, .button, .btn-hero-primary, .btn-hero-outline, .traceceni-floating-tool,
        .principal-chatbot-toggle, .admin-nav-item, .account-nav-item) {
        transition: background-color var(--tc-motion-fast) ease,
            border-color var(--tc-motion-fast) ease, color var(--tc-motion-fast) ease,
            box-shadow var(--tc-motion-normal) ease,
            translate var(--tc-motion-fast) var(--tc-motion-ease),
            scale var(--tc-motion-fast) var(--tc-motion-ease);
    }
    body :is(.btn, .button, .btn-hero-primary, .btn-hero-outline, .traceceni-floating-tool,
        .principal-chatbot-toggle):active:not(:disabled):not(.disabled):not([aria-disabled='true']) {
        scale: .97;
    }
    body :is(.admin-nav-item, .account-nav-item) {
        transition: background-color var(--tc-motion-normal) ease, color var(--tc-motion-normal) ease;
    }
    body :is(.form-control, .form-select) {
        transition: border-color var(--tc-motion-fast) ease, box-shadow var(--tc-motion-fast) ease;
    }
    body .form-check-input {
        transition: background-color var(--tc-motion-fast) ease,
            background-position var(--tc-motion-fast) ease, border-color var(--tc-motion-fast) ease;
    }

    /* CSS restarts these on insertion or when display:none sections are shown.
       No forward fill: completed animations must not create containing blocks. */
    body :is(.hero-content, .hero-image-wrapper, .access-intro, .access-form-card,
        .projects-panel, .principal-panel, .classes-panel, .class-card,
        .classes-summary article, .about-shell, .about-author-card) {
        animation: tc-surface-enter var(--tc-motion-enter) var(--tc-motion-ease) backwards;
    }
    body :is([data-admin-panel], [data-account-panel], .access-tab-panel,
        .tab-pane.active, .alert, .artifact-edit-row, .class-knowledge-document) {
        animation: tc-content-enter var(--tc-motion-normal) ease backwards;
    }
    body .classes-summary article:nth-child(2),
    body .classes-grid > .class-card:nth-child(2) { animation-delay: 45ms; }
    body .classes-summary article:nth-child(3),
    body .classes-grid > .class-card:nth-child(3) { animation-delay: 90ms; }
    body .classes-grid > .class-card:nth-child(n+4) { animation-delay: 120ms; }

    /* Bootstrap retains responsibility for measurements, positioning and focus. */
    body .collapsing { transition: height var(--tc-motion-normal) var(--tc-motion-ease); }
    body .collapsing.collapse-horizontal { transition-property: width; }
    body .collapse.show > :is(.accordion-body, .imported-artifact-body) {
        animation: tc-content-enter 180ms ease;
    }
    body .modal.fade .modal-dialog {
        transition: transform var(--tc-motion-normal) var(--tc-motion-ease);
    }
    body .dropdown-menu.show,
    body .traceceni-header .traceceni-main-nav .traceceni-nav-item.dropdown:hover > .dropdown-menu,
    body .traceceni-header .traceceni-main-nav .traceceni-nav-item.dropdown:focus-within > .dropdown-menu {
        animation: tc-content-enter 160ms ease;
    }
    body .principal-chatbot.is-open .principal-chatbot-panel {
        animation: tc-surface-enter var(--tc-motion-normal) var(--tc-motion-ease);
    }
    body .tc-ripple-ink { animation: tc-ripple-expand 480ms ease-out; }
}

@media (prefers-reduced-motion: no-preference) and (hover: hover) and (pointer: fine) {
    body :is(.btn, .button, .btn-hero-primary, .btn-hero-outline):hover:not(:disabled):not(.disabled):not([aria-disabled='true']) {
        translate: 0 -1px;
    }
    body :is(.class-card, .about-author-card, .classes-summary article) {
        transition: box-shadow var(--tc-motion-normal) ease, border-color var(--tc-motion-normal) ease;
    }
    body :is(.class-card, .about-author-card, .classes-summary article):hover {
        box-shadow: var(--tc-material-shadow-raised);
        border-color: var(--tc-control-border);
    }
    body .table tbody tr > * {
        transition: background-color var(--tc-motion-fast) ease;
    }
}

@media (prefers-reduced-motion: reduce) {
    body .tc-ripple-surface { display: none; }
}

@media print {
    body .tc-ripple-surface { display: none; }
    html body *, html body *::before, html body *::after {
        animation: none !important;
        transition: none !important;
    }
}
