/* =========================================================
   MASCOTA INTERACTIVA
   Proyecto: Mapa interactivo de la UTTECAM
   Autor: Cristobal Torres Ramos
   Año: 2026
   ========================================================= */


/* =========================================================
   CONTENEDOR PRINCIPAL
   ========================================================= */

#mascota {

    --mascota-scale: 1;

    position: fixed;
    right: 20px;
    bottom: 20px;

    width: 110px;
    height: 160px;

    pointer-events: auto;
    z-index: 9999;

    overflow: visible;
    cursor: pointer;

    user-select: none;
    -webkit-user-select: none;

    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;

    transform-origin: bottom right;
    transform: scale(var(--mascota-scale));

    transition:
        transform 0.35s ease,
        opacity 0.35s ease,
        visibility 0.35s ease,
        filter 0.35s ease;

}

#mascota:focus-visible {
    outline: 3px solid var(--color-institucional-naranja-oscuro);
    outline-offset: 3px;
}


/* =========================================================
   OCULTAR LA MASCOTA DE FORMA EXPLÍCITA
   ========================================================= */

#mascota.mascota-oculta {

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transform:
        scale(calc(var(--mascota-scale) * 0.8))
        translateY(60px);

}


/* =========================================================
   CONTENEDOR E IMAGEN GIF
   ========================================================= */

/*
 * El HTML nuevo utiliza #mascota-animacion como contenedor
 * y #mascota-gif como imagen animada de la mascota completa.
 */

#mascota-animacion {

    position: absolute;

    top: 0;
    left: 0;

    width: 100%;
    height: 100%;

    overflow: visible;

    pointer-events: none;

}

/* Imagen GIF completa, con transparencia */

#mascota-gif {

    position: absolute;

    inset: 0;

    width: 100%;
    height: 100%;

    object-fit: contain;
    object-position: center bottom;

    display: block;

    pointer-events: none;

    user-select: none;
    -webkit-user-drag: none;

    transform-origin: center bottom;

}

/* Movimiento suave de reposo del contenedor */

@keyframes mascotaRespirar {

    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-2px);
    }

    100% {
        transform: translateY(0);
    }

}

/*
 * Se aplica solamente cuando la mascota está en reposo.
 * Si el GIF ya incluye respiración, puedes quitar esta regla
 * para evitar que se duplique el movimiento.
 */

#mascota.reposo #mascota-animacion {

    animation: mascotaRespirar 2.4s ease-in-out infinite;

}


/* =========================================================
   EFECTO AL TOCAR
   ========================================================= */

#mascota.tocando {

    transform:
        scale(calc(var(--mascota-scale) * 1.04))
        translateY(-3px);

}


/* =========================================================
   ANIMACIÓN CUANDO HABLA
   ========================================================= */

@keyframes mascotaHabla {

    0% {
        transform:
            scale(var(--mascota-scale))
            translateY(0)
            rotate(0deg);
    }

    25% {
        transform:
            scale(var(--mascota-scale))
            translateY(-2.5px)
            rotate(-1deg);
    }

    50% {
        transform:
            scale(var(--mascota-scale))
            translateY(-4px)
            rotate(1deg);
    }

    75% {
        transform:
            scale(var(--mascota-scale))
            translateY(-2px)
            rotate(-0.5deg);
    }

    100% {
        transform:
            scale(var(--mascota-scale))
            translateY(0)
            rotate(0deg);
    }

}

#mascota.hablando {

    animation: mascotaHabla 0.7s ease;

}


#mascota-messages-layer {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
}

/* =========================================================
   INDICADOR DE ACCESO AL ASISTENTE
   ========================================================= */
#mascota-ayuda {

    position: absolute;

    left: 12px;
    top: 12px;
    width: max-content;
    max-width: min(320px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    box-sizing: border-box;
    padding: 11px 15px;

    color: #173c36;
    background: #fff;
    border: 2px solid var(--primary);
    border-radius: 16px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18);

    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;

    opacity: 0;
    visibility: hidden;
    overflow-wrap: anywhere;
    white-space: normal;
    overflow-y: auto;
    transition: opacity 220ms ease, visibility 220ms ease;

    z-index: 10000;
    pointer-events: none;

}

#mascota-ayuda.visible {

    opacity: 1;
    visibility: visible;

}


/* =========================================================
   BURBUJA
   ========================================================= */

#mascota-mensaje {

    position: absolute;

    left: 12px;
    top: 12px;

    width: max-content;
    max-width: min(320px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    min-height: 0;

    padding: 15px 20px;

    box-sizing: border-box;

    background: rgba(255, 255, 255, 0.97);

    border: 2px solid var(--color-institucional-verde-profundo);
    border-radius: 20px;

    box-shadow:
        0 8px 25px
        rgba(0, 0, 0, 0.18);

    opacity: 0;
    visibility: hidden;
    overflow-wrap: anywhere;
    white-space: normal;
    overflow-y: auto;

    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;

    z-index: 10000;

    pointer-events: none;

}


/* =========================================================
   BURBUJA VISIBLE
   ========================================================= */

#mascota-mensaje.visible {

    opacity: 1;
    visibility: visible;

}


/* =========================================================
   PICO DE LA BURBUJA
   ========================================================= */

#mascota-mensaje::after {

    content: "";

    position: absolute;

    left: var(--mensaje-tail-left, 50%);
    bottom: -11px;

    width: 20px;
    height: 20px;

    background: white;

    border-right: 2px solid var(--color-institucional-verde-profundo);
    border-bottom: 2px solid var(--color-institucional-verde-profundo);

    transform:
        translateX(-50%)
        rotate(45deg);

}

#mascota-mensaje.below-mascot::after {
    top: -11px;
    bottom: auto;
    transform: translateX(-50%) rotate(225deg);
}


/* =========================================================
   TEXTO
   ========================================================= */

#mensaje-texto {

    display: block;

    color: var(--color-institucional-verde-profundo);

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    font-size: 15px;
    font-weight: 600;

    line-height: 1.45;

    text-align: center;

}


/* =========================================================
   INDICADOR DE INTERACCIÓN
   ========================================================= */

#mascota::before {

    content: "🌱";

    position: absolute;

    top: 3px;
    left: 8px;

    font-size: 11px;

    opacity: 0;

    transform: scale(0.5);

    transition:
        opacity 0.3s ease,
        transform 0.3s ease;

    pointer-events: none;

}


@media (hover: hover) {

    #mascota:hover::before {

        opacity: 1;

        transform: scale(1);

    }

}


/* =========================================================
   ESTADO DE HABLAR
   ========================================================= */

/*
 * La animación del habla se realiza dentro del GIF.
 * Esta clase conserva un pequeño movimiento del personaje,
 * sin depender de las antiguas imágenes #cabeza y #torso.
 */

#mascota.hablando #mascota-animacion {

    animation: mascotaHabla 0.7s ease-in-out;

}


/* =========================================================
   MÓVILES
   ========================================================= */

/* =========================================================
   MÓVILES
   ========================================================= */

@media (max-width: 768px) {

    #mascota.details-card-open + #mascota-messages-layer {
        visibility: hidden;
    }

    #mascota {

        --mascota-scale: 0.85;

        transform-origin:
            bottom right;

        right:
            10px;

        bottom:
            10px;

        z-index:
            9999;

        pointer-events:
            auto;

        touch-action:
            manipulation;

    }

    #mascota.details-card-open {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }


    /*
     * Al tocar
     */

    #mascota.tocando {

        transform:
            scale(calc(var(--mascota-scale) * 1.04))
            translateY(-2.5px);

    }


    /*
     * La clase mascota-oculta
     * conserva la ocultación explícita en móvil.
     */

    #mascota.mascota-oculta {

        transform:
            scale(calc(var(--mascota-scale) * 0.85))
            translateY(60px);

        opacity:
            0;

        visibility:
            hidden;

        pointer-events:
            none;

    }


    /*
     * Burbuja
     */

    #mascota-mensaje {
        max-height: calc(100vh - 24px);
        padding:
            12px 15px;

    }

    #mascota-ayuda {
        max-height: calc(100vh - 24px);
        padding:
            10px 12px;

        font-size:
            12px;

    }


    #mensaje-texto {

        font-size:
            13px;

        line-height:
            1.4;

    }


    #mascota::before {

        display:
            none;

    }

}


/* =========================================================
   CELULARES PEQUEÑOS
   ========================================================= */

@media (max-width: 480px) {

    #mascota {

        --mascota-scale: 0.72;

        right:
            5px;

        bottom:
            5px;

    }


    #mascota.tocando {

        transform:
            scale(calc(var(--mascota-scale) * 1.04))
            translateY(-2.5px);

    }


    #mascota.mascota-oculta {

        transform:
            scale(calc(var(--mascota-scale) * 0.72))
            translateY(60px);

    }


    #mascota-mensaje {
        max-height: calc(100vh - 24px);
        padding:
            11px 13px;

    }

    #mascota-ayuda {
        max-height: calc(100vh - 24px);
        padding:
            9px 11px;

        font-size:
            11px;

    }


    #mensaje-texto {

        font-size:
            12px;

        line-height:
            1.4;

    }


    #mascota-mensaje::after {

        width:
            16px;

        height:
            16px;

        bottom:
            -9px;

    }

}


/* =========================================================
   DISPOSITIVOS TÁCTILES
   ========================================================= */

@media (hover: none) and (pointer: coarse) {

    #mascota {

        cursor:
            pointer;

        user-select:
            none;

        -webkit-user-select:
            none;

        touch-action:
            manipulation;

    }


    @media (prefers-reduced-motion: reduce) {

        #mascota-ayuda {
            transition: none;
        }

    }
}

@media (max-width: 768px) {
    #mascota-mensaje,
    #mascota-ayuda {
        max-width: calc(46vw - 14px) !important;
    }
}