/*
   ==========================================================================
   CHESHIRE CAT — Avatar
   Technique: pure black + layered box-shadow glow (no filters on the face)
   ==========================================================================
*/

/* ─── tokens ─────────────────────────────────────────────────────────────── */
:root {
    --eye-green: #00e676;
    /* mid green, punchy */
    --eye-glow-1: rgba(0, 230, 118, 0.9);
    --eye-glow-2: rgba(0, 200, 100, 0.55);
    --eye-glow-3: rgba(0, 170, 80, 0.25);
    --eye-glow-4: rgba(0, 140, 60, 0.10);

    --tooth-top: #efecdf;
    --tooth-mid: #d0cdc3;
    --tooth-bottom: #b8b5ab;

    --mouth-bg: #142e1a;
    /* green-tinted inner darkness */

    --state-idle: #00e676;
    --state-listening: #00e676;
    /* Forced green per user request */
    --state-thinking: #00e676;
    /* Forced green per user request */
    --state-speaking: #00e676;
    /* Forced green per user request */
    --state-error: #00e676;
    /* Forced green per user request */

    /* Responsive scaling token */
    --avatar-scale: 1;
}

@media (max-width: 768px) {
    :root {
        --avatar-scale: 0.8;
    }
}

@media (max-width: 480px) {
    :root {
        --avatar-scale: 0.65;
    }
}

/* ─── page / background ──────────────────────────────────────────────────── */
/* Quasar/NiceGUI sets a body/html bg — nuke it globally */
html,
body,
.q-app,
.q-layout,
.q-page-container,
.q-page {
    background: #000 !important;
    margin: 0;
    padding: 0;
}

.cheshire-background {
    /* pure black is non-negotiable for glow to read */
    background: #000 !important;
}

/* kill every pseudo / overlay that NiceGUI or Tailwind might add */
.cheshire-background::before,
.cheshire-background::after {
    display: none !important;
}

/* Hide NiceGUI error popups — avatar stays green, errors are silent */
.nicegui-error-popup {
    display: none !important;
}

/* Kill scrollbar — full-bleed black */
html,
body,
.q-app {
    overflow: hidden !important;
}

::-webkit-scrollbar {
    display: none;
}

* {
    scrollbar-width: none;
}

/* ─── particle canvas (behind everything, no pointer) ───────────────────── */
.particle-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
    opacity: 0.45;
    /* subtle — background, not foreground */
}

/* ─── avatar wrapper ─────────────────────────────────────────────────────── */
.avatar-container {
    position: relative;
    width: 520px;
    height: 460px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    user-select: none;
    /* single gentle float — no rotation, no scale jitter */
    animation: float 8s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

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

/* ─── face layout ────────────────────────────────────────────────────────── */
.avatar-face {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* gap between eyes row and mouth */
    gap: 40px;
    transform: scale(var(--avatar-scale));
    transform-origin: center center;
    transition: transform 0.3s ease;
}

/* ─── EYES ───────────────────────────────────────────────────────────────── */
/*
   Each .eye is an almond/oval filled with the green.
   The ENTIRE visible glow comes from layered box-shadow.
   No filter, no pseudo-element glow layer — keeps it crisp.
*/
.avatar-eyes {
    display: flex;
    gap: 70px;
    /* closer together — matches reference */
    align-items: center;
}

.eye {
    position: relative;
    /* almond shape: taller than wide, pointed at top & bottom */
    width: 90px;
    height: 105px;
    /* the actual green fill */
    background:
        radial-gradient(ellipse at 42% 38%,
            rgba(255, 255, 255, 0.18) 0%,
            /* tiny highlight */
            transparent 12%),
        radial-gradient(ellipse at 50% 50%,
            #00ff88 0%,
            var(--eye-green) 40%,
            #00a855 70%,
            #005530 100%);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    overflow: hidden;
    /* clip the pupil */

    /* THE glow — 4 layers, each bigger & softer */
    box-shadow:
        0 0 18px 6px var(--eye-glow-1),
        0 0 50px 18px var(--eye-glow-2),
        0 0 100px 40px var(--eye-glow-3),
        0 0 180px 70px var(--eye-glow-4);

    /* smooth state transitions on box-shadow */
    transition: box-shadow 0.6s ease, background 0.6s ease;
}

/* ── pupil (vertical slit) ── */
.pupil {
    position: absolute;
    width: 11px;
    height: 58px;
    background: #000;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* very faint inner glow so the slit doesn't look pasted */
    box-shadow: 0 0 8px 3px rgba(0, 0, 0, 0.7);
    /* eye-tracking will override transform via JS */
    transition: width 0.3s ease, height 0.3s ease;
}

/* ── reflections (pure white dots, z on top) ── */
.eye-reflection-primary {
    position: absolute;
    width: 20px;
    height: 13px;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 50%;
    top: 18%;
    left: 22%;
    transform: rotate(-20deg);
    z-index: 2;
    pointer-events: none;
}

.eye-reflection-secondary {
    position: absolute;
    width: 9px;
    height: 9px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    bottom: 24%;
    right: 24%;
    z-index: 2;
    pointer-events: none;
}

/* ── blink (JS adds .blink to .avatar-face) ── */
.avatar-face.blink .eye {
    height: 4px;
    border-radius: 50%;
    box-shadow: none;
    /* kill glow during blink */
    background: #000;
    transition: height 0.1s ease, border-radius 0.1s ease;
}

.avatar-face.blink .pupil,
.avatar-face.blink .eye-reflection-primary,
.avatar-face.blink .eye-reflection-secondary {
    opacity: 0;
}

/* ─── NOSE (barely there) ────────────────────────────────────────────────── */
.avatar-nose {
    position: absolute;
    /* sits between eyes and mouth */
    top: 38px;
    width: 10px;
    height: 6px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    filter: blur(2px);
    pointer-events: none;
}

/* ─── WHISKERS ───────────────────────────────────────────────────────────── */
.whiskers {
    position: absolute;
    top: 30px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    pointer-events: none;
}

.left-whiskers {
    right: calc(50% + 50px);
}

.right-whiskers {
    left: calc(50% + 50px);
}

.whisker {
    height: 1px;
    background: linear-gradient(var(--dir), rgba(0, 230, 118, 0.25), transparent);
    transition: opacity 0.4s ease;
}

.left-whiskers .whisker {
    --dir: to left;
    width: 130px;
}

.right-whiskers .whisker {
    --dir: to right;
    width: 130px;
}

.whisker:nth-child(1) {
    width: 110px;
    transform: rotate(12deg);
}

.whisker:nth-child(2) {
    width: 140px;
}

.whisker:nth-child(3) {
    width: 110px;
    transform: rotate(-12deg);
}

/* ─── SMILE (SVG crescent + triangular teeth) ───────────────────────────── */
.avatar-mouth {
    position: relative;
    width: 440px;
}

.cheshire-smile {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
    /* let shadow bleed */
}

/* speaking: lower jaw bobs */
.avatar-container.speaking .lower-teeth {
    animation: jawMove 0.18s ease-in-out infinite alternate;
}

@keyframes jawMove {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(3px);
    }
}

/* ── mouth glow (soft green under the smile) ── */
.mouth-glow {
    position: absolute;
    bottom: -18px;
    left: -8%;
    width: 116%;
    height: 50px;
    background: radial-gradient(ellipse at center,
            rgba(0, 230, 118, 0.28) 0%,
            rgba(0, 200, 100, 0.10) 40%,
            transparent 70%);
    filter: blur(18px);
    pointer-events: none;
}

/* ─── LABEL ──────────────────────────────────────────────────────────────── */
.avatar-info {
    margin-top: 36px;
    opacity: 0.35;
    transition: opacity 0.4s;
}

.avatar-container:hover .avatar-info {
    opacity: 0.8;
}

.avatar-name {
    color: #fff;
    font-size: 0.85rem;
    font-weight: 300;
    letter-spacing: 6px;
    text-transform: uppercase;
    text-shadow: 0 0 12px rgba(0, 230, 118, 0.4);
}

/* ─── MESSAGE BUBBLE ─────────────────────────────────────────────────────── */
.avatar-message {
    position: absolute;
    bottom: -75px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    max-width: 560px;
    width: max-content;
    padding: 16px 28px;
    border: none;
    background: transparent;
    box-shadow: none;
    color: #d4f5ec;
    color: #d4f5ec;
    font-size: 17px;
    line-height: 1.55;
    text-align: center;

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.7s cubic-bezier(.4, 0, .2, 1),
        transform 0.7s cubic-bezier(.4, 0, .2, 1);
    z-index: 10;
}

.avatar-message.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.avatar-message.fade-out {
    opacity: 0;
    transform: translateX(-50%) translateY(-8px);
    transition-duration: 0.4s;
}

/* typing cursor */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--eye-green);
    margin-left: 3px;
    vertical-align: middle;
    animation: blink-cursor 0.8s step-end infinite;
}

@keyframes blink-cursor {

    0%,
    49% {
        opacity: 1;
    }

    50%,
    100% {
        opacity: 0;
    }
}

/* ─── STATE OVERRIDES ────────────────────────────────────────────────────── */

/* listening — eyes widen, pupils dilate, cyan tint */
.avatar-container.listening .eye {
    --eye-green: var(--state-listening);
    box-shadow:
        0 0 18px 6px rgba(0, 229, 255, 0.9),
        0 0 50px 18px rgba(0, 229, 255, 0.55),
        0 0 100px 40px rgba(0, 229, 255, 0.25),
        0 0 180px 70px rgba(0, 229, 255, 0.10);
    background:
        radial-gradient(ellipse at 42% 38%, rgba(255, 255, 255, 0.18) 0%, transparent 12%),
        radial-gradient(ellipse at 50% 50%, #00ffff 0%, #00bcd4 40%, #0088aa 70%, #004455 100%);
}

.avatar-container.listening .pupil {
    width: 28px;
    /* round, alert pupil */
}

/* thinking — amber */
.avatar-container.thinking .eye {
    box-shadow:
        0 0 18px 6px rgba(255, 202, 40, 0.9),
        0 0 50px 18px rgba(255, 202, 40, 0.55),
        0 0 100px 40px rgba(255, 202, 40, 0.25),
        0 0 180px 70px rgba(255, 202, 40, 0.10);
    background:
        radial-gradient(ellipse at 42% 38%, rgba(255, 255, 255, 0.18) 0%, transparent 12%),
        radial-gradient(ellipse at 50% 50%, #ffe082 0%, #ffca28 40%, #f9a825 70%, #f57f17 100%);
    animation: thinkLook 2.4s ease-in-out infinite alternate;
}

@keyframes thinkLook {
    from {
        transform: translateX(-6px);
    }

    to {
        transform: translateX(6px);
    }
}

/* speaking — blue, teeth bounce gently */
.avatar-container.speaking .eye {
    box-shadow:
        0 0 18px 6px rgba(68, 138, 255, 0.9),
        0 0 50px 18px rgba(68, 138, 255, 0.55),
        0 0 100px 40px rgba(68, 138, 255, 0.25),
        0 0 180px 70px rgba(68, 138, 255, 0.10);
    background:
        radial-gradient(ellipse at 42% 38%, rgba(255, 255, 255, 0.18) 0%, transparent 12%),
        radial-gradient(ellipse at 50% 50%, #90caf9 0%, #448aff 40%, #1565c0 70%, #0d47a1 100%);
}

/* speaking jaw bob moved to SMILE section above */
.avatar-container.speaking .whisker {
    animation: whiskerPulse 0.18s ease-in-out infinite alternate;
}

@keyframes whiskerPulse {
    from {
        opacity: 0.25;
    }

    to {
        opacity: 0.7;
    }
}

/* error — red shake */
.avatar-container.error .eye {
    box-shadow:
        0 0 18px 6px rgba(255, 82, 82, 0.9),
        0 0 50px 18px rgba(255, 82, 82, 0.55),
        0 0 100px 40px rgba(255, 82, 82, 0.25),
        0 0 180px 70px rgba(255, 82, 82, 0.10);
    background:
        radial-gradient(ellipse at 42% 38%, rgba(255, 255, 255, 0.18) 0%, transparent 12%),
        radial-gradient(ellipse at 50% 50%, #ef5350 0%, #ff5252 40%, #c62828 70%, #6e0000 100%);
}

.avatar-container.error {
    animation: shake 0.25s ease-in-out 3;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-7px);
    }

    75% {
        transform: translateX(7px);
    }
}

/* ─── CHESHIRE FADE (idle timeout) ───────────────────────────────────────── */
.avatar-container.fading {
    animation: cheshireFade 3.5s ease-out forwards;
}

.avatar-container.fading .avatar-eyes,
.avatar-container.fading .avatar-nose,
.avatar-container.fading .whiskers {
    animation: vanish 2s ease-out forwards;
}

.avatar-container.fading .avatar-mouth {
    animation: vanish 4s ease-out forwards;
}

@keyframes cheshireFade {
    to {
        opacity: 0.12;
        filter: blur(6px);
    }
}

@keyframes vanish {
    to {
        opacity: 0;
    }
}

.avatar-container.fading-in {
    animation: cheshireFadeIn 2s ease-out forwards;
}

@keyframes cheshireFadeIn {
    from {
        opacity: 0.12;
        filter: blur(6px);
    }

    to {
        opacity: 1;
        filter: blur(0);
    }
}

/* ─── NiceGUI button z-index fix ─────────────────────────────────────────── */
/* ensure the button row (rendered by NiceGUI) sits above canvas & vignette */
/* ─── ETHEREAL COMMUNICATION ─────────────────────────────────────────────── */

.ethereal-text {
    font-family: 'Inter', sans-serif;
    /* Or a more mystical font if available */
    font-weight: 300;
    letter-spacing: 1px;
    text-align: center;
    opacity: 0;
    /* Start hidden */
    max-width: 80%;
    margin: 0 auto;
    text-shadow: 0 0 10px currentColor;
    pointer-events: none;
    /* Let clicks pass through ghost text */
}

/* Cycle: Appear (3s) -> Stay (4s) -> Disappear (3s) */
.ethereal-cycle {
    animation: etherealCycle 10s ease-in-out forwards;
}

@keyframes etherealCycle {
    0% {
        opacity: 0;
        filter: blur(8px);
        transform: translateY(10px) scale(0.95);
    }

    30% {
        opacity: 1;
        filter: blur(0px);
        transform: translateY(0) scale(1);
    }

    70% {
        opacity: 1;
        filter: blur(0px);
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 0;
        filter: blur(12px);
        transform: translateY(-10px) scale(1.05);
    }
}

/* User: Blue/Cyan Glow */
.ethereal-text-user {
    color: #00e5ff;
    text-shadow:
        0 0 10px rgba(0, 229, 255, 0.6),
        0 0 20px rgba(0, 229, 255, 0.4),
        0 0 40px rgba(0, 229, 255, 0.2);
}

/* Bot: Green Glow */
.ethereal-text-bot {
    color: #00e676;
    text-shadow:
        0 0 10px rgba(0, 230, 118, 0.6),
        0 0 20px rgba(0, 230, 118, 0.4),
        0 0 40px rgba(0, 230, 118, 0.2);
}

/* Smoky Input Container */
.smoky-input-container {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 0 20px rgba(0, 229, 255, 0.1),
        inset 0 0 20px rgba(0, 229, 255, 0.05);
    backdrop-filter: blur(5px);
    border-radius: 50px;
    /* Pill shape */
    transition: all 0.4s ease;
}

.smoky-input-container:focus-within {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(0, 229, 255, 0.4);
    box-shadow:
        0 0 30px rgba(0, 229, 255, 0.2),
        inset 0 0 30px rgba(0, 229, 255, 0.1);
}

/* ─── SMOKY MESSAGE EFFECT ───────────────────────────────────────────────── */
/* Enhanced smoke/mist effect around text */
.smoky-message {
    position: relative;
    padding: 12px 20px;
    display: inline-block;
    width: 100%;
}

/* Smoke haze behind text */
.smoky-message::before {
    content: '';
    position: absolute;
    inset: -20px -40px;
    background: radial-gradient(ellipse at center,
            rgba(0, 229, 255, 0.15) 0%,
            rgba(0, 229, 255, 0.05) 40%,
            transparent 70%);
    filter: blur(20px);
    z-index: -1;
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
}

.smoky-message.ethereal-cycle::before {
    animation: smokeHaze 10s ease-in-out forwards;
}

/* Bot message uses green smoke */
.smoky-message.ethereal-text-bot::before {
    background: radial-gradient(ellipse at center,
            rgba(0, 230, 118, 0.18) 0%,
            rgba(0, 230, 118, 0.06) 40%,
            transparent 70%);
}

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

    20% {
        opacity: 1;
        transform: scale(1.1);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }

    80% {
        opacity: 0.6;
        transform: scale(1.15);
    }

    100% {
        opacity: 0;
        transform: scale(1.3);
    }
}

/* Stronger text glow for both */
.ethereal-text-user.smoky-message {
    text-shadow:
        0 0 8px rgba(0, 229, 255, 0.9),
        0 0 16px rgba(0, 229, 255, 0.7),
        0 0 32px rgba(0, 229, 255, 0.5),
        0 0 64px rgba(0, 229, 255, 0.3);
}

.ethereal-text-bot.smoky-message {
    text-shadow:
        0 0 8px rgba(0, 230, 118, 0.9),
        0 0 16px rgba(0, 230, 118, 0.7),
        0 0 32px rgba(0, 230, 118, 0.5),
        0 0 64px rgba(0, 230, 118, 0.3);
}

/* ─── TEXT OVERLAY SYSTEM ────────────────────────────────────────────────── */
/* Contenedor de texto superpuesto sobre el gato */
.text-overlay-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: 80%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    pointer-events: none;
}

/* Mensajes con posición fija que no afectan al layout */
.overlay-message {
    position: relative;
    width: 100%;
    text-align: center;
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    transition:
        opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.8s cubic-bezier(0.4, 0, 0.2, 1),
        filter 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    filter: blur(4px);
}

.overlay-message.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
    pointer-events: auto;
}

.overlay-message.fade-out {
    opacity: 0;
    transform: translateY(-10px) scale(1.02);
    filter: blur(8px);
}

/* ─── CAT FADE WHEN TEXT VISIBLE ─────────────────────────────────────────── */
/* Estado cuando hay texto visible - el gato se difumina */
.avatar-container.text-visible .avatar-face {
    opacity: 0.15;
    filter: blur(8px);
    transform: scale(0.95);
    transition:
        opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1),
        filter 1.2s cubic-bezier(0.4, 0, 0.2, 1),
        transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.avatar-container.text-visible .avatar-info {
    opacity: 0 !important;
    transition: opacity 0.8s ease;
}

/* Transición de vuelta cuando el texto desaparece */
.avatar-container:not(.text-visible) .avatar-face {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
    transition:
        opacity 1.5s cubic-bezier(0.4, 0, 0.2, 1) 0.3s,
        filter 1.5s cubic-bezier(0.4, 0, 0.2, 1) 0.3s,
        transform 1.5s cubic-bezier(0.4, 0, 0.2, 1) 0.3s;
}

.avatar-container:not(.text-visible) .avatar-info {
    transition: opacity 0.8s ease 0.5s;
}

/* Reducir las partículas cuando hay texto */
.text-visible~.particle-canvas,
body.text-visible .particle-canvas {
    opacity: 0.2 !important;
    transition: opacity 1s ease;
}

/* ─── IMPROVED ETHEREAL TEXT ─────────────────────────────────────────────── */
/* Texto etéreo mejorado para overlay */
.ethereal-text.overlay {
    font-size: 22px;
    line-height: 1.6;
    letter-spacing: 0.5px;
    padding: 16px 24px;
    max-width: 100%;
    word-wrap: break-word;
}

.ethereal-text-user.overlay {
    color: #00e5ff;
    font-size: 18px;
    text-shadow:
        0 0 12px rgba(0, 229, 255, 0.8),
        0 0 24px rgba(0, 229, 255, 0.5),
        0 0 48px rgba(0, 229, 255, 0.3);
}

.ethereal-text-bot.overlay {
    color: #00e676;
    font-size: 22px;
    text-shadow:
        0 0 12px rgba(0, 230, 118, 0.8),
        0 0 24px rgba(0, 230, 118, 0.5),
        0 0 48px rgba(0, 230, 118, 0.3);
}

/* Efecto de humo detrás del texto overlay */
.overlay-message::before {
    content: '';
    position: absolute;
    inset: -30px -50px;
    background: radial-gradient(ellipse at center,
            rgba(0, 0, 0, 0.6) 0%,
            rgba(0, 0, 0, 0.3) 50%,
            transparent 70%);
    filter: blur(30px);
    z-index: -1;
    opacity: 0;
    transition: opacity 0.8s ease;
    border-radius: 50%;
}

.overlay-message.visible::before {
    opacity: 1;
}

/* ─── LAYOUT FIX: Input always at same position ──────────────────────────── */
/* El contenedor del chat no debe cambiar de tamaño */
.chat-input-fixed {
    position: fixed !important;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    z-index: 200;
}

/* Botones de control también fijos */
.control-buttons-fixed {
    position: fixed !important;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
}

/* Accessibility: Support prefers-reduced-motion to pause or slow down animations */
@media (prefers-reduced-motion: reduce) {
    .avatar-container {
        animation: none !important;
    }
    .avatar-container.speaking .lower-teeth,
    .avatar-container.thinking .eye,
    .avatar-container.error,
    .avatar-container.fading,
    .avatar-container.fading .avatar-eyes,
    .avatar-container.fading .avatar-nose,
    .avatar-container.fading .whiskers,
    .avatar-container.fading .avatar-mouth,
    .avatar-container.fading-in,
    .avatar-container.speaking .whisker {
        animation: none !important;
        transition: none !important;
    }
}