.social-fab-stack {
    --sf-size: 46px;
    --sf-pad: 0.4rem;
    --sf-gap: 0.35rem;
    --sf-radius: 1.35rem;

    position: fixed;
    right: var(--space-6, 1.5rem);
    bottom: calc(var(--space-6, 1.5rem) + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-toast, 60);
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: var(--sf-gap);
    padding: var(--sf-pad);
    border-radius: var(--sf-radius);
    background:
        linear-gradient(
            165deg,
            color-mix(in srgb, #fff 10%, transparent),
            color-mix(in srgb, #fff 2%, transparent) 40%,
            color-mix(in srgb, #000 22%, transparent)
        ),
        color-mix(in srgb, var(--color-surface, #161016) 78%, transparent);
    border: 1px solid color-mix(in srgb, #fff 12%, transparent);
    box-shadow:
        0 18px 40px -18px rgba(0, 0, 0, 0.72),
        0 0 0 1px color-mix(in srgb, #000 35%, transparent),
        inset 0 1px 0 color-mix(in srgb, #fff 14%, transparent);
    backdrop-filter: blur(18px) saturate(1.25);
    -webkit-backdrop-filter: blur(18px) saturate(1.25);
    animation: social-fab-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.social-fab-stack[hidden] {
    display: none !important;
}

.social-fab {
    position: relative;
    width: var(--sf-size);
    height: var(--sf-size);
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: #fff;
    text-decoration: none;
    isolation: isolate;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    transition:
        transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.22s ease,
        filter 0.22s ease;
    box-shadow:
        0 8px 18px -10px rgba(0, 0, 0, 0.65),
        inset 0 1px 0 color-mix(in srgb, #fff 22%, transparent);
}

.social-fab::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(
        145deg,
        color-mix(in srgb, #fff 28%, transparent),
        transparent 42%,
        color-mix(in srgb, #000 18%, transparent)
    );
    opacity: 0.55;
    pointer-events: none;
    z-index: 0;
}

.social-fab::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 16%, transparent);
    pointer-events: none;
    z-index: 1;
}

.social-fab:hover {
    transform: translateY(-2px) scale(1.04);
    color: #fff;
    filter: brightness(1.06);
}

.social-fab:active {
    transform: scale(0.96);
    filter: brightness(0.98);
}

.social-fab:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--color-primary, #ef4444) 70%, #fff);
    outline-offset: 2px;
}

.social-fab > svg {
    position: relative;
    z-index: 2;
    width: 1.15rem;
    height: 1.15rem;
    display: block;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}

.social-fab--telegram {
    background:
        radial-gradient(circle at 30% 25%, color-mix(in srgb, #fff 22%, transparent), transparent 45%),
        linear-gradient(
            145deg,
            color-mix(in srgb, var(--color-primary, #ef4444) 92%, #fff),
            var(--color-primary, #ef4444) 45%,
            color-mix(in srgb, var(--color-primary-hover, #f97316) 85%, #7c2d12)
        );
}

.social-fab--facebook {
    background:
        radial-gradient(circle at 30% 25%, color-mix(in srgb, #fff 24%, transparent), transparent 45%),
        linear-gradient(145deg, #4b9bff, #1877f2 48%, #0b5ed7);
}

.social-fab-stack__close {
    position: absolute;
    top: -0.45rem;
    right: -0.45rem;
    width: 1.35rem;
    height: 1.35rem;
    border: 0;
    border-radius: 999px;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: color-mix(in srgb, #fff 72%, transparent);
    background:
        linear-gradient(
            165deg,
            color-mix(in srgb, #fff 12%, transparent),
            color-mix(in srgb, #000 20%, transparent)
        ),
        color-mix(in srgb, var(--color-bg, #0b090c) 88%, transparent);
    border: 1px solid color-mix(in srgb, #fff 14%, transparent);
    box-shadow: 0 6px 14px -8px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: transform 0.15s ease, color 0.15s ease, background 0.15s ease;
    padding: 0;
    line-height: 0;
    -webkit-tap-highlight-color: transparent;
    z-index: 3;
}

.social-fab-stack__close:hover,
.social-fab-stack__close:active {
    transform: scale(1.08);
    color: #fff;
    background: color-mix(in srgb, var(--color-primary, #ef4444) 28%, #121016);
}

.social-fab-stack__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

.social-fab-stack__close svg {
    width: 0.6rem;
    height: 0.6rem;
    display: block;
}

@keyframes social-fab-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .social-fab-stack,
    .social-fab,
    .social-fab-stack__close {
        animation: none;
        transition: none;
    }
}

@media (width <= 1100px) {
    .social-fab-stack {
        right: var(--space-4, 1rem);
        bottom: calc(var(--space-4, 1rem) + env(safe-area-inset-bottom, 0px));
    }
}

@media (width <= 900px) {
    .social-fab-stack {
        --sf-size: 44px;
        --sf-pad: 0.35rem;
        --sf-gap: 0.3rem;
        --sf-radius: 1.25rem;

        right: max(0.8rem, env(safe-area-inset-right, 0px));
        bottom: calc(
            var(--bottom-nav-h, 64px) + 0.7rem + env(safe-area-inset-bottom, 0px)
        );
    }

    .social-fab > svg {
        width: 1.05rem;
        height: 1.05rem;
    }
}

@media (width <= 420px) {
    .social-fab-stack {
        --sf-size: 42px;
        --sf-pad: 0.32rem;
        --sf-radius: 1.15rem;

        right: max(0.65rem, env(safe-area-inset-right, 0px));
        bottom: calc(
            var(--bottom-nav-h, 64px) + 0.6rem + env(safe-area-inset-bottom, 0px)
        );
    }
}
