/* --- VARIABLES GLOBALES (Design System) --- */
:root {
    --primary: #4361EE;
    --primary-hover: #3A0CA3;
    --secondary: #4CC9F0;
    --accent: #F72585;
    --success: #2ECC71;
    --bg-light: #F8F9FA;
    --text-main: #2B2D42;
    --text-muted: #8D99AE;
    --card-bg: #FFFFFF;
    --shadow: 0 8px 30px rgba(0,0,0,0.08);
    --border-radius: 16px;
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* --- RESET & BASICS --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { 
    font-family: var(--font-family); 
    background-color: var(--bg-light); 
    color: var(--text-main); 
    line-height: 1.6; 
    /* NUEVO ENFOQUE: Flexbox en todo el body para centrado matemático */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 1rem;
}
a { text-decoration: none; color: inherit; }

/* --- HEADER & FOOTER --- */
.main-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; background: var(--card-bg); box-shadow: var(--shadow); }
.main-header .logo { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.user-nav { display: flex; align-items: center; gap: 1rem; }
.btn-logout { background: #FFE5E5; color: #D63031; padding: 0.5rem 1rem; border-radius: 8px; font-weight: 600; transition: all 0.3s; }
.btn-logout:hover { background: #D63031; color: white; }

.main-footer { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 0.9rem; margin-top: auto; }

/* CORRECCIÓN DEL CONTENEDOR PRINCIPAL */
.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
    z-index: 1; /* Asegura que el contenido esté al frente */
}

.dashboard-wrapper, .exams-wrapper{
    max-width: 1360px;
    margin: auto;
    width: 100%;
}

/* CORRECCIÓN DE LA TARJETA DE LOGIN */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 20px;
}

.auth-card {
    background-color: var(--card-bg) !important; /* Forzamos el color blanco */
    background: #FFFFFF; /* Fallback directo */
    padding: 3rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 420px;
    text-align: center;
    border: 1px solid #EEEEEE; /* Un borde sutil para definir el marco */
    display: block; /* Asegura que no se colapse */
}


.form-group { margin-bottom: 1.5rem; text-align: left; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-main); font-size: 0.9rem; }
.form-group input { width: 100%; padding: 0.8rem 1rem; border: 2px solid #E2E8F0; border-radius: 8px; font-family: inherit; transition: border-color 0.3s; }
.form-group input:focus { outline: none; border-color: var(--primary); }

.btn-primary { width: 100%; padding: 1rem; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: background 0.3s; }
.btn-primary:hover { background: var(--primary-hover); }

.alert { padding: 1rem; border-radius: 8px; margin-bottom: 1.5rem; font-weight: 600; }
.alert-error { background: #FFE5E5; color: #D63031; }

/* --- DASHBOARD & GRID --- */
.dashboard-header { text-align: center; margin-top: 2rem; margin-bottom: 3rem; }
.dashboard-header h1 span { color: var(--accent); }

.subjects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1.5rem; }

/* --- COMPONENTES DINÁMICOS JS --- */
.subject-card { background: var(--card-bg); padding: 1.5rem; border-radius: var(--border-radius); box-shadow: var(--shadow); cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; border-bottom: 4px solid var(--primary); display: flex; flex-direction: column; gap: 0.5rem; }
.subject-card:hover { transform: translateY(-5px); box-shadow: 0 12px 40px rgba(0,0,0,0.12); }
.subject-card.elite { border-bottom-color: var(--accent); }
.subject-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.subject-title { font-weight: 700; font-size: 1.1rem; color: var(--text-main); }
.subject-type { font-size: 0.8rem; font-weight: 600; padding: 0.2rem 0.6rem; border-radius: 12px; display: inline-block; width: fit-content; }
.type-regular { background: #E3F2FD; color: #1976D2; }
.type-elite { background: #FCE4EC; color: #C2185B; }

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 600px) {
    .app-container { padding: 1rem; }
    .main-header { flex-direction: column; gap: 1rem; }
    .subjects-grid { grid-template-columns: 1fr; }
}


/* --- NAVEGACIÓN Y EXÁMENES --- */
.user-nav { display: flex; align-items: center; gap: 2rem; }
.nav-links { display: flex; gap: 1.5rem; }
.nav-links a { font-weight: 600; color: var(--text-muted); padding: 0.5rem; transition: color 0.3s, border-bottom 0.3s; border-bottom: 2px solid transparent; }
.nav-links a:hover, .nav-links a.active { color: var(--primary); border-bottom-color: var(--primary); }
.user-profile { display: flex; align-items: center; gap: 1rem; border-left: 1px solid #E2E8F0; padding-left: 1.5rem; }
.alert-info { background: #E3F2FD; color: #1976D2; border-left: 4px solid #1976D2; text-align: center; font-size: 1.1rem; }
.type-exam { background: #FFF3CD; color: #856404; }
.subject-card.exam-card { border-bottom-color: #FFC107; }

@media (max-width: 768px) {
    .user-nav { flex-direction: column; gap: 1rem; width: 100%; }
    .user-profile { border-left: none; border-top: 1px solid #E2E8F0; padding-top: 1rem; padding-left: 0; width: 100%; justify-content: space-between; }
}


/* --- REPRODUCTOR DE CLASES (MODAL INMERSIVO) --- */
.player-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(10, 15, 44, 0.9); z-index: 1000; justify-content: center; align-items: center; padding: 1rem; backdrop-filter: blur(5px); }
.player-overlay.active { display: flex; animation: fadeIn 0.3s ease; }

.player-card { background: var(--card-bg); width: 100%; max-width: 800px; height: 90vh; border-radius: var(--border-radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
.player-header { padding: 1.5rem 2rem; background: var(--primary); color: white; display: flex; justify-content: space-between; align-items: center; }
.player-header h2 { font-size: 1.3rem; margin: 0; }
.btn-close { background: rgba(255,255,255,0.2); border: none; color: white; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; transition: background 0.2s; }
.btn-close:hover { background: rgba(255,255,255,0.4); }

.player-content { padding: 2rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2rem; }

/* Secciones del Aprendizaje */
.section-title { color: var(--primary-hover); margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; font-size: 1.4rem; border-bottom: 2px solid #E2E8F0; padding-bottom: 0.5rem; }
.theory-box { font-size: 1.1rem; color: #334155; line-height: 1.8; }
.mnemonic-box { background: #FFF8E1; border-left: 6px solid #FFC107; padding: 1.5rem; border-radius: 8px; font-size: 1.2rem; color: #856404; font-weight: 600; white-space: pre-line; }

/* Motor de Juego (Ordenamiento Táctil) */
.game-box { background: #F8FAFC; padding: 1.5rem; border-radius: 12px; border: 2px dashed #CBD5E1; }
.game-question { font-weight: bold; font-size: 1.2rem; margin-bottom: 1rem; color: var(--accent); }
.game-options { display: flex; flex-direction: column; gap: 0.8rem; }
.game-option-btn { background: white; border: 2px solid var(--primary); padding: 1rem; border-radius: 8px; font-size: 1.1rem; cursor: pointer; transition: all 0.2s; text-align: left; font-weight: bold; color: var(--primary); }
.game-option-btn:hover { background: #EFF6FF; transform: translateX(5px); }
.game-option-btn.selected { background: var(--primary); color: white; }

.game-status { margin-top: 1.5rem; padding: 1rem; border-radius: 8px; font-weight: bold; text-align: center; display: none; font-size: 1.2rem; }
.game-status.success { display: block; background: #DCFCE7; color: #166534; animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.game-status.error { display: block; background: #FEE2E2; color: #991B1B; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { 0% { transform: scale(0.8); } 100% { transform: scale(1); } }

/* --- IMAGEN PRINCIPAL DEL TEMA --- */
.topic-main-image {
    width: 100%;
    max-height: 450px;
    object-fit: cover;
    border-radius: 16px;
    margin-bottom: 1.5rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border: 3px solid #E2E8F0;
}

/* --- MOTOR DE LECTURA (TEXT-TO-SPEECH) --- */
.tts-btn {
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: 10px;
    transition: transform 0.2s, background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.tts-btn:hover {
    transform: scale(1.1);
    background: #00B4D8;
}
.tts-word {
    transition: background 0.1s, color 0.1s;
    border-radius: 3px;
}
.tts-word.active {
    background: #FFF3CD;
    color: #D97706;
    font-weight: bold;
    border-bottom: 2px solid #F59E0B;
}

/* --- REPRODUCTOR DE VIDEO SEGURO --- */
.video-container {
    position: relative;
    padding-bottom: 56.25%; /* Ratio 16:9 */
    height: 0;
    overflow: hidden;
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    border: 3px solid #E2E8F0;
    background: #000;
}
.video-container iframe, .video-container object, .video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}
/* Capa invisible para bloquear clics hacia YouTube exterior si fuera necesario, aunque con rel=0 es suficiente */
.admin-video-alert {
    background: #FEE2E2;
    color: #991B1B;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #DC2626;
    font-weight: bold;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}


/* --- DISEÑO DE LISTA DE TEMAS --- */
.topics-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px;
}

.topic-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.topic-btn-main {
    flex: 4;
    padding: 15px;
    background: #F8FAFC;
    border: 2px solid #E2E8F0;
    border-radius: 12px;
    text-align: left;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.topic-btn-main:hover {
    background: #EFF6FF;
    border-color: var(--primary);
    transform: translateX(5px);
}

.topic-btn-exam {
    flex: 1;
    background: #EEF2FF;
    border: 2px solid #C7D2FE;
    color: #4338CA;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.topic-btn-exam:hover {
    background: #4338CA;
    color: white;
}

/* Botón de volver dentro del modal */
.btn-back-modal {
    background: #F1F5F9;
    border: none;
    padding: 5px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    margin-right: 15px;
}