:root {
    --primary: #4CAF50; /* Verde vibrante */
    --primary-dark: #388E3C;
    --secondary: #FF6F61; /* Coral/Rojo Suave */
    --background: #f4f4f9;
    --text-color: #333;
    --card-bg: #ffffff;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 700px;
    padding: 20px;
    margin-top: 30px;
    background-color: var(--card-bg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius);
}

/* ------------------------------------------- */
/* 1. Header y Avatar de Yakdiel */
/* ------------------------------------------- */

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 2px solid #eee;
    margin-bottom: 25px;
}

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

.yakdiel-avatar h1 {
    font-size: 1.8em;
    margin: 0;
    color: var(--primary-dark);
}

.user-status-text {
    font-size: 0.85em;
    color: #666;
    margin-top: 2px;
}

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

/* Animaciones del avatar */
@keyframes pulse-animation {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(76, 175, 80, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

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

.avatar-circle.happy {
    background-color: #FFC107; /* Amarillo */
    transform: rotate(10deg);
}

.avatar-circle.sad {
    background-color: #E91E63; /* Rosa Triste */
}

.avatar-circle.thinking {
    background-color: #2196F3; /* Azul Pensante */
    animation: none;
}


/* ------------------------------------------- */
/* 2. Botones y Formularios */
/* ------------------------------------------- */

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background-color 0.3s, transform 0.1s;
    text-decoration: none;
    text-align: center;
    display: inline-block;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-secondary {
    background-color: #9E9E9E; /* Gris */
    color: white;
}

.btn-dark {
    background-color: #333;
    color: white;
}

.btn-link {
    background: none;
    color: var(--primary-dark);
    font-weight: 500;
    padding: 10px 0;
}

.btn-link:hover {
    color: var(--secondary);
    text-decoration: underline;
}

.btn-primary:hover, .btn-secondary:hover, .btn-dark:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-error {
    background-color: var(--secondary);
    color: white;
}
.btn-error:hover {
    background-color: #D32F2F;
}

.input-group {
    margin-bottom: 15px;
}

input[type="text"], input[type="password"], input[type="email"], select {
    width: 100%;
    padding: 12px;
    margin: 5px 0;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s;
}

input:focus, select:focus {
    border-color: var(--primary);
    outline: none;
}

.action-buttons-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.action-buttons-group button, .action-buttons-group a {
    flex-grow: 1;
    min-width: 150px;
}


/* ------------------------------------------- */
/* 3. Estructura de Secciones y Mensajes */
/* ------------------------------------------- */

.main-section h2 {
    color: var(--primary-dark);
    border-bottom: 2px dashed #eee;
    padding-bottom: 10px;
    margin-top: 0;
}
.section-subtitle {
    color: #666;
    font-style: italic;
    margin-bottom: 20px;
}

.error-feedback {
    color: var(--secondary);
    font-weight: bold;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid var(--secondary);
    border-radius: 8px;
    background-color: #ffe0e0;
    display: none;
}

.success-feedback {
    color: var(--primary-dark);
    font-weight: bold;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background-color: #e6ffeb;
    display: none;
}

/* ------------------------------------------- */
/* 4. Menú Principal y Categorías (Grid) */
/* ------------------------------------------- */

.menu-grid, .category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.main-menu-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 150px;
    background-color: var(--card-bg);
    border: 1px solid #ddd;
    box-shadow: var(--shadow);
    transition: all 0.2s ease-in-out;
}

.main-menu-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.main-menu-card .icon-xl {
    font-size: 3em;
    margin-bottom: 5px;
}
.main-menu-card .card-title {
    font-weight: bold;
    font-size: 1.1em;
}
.main-menu-card .card-description {
    font-size: 0.75em;
    color: #888;
    margin-top: 5px;
}

/* Estilos específicos para tarjetas del menú */
.card-ia .icon-xl { color: #FFD700; }
.card-saved .icon-xl { color: #2196F3; }
.card-memory .icon-xl { color: #9C27B0; }
.card-stats .icon-xl { color: var(--primary); }
.card-master .icon-xl { color: #607D8B; }
.card-admin .icon-xl { color: var(--secondary); }

/* Category Cards */
.category-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100px;
    border: 1px solid var(--primary);
    background-color: #e8f5e9;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.category-card:hover {
    background-color: var(--primary);
    color: white;
}
.category-card:hover .icon-lg {
    color: white;
}

.icon-lg {
    font-size: 2em;
    color: var(--primary-dark);
    margin-bottom: 5px;
}


/* ------------------------------------------- */
/* 5. Área de Juego (Quiz) */
/* ------------------------------------------- */

.question-counter {
    text-align: right;
    color: #666;
    font-style: italic;
    margin-bottom: 5px;
}

.topic-header {
    color: var(--secondary);
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
}

.question-box {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 25px;
    position: relative;
}

.question-box p {
    font-size: 1.15em;
    font-weight: 500;
    margin: 0;
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.option-btn {
    width: 100%;
    background-color: #f0f0f0;
    color: var(--text-color);
    text-align: left;
    padding: 15px;
    border: 1px solid #ddd;
    font-weight: normal;
}

.option-btn:hover:not(:disabled) {
    background-color: #e0e0e0;
    transform: none;
}

.btn-success {
    background-color: #66BB6A; /* Verde éxito */
    color: white;
}
.btn-error {
    background-color: var(--secondary); /* Rojo error */
    color: white;
}

.feedback-text {
    margin-top: 15px;
    padding: 10px;
    border-radius: 8px;
    font-weight: bold;
    display: none;
}
.feedback-icon {
    margin-right: 8px;
}

/* Botón de voz en la pregunta */
.btn-speak {
    background: none;
    border: none;
    font-size: 1.5em;
    color: #2196F3;
    cursor: pointer;
    padding: 0;
    margin-left: 10px;
    position: absolute;
    top: 15px;
    right: 15px;
    transition: color 0.2s;
}
.btn-speak:hover {
    color: var(--primary-dark);
}

.btn-inline-save {
    margin-left: 10px;
}

/* ------------------------------------------- */
/* 6. Resultados */
/* ------------------------------------------- */

.score-display {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--primary-dark);
    margin: 20px 0;
    text-align: center;
}

.results-message {
    font-size: 1.2em;
    text-align: center;
    margin-bottom: 30px;
    color: #666;
}

/* ------------------------------------------- */
/* 7. Modal y Loading */
/* ------------------------------------------- */

.loading-overlay, .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-content, .modal-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
    max-width: 90%;
}

.loading-content p {
    color: #666;
    margin-top: 15px;
}

.modal-content {
    position: relative;
    padding-top: 40px;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #aaa;
}
.close-btn:hover {
    color: var(--secondary);
}


/* ------------------------------------------- */
/* 8. Temas Guardados (Lista) */
/* ------------------------------------------- */

.topics-list {
    margin-top: 20px;
}

.saved-topic-item, .achievement-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-left: 5px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.achievement-item {
    border-left: 5px solid gold;
    font-weight: 500;
}

.saved-topic-item span {
    font-weight: 500;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-topic-item .actions {
    display: flex;
    gap: 8px;
}

.btn-small {
    padding: 6px 10px;
    font-size: 0.85em;
}

.no-items {
    text-align: center;
    color: #999;
    padding: 30px;
    border: 1px dashed #ccc;
    border-radius: 8px;
}

/* ------------------------------------------- */
/* 9. Dashboard de Estadísticas */
/* ------------------------------------------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: #f9f9f9;
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.stat-icon {
    font-size: 1.5em;
    display: block;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 2em;
    font-weight: bold;
    color: var(--primary-dark);
    display: block;
}

.stat-label {
    font-size: 0.9em;
    color: #666;
}


/* ------------------------------------------- */
/* 10. Juego de Memoria */
/* ------------------------------------------- */

.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 20px;
    background-color: #e0f2f1; /* Fondo suave */
    border-radius: var(--radius);
}

.memory-card {
    perspective: 1000px;
    width: 100%;
    padding-top: 100%; /* Truco para hacer la tarjeta cuadrada */
    position: relative;
    cursor: pointer;
    user-select: none;
    transition: transform 0.6s;
}

.face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5em;
    border-radius: 8px;
    transition: transform 0.6s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.front {
    background-color: var(--secondary);
    color: white;
    transform: rotateY(0deg);
    z-index: 2;
}

.back {
    background-color: var(--card-bg);
    color: var(--text-color);
    transform: rotateY(180deg);
}

.memory-card.flip .front {
    transform: rotateY(180deg);
}

.memory-card.flip .back {
    transform: rotateY(360deg);
}

/* Para tarjetas emparejadas */
.memory-card.matched {
    cursor: default;
    opacity: 0.8;
}

.game-feedback-text {
    text-align: center;
    font-weight: bold;
    margin-bottom: 20px;
    color: var(--primary-dark);
}

/* ------------------------------------------- */
/* 11. Panel de Administración */
/* ------------------------------------------- */

.admin-table-container {
    overflow-x: auto;
    margin-top: 20px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
}

#userTable {
    width: 100%;
    border-collapse: collapse;
}

#userTable th, #userTable td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 0.9em;
}

#userTable th {
    background-color: #f0f0f0;
    color: var(--text-color);
    font-weight: 600;
}

#userTable tr:hover {
    background-color: #fafafa;
}

.select-role {
    padding: 5px;
    border-radius: 4px;
    font-size: 0.85em;
}

/* ------------------------------------------- */
/* 12. PWA y Responsividad */
/* ------------------------------------------- */

@media (max-width: 600px) {
    .container {
        padding: 15px;
        margin-top: 0;
        border-radius: 0;
    }
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        padding-bottom: 10px;
    }
    .yakdiel-avatar {
        margin-bottom: 10px;
    }
    .action-buttons-group button {
        flex-basis: 100%;
    }
    .menu-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
    .memory-grid {
        gap: 5px;
        padding: 10px;
    }
    .face {
        font-size: 2em;
    }
}
