/* =============================
   1. VARIABLES & RESET
   ============================= */
:root {
    --bg-main: #0f172a;
    --sidebar-bg: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #06b6d4;
    --accent-hover: #0891b2;
    --glass: rgba(30, 41, 59, 0.85); 
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --correct: #22c55e;
    --wrong: #ef4444;
}

body.light-mode {
    --bg-main: #e2e8f0;
    --sidebar-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --accent: #0891b2;
    --accent-hover: #0e7490;
    --glass: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.6);
    --glass-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* =============================
   2. LAYOUT
   ============================= */
.app-container { display: flex; height: 100%; }

.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    display: flex; flex-direction: column;
    padding: 30px 20px;
    border-right: 1px solid var(--glass-border);
    flex-shrink: 0;
    transition: background-color 0.4s ease;
}

.logo {
    font-size: 24px; font-weight: 700; color: var(--accent);
    margin-bottom: 50px; display: flex; align-items: center; gap: 10px;
}

.menu { display: flex; flex-direction: column; gap: 10px; flex: 1; }

.menu-btn {
    background: transparent; border: none; color: var(--text-muted);
    font-size: 16px; font-family: inherit; text-align: left;
    padding: 12px 15px; border-radius: 12px; cursor: pointer;
    transition: 0.3s; display: flex; align-items: center; gap: 12px;
}
.menu-btn:hover { background: rgba(125, 125, 125, 0.1); color: var(--text-main); }
.menu-btn.active { 
    background: var(--accent); color: white !important; 
    font-weight: 600; box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4); 
}

.footer-note { font-size: 12px; color: var(--text-muted); text-align: center; }

.content {
    flex: 1; display: flex; justify-content: center; align-items: center;
    background: radial-gradient(circle at top right, var(--sidebar-bg) 0%, var(--bg-main) 70%);
    padding: 20px; position: relative; overflow-y: auto;
    transition: background 0.4s ease;
}

/* =============================
   3. GLASS CARD & ANIMATIONS
   ============================= */
.glass-card {
    background: var(--glass);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    width: 100%; max-width: 750px; padding: 45px;
    border-radius: 24px; border: 1px solid var(--glass-border);
    text-align: center; box-shadow: var(--glass-shadow);
    animation: fadeInScale 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-12px); }
    100% { transform: translateY(0px); }
}

.card-icon { font-size: 50px; color: var(--accent); margin-bottom: 20px; display: inline-block; }
.card-icon.floating { animation: float 4s ease-in-out infinite; }

h1 { font-size: 2.4rem; margin-bottom: 10px; font-weight: 700; letter-spacing: -1px; }
#sub-title { color: var(--text-muted); font-size: 1.05rem; margin-bottom: 30px; line-height: 1.6; }

/* =============================
   4. UI COMPONENTS (Buttons, Search)
   ============================= */
.btn-group { display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; margin-top: 25px; }

.action-btn {
    background: var(--accent); color: white; border: none; padding: 14px 32px;
    font-size: 1rem; font-weight: 600; border-radius: 12px; cursor: pointer; 
    transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.action-btn:hover { background: var(--accent-hover); transform: translateY(-3px); }

.action-btn.secondary { background: transparent; border: 2px solid var(--accent); color: var(--accent); box-shadow: none; }
.action-btn.secondary:hover { background: var(--accent); color: white; transform: translateY(-3px); }

.search-bar {
    width: 100%; padding: 12px 20px; border-radius: 50px; border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2); color: var(--text-main); font-family: inherit; font-size: 1rem;
    outline: none; text-align: center; transition: 0.3s; margin-bottom: 15px;
}
.search-bar:focus { border-color: var(--accent); background: rgba(0,0,0,0.3); }

/* Category Pills */
.filter-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 20px; }
.cat-btn {
    background: rgba(125,125,125,0.1); border: 1px solid var(--glass-border);
    color: var(--text-muted); padding: 6px 14px; border-radius: 20px;
    font-size: 0.85rem; cursor: pointer; transition: 0.2s;
}
.cat-btn:hover, .cat-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* =============================
   5. TRAIN SCHOOL (FIXED SCROLLING)
   ============================= */
.school-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;
}

.school-card {
    background: rgba(125, 125, 125, 0.05); border: 1px solid var(--glass-border);
    border-radius: 16px; padding: 30px; cursor: pointer; transition: all 0.3s;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center;
}
.school-card:hover {
    background: rgba(125, 125, 125, 0.1); border-color: var(--accent);
    transform: translateY(-5px);
}
.school-icon { font-size: 30px; color: var(--accent); margin-bottom: 15px; }
.school-title { font-size: 1.1rem; font-weight: 600; color: var(--text-main); }

/* FIXED: Lesson Container uses flex space, not fixed pixel height */
.lesson-container { 
    text-align: left; 
    height: 60vh; /* Dynamic height based on screen size */
    overflow-y: auto; /* Allows scrolling the whole list */
    padding-right: 10px; 
    padding-bottom: 20px;
}
.lesson-container::-webkit-scrollbar { width: 6px; }
.lesson-container::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 10px; }

.accordion-item {
    background: rgba(125, 125, 125, 0.05); border: 1px solid var(--glass-border);
    border-radius: 12px; margin-bottom: 10px; overflow: hidden;
}
.accordion-header {
    padding: 15px 20px; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
    font-weight: 600; color: var(--text-main); background: rgba(125, 125, 125, 0.02);
    transition: background 0.2s;
}
.accordion-header:hover { background: rgba(125, 125, 125, 0.1); }

/* FIXED: Content expands freely */
.accordion-content {
    max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out;
    background: rgba(0, 0, 0, 0.2); color: var(--text-main);
    font-size: 0.95rem; line-height: 1.7; opacity: 0.9;
}
.accordion-content.open { 
    /* Padding is applied only when open to avoid jumpiness */
    padding: 20px; 
    border-top: 1px solid var(--glass-border);
}
.arrow-icon { transition: transform 0.3s; font-size: 0.8rem; }
.accordion-item.active .arrow-icon { transform: rotate(180deg); }

/* =============================
   6. NEWS FEED
   ============================= */
.news-container { text-align: left; max-height: 450px; overflow-y: auto; padding-right: 12px; }
.news-container::-webkit-scrollbar { width: 6px; }
.news-container::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 10px; }

.news-card {
    display: flex; gap: 15px; align-items: flex-start;
    background: rgba(125, 125, 125, 0.05); border: 1px solid var(--glass-border);
    border-radius: 16px; padding: 15px; margin-bottom: 15px;
    transition: all 0.3s; cursor: pointer; overflow: hidden;
}
.news-card:hover { 
    border-color: var(--accent); transform: translateY(-3px); 
    background: rgba(125, 125, 125, 0.08); 
}

.news-thumb {
    width: 80px; height: 80px; border-radius: 10px; object-fit: cover; flex-shrink: 0;
    background-color: #333;
}
.news-content { flex: 1; }
.news-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.news-tag { 
    background: var(--accent); color: white; font-size: 0.7rem; font-weight: 700; 
    padding: 3px 8px; border-radius: 4px; text-transform: uppercase; 
}
.news-date { font-size: 0.75rem; color: var(--text-muted); }
.news-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 5px; color: var(--text-main); line-height: 1.3; }
.news-excerpt { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Loading Spinner */
.spinner {
    border: 4px solid rgba(255,255,255,0.1); border-left-color: var(--accent);
    border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite;
    margin: 30px auto;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* =============================
   7. MODAL (POPUP)
   ============================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8); z-index: 2000;
    display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(5px); opacity: 0; transition: opacity 0.3s;
}
.modal-overlay.show { display: flex; opacity: 1; }

.modal-content {
    text-align: left; position: relative; width: 90%; max-width: 600px; padding: 0; overflow: hidden;
    background: var(--bg-main); border: 1px solid var(--accent);
}

.modal-image { width: 100%; height: 200px; object-fit: cover; }
.modal-body { padding: 30px; max-height: 60vh; overflow-y: auto; }

.close-modal {
    position: absolute; top: 15px; right: 15px; background: rgba(0,0,0,0.5); 
    color: white; border: none; font-size: 24px; width: 35px; height: 35px; 
    border-radius: 50%; cursor: pointer; z-index: 10; display: flex; justify-content: center; align-items: center;
}
.close-modal:hover { background: var(--accent); }

.article-text { font-size: 1rem; line-height: 1.8; color: var(--text-main); white-space: pre-wrap; margin-top: 15px; }

/* =============================
   8. FACTS & QUIZ
   ============================= */
.fact-display-card {
    background: rgba(125,125,125,0.05); padding: 30px; border-radius: 16px;
    border: 1px solid var(--glass-border); min-height: 150px;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    margin-bottom: 20px; animation: fadeInScale 0.3s ease-out;
}
.fact-category-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); font-weight: 700; margin-bottom: 10px; }
.fact-text { font-size: 1.2rem; line-height: 1.5; font-weight: 500; }

.score-badge { background: rgba(125,125,125, 0.1); padding: 8px 16px; border-radius: 30px; font-size: 0.9rem; color: var(--accent); font-weight: 700; margin-bottom: 25px; display: inline-block; border: 1px solid var(--glass-border); }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 25px; }
.option-btn { background: rgba(125,125,125, 0.05); border: 1px solid var(--glass-border); color: var(--text-main); padding: 22px; border-radius: 16px; font-size: 1rem; cursor: pointer; transition: 0.2s; }
.option-btn:hover:not(:disabled) { background: rgba(125,125,125, 0.15); border-color: var(--accent); }
.option-btn.correct { background: var(--correct) !important; border-color: var(--correct); color: white; }
.option-btn.wrong { background: var(--wrong) !important; border-color: var(--wrong); opacity: 0.8; color: white; }

/* =============================
   9. GAME & EXTRAS
   ============================= */
.game-board { background-color: #000000; border: 2px solid #333; border-radius: 12px; width: 100%; max-width: 600px; height: 300px; position: relative; margin: 0 auto 20px auto; overflow: hidden; box-shadow: inset 0 0 30px rgba(0,0,0,0.9); }
.track-line { stroke: #555; stroke-width: 6; stroke-linecap: round; }
.switch-line { stroke: #06b6d4; stroke-width: 6; cursor: pointer; transition: all 0.3s; }
.signal-light { cursor: pointer; transition: fill 0.2s; filter: drop-shadow(0 0 8px currentColor); }
.game-controls { display: flex; gap: 10px; justify-content: center; margin-top: 15px; }
.status-text { font-family: 'Courier New', monospace; color: #06b6d4; margin-bottom: 15px; font-weight: bold; }

.update-banner {
    background: rgba(6, 182, 212, 0.1); border: 1px solid var(--accent);
    color: var(--accent); padding: 12px 24px; border-radius: 50px;
    margin-bottom: 30px; font-weight: 600; font-size: 0.9rem;
    display: inline-block; animation: fadeInScale 0.8s ease-out;
}

.credits { position: fixed; bottom: 25px; right: 30px; display: flex; flex-direction: column; align-items: center; gap: 0px; z-index: 1000; opacity: 0.8; pointer-events: none; }
.credits:hover { opacity: 1; }
.credits span { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 2px; }
.credits img { height: 60px; width: auto; display: block; }

@keyframes fadeInScale { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* =============================
   10. MOBILE
   ============================= */
@media (max-width: 768px) {
    .app-container { flex-direction: column; height: 100vh; overflow: hidden; }
    .sidebar { width: 100%; min-height: 60px; padding: 10px 15px; flex-direction: row; justify-content: space-between; align-items: center; border-right: none; border-bottom: 1px solid var(--glass-border); z-index: 100; }
    .logo { font-size: 18px; margin: 0; } .logo span { display: none; }
    .menu { flex-direction: row; gap: 8px; flex: 1; justify-content: flex-end; align-items: center; }
    .menu-btn { padding: 0; width: 40px; height: 40px; border-radius: 50%; justify-content: center; }
    .menu-btn span, #theme-text { display: none; }
    #btn-theme { margin-top: 0 !important; }
    .footer-note { display: none; }
    .content { padding: 15px; align-items: flex-start; padding-bottom: 90px; }
    .glass-card { padding: 30px 20px; margin-top: 10px; }
    .quiz-options, .school-grid { grid-template-columns: 1fr; } /* Stack school cards on mobile */
    .credits { bottom: 10px; right: 10px; opacity: 0.5; }
    .credits img { height: 35px; }
    .action-btn { width: 100%; margin-bottom: 10px; }
}