/* ======================================================= */
/* CANASTATRON — Esfera glass tech · mensaje on-touch      */
/* ======================================================= */

@property --sphere-shine-o {
    syntax: '<number>';
    initial-value: 0.2;
    inherits: false;
}

.canasta-ai-float {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 0;
    flex-shrink: 0;
    min-width: 0;
    max-width: min(340px, calc(100vw - 28px - env(safe-area-inset-right, 0px) - env(safe-area-inset-left, 0px)));
    pointer-events: none;
}

.canasta-ai-float--launcher {
    pointer-events: auto;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    border: none;
    background: transparent;
    padding: 0;
    margin: 0;
    font: inherit;
    text-align: left;
    border-radius: 999px;
    outline: none;
}

/* Mensaje oculto hasta toque / hover / foco */
.canasta-ai-float__bubble {
    position: relative;
    order: 1;
    margin: 0 10px 0 0;
    padding: 0;
    max-width: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateX(12px) scale(0.92);
    background: rgba(10, 12, 16, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: rgba(240, 242, 248, 0.95);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.35;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        0 8px 28px rgba(0, 0, 0, 0.4);
    transition:
        opacity 0.35s ease,
        visibility 0.35s ease,
        transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
        max-width 0.4s ease,
        max-height 0.4s ease,
        padding 0.35s ease;
    overflow-wrap: anywhere;
    hyphens: auto;
    white-space: nowrap;
}

.canasta-ai-float__bubble::before {
    content: "[ CANASTATRON // LINK ACTIVO ]";
    display: block;
    margin-bottom: 0.35rem;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.4375rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    color: rgba(255, 160, 80, 0.75);
}

.canasta-ai-float__bubble::after {
    content: "";
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 6px solid rgba(255, 255, 255, 0.12);
}

.canasta-ai-float--engaged .canasta-ai-float__bubble,
.canasta-ai-float--launcher:focus-visible .canasta-ai-float__bubble,
.canasta-ai-float--intro .canasta-ai-float__bubble {
    opacity: 1;
    visibility: visible;
    transform: translateX(0) scale(1);
    max-width: min(240px, calc(100vw - 120px));
    max-height: 200px;
    padding: 10px 12px;
    white-space: normal;
}

/* ── Intro al cargar: esfera grande + mensaje centrado ── */
body.canastatron-intro-active::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 100001;
    background: rgba(0, 0, 0, 0.62);
    pointer-events: none;
    animation: canastatronBackdropIn 0.45s ease forwards;
}

.floating-contact-cluster.floating-contact-cluster--intro {
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate3d(-50%, -50%, 0) !important;
    align-items: center;
    justify-content: center;
    width: auto;
    max-width: none;
    z-index: 100002;
    transition: none !important;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.floating-contact-cluster--intro .floating-btns {
    opacity: 0;
    visibility: hidden;
    width: 0;
    height: 0;
    overflow: hidden;
    margin: 0;
    pointer-events: none;
}

.canasta-ai-float--intro {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: min(92vw, 400px);
    pointer-events: auto;
}

.canasta-ai-float--intro .canasta-ai-float__bubble {
    order: -1;
    margin: 0 0 1.35rem;
    max-width: min(340px, 88vw) !important;
    max-height: 320px !important;
    padding: 1rem 1.15rem !important;
    font-size: clamp(0.9375rem, 3.8vw, 1.125rem);
    line-height: 1.45;
    text-align: center;
    border-radius: 18px;
    transform: translate3d(0, 0, 0) scale(1);
    background: rgba(14, 16, 22, 0.94);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    -webkit-font-smoothing: antialiased;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.16),
        0 16px 48px rgba(0, 0, 0, 0.5),
        0 0 32px rgba(255, 140, 40, 0.15);
}

.canasta-ai-float--intro .canasta-ai-float__bubble::before {
    font-size: 0.5rem;
    margin-bottom: 0.5rem;
}

.canasta-ai-float--intro .canasta-ai-float__bubble::after {
    left: 50%;
    right: auto;
    top: 100%;
    transform: translateX(-50%);
    border-top: 7px solid rgba(255, 255, 255, 0.14);
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: none;
}

.canasta-ai-float--intro .canasta-ai-sphere {
    width: clamp(108px, 30vw, 140px);
    height: clamp(108px, 30vw, 140px);
    --sphere-shine-o: 0.62;
    animation: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow:
        inset -8px -12px 22px rgba(0, 0, 0, 0.48),
        inset 6px 10px 18px rgba(255, 255, 255, 0.16),
        0 0 0 2px rgba(255, 255, 255, 0.1),
        0 20px 56px rgba(0, 0, 0, 0.55),
        0 0 48px rgba(255, 140, 40, 0.35);
}

.canasta-ai-float--intro .canasta-ai-sphere__robot {
    width: clamp(76px, 22vw, 98px);
    height: clamp(76px, 22vw, 98px);
    image-rendering: -webkit-optimize-contrast;
    transform: translate3d(-50%, -50%, 0);
}

.canasta-ai-float--intro-out .canasta-ai-float__bubble {
    opacity: 0 !important;
    visibility: hidden !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    transition: opacity 0.45s ease, visibility 0.45s ease, max-height 0.45s ease, margin 0.45s ease, padding 0.45s ease;
}

.floating-contact-cluster--intro-dock {
    transition: none !important;
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.floating-contact-cluster--intro-dock .canasta-ai-sphere {
    transition: width 0.55s ease 0.75s, height 0.55s ease 0.75s, box-shadow 0.55s ease 0.75s;
}

@keyframes canastatronBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 767px) {
    body.canastatron-intro-active::after {
        background: rgba(0, 0, 0, 0.78);
    }

    .canasta-ai-float--intro .canasta-ai-float__bubble {
        font-size: 0.875rem;
        padding: 0.9rem 1rem !important;
        margin-bottom: 1.1rem;
        background: rgba(12, 14, 20, 0.97);
    }

    .canasta-ai-float--intro .canasta-ai-sphere {
        background-image:
            radial-gradient(
                circle at var(--sphere-shine-x) var(--sphere-shine-y),
                rgba(255, 255, 255, calc(var(--sphere-shine-o) * 0.2)) 0%,
                rgba(255, 200, 120, calc(var(--sphere-shine-o) * 0.08)) 18%,
                transparent 42%
            ),
            radial-gradient(
                circle at 38% 32%,
                rgba(255, 255, 255, 0.22) 0%,
                rgba(18, 20, 28, 0.88) 55%,
                rgba(6, 8, 12, 0.96) 100%
            );
    }
}

@media (prefers-reduced-motion: reduce) {
    body.canastatron-intro-active::after {
        display: none;
    }

    .floating-contact-cluster.floating-contact-cluster--intro {
        top: auto !important;
        left: auto !important;
        right: max(14px, env(safe-area-inset-right, 0px)) !important;
        bottom: max(24px, env(safe-area-inset-bottom, 0px)) !important;
        transform: none !important;
    }
}

/* ── Esfera glass 3D ── */
.canasta-ai-sphere {
    order: 2;
    position: relative;
    flex-shrink: 0;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    --sphere-shine-x: 32%;
    --sphere-shine-y: 28%;
    --sphere-shine-o: 0.22;
    background-image:
        radial-gradient(
            circle at var(--sphere-shine-x) var(--sphere-shine-y),
            rgba(255, 255, 255, calc(var(--sphere-shine-o) * 0.2)) 0%,
            rgba(255, 200, 120, calc(var(--sphere-shine-o) * 0.08)) 18%,
            transparent 42%
        ),
        radial-gradient(
            circle at 38% 32%,
            rgba(255, 255, 255, 0.28) 0%,
            rgba(255, 255, 255, 0.06) 18%,
            rgba(14, 16, 22, 0.72) 52%,
            rgba(4, 6, 10, 0.92) 100%
        );
    backdrop-filter: blur(8px) saturate(160%);
    -webkit-backdrop-filter: blur(8px) saturate(160%);
    border: 2px solid rgba(255, 255, 255, 0.22);
    box-shadow:
        inset -6px -10px 18px rgba(0, 0, 0, 0.5),
        inset 5px 8px 14px rgba(255, 255, 255, 0.14),
        0 0 0 1px rgba(255, 255, 255, 0.06),
        0 10px 32px rgba(0, 0, 0, 0.5),
        0 0 24px rgba(255, 140, 40, calc(var(--sphere-shine-o) * 0.08));
    overflow: hidden;
    transition:
        --sphere-shine-o 0.35s ease,
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.3s ease;
    animation: canastaSphereFloat 4s ease-in-out infinite;
}

@keyframes canastaSphereFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.canasta-ai-sphere__grid {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    opacity: 0.22;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
    background-size: 10px 10px;
    mask-image: radial-gradient(circle at 50% 50%, #000 55%, transparent 78%);
    -webkit-mask-image: radial-gradient(circle at 50% 50%, #000 55%, transparent 78%);
    pointer-events: none;
    z-index: 1;
}

.canasta-ai-sphere__ring {
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    border: 1px solid rgba(255, 140, 40, 0.35);
    box-shadow: 0 0 12px rgba(255, 106, 0, 0.25);
    pointer-events: none;
    z-index: 3;
    opacity: 0.7;
}

.canasta-ai-sphere__robot {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    display: block;
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
    transition: transform 0.3s ease;
}

.canasta-ai-float--engaged .canasta-ai-sphere,
.canasta-ai-sphere.canasta-ai-sphere--touch {
    --sphere-shine-o: 0.85;
    transform: translateY(-3px) scale(1.05);
    box-shadow:
        inset -6px -10px 18px rgba(0, 0, 0, 0.45),
        inset 5px 8px 16px rgba(255, 255, 255, 0.2),
        0 0 0 2px rgba(255, 200, 120, 0.35),
        0 14px 40px rgba(0, 0, 0, 0.55),
        0 0 32px rgba(255, 140, 40, 0.45);
    animation: none;
}

.canasta-ai-float--engaged .canasta-ai-sphere__robot {
    transform: translate(-50%, -50%) scale(1.06);
}

.canasta-ai-float--launcher:focus-visible .canasta-ai-sphere {
    outline: 2px solid #ffec00;
    outline-offset: 3px;
}

.canasta-ai-float--launcher:active .canasta-ai-sphere {
    transform: scale(0.96);
}

@media (max-width: 767px) {
    .canasta-ai-sphere {
        width: 68px;
        height: 68px;
    }

    .canasta-ai-sphere__robot {
        width: 48px;
        height: 48px;
    }

    .canasta-ai-float__bubble {
        font-size: 0.78rem;
    }

    .canasta-ai-float--engaged .canasta-ai-float__bubble,
    .canasta-ai-float--launcher:focus-visible .canasta-ai-float__bubble {
        max-width: min(210px, calc(100vw - 100px));
        padding: 9px 11px;
    }
}

@media (max-width: 380px) {
    .canasta-ai-float__bubble {
        font-size: 0.72rem;
        line-height: 1.3;
    }

    .canasta-ai-sphere {
        width: 62px;
        height: 62px;
    }

    .canasta-ai-sphere__robot {
        width: 44px;
        height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .canasta-ai-sphere {
        animation: none;
    }

    .canasta-ai-float__bubble {
        transition: opacity 0.2s ease, visibility 0.2s ease;
    }
}
