@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #f5f5f5;
    color: #333;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.main-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

/* This wrapper acts as the coordinate system for the image and mouth */
/* This wrapper acts as the coordinate system for the image and mouth */
#avatar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: transparent;
    /* Fallback */
}

#avatar-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* Removed background-image, it should be an img tag if it's dynamic, 
       but here it is likely a placeholder or the actual video element. 
       If we want a background BEHIND the model, it should be on .main-container or a separate div */
}

/* New Background Layer */
.background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('background.jpg');
    background-size: cover;
    background-position: center;
    z-index: 0;
}


canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Mouth Overlay */
#mouth-overlay {
    position: absolute;
    z-index: 10;
    /* Debug border to see where it is temporarily, remove later */
    /* border: 1px solid red; */

    /* Key for the animation effect: */
    background-repeat: no-repeat;
    background-size: 100% 100%;
    /* Cover the div with the slice */
    transform-origin: top center;
    will-change: transform;
    pointer-events: none;
}

.ui-controls {
    position: absolute;
    bottom: 2vh;
    width: 100%;
    z-index: 200;
    text-align: center;
}

.language-selector {
    display: flex;
    gap: 4vw;
    justify-content: center;
}

.lang-btn {
    background-color: transparent;
    border: none;
    color: white;
    padding: 0;
    width: 15vw;
    height: 15vw;
    max-width: 80px;
    max-height: 80px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    box-shadow: 0 0.5vw 1vw rgba(0, 0, 0, 0.3);
}


#reload-btn {
    background-color: transparent;
    border: none;
    color: white;
    width: 10vw;
    height: 10vw;
    max-width: 50px;
    max-height: 50px;
    cursor: pointer;
    margin-bottom: 0.5vh;
    /* Lowered: Was 3vh, now closer to flags */
    transition: transform 0.5s ease;
    padding: 1vw;

}

#reload-btn svg {
    width: 100%;
    height: 100%;
    stroke: #333;
}

#reload-btn:hover {
    background-color: transparent;
    transform: rotate(-360deg);
    /* Rotate CCW or CW */
}

#mic-btn {
    background-color: rgba(0, 0, 0, 0.3);
    /* Slight background to see if it renders */
    border: 2px solid white;
    border-radius: 50%;
    color: white;
    width: 10vw;
    height: 10vw;
    max-width: 60px;
    max-height: 60px;
    cursor: pointer;
    margin-bottom: 3vh;
    transition: transform 0.2s ease;
    padding: 0;
    /* padding reset */
    display: inline-flex;
    /* flex for centering */
    align-items: center;
    justify-content: center;
}

#mic-btn span {
    font-size: clamp(20px, 5vw, 30px);
    line-height: 1;
}

#mic-btn:hover {
    transform: scale(1.1);
    background-color: rgba(255, 255, 255, 0.2);
}

#mic-btn.listening {
    border-color: #ff4444;
    background-color: rgba(255, 68, 68, 0.2);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.flag-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.lang-btn:hover {
    background-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-0.2vh);
    box-shadow: 0 0.5vh 1.5vh rgba(0, 0, 0, 0.5);
}

.lang-btn:active {
    transform: translateY(0);
}

#status-display {
    margin-top: 1.5vh;
    font-size: 1.6vh;
    opacity: 0.7;
    height: 2vh;
}

.status-hidden {
    visibility: hidden;
}

.logo-corner {
    position: absolute;
    top: 2vh;
    height: 12vw;
    max-height: 80px;
    width: auto;
    z-index: 100;
    opacity: 0.9;
}

.logo-left {
    left: 5vw;
}

.logo-right {
    right: 5vw;
}

#datetime-display {
    position: absolute;
    bottom: 3vh;
    right: 5vw;
    font-size: clamp(14px, 3.5vw, 24px);
    font-weight: 700;
    color: #333;
    opacity: 1;
    text-align: right;
    z-index: 100;
    text-shadow: 0 0.1vh 0.2vh rgba(0, 0, 0, 0.1);
}

.logo-bottom-left {
    position: absolute;
    bottom: 3vh;
    left: 5vw;
    height: 12vw;
    max-height: 80px;
    width: auto;
    z-index: 100;
}

#chat-history {
    position: absolute;
    bottom: 22vh;
    /* Positioned above the lower controls */
    left: 0;
    width: 100%;
    max-height: 45vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    /* Keeps latest messages at the bottom */
    gap: 1.5vh;
    padding: 0 5vw;
    z-index: 40;
    pointer-events: none;
    overflow: hidden;
}

.chat-bubble {
    max-width: 65vw;
    padding: 1.2vh 1.8vw;
    font-size: clamp(14px, 3.8vw, 22px);
    line-height: 1.35;
    animation: bubbleFadeIn 0.4s ease forwards;
    box-shadow: 0 0.5vh 1.5vh rgba(0, 0, 0, 0.2);
    word-wrap: break-word;
}

.bubble-avatar {
    align-self: flex-start;
    background: rgba(58, 58, 58, 0.75);
    backdrop-filter: blur(8px);
    border: 2px solid #000;
    border-radius: 2vh 2vh 2vh 0;
    color: #ffffff;
    font-weight: 500;
}

.bubble-user {
    align-self: flex-end;
    background: rgba(58, 58, 58, 0.75);
    backdrop-filter: blur(8px);
    border: 2px solid #000;
    border-radius: 2vh 2vh 0 2vh;
    color: #ffffff;
}

.chat-bubble.fade-out {
    animation: bubbleFadeOut 2s ease forwards;
}

@keyframes bubbleFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bubbleFadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ── TYPEWRITER LIVE BUBBLE ─────────────────────────────────────── */
.typewriter-live {
    /* Leggero bordo luminoso per segnalare che è in corso */
    border-color: rgba(255, 255, 255, 0.55) !important;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.18), 0 0.5vh 1.5vh rgba(0, 0, 0, 0.2);
    transition: border-color 0.5s ease;
}

/* Cursore a blocco lampeggiante durante il typing */
.tw-cursor {
    display: inline-block;
    color: rgba(255, 255, 255, 0.85);
    animation: twBlink 0.55s step-end infinite;
    margin-left: 1px;
    line-height: 1;
}

@keyframes twBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}
/* ─────────────────────────────────────────────────────────────── */

#subtitles {
    display: none;
    /* No longer used, handled by chat bubbles */
}

/* --- ADMIN UI --- */
.admin-overlay {
    position: absolute;
    top: 5vh;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    padding: 20px;
    border-radius: 10px;
    color: white;
    backdrop-filter: blur(5px);
    max-width: 600px;
    text-align: center;
}

.admin-overlay h2 {
    margin-bottom: 10px;
    font-size: 20px;
}

.admin-overlay p {
    font-size: 14px;
    color: #ddd;
}

.admin-input-container {
    position: absolute;
    bottom: 5vh;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    gap: 10px;
    width: 80%;
    max-width: 800px;
    background: rgba(0, 0, 0, 0.7);
    padding: 15px;
    border-radius: 10px;
    backdrop-filter: blur(5px);
}

#admin-chat-input {
    flex-grow: 1;
    padding: 12px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    background: #333;
    color: white;
}

#admin-chat-input:focus {
    outline: none;
    background: #444;
}

#admin-chat-send {
    padding: 12px 24px;
    background: #1a73e8;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

#admin-chat-send:hover {
    background: #1557b0;
}

#admin-logout {
    padding: 12px 15px;
    background: #cc0000;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
}

#admin-logout:hover {
    background: #990000;
}

/* Mic Button specific to Admin UI */
.admin-input-container #mic-btn {
    position: relative;
    margin: 0;
    padding: 0;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    align-self: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s;
}

.admin-input-container #mic-btn svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    padding: 0;
    display: block;
}

.admin-input-container #mic-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.admin-input-container #mic-btn.listening {
    background: rgba(255, 0, 0, 0.6);
    border-color: #ff0000;
    animation: pulse 1.5s infinite;
}

/* ── IMMAGINE SOCRATE (mobile / fallback) ────────────────────── */
#socrates-img-avatar {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    height: 85vh;
    max-height: 85vh;
    width: auto;
    object-fit: contain;
    z-index: 2;
    pointer-events: none;
    transform-origin: bottom center;
    animation: socratesBreath 4s ease-in-out infinite;
    filter: drop-shadow(0 8px 32px rgba(0,0,0,0.35));
}

@keyframes socratesBreath {
    0%   { transform: translateX(-50%) scale(1.000) translateY(0px); }
    30%  { transform: translateX(-50%) scale(1.008) translateY(-4px); }
    60%  { transform: translateX(-50%) scale(1.003) translateY(-2px); }
    100% { transform: translateX(-50%) scale(1.000) translateY(0px); }
}

@media (max-width: 480px) {
    #socrates-img-avatar {
        height: 78vh;
    }
    #chat-history {
        bottom: 18vh;
        padding: 0 3vw;
    }
    .chat-bubble {
        font-size: clamp(13px, 4vw, 18px);
        max-width: 88vw;
    }
    .ui-controls {
        bottom: 1vh;
    }
    .lang-btn {
        width: 12vw;
        height: 12vw;
    }
    #datetime-display {
        font-size: clamp(11px, 3vw, 16px);
        bottom: 2vh;
    }
}
/* ─────────────────────────────────────────────────────────────── */

/* ── TEXT INPUT BAR ───────────────────────────────────────────── */
#text-input-bar {
    display: flex;
    gap: 8px;
    margin-top: 1.5vh;
    padding: 0 5vw;
    max-width: 500px;
    width: 90%;
    margin-left: auto;
    margin-right: auto;
}

#text-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    font-size: clamp(14px, 3.5vw, 16px);
    font-family: 'Inter', sans-serif;
    background: rgba(58, 58, 58, 0.75);
    backdrop-filter: blur(8px);
    color: #fff;
    outline: none;
    transition: border-color 0.3s;
}

#text-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#text-input:focus {
    border-color: rgba(255, 255, 255, 0.6);
}

#text-send-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: rgba(58, 58, 58, 0.75);
    backdrop-filter: blur(8px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, transform 0.2s;
    flex-shrink: 0;
}

#text-send-btn svg {
    width: 20px;
    height: 20px;
}

#text-send-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

#text-send-btn:active {
    transform: scale(0.95);
}
/* ─────────────────────────────────────────────────────────────── */