.toast-stack {
    position: fixed;
    z-index: 1300;
    top: max(5.25rem, calc(env(safe-area-inset-top) + 1rem));
    right: max(1rem, calc((100vw - 1460px) / 2));
    display: grid;
    width: min(380px, calc(100vw - 2rem));
    gap: 0.65rem;
    pointer-events: none;
}

.app-toast {
    --toast-accent: #2aaf74;
    --toast-soft: rgba(42, 175, 116, 0.12);
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 30px;
    gap: 0.75rem;
    align-items: start;
    padding: 0.85rem;
    border: 1px solid rgba(20, 57, 44, 0.13);
    border-radius: 16px;
    color: #12251f;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 48px rgba(8, 38, 29, 0.17), 0 2px 8px rgba(8, 38, 29, 0.08);
    backdrop-filter: blur(18px);
    pointer-events: auto;
    animation: toast-enter 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.app-toast--error,
.app-toast--danger {
    --toast-accent: #dc4d55;
    --toast-soft: rgba(220, 77, 85, 0.12);
}

.app-toast--warning {
    --toast-accent: #db922e;
    --toast-soft: rgba(219, 146, 46, 0.13);
}

.app-toast--info,
.app-toast--debug {
    --toast-accent: #347fce;
    --toast-soft: rgba(52, 127, 206, 0.12);
}

.app-toast__icon {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 12px;
    color: var(--toast-accent);
    background: var(--toast-soft);
}

.app-toast__icon svg {
    width: 20px;
    height: 20px;
}

.app-toast__content {
    display: grid;
    min-width: 0;
    gap: 0.2rem;
    padding-top: 0.1rem;
}

.app-toast__content strong {
    color: #10251e;
    font-size: 0.75rem;
    font-weight: 780;
    line-height: 1.3;
}

.app-toast__content > span {
    overflow-wrap: anywhere;
    color: #687970;
    font-size: 0.68rem;
    line-height: 1.5;
}

.app-toast__close {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    color: #809088;
    background: transparent;
    cursor: pointer;
    transition: color 160ms ease, background 160ms ease;
}

.app-toast__close:hover,
.app-toast__close:focus-visible {
    color: #253d34;
    background: rgba(16, 37, 30, 0.07);
    outline: 0;
}

.app-toast__close svg {
    width: 17px;
    height: 17px;
}

.app-toast__progress {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--toast-accent);
    transform-origin: left center;
    animation: toast-progress 5s linear both;
}

.app-toast.is-paused .app-toast__progress {
    animation-play-state: paused;
}

.app-toast.is-leaving {
    animation: toast-leave 220ms ease both;
}

html.theme-dark .app-toast {
    color: #eef8f4;
    border-color: rgba(171, 207, 192, 0.16);
    background: rgba(13, 31, 25, 0.94);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.34);
}

html.theme-dark .app-toast__content strong {
    color: #f0faf6;
}

html.theme-dark .app-toast__content > span {
    color: #a8bbb2;
}

html.theme-dark .app-toast__close {
    color: #90a69c;
}

html.theme-dark .app-toast__close:hover,
html.theme-dark .app-toast__close:focus-visible {
    color: #f0faf6;
    background: rgba(255, 255, 255, 0.08);
}

@keyframes toast-enter {
    from { opacity: 0; transform: translate3d(18px, -8px, 0) scale(0.98); }
    to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes toast-leave {
    from { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
    to { opacity: 0; transform: translate3d(18px, -5px, 0) scale(0.98); }
}

@keyframes toast-progress {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

@media (max-width: 680px) {
    .toast-stack {
        top: auto;
        right: 1rem;
        bottom: max(1rem, calc(env(safe-area-inset-bottom) + 0.75rem));
        left: 1rem;
        width: auto;
    }

    .app-toast {
        grid-template-columns: 38px minmax(0, 1fr) 28px;
        padding: 0.75rem;
        border-radius: 15px;
        animation-name: toast-enter-mobile;
    }

    .app-toast__icon {
        width: 38px;
        height: 38px;
    }

    .app-toast.is-leaving {
        animation-name: toast-leave-mobile;
    }
}

@keyframes toast-enter-mobile {
    from { opacity: 0; transform: translate3d(0, 18px, 0) scale(0.98); }
    to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes toast-leave-mobile {
    from { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
    to { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.98); }
}

@media (prefers-reduced-motion: reduce) {
    .app-toast,
    .app-toast.is-leaving,
    .app-toast__progress {
        animation: none;
    }
}
