:root {
    --interactive-state-enter-duration: 0.38s;
    --interactive-state-exit-duration: 0.2s;
    --interactive-state-enter-easing: cubic-bezier(0.22, 1, 0.36, 1);
    --interactive-state-exit-easing: ease-in;
}

@keyframes interactiveStateEnter {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes interactiveStateExit {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes interactiveNotificationEnter {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes interactiveNotificationExit {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

@keyframes siteNotificationTimer {
    from {
        transform: scaleX(1);
    }

    to {
        transform: scaleX(0);
    }
}

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

@keyframes interactivePenaltyPop {
    0% {
        opacity: 0;
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes interactiveCarouselForward {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(-50%);
    }
}

@keyframes interactiveCarouselReverse {
    from {
        transform: translateX(-50%);
    }

    to {
        transform: translateX(0);
    }
}

:is(
    .account-template,
    .community-template,
    .goshuin-game-template,
    .homework-template,
    .stories-template,
    .stories-game-template,
    .trophy-room-template,
    .vocabulary-template,
    .vocabulary-game-template,
    .youtube-template
) .fade-in {
    opacity: 0;
    animation: interactiveStateEnter var(--interactive-state-enter-duration) var(--interactive-state-enter-easing) both;
}

:is(
    .homework-template,
    .stories-game-template,
    .vocabulary-game-template
) .game-screen.active {
    animation: interactiveStateEnter var(--interactive-state-enter-duration) var(--interactive-state-enter-easing) both;
}

:is(
    .homework-template .homework-results .unlocked-achievement-item,
    .homework-template .notebook-results-container,
    .stories-game-template .pronunciation-results,
    .stories-game-template .story-report-screen.active,
    .vocabulary-game-template .unlocked-achievement-item
) {
    animation: interactiveStateEnter var(--interactive-state-enter-duration) var(--interactive-state-enter-easing) both;
}

:is(
    .account-template,
    .community-template,
    .goshuin-game-template,
    .homework-template,
    .stories-template,
    .stories-game-template,
    .trophy-room-template,
    .vocabulary-template,
    .vocabulary-game-template,
    .youtube-template
) .fade-out {
    animation: interactiveStateExit var(--interactive-state-exit-duration) var(--interactive-state-exit-easing) forwards;
}

.site-toast-stack {
    position: fixed;
    z-index: 99999;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    display: grid;
    width: min(360px, calc(100vw - 40px));
    max-height: calc(100vh - 40px);
    gap: 10px;
    overflow-y: auto;
    pointer-events: none;
    scrollbar-width: none;
}

.site-toast-stack::-webkit-scrollbar {
    display: none;
}

.site-toast-stack > * {
    pointer-events: auto;
}

.site-notification {
    --site-notification-accent: var(--ghost-accent-color, #d9a443);
    --site-notification-soft: color-mix(in srgb, var(--site-notification-accent) 12%, transparent);
    --site-notification-shadow: color-mix(in srgb, var(--site-notification-accent) 20%, transparent);
    position: relative;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 28px;
    width: 100%;
    min-width: 0;
    gap: 12px;
    align-items: start;
    overflow: hidden;
    padding: 14px 12px 14px 14px;
    border: 1px solid color-mix(in srgb, var(--site-notification-accent) 58%, var(--color-border));
    border-left: 4px solid var(--site-notification-accent);
    border-radius: 12px;
    background: color-mix(in srgb, var(--site-notification-accent) 7%, #fff);
    box-shadow: 0 8px 22px var(--site-notification-shadow);
    color: var(--color-primary-text);
    overflow-wrap: anywhere;
    transition: box-shadow 0.2s ease;
    will-change: opacity, transform;
}

.site-notification:hover {
    box-shadow: 0 10px 28px var(--site-notification-shadow);
}

.site-notification.success {
    --site-notification-accent: #28a745;
    background: color-mix(in srgb, var(--site-notification-accent) 7%, #fff);
}

.site-notification.error {
    --site-notification-accent: #dc3545;
    background: color-mix(in srgb, var(--site-notification-accent) 7%, #fff);
}

.site-notification-icon {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 50%;
    background: var(--site-notification-soft);
    color: var(--site-notification-accent);
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
}

.site-notification-content {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
    padding-top: 1px;
}

.site-notification-label {
    margin: 0;
    color: var(--site-notification-accent);
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
}

.site-notification-title {
    margin: 0;
    color: var(--color-primary-text);
    font-size: 1.5rem;
    font-weight: 650;
    line-height: 1.35;
}

.site-notification-description {
    margin: 1px 0 0;
    color: var(--color-secondary-text);
    font-size: 1.3rem;
    line-height: 1.4;
}

.site-notification-close {
    display: grid;
    width: 28px;
    height: 28px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-secondary-text);
    cursor: pointer;
    font: inherit;
    font-size: 2rem;
    line-height: 1;
    transition: background 0.2s ease, color 0.2s ease;
}

.site-notification-close:hover {
    background: var(--site-notification-soft);
    color: var(--site-notification-accent);
}

.site-notification-close:focus-visible {
    outline: 2px solid var(--site-notification-accent);
    outline-offset: 2px;
}

.site-notification-progress {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--site-notification-accent);
    transform-origin: left;
    animation: siteNotificationTimer var(--site-notification-duration) linear forwards;
}

.site-notification.is-paused .site-notification-progress {
    animation-play-state: paused;
}

.site-notification.is-entering {
    animation: interactiveNotificationEnter var(--interactive-state-exit-duration) ease-out both;
}

.site-notification.is-leaving {
    animation: interactiveNotificationExit var(--interactive-state-exit-duration) ease-in both;
}

[data-theme="dark"] .site-notification {
    background: color-mix(in srgb, var(--site-notification-accent) 9%, var(--dark-surface-elevated));
}

@media (max-width: 600px) {
    .site-toast-stack {
        top: max(12px, env(safe-area-inset-top));
        right: 12px;
        width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
    }
}

:where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
) {
    transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.3s ease;
}

:where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).placeholder-state.transitioning {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    transition: opacity 0.3s ease;
}

[data-theme="dark"] :where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).placeholder-state.transitioning:not(.results-loading-state) {
    border-color: var(--color-border);
    background: var(--dark-surface-elevated);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.24);
}

[data-theme="dark"] :where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).placeholder-state:not(.transitioning):not(.error-state) {
    border-color: var(--color-border);
    background: var(--dark-surface-elevated);
}

:where(
    .homework-container,
    .stories-game-container,
    .vocabulary-game-container
).placeholder-state.transitioning.results-loading-state {
    border-color: var(--color-border);
    background: var(--color-lighter-gray, #f8f8f8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03), 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: none;
}

[data-theme="dark"] :where(
    .homework-container,
    .stories-game-container,
    .vocabulary-game-container
).placeholder-state.transitioning.results-loading-state {
    border-color: var(--color-border);
    background: var(--dark-surface-elevated);
}

:where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).error-state {
    display: flex;
    min-height: 300px;
    padding: 4rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-lighter-gray, #f8f8f8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03), 0 1px 3px rgba(0, 0, 0, 0.05);
    text-align: center;
    transition: none;
}

[data-theme="dark"] :where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).error-state {
    border-color: var(--color-border);
    background: var(--dark-surface);
}

:where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).transitioning > *,
:where(
    .account-container,
    .community-container,
    .homework-container,
    .stories-container,
    .stories-game-container,
    .trophy-room-container,
    .vocabulary-container,
    .vocabulary-game-container,
    .youtube-container
).error-state > *,
.goshuin-game-template :is(.gj-error, .gj-app) {
    animation: interactiveStateEnter var(--interactive-state-enter-duration) var(--interactive-state-enter-easing) both;
}

.goshuin-game-template .gj-error {
    flex-direction: column;
    min-height: 300px;
    gap: 1.5rem;
    padding: 4rem;
    border-radius: 12px;
    background: var(--color-lighter-gray, #f8f8f8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03), 0 1px 3px rgba(0, 0, 0, 0.05);
    text-align: center;
}

[data-theme="dark"] .goshuin-game-template .gj-error {
    border-color: var(--color-border);
    background: var(--dark-surface);
}

[data-theme="dark"] .goshuin-game-template .gj-loading {
    border-color: var(--color-border);
    background: var(--dark-surface-elevated);
}

:is(
    .homework-template,
    .stories-game-template,
    .vocabulary-game-template
) :is(
    .homework-exercise-progress,
    .story-progress,
    .vocabulary-game-progress
) {
    border-color: var(--color-border);
    background: var(--game-option-background);
    background-image: none;
}

[data-theme="dark"] :is(
    .homework-template,
    .stories-game-template,
    .vocabulary-game-template
) :is(
    .homework-exercise-progress,
    .story-progress,
    .vocabulary-game-progress
) {
    border-color: var(--color-border);
    background: var(--game-option-background);
    background-image: none;
}

[data-theme="dark"] .homework-template :is(
    .homework-audio-player,
    .homework-romaji-btn,
    .homework-spanish-btn,
    .homework-hint-btn
) {
    border-color: var(--color-border);
    background: var(--game-option-background);
    color: var(--color-primary-text);
}

[data-theme="dark"] .stories-template .story-audio-player {
    border-color: var(--color-border);
    background: var(--game-option-background);
    color: var(--color-primary-text);
}

[data-theme="dark"] .stories-template .story-progress-bar {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .homework-template :is(
    .homework-romaji-btn,
    .homework-spanish-btn,
    .homework-hint-btn
):hover:not(:disabled) {
    background: var(--game-option-background);
}

[data-theme="dark"] .homework-template :is(
    .homework-romaji-btn,
    .homework-spanish-btn,
    .homework-hint-btn
):disabled {
    background: var(--game-option-background);
}

[data-theme="dark"] :is(
    .account-placeholder-buttons,
    .community-placeholder-buttons,
    .goshuin-login-actions,
    .homework-placeholder-buttons,
    .stories-game-placeholder-buttons,
    .trophy-room-placeholder-buttons,
    .vocabulary-game-placeholder-buttons
) .gh-secondary-btn[data-portal="signup"] {
    border: 1px solid var(--color-border);
    background: var(--dark-surface);
    color: var(--color-primary-text);
}

[data-theme="dark"] :is(
    .account-placeholder-buttons,
    .community-placeholder-buttons,
    .goshuin-login-actions,
    .homework-placeholder-buttons,
    .stories-game-placeholder-buttons,
    .trophy-room-placeholder-buttons,
    .vocabulary-game-placeholder-buttons
) .gh-secondary-btn[data-portal="signup"]:hover {
    background: var(--dark-surface-elevated);
}

.goshuin-game-template .gj-error > span:first-child {
    width: 80px;
    height: 80px;
    border: 3px double rgba(255, 255, 255, 0.75);
    background: #dc3545;
    box-shadow: 0 9px 24px rgba(220, 53, 69, 0.22);
    font-size: 2.4rem;
    font-weight: 700;
}

.goshuin-game-template .gj-error > div {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.goshuin-game-template .gj-error strong {
    font-size: 1.8rem;
    font-weight: 500;
}

:is(
    .account-placeholder-kanji,
    .community-placeholder-kanji,
    .homework-placeholder-kanji,
    .stories-placeholder-kanji,
    .stories-game-placeholder-kanji,
    .trophy-room-placeholder-kanji,
    .vocabulary-placeholder-kanji,
    .vocabulary-game-placeholder-kanji,
    .youtube-placeholder-kanji,
    .gj-loading-seal,
    .gj-error > span:first-child
) {
    font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
}

[data-theme="dark"] :is(
    .account-placeholder-kanji,
    .community-placeholder-kanji,
    .homework-placeholder-kanji,
    .stories-placeholder-kanji,
    .stories-game-placeholder-kanji,
    .trophy-room-placeholder-kanji,
    .vocabulary-placeholder-kanji,
    .vocabulary-game-placeholder-kanji,
    .youtube-placeholder-kanji
):not([class*="placeholder-error"]),
[data-theme="dark"] .gj-loading-seal {
    border: 3px double rgba(255, 255, 255, 0.75);
    background: var(--ghost-accent-color, #a7312a);
    color: #fff;
}

@media (prefers-reduced-motion: reduce) {
    :is(
        .account-template,
        .community-template,
        .goshuin-game-template,
        .homework-template,
        .stories-template,
        .stories-game-template,
        .trophy-room-template,
        .vocabulary-template,
        .vocabulary-game-template,
        .youtube-template
    ) :is(.fade-in, .fade-out),
    .site-notification:is(.is-entering, .is-leaving),
    .site-notification-progress,
    :is(
        .homework-template .homework-results .unlocked-achievement-item,
        .homework-template .notebook-results-container,
        .stories-game-template .pronunciation-results,
        .stories-game-template .story-report-screen.active,
        .vocabulary-game-template .unlocked-achievement-item
    ),
    :where(
        .account-container,
        .community-container,
        .homework-container,
        .stories-container,
        .stories-game-container,
        .trophy-room-container,
        .vocabulary-container,
        .vocabulary-game-container,
        .youtube-container
    ) > *,
    .goshuin-game-template :is(.gj-error, .gj-app) {
        opacity: 1;
        animation: none;
        transform: none;
    }
}
