:root {
    /* Variables base (Tema Claro por defecto si no hay preferencia) */
    --bg-color: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    
    /* Glassmorphism Light */
    --card-bg: rgba(255, 255, 255, 0.7);
    --card-border: rgba(255, 255, 255, 0.5);
    --card-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
    
    /* Estado de notas */
    --aprobado-bg: rgba(16, 185, 129, 0.15);
    --aprobado-text: #047857;
    --desaprobado-bg: rgba(239, 68, 68, 0.15);
    --desaprobado-text: #b91c1c;
    --neutro-bg: rgba(107, 114, 128, 0.1);
    --neutro-text: #4b5563;
    
    --accent: #3b82f6;
}

/* Preferencia del sistema: Oscuro */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f172a;
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        
        /* Glassmorphism Dark */
        --card-bg: rgba(30, 41, 59, 0.7);
        --card-border: rgba(255, 255, 255, 0.05);
        --card-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
        
        /* Estado de notas Dark */
        --aprobado-bg: rgba(16, 185, 129, 0.2);
        --aprobado-text: #34d399;
        --desaprobado-bg: rgba(239, 68, 68, 0.2);
        --desaprobado-text: #f87171;
        --neutro-bg: rgba(148, 163, 184, 0.15);
        --neutro-text: #94a3b8;
        
        --accent: #60a5fa;
    }
}

/* Forzar Tema Oscuro (cuando el usuario usa el toggle) */
body.dark-theme {
    --bg-color: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(255, 255, 255, 0.05);
    --card-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
    --aprobado-bg: rgba(16, 185, 129, 0.2);
    --aprobado-text: #34d399;
    --desaprobado-bg: rgba(239, 68, 68, 0.2);
    --desaprobado-text: #f87171;
    --neutro-bg: rgba(148, 163, 184, 0.15);
    --neutro-text: #94a3b8;
    --accent: #60a5fa;
}

/* Forzar Tema Claro (cuando el usuario usa el toggle) */
body.light-theme {
    --bg-color: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --card-bg: rgba(255, 255, 255, 0.7);
    --card-border: rgba(255, 255, 255, 0.5);
    --card-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
    --aprobado-bg: rgba(16, 185, 129, 0.15);
    --aprobado-text: #047857;
    --desaprobado-bg: rgba(239, 68, 68, 0.15);
    --desaprobado-text: #b91c1c;
    --neutro-bg: rgba(107, 114, 128, 0.1);
    --neutro-text: #4b5563;
    --accent: #3b82f6;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.header-titles h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-titles p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Toggle Switch Botón */
.theme-toggle {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px 14px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease;
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle span {
    font-size: 16px;
    display: none;
}

/* Mostrar sol o luna según el tema */
body.dark-theme .icon-sun { display: block; }
body.light-theme .icon-moon { display: block; }

/* Casos por defecto según sistema si no hay clase forzada */
@media (prefers-color-scheme: dark) {
    body:not(.light-theme):not(.dark-theme) .icon-sun { display: block; }
}
@media (prefers-color-scheme: light) {
    body:not(.light-theme):not(.dark-theme) .icon-moon { display: block; }
}

/* Contenedor de Materias */
main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Tarjeta de Materia (Glassmorphism) */
.materia-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.materia-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.1);
}

.materia-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.materia-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.materia-date {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--neutro-bg);
    padding: 4px 8px;
    border-radius: 12px;
}

/* Grilla de Notas */
.notas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.notas-vacias {
    grid-column: 1 / -1;
    color: var(--text-secondary);
    font-size: 14px;
}

.nota-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: 12px;
    background: var(--neutro-bg);
}

.nota-item .label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.nota-item .valor {
    font-size: 18px;
    font-weight: 700;
    color: var(--neutro-text);
}

/* Estados Visuales */
.nota-item.aprobado {
    background: var(--aprobado-bg);
}
.nota-item.aprobado .valor {
    color: var(--aprobado-text);
}

.nota-item.desaprobado {
    background: var(--desaprobado-bg);
}
.nota-item.desaprobado .valor {
    color: var(--desaprobado-text);
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--card-border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

footer {
    text-align: center;
    padding: 20px 0;
    font-size: 12px;
    color: var(--text-secondary);
}
