/* =======================================================
   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;
}

.menu-grid {
    grid-template-columns: 1fr 1fr;
}

.category-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.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
   ======================================================= */
.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;
}

.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);
    animation: none; /* Se activa con la clase .pulse en JS */
}

/* =======================================================
   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);
}
.question-box p {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 0;
    display: inline;
}

.option-btn {
    width: 100%;
    text-align: left;
    white-space: normal;
    height: auto;
    min-height: 50px;
}

/* ESTILOS DE FEEDBACK (LO QUE ESTABA FALTANDO) */
.option-btn.btn-success {
    background-color: var(--success);
    color: var(--light);
    box-shadow: 0 6px 0 #388e3c;
    position: relative;
    top: 0;
}
.option-btn.btn-error {
    background-color: var(--error);
    color: var(--light);
    box-shadow: 0 6px 0 #d32f2f;
    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; /* Fondo suave para el feedback */
    color: var(--dark);
    min-height: 50px; /* Para mantener el espacio */
}
.feedback-icon {
    margin-right: 5px;
    font-size: 1.5rem;
}
#nextQuestionBtn {
    margin-top: 20px;
}

/* =======================================================
   7. SECCIONES GENERALES
   ======================================================= */

/* Input de Tema */
.input-group {
    margin-bottom: 20px;
}
#topicField {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: var(--radius-m);
    font-size: 1rem;
    transition: border-color 0.2s;
}
#topicField: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;
}

/* =======================================================
   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
   ======================================================= */
.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;
}

/* =======================================================
   10. TEMAS GUARDADOS
   ======================================================= */
.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;
}

/* =======================================================
   11. JUEGO DE MEMORIA
   ======================================================= */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    max-width: 400px; /* Tamaño máximo para centrar */
    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;
}

/* Parte de atrás (icono) */
.face.back {
    background: var(--light);
    color: var(--dark);
    transform: rotateY(180deg);
    border: 3px solid var(--secondary);
}
/* Parte de adelante (?) */
.face.front {
    background: var(--primary);
    color: var(--light);
    border: 3px solid var(--primary-dark);
}

/* Estilo para las parejas encontradas */
.memory-card.matched {
    box-shadow: 0 0 15px var(--success);
    pointer-events: none; /* No se puede clickear una vez emparejada */
}

/* Feedback del juego */
.game-feedback-text {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-top: 20px;
    text-align: center;
    min-height: 30px; 
}

/* =======================================================
   12. MODAL MAESTRO
   ======================================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}
.modal-content {
    background: var(--light);
    padding: 30px;
    border-radius: var(--radius-l);
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-deep);
    position: relative;
    text-align: center;
}
.modal-content h3 {
    color: var(--dark);
    margin-bottom: 15px;
}
.modal-content input {
    margin: 15px 0 20px 0;
    width: 100%;
    padding: 10px;
    border: 2px solid var(--secondary);
    border-radius: var(--radius-m);
}
.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--dark);
}

/* =======================================================
   13. ANIMACIÓN PULSO IA
   ======================================================= */
@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);
    }
}

.avatar-circle.pulse {
    animation: pulse 1.5s infinite;
}

/* =======================================================
   14. RESPONSIVE / MOBILE
   ======================================================= */

@media (max-width: 500px) {
    .container {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        padding: 15px;
    }
    .menu-grid, .category-grid {
        grid-template-columns: 1fr;
    }
    .menu-btn {
        font-size: 1.1rem;
    }
    .memory-card {
        height: 60px;
    }
    .face {
        font-size: 1.5rem;
    }
    body {
        padding: 0;
    }
}



