/* =======================================================
   1. VARIABLES DE COLOR (PALETA VIBRANTE PARA NIÑOS)
   ======================================================= */
:root {
    /* Colores primarios (más vibrantes) */
    --primary: #FF6F61; /* Rojo Coral / Amigable */
    --primary-dark: #E65A51;
    --secondary: #00BCD4; /* Turquesa Brillante */
    --secondary-dark: #00ACC1;
    --tertiary: #FFD23F; /* Amarillo Juguetón */
    --tertiary-dark: #FFC300;
    
    /* Colores neutros y de feedback */
    --background-app: #F5F7FA; /* Fondo claro de la app */
    --light: #FFFFFF;
    --dark: #333333;
    --text: #4A4A4A;
    --success: #4CAF50; /* Verde */
    --error: #F44336; /* Rojo */
    
    /* Bordes y sombras */
    --radius-l: 20px;
    --radius-m: 12px;
    --shadow-light: 0 4px 15px rgba(0, 0, 0, 0.1);
    --shadow-deep: 0 8px 25px rgba(0, 0, 0, 0.2);
    --shadow-btn: 0 6px 0 rgba(0, 0, 0, 0.2);
    --shadow-btn-dark: 0 6px 0 var(--primary-dark);
}

/* =======================================================
   2. REINICIO BÁSICO Y TIPOGRAFÍA
   ======================================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--background-app);
    color: var(--text);
    line-height: 1.6;
    padding: 10px;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

/* Contenedor principal para centrar la app */
.container {
    max-width: 600px;
    width: 100%;
    background: var(--light);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-deep);
    padding: 20px;
    margin: 10px auto;
}

h1, h2 {
    color: var(--primary-dark);
    margin-bottom: 10px;
    text-align: center;
}

h2 {
    font-size: 1.8rem;
    color: var(--secondary-dark);
}

p {
    margin-bottom: 15px;
}

/* =======================================================
   3. BOTONES GENERALES
   ======================================================= */
.btn {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin-bottom: 15px;
    border: none;
    border-radius: var(--radius-m);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease-in-out;
    position: relative;
    top: 0;
    text-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

.btn:active {
    top: 4px;
    box-shadow: 0 2px 0 var(--shadow-btn-dark);
}

/* Estilos de botones */
.btn-primary {
    background-color: var(--primary);
    color: var(--light);
    box-shadow: var(--shadow-btn-dark);
}
.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--secondary);
    color: var(--light);
    box-shadow: 0 6px 0 var(--secondary-dark);
}
.btn-secondary:hover {
    background-color: var(--secondary-dark);
}

.btn-tertiary {
    background-color: var(--tertiary);
    color: var(--dark);
    box-shadow: 0 6px 0 var(--tertiary-dark);
}
.btn-tertiary:hover {
    background-color: var(--tertiary-dark);
}

.btn-dark {
    background-color: var(--dark);
    color: var(--light);
    box-shadow: 0 6px 0 #111;
}
.btn-dark:hover {
    background-color: #111;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    text-decoration: underline;
    display: inline;
    width: auto;
    padding: 5px 0;
    margin: 10px 0;
    font-size: 0.9rem;
    font-weight: normal;
    box-shadow: none;
    top: 0;
}
.btn-link:active {
    top: 0;
    color: var(--primary-dark);
    text-shadow: none;
}

.btn-icon {
    background: var(--tertiary);
    color: var(--dark);
    padding: 8px 12px;
    display: inline-block;
    width: auto;
    margin-left: 10px;
    box-shadow: 0 4px 0 var(--tertiary-dark);
}
.btn-icon:active {
    top: 2px;
    box-shadow: 0 2px 0 var(--tertiary-dark);
}

/* Botones pequeños para listas */
.btn-small {
    padding: 5px 10px;
    width: auto;
    display: inline-block;
    margin-bottom: 0;
    font-size: 0.85rem;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}
.btn-small:active {
    top: 2px;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

/* Deshabilitado */
.btn:disabled {
    background-color: #ccc;
    box-shadow: 0 4px 0 #999;
    cursor: not-allowed;
    top: 0;
}
.btn:disabled:active {
    box-shadow: 0 4px 0 #999;
    top: 0;
}

/* =======================================================
   4. LAYOUTS PRINCIPALES
   ======================================================= */
.main-section {
    padding: 10px 0;
    margin-bottom: 20px;
}

.menu-grid, .category-grid, .options-grid {
    display: grid;
    gap: 15px;
    margin-top: 20px;
}

/* Estilo para las Tarjetas del Menú Principal (NUEVO) */
.menu-card-grid {
    grid-template-columns: 1fr; /* Una columna por defecto */
    gap: 15px;
}
@media (min-width: 450px) {
    .menu-card-grid {
        grid-template-columns: 1fr 1fr; /* Dos columnas en pantallas medianas */
    }
}

.main-menu-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Alineación a la izquierda */
    text-align: left;
    height: 120px; /* Altura fija para consistencia */
    padding: 15px;
    margin-bottom: 0;
    
    background-color: var(--light);
    border: 3px solid var(--primary); /* Borde por defecto */
    box-shadow: 0 6px 0 var(--primary-dark); 
    transition: transform 0.2s, box-shadow 0.2s;
    color: var(--dark);
}

.main-menu-card:active {
    top: 4px;
    box-shadow: 0 2px 0 var(--primary-dark);
}

.main-menu-card .icon-xl {
    font-size: 2rem; /* Icono grande */
    margin-bottom: 5px;
}

.main-menu-card .card-title {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--dark);
    margin-bottom: 2px;
}

.main-menu-card .card-description {
    font-size: 0.85rem;
    font-weight: normal;
    color: #777;
    width: 100%;
}

/* Colores Distintivos para cada Tarjeta de Menú */
.main-menu-card.card-ia {
    border-color: var(--primary);
    box-shadow: 0 6px 0 var(--primary-dark);
}
.main-menu-card.card-saved {
    border-color: var(--secondary);
    box-shadow: 0 6px 0 var(--secondary-dark);
}
.main-menu-card.card-memory {
    border-color: var(--tertiary);
    box-shadow: 0 6px 0 var(--tertiary-dark);
}
.main-menu-card.card-master {
    border-color: var(--dark);
    box-shadow: 0 6px 0 #111;
}

/* --- ESTILO DE TARJETA DE CATEGORÍA (MANTENIDO) --- */
.category-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
}
.category-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 140px; 
    background-color: var(--light);
    color: var(--dark);
    border: 3px solid var(--secondary);
    box-shadow: 0 8px 0 var(--secondary-dark); 
    padding: 10px;
    margin-bottom: 0;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
}
.category-card:hover {
    background-color: #e0f7fa; 
}
.category-card:active {
    top: 4px;
    box-shadow: 0 4px 0 var(--secondary-dark);
}
.category-card .icon-lg {
    font-size: 3rem;
    margin-bottom: 5px;
}
.category-card .card-text {
    font-weight: bold;
    font-size: 0.9rem;
    line-height: 1.2;
}
.category-card.btn {
    width: auto;
}
/* ----------------------------------------------- */

.action-buttons-group {
    display: flex;
    justify-content: space-around;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
}
.action-buttons-group .btn {
    flex-grow: 1;
    margin-bottom: 0;
}

/* =======================================================
   5. CABECERA Y AVATAR (MASCOTA DINÁMICA)
   ======================================================= */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--secondary);
}

.yakdiel-avatar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-status-text {
    font-size: 0.9rem;
    color: var(--secondary-dark);
    margin: 0;
}

.avatar-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--primary);
    color: var(--light);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    box-shadow: var(--shadow-light);
    transition: background-color 0.3s, transform 0.3s;
    animation: none; 
}

/* Estados Dinámicos de la Mascota */
.avatar-circle.pulse {
    animation: pulse 1.5s infinite;
}
.avatar-circle.happy {
    background-color: var(--success);
    transform: rotate(10deg);
}
.avatar-circle.sad {
    background-color: var(--error);
    transform: rotate(-10deg);
}
.avatar-circle.thinking {
    background-color: var(--tertiary);
    animation: bounce 0.5s infinite alternate;
}

/* =======================================================
   6. QUIZ: PREGUNTA Y OPCIONES
   ======================================================= */
.topic-header {
    font-size: 1.5rem;
    color: var(--dark);
    margin-bottom: 5px;
}
.question-counter {
    font-style: italic;
    color: var(--secondary-dark);
    margin-bottom: 15px;
    text-align: center;
}

.question-box {
    background: var(--secondary);
    color: var(--light);
    padding: 20px;
    border-radius: var(--radius-m);
    margin-bottom: 20px;
    box-shadow: var(--shadow-light);
    position: relative; 
    padding-right: 70px; /* Deja espacio para el botón de voz */
}
.question-box p {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 0;
    display: block; 
}

/* Estilo del botón de voz flotante */
.btn-speak {
    position: absolute; 
    top: 10px;
    right: 10px;
    margin: 0;
    padding: 8px 12px;
    font-size: 0.8rem;
    box-shadow: 0 4px 0 var(--tertiary-dark);
}
.btn-speak:active {
    top: 12px;
}

/* Estilo de las opciones de respuesta (MEJORADO) */
.option-btn {
    width: 100%;
    text-align: left;
    white-space: normal;
    height: auto;
    min-height: 60px; /* Altura aumentada */
    padding: 15px 20px;
    background-color: var(--light);
    color: var(--dark);
    border: 2px solid var(--secondary); 
    box-shadow: 0 6px 0 var(--secondary-dark);
    transition: all 0.1s ease-in-out;
}
.option-btn:not(:disabled):hover {
    background-color: #e3f2fd; 
}
.option-btn:not(:disabled):active {
    top: 4px;
    box-shadow: 0 2px 0 var(--secondary-dark);
}

/* ESTILOS DE FEEDBACK */
.option-btn.btn-success {
    background-color: var(--success);
    border-color: #388e3c;
    color: var(--light);
    box-shadow: 0 6px 0 #2e7d32; 
    position: relative;
    top: 0;
}
.option-btn.btn-error {
    background-color: var(--error);
    border-color: #d32f2f;
    color: var(--light);
    box-shadow: 0 6px 0 #b71c1c; 
    position: relative;
    top: 0;
}

.feedback-text {
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 15px;
    margin-top: 15px;
    border-radius: var(--radius-m);
    background-color: #e0f2f1; 
    color: var(--dark);
    min-height: 50px; 
}
.feedback-icon {
    margin-right: 5px;
    font-size: 1.5rem;
}
#nextQuestionBtn {
    margin-top: 20px;
}

/* =======================================================
   7. SECCIONES GENERALES (INPUTS DE LOGIN)
   ======================================================= */
.input-group {
    margin-bottom: 20px;
}
#topicField, #usernameField, #passwordField, #masterKeyField {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: var(--radius-m);
    font-size: 1rem;
    transition: border-color 0.2s;
}
#topicField:focus, #usernameField:focus, #passwordField:focus, #masterKeyField:focus {
    border-color: var(--primary);
    outline: none;
}
.error-feedback {
    color: var(--error);
    font-weight: bold;
    margin-top: 5px;
    text-align: center;
}
.section-subtitle {
    text-align: center;
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 20px;
}

/* Clase de feedback de éxito para Auth */
.success-feedback {
    color: var(--success);
    font-weight: bold;
    margin-top: 5px;
    text-align: center;
}

/* =======================================================
   8. LOADER
   ======================================================= */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.loading-content {
    text-align: center;
    padding: 40px;
    background: var(--light);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-deep);
}
.loading-content p {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--primary-dark);
}

/* =======================================================
   9. RESULTADOS, TEMAS GUARDADOS Y MEMORIA (Mantenido)
   ======================================================= */

.score-display {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--success);
    text-align: center;
    padding: 20px;
    border: 3px solid var(--success);
    border-radius: var(--radius-m);
    margin: 20px 0;
}
.results-message {
    font-size: 1.3rem;
    text-align: center;
    color: var(--secondary-dark);
    margin-bottom: 30px;
}
.topics-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}
.saved-topic-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #e9ecef;
    padding: 15px;
    border-radius: var(--radius-m);
    font-weight: 500;
}
.saved-topic-item .actions {
    display: flex;
    gap: 5px;
}
.no-items {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 20px;
}
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    max-width: 400px; 
    margin: 0 auto 20px auto;
}
.memory-card {
    background-color: var(--primary);
    height: 80px;
    border-radius: var(--radius-m);
    cursor: pointer;
    perspective: 1000px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    box-shadow: var(--shadow-light);
}
.memory-card.flip {
    transform: rotateY(180deg);
}

.face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    border-radius: var(--radius-m);
    font-weight: bold;
}
.face.back {
    background: var(--light);
    color: var(--dark);
    transform: rotateY(180deg);
    border: 3px solid var(--secondary);
}
.face.front {
    background: var(--primary);
    color: var(--light);
    border: 3px solid var(--primary-dark);
}
.memory-card.matched {
    box-shadow: 0 0 15px var(--success);
    pointer-events: none; 
}
.game-feedback-text {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-top: 20px;
    text-align: center;
    min-height: 30px; 
}

/* =======================================================
   10. ANIMACIONES DE LA MASCOTA
   ======================================================= */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0px rgba(255, 111, 97, 0.7); /* Color de pulso: Primary */
    }
    70% {
        box-shadow: 0 0 0 15px rgba(255, 111, 97, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 111, 97, 0);
    }
}
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

/* =======================================================
   11. RESPONSIVE / MOBILE
   ======================================================= */

@media (max-width: 500px) {
    .container {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 15px;
    }
    .menu-grid {
        grid-template-columns: 1fr;
    }
    .menu-card-grid {
        grid-template-columns: 1fr; /* Una columna en móvil */
    }
    .category-grid {
        grid-template-columns: 1fr 1fr; 
    }
    .memory-card {
        height: 60px;
    }
    .face {
        font-size: 1.5rem;
    }
    body {
        padding: 0;
    }
    .question-box {
        padding-right: 60px; 
        position: relative;
    }
    
    .btn-speak {
        top: 15px; 
        right: 8px;
        padding: 6px 8px;
    }
}
