:root {
    --primary-color: #4a6fa5;
    --secondary-color: #ff9f1c;
    --accent-color: #2ec4b6;
    --background-color: #f8f9fa;
    --text-color: #333;
    --received-bubble: #e9f5ff;
    --sent-bubble: #d4edda;
    --dark-primary: #3a5a80;
    --modal-bg: white;
    --modal-text: #333;
    --emoji-panel-bg: #f0f2f5;
    --emoji-category-active: #e6e9ed;
}

[data-theme="dark"] {
    --primary-color: #3a5a80;
    --secondary-color: #ff9f1c;
    --accent-color: #2ec4b6;
    --background-color: #2d3748;
    --text-color: #f8f9fa;
    --received-bubble: #4a5568;
    --sent-bubble: #4a6fa5;
    --modal-bg: #2d3748;
    --modal-text: #f8f9fa;
    --emoji-panel-bg: #2a2f32;
    --emoji-category-active: #33383b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* =========================================
   ESTRUCTURA PRINCIPAL (SOLUCIÓN DEL SCROLL)
   ========================================= */

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* ELIMINA EL SCROLL GIGANTE */
    font-family: 'Comic Neue', cursive;
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

.app-container {
    height: 100%; /* Fuerza altura completa */
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column; /* Organiza verticalmente */
    background-color: var(--background-color);
    position: relative;
    padding: 0; /* Controlamos el padding en los hijos */
}

/* HEADER */
header {
    flex-shrink: 0; /* No se aplasta */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 3px solid var(--secondary-color);
    background-color: var(--background-color);
    z-index: 10;
}

/* CONTENEDOR CENTRAL */
.main-content {
    flex: 1; /* Ocupa el espacio restante */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Mantiene todo adentro */
    padding: 10px 20px; /* Margen lateral */
    min-height: 0; /* Truco para Firefox */
}

/* CAJA DEL CHAT */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1; /* Se estira hasta abajo */
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border: 2px solid var(--primary-color);
    overflow: hidden; /* Contiene el historial */
    height: 100%;
}

/* HISTORIAL (ÚNICA ZONA CON SCROLL) */
.chat-history {
    flex: 1; /* Ocupa todo menos el input */
    overflow-y: auto; /* Scroll aquí */
    padding: 20px;
    background-color: var(--background-color);
    scroll-behavior: auto; /* 'auto' es mejor para saltos instantáneos con JS */
    display: flex;
    flex-direction: column;
}

/* ÁREA DE INPUT (FIJA ABAJO) */
.input-area {
    flex-shrink: 0;
    display: flex;
    padding: 10px 15px;
    background-color: white;
    border-top: 1px solid #eee;
    align-items: center;
    gap: 8px;
    z-index: 20;
}

/* =========================================
   ESTILOS VISUALES Y COMPONENTES
   ========================================= */

.logo-container { display: flex; align-items: center; gap: 10px; }
.robot-icon { width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; }
.robot-head { width: 40px; height: 40px; background-color: var(--primary-color); border-radius: 50%; position: relative; display: flex; justify-content: center; align-items: center; }
.robot-eye { width: 8px; height: 8px; background-color: white; border-radius: 50%; position: absolute; top: 15px; }
.left-eye { left: 10px; } .right-eye { right: 10px; }
.robot-mouth { width: 16px; height: 4px; background-color: white; border-radius: 5px; position: absolute; bottom: 10px; }
h1 { font-family: 'Fredoka One', cursive; color: var(--primary-color); font-size: 1.5rem; margin: 0; }

/* Botones del menú superior */
.menu-buttons { display: flex; gap: 8px; }
.menu-buttons button { 
    background-color: var(--primary-color); 
    color: white; 
    border: none; 
    width: 35px; 
    height: 35px; 
    border-radius: 50%; 
    font-size: 1rem; 
    cursor: pointer; 
    transition: transform 0.2s; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}
.menu-buttons button:hover { transform: scale(1.1); background-color: var(--dark-primary); }

/* Botón de voz específico (generado por JS) */
#voice-toggle-btn {
    /* Usa los mismos estilos que los otros botones */
}

/* Mensajes */
.chat-message { display: flex; margin-bottom: 15px; max-width: 85%; animation: bubbleIn 0.3s ease-out; flex-shrink: 0; }
.chat-message.received { align-self: flex-start; }
.chat-message.sent { align-self: flex-end; flex-direction: row-reverse; }

.robot-avatar { width: 32px; height: 32px; background-color: var(--primary-color); color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; margin-right: 8px; font-size: 0.9rem; flex-shrink: 0; }
.sent .robot-avatar { margin-right: 0; margin-left: 8px; background-color: var(--secondary-color); }

.message-content { padding: 10px 14px; border-radius: 15px; font-size: 1rem; line-height: 1.4; word-wrap: break-word; position: relative; }
.received .message-content { background-color: var(--received-bubble); color: var(--text-color); border-bottom-left-radius: 2px; }
.sent .message-content { background-color: var(--sent-bubble); color: var(--text-color); border-bottom-right-radius: 2px; }

/* Animaciones */
@keyframes robotTalk { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.robot-icon.talking .robot-head { animation: robotTalk 0.5s infinite; }
@keyframes bubbleIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Input y Botones inferiores */
.input-area textarea {
    flex-grow: 1;
    padding: 10px;
    border: 2px solid var(--primary-color);
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    height: 45px;
    max-height: 100px;
    outline: none;
    transition: border-color 0.3s;
}
.input-area textarea:focus { border-color: var(--accent-color); }

.input-area button {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.input-area button:hover { transform: scale(1.05); }

#mic-btn { background-color: var(--accent-color); }
#image-btn { background-color: var(--secondary-color); }

/* Modales */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 2000; }
.modal-content { background-color: var(--modal-bg); color: var(--modal-text); padding: 25px; border-radius: 15px; width: 90%; max-width: 450px; max-height: 80vh; overflow-y: auto; position: relative; border: 3px solid var(--accent-color); }
.close-modal { position: absolute; top: 10px; right: 10px; border: none; background: none; font-size: 1.5rem; cursor: pointer; color: var(--modal-text); }
.hidden { display: none !important; }

/* Contenido de Ayuda */
.help-content { display: flex; flex-direction: column; gap: 15px; margin-top: 15px; }
.help-item { display: flex; align-items: center; gap: 15px; }
.help-item i { font-size: 1.5rem; color: var(--accent-color); min-width: 30px; text-align: center; }
.modal h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; color: var(--primary-color); }

/* Juegos */
.games-container { display: flex; flex-wrap: wrap; gap: 15px; justify-content: center; margin-top: 15px; }
.game-card { background: #fff; padding: 15px; border-radius: 10px; text-align: center; cursor: pointer; width: 45%; box-shadow: 0 2px 5px rgba(0,0,0,0.1); border: 1px solid #eee; transition: transform 0.2s; }
.game-card:hover { transform: translateY(-3px); box-shadow: 0 5px 10px rgba(0,0,0,0.15); }
.game-icon { font-size: 2rem; color: var(--primary-color); margin-bottom: 10px; }
.game-card h3 { font-size: 1rem; margin: 5px 0; color: #333; }
.game-card p { font-size: 0.8rem; color: #666; }

/* Responsive */
@media (max-width: 480px) {
    .app-container { max-width: 100%; }
    header { padding: 5px 10px; }
    h1 { font-size: 1.2rem; }
    .main-content { padding: 5px; }
    .chat-container { border-radius: 10px; border-width: 1px; }
    .input-area { padding: 5px 10px; gap: 5px; }
    .input-area button { width: 38px; height: 38px; font-size: 1rem; }
    .menu-buttons button { width: 30px; height: 30px; font-size: 0.9rem; }
}
#image-btn, #image-upload { display: none !important; }


/* ========================================================
   REPRODUCTOR FLOTANTE DE JUEGOS EN CHAT CON BOTÓN CERRAR
   ======================================================== */
.game-player-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(15, 23, 42, 0.85) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
    z-index: 999999 !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    padding: 15px !important;
    box-sizing: border-box !important;
}

.game-player-window {
    background: #ffffff !important;
    width: 920px !important;
    max-width: 98vw !important;
    height: 660px !important;
    max-height: 94vh !important;
    border-radius: 18px !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.45) !important;
    border: 3px solid #4361ee !important;
}

.game-player-header {
    background: #4361ee !important;
    color: #ffffff !important;
    padding: 12px 18px !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    border-bottom: 2px solid #3a0ca3 !important;
    flex-shrink: 0 !important;
}

.game-player-title {
    font-size: 16px !important;
    font-weight: 700 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    color: #ffffff !important;
}

.game-player-actions {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

.gp-btn {
    border: none !important;
    border-radius: 10px !important;
    padding: 6px 12px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    transition: all 0.2s ease !important;
    text-decoration: none !important;
    outline: none !important;
}

.gp-btn-back, .gp-btn-reload, .gp-btn-fullscreen {
    background: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}
.gp-btn-back:hover, .gp-btn-reload:hover, .gp-btn-fullscreen:hover {
    background: rgba(255, 255, 255, 0.35) !important;
}

.gp-btn-close {
    background: #ef4444 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4) !important;
}
.gp-btn-close:hover {
    background: #dc2626 !important;
    transform: scale(1.05) !important;
}

.game-player-body {
    flex: 1 !important;
    width: 100% !important;
    height: 100% !important;
    background: #000000 !important;
    position: relative !important;
}

.game-player-body iframe {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    display: block !important;
}

@media (max-width: 600px) {
    .game-player-window {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    .game-player-title span {
        display: none !important;
    }
}