:root {
    --motion-fast: 170ms;
    --motion-base: 330ms;
    --motion-slow: 560ms;
    --motion-ease: cubic-bezier(.2, .82, .22, 1);
    --motion-spring: cubic-bezier(.18, .85, .24, 1.08);
}

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

@keyframes portal-rise-in {
    from { opacity: .28; transform: translate3d(0, 16px, 0) scale(.992); }
    to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes portal-pop-in {
    from { opacity: 0; transform: translateY(8px) scale(.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes portal-home-menu-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(.97); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes portal-toast-in {
    from { opacity: 0; transform: translateX(18px) scale(.98); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes portal-focus-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(69, 212, 131, 0); }
    45% { box-shadow: 0 0 0 4px rgba(69, 212, 131, .16); }
}

@keyframes portal-login-in {
    from { opacity: 0; transform: translateY(18px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes portal-login-item-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

html { scroll-behavior: smooth; }
body { animation: none; }

body > .card {
    animation: portal-login-in var(--motion-slow) var(--motion-ease) both;
}

body > .card > * {
    animation: portal-login-item-in var(--motion-base) var(--motion-ease) both;
}

body > .card form > * {
    animation: portal-login-item-in var(--motion-base) var(--motion-ease) both;
}

body > .card > *:nth-child(2),
body > .card form > *:nth-child(2) { animation-delay: 55ms; }

body > .card > *:nth-child(3),
body > .card form > *:nth-child(3) { animation-delay: 110ms; }

body > .card > *:nth-child(4),
body > .card form > *:nth-child(4) { animation-delay: 165ms; }

body > .card .choices > *:nth-child(2) { animation-delay: 70ms; }

a,
button,
input,
textarea,
select {
    transition: color var(--motion-fast) ease,
        background-color var(--motion-fast) ease,
        border-color var(--motion-fast) ease,
        box-shadow var(--motion-fast) ease,
        opacity var(--motion-fast) ease,
        transform var(--motion-fast) var(--motion-spring);
}

button:not(:disabled):not(.clear-search):not(.portal-menu-toggle):not(.announcement-toggle):hover,
a:not(.back):not(.brand):not(.quick-site-link):not(.game-card):hover {
    transform: translateY(-2px);
}

button:not(:disabled):not(.clear-search):active,
a:active {
    transform: translateY(0) scale(.97);
}

:where(button, a, input, textarea, select):focus-visible {
    outline: 2px solid rgba(69, 212, 131, .8);
    outline-offset: 3px;
    animation: portal-focus-pulse 500ms ease-out;
}

main > *:not(.shell):not(.card),
.games-grid > *,
.dashboard-section,
.card,
.notification,
.change,
.account-favourites,
.favourite-games {
    animation: portal-rise-in var(--motion-base) var(--motion-ease) both;
}

main > *:nth-child(2),
.games-grid > *:nth-child(2),
.card:nth-child(2),
.notification:nth-child(2),
.change:nth-child(2),
.account-favourites:nth-child(2) { animation-delay: 45ms; }

main > *:nth-child(3),
.games-grid > *:nth-child(3),
.card:nth-child(3),
.notification:nth-child(3),
.change:nth-child(3),
.account-favourites:nth-child(3) { animation-delay: 90ms; }

main > *:nth-child(4),
.games-grid > *:nth-child(4),
.card:nth-child(4),
.notification:nth-child(4),
.change:nth-child(4),
.account-favourites:nth-child(4) { animation-delay: 135ms; }

main > *:nth-child(5),
.games-grid > *:nth-child(5),
.card:nth-child(5),
.notification:nth-child(5),
.change:nth-child(5) { animation-delay: 175ms; }

.game-card,
.quick-site-link,
.tool-link,
.conversation,
.browser-menu-item,
.member-row,
.message,
.notification,
.change,
.account-activity li,
.top-games li {
    transition: transform var(--motion-base) var(--motion-spring),
        border-color var(--motion-fast) ease,
        background-color var(--motion-fast) ease,
        box-shadow var(--motion-base) ease;
}

.game-card:hover,
.quick-site-link:hover,
.tool-link:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 32px rgba(0, 0, 0, .18);
}

.conversation:hover,
.browser-menu-item:hover,
.member-row:hover,
.account-activity li:hover,
.top-games li:hover {
    transform: translateX(3px);
}

.message { animation: portal-rise-in var(--motion-base) var(--motion-ease) both; }

.browser-menu:not([hidden]),
.announcement-popover.open,
.portal-menu-options,
dialog[open],
.changelog-dialog[open] {
    animation: portal-pop-in var(--motion-base) var(--motion-ease) both;
    transform-origin: top right;
}

.browser-menu.home-position:not([hidden]) {
    animation-name: portal-home-menu-in;
    transform-origin: center;
}

.changelog-dialog[open] { transform-origin: center; }
.chat-toast { animation: portal-toast-in var(--motion-base) var(--motion-ease) both; }
.chat-toast.closing { animation: none; }
[hidden] { animation: none !important; }

/* The persistent shell blends a prepared portal document over the current one. */
#main-container.portal-motion-locked > .browser-frame { pointer-events: none; }
.portal-motion-preview {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: #0e2433;
    opacity: 0;
    pointer-events: none;
    will-change: opacity, transform, clip-path;
}
.portal-motion-ghost {
    position: absolute;
    z-index: 3;
    box-sizing: border-box;
    border: 1px solid #d9f1ff8c;
    box-shadow: inset 0 1px #ffffff65, 0 24px 60px #0004;
    pointer-events: none;
    will-change: left, top, width, height, opacity;
}

/* A few pixels of depth are enough to make the hero react to a pointer. */
html[data-portal-page="home"] .hero::after,
html[data-portal-page="games"] .hero::after {
    transform: translate3d(var(--portal-parallax-x, 0px), var(--portal-parallax-y, 0px), 0);
    transition: transform 620ms var(--motion-ease);
}
html[data-portal-page="home"] .destination-card .destination-shapes {
    transition: filter 420ms var(--motion-ease), opacity 420ms var(--motion-ease);
}
html[data-portal-page="home"] .destination-card:hover .destination-shapes,
html[data-portal-page="home"] .destination-card:focus-visible .destination-shapes {
    filter: brightness(1.22);
}
html[data-portal-page] :is(.destination-card, .game-card, .tool-link, .quick-site-link):hover {
    box-shadow: inset 0 1px #ffffff70, 0 24px 52px #0005, 0 0 32px #8dcfff18;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 1ms !important;
    }
}
