/* Motion on the home page is intentionally short and spatially restrained.
   It complements the global page transition without delaying useful content. */
body.home-page {
    --home-motion-out: cubic-bezier(0.22, 1, 0.36, 1);
    --home-motion-soft: cubic-bezier(0.2, 0, 0, 1);
}

body.home-page .home-header h1,
body.home-page .home-header p,
body.home-page .stats,
body.home-page .grade-tabs,
body.home-page .grade-panel:not([hidden]),
body.home-page .subject-card,
body.home-page .class-section .section-title,
body.home-page .extra-section .section-title,
body.home-page .home-footer {
    animation: none;
}

body.home-page .home-header h1 {
    animation: home-title-in 380ms var(--home-motion-out) both;
}

body.home-page .home-header h1 svg {
    transform-origin: 50% 55%;
    animation: home-mark-in 420ms 35ms var(--home-motion-out) both;
}

body.home-page .stats {
    animation: home-soft-in 300ms 45ms var(--home-motion-out) both;
}

body.home-page .grade-tabs {
    --home-grade-index: 1;
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    isolation: isolate;
    animation: home-soft-in 300ms 75ms var(--home-motion-out) both;
}

body.home-page .grade-tabs::before {
    content: '';
    position: absolute;
    z-index: -1;
    top: 0.32rem;
    bottom: 0.32rem;
    left: 0.32rem;
    width: calc((100% - 1.54rem) / 4);
    border-radius: 999px;
    background: var(--accent-color);
    box-shadow: 0 1px 2px color-mix(in srgb, var(--accent-color) 22%, transparent);
    transform: translateX(calc(var(--home-grade-index) * (100% + 0.3rem)));
    transition: transform 240ms var(--home-motion-out),
                background-color 180ms ease,
                box-shadow 180ms ease;
}

body.home-page .grade-tabs:not(.home-tabs-ready)::before {
    transition: none;
}

body.home-page .grade-tabs[data-active-grade='9'] { --home-grade-index: 0; }
body.home-page .grade-tabs[data-active-grade='10'] { --home-grade-index: 1; }
body.home-page .grade-tabs[data-active-grade='11'] { --home-grade-index: 2; }
body.home-page .grade-tabs[data-active-grade='archive'] { --home-grade-index: 3; }

body.home-page .grade-tab,
body.experimental.home-page .grade-tab,
body.experimental.home-page .grade-tab.active {
    position: relative;
    z-index: 1;
    background: transparent;
    transition: color 170ms ease, background-color 170ms ease, transform 130ms ease;
}

body.home-page .grade-tab.active,
body.experimental.home-page .grade-tab.active {
    color: #fff;
}

body.experimental.home-page .grade-tab.active {
    color: var(--exp-accent-contrast, #fff);
}

body:not(.no-hover).home-page .grade-tab:not(.active):hover {
    background: color-mix(in srgb, var(--accent-color) 7%, transparent);
}

body.experimental.home-page .grade-tabs::before {
    background: var(--exp-accent);
}

body.home-page .grade-tab:active {
    transform: scale(0.98) !important;
}

body.home-page .grade-panel:not([hidden]) {
    animation: home-panel-in 205ms var(--home-motion-out) both;
}

body.home-page .subjects-grid > .subject-card {
    --home-card-order: 0;
    animation: none;
    transition: border-color 190ms ease,
                box-shadow 220ms var(--home-motion-soft),
                background-color 190ms ease,
                transform 130ms ease !important;
}

body.home-page .subjects-grid > .subject-card:nth-child(2) { --home-card-order: 1; }
body.home-page .subjects-grid > .subject-card:nth-child(3) { --home-card-order: 2; }
body.home-page .subjects-grid > .subject-card:nth-child(4) { --home-card-order: 3; }
body.home-page .subjects-grid > .subject-card:nth-child(5) { --home-card-order: 4; }
body.home-page .subjects-grid > .subject-card:nth-child(n + 6) { --home-card-order: 5; }

body.home-page.home-motion-initial .grade-panel:not([hidden]) .subjects-grid > .subject-card,
body.home-page.home-motion-initial .extra-section .subjects-grid > .subject-card {
    animation: home-card-in 330ms var(--home-motion-out) both;
    animation-delay: calc(90ms + var(--home-card-order) * 38ms);
}

body.home-page .extra-section .section-title {
    animation: home-soft-in 300ms 150ms var(--home-motion-out) both;
}

body.home-page .class-section .section-title {
    animation: home-soft-in 280ms 125ms var(--home-motion-out) both;
}

body.home-page.home-motion-initial .extra-section .subjects-grid > .subject-card {
    animation-delay: calc(185ms + var(--home-card-order) * 38ms);
}

body.home-page .subject-card::before {
    background: var(--subject-color);
    color: var(--subject-color);
    transform: scaleX(0.28);
    transform-origin: left center;
    transition: opacity 180ms ease, transform 240ms var(--home-motion-out);
}

body:not(.no-hover).home-page .subject-card:hover {
    transform: none !important;
    border-color: color-mix(in srgb, var(--subject-color) 48%, var(--border-color));
    box-shadow: 0 10px 28px color-mix(in srgb, var(--subject-color) 10%, transparent);
}

body:not(.no-hover).home-page .subject-card:hover::before {
    transform: scaleX(1);
}

body.home-page .subject-icon,
body.home-page .subject-icon svg,
body.home-page .status-badge,
body.home-page .home-editor-link svg {
    transition: transform 220ms var(--home-motion-out),
                color 180ms ease,
                background-color 180ms ease,
                border-color 180ms ease;
}

body:not(.no-hover).home-page .subject-card:hover .subject-icon {
    transform: translateY(-1px);
}

body:not(.no-hover).home-page .subject-card:hover .subject-icon svg {
    transform: scale(1.045);
}

body.home-page .subject-card:active {
    transform: scale(0.992) !important;
}

body:not(.no-hover).home-page .home-editor-link:hover svg {
    transform: translateX(1px);
}

body.home-page .subject-card:focus-visible,
body.home-page .grade-tab:focus-visible,
body.home-page .home-editor-link:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent-color) 72%, white);
    outline-offset: 3px;
}

body.home-page .home-footer {
    animation: home-soft-in 300ms 230ms var(--home-motion-out) both;
}

body.home-page .home-editor-link:not([hidden]) {
    animation: home-action-in 240ms var(--home-motion-out) both;
}

body.home-page .settings-button,
body.home-page .account-btn.home-account-btn {
    animation: home-corner-in 280ms var(--home-motion-out) both;
}

@keyframes home-title-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes home-mark-in {
    from { opacity: 0; transform: translateY(2px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes home-soft-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes home-card-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes home-action-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes home-panel-in {
    from { opacity: 0.58; transform: translate3d(var(--home-grade-shift, 0px), 0, 0); }
    68% { opacity: 1; }
    to { opacity: 1; transform: translate3d(0, 0, 0); }
}

body.animations-medium.home-page .home-header h1,
body.animations-medium.home-page .home-header h1 svg,
body.animations-medium.home-page .stats,
body.animations-medium.home-page .grade-tabs,
body.animations-medium.home-page .grade-panel:not([hidden]),
body.animations-medium.home-page .subject-card,
body.animations-medium.home-page .class-section .section-title,
body.animations-medium.home-page .extra-section .section-title,
body.animations-medium.home-page .home-footer {
    animation-duration: 220ms;
    animation-delay: 0ms;
}

body.animations-medium.home-page .home-editor-link:not([hidden]),
body.animations-medium.home-page .settings-button,
body.animations-medium.home-page .account-btn.home-account-btn {
    animation-duration: 180ms;
}

body.animations-medium.home-page .grade-panel:not([hidden]) {
    animation-duration: 160ms;
}

body.animations-medium.home-page .grade-tabs::before {
    transition-duration: 180ms, 160ms, 160ms;
}

body.animations-off.home-page .home-header h1,
body.animations-off.home-page .home-header h1 svg,
body.animations-off.home-page .stats,
body.animations-off.home-page .grade-tabs,
body.animations-off.home-page .grade-panel:not([hidden]),
body.animations-off.home-page .subject-card,
body.animations-off.home-page .class-section .section-title,
body.animations-off.home-page .extra-section .section-title,
body.animations-off.home-page .home-footer {
    animation: none !important;
    transition: none !important;
}

body.animations-off.home-page .home-editor-link:not([hidden]),
body.animations-off.home-page .settings-button,
body.animations-off.home-page .account-btn.home-account-btn {
    animation: none !important;
}

body.animations-off.home-page .grade-tabs::before,
body.animations-off.home-page .subject-card::before,
body.animations-off.home-page .subject-icon,
body.animations-off.home-page .subject-icon svg,
body.animations-off.home-page .status-badge,
body.animations-off.home-page .home-editor-link svg {
    transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
    body.home-page .home-header h1,
    body.home-page .home-header h1 svg,
    body.home-page .stats,
    body.home-page .grade-tabs,
    body.home-page .grade-panel:not([hidden]),
    body.home-page .subject-card,
    body.home-page .class-section .section-title,
    body.home-page .extra-section .section-title,
    body.home-page .home-footer {
        animation: none !important;
        transition: none !important;
    }

    body.home-page .home-editor-link:not([hidden]),
    body.home-page .settings-button,
    body.home-page .account-btn.home-account-btn {
        animation: none !important;
    }

    body.home-page .grade-tabs::before,
    body.home-page .subject-card::before,
    body.home-page .subject-icon,
    body.home-page .subject-icon svg,
    body.home-page .status-badge,
    body.home-page .home-editor-link svg {
        transition: none !important;
    }
}
