/* ==================== المتغيرات الأساسية (الوضع الليلي والنهاري) ==================== */
:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --primary: #10b981;
    --primary-hover: #059669;
    --danger: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --code-bg: #000000;
}

body.light-mode {
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --primary: #059669;
    --primary-hover: #047857;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border-color: #cbd5e1;
    --code-bg: #1e293b;
}

/* ==================== الإعدادات العامة ==================== */
body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Segoe UI', Tahoma, sans-serif;
    margin: 0;
    padding: 0;
    transition: background 0.3s, color 0.3s;
    padding-bottom: 80px; /* مساحة للشريط السفلي في الموبايل */
}

.scrollable-body { overflow-y: auto; padding-bottom: 50px; }
.app-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.app-header { flex-shrink: 0; }
.app-workspace { flex-grow: 1; display: grid; grid-template-columns: 1fr 1.5fr; gap: 30px; padding: 15px 30px; overflow: hidden; }
.panel { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* ==================== شريط التنقل (Navbar) ==================== */
.navbar {
    background-color: var(--card-bg);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
}
.navbar .logo { font-size: 20px; font-weight: bold; color: var(--primary); }
.navbar .menu { display: flex; align-items: center; gap: 5px; }
.navbar .menu a {
    color: var(--text-muted);
    text-decoration: none;
    margin: 0 5px;
    padding: 8px 15px;
    border-radius: 8px;
    font-weight: bold;
    transition: 0.3s;
}
.navbar .menu a.active, .navbar .menu a:hover {
    background-color: rgba(16, 185, 129, 0.2);
    color: var(--primary);
}
.theme-btn { background: none; border: none; font-size: 24px; cursor: pointer; padding: 0 10px; }

/* ==================== واجهة الدرس (الشرح والكود) ==================== */
.live-explanation {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    padding: 15px 20px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    border: 2px solid #34d399;
    min-height: 60px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.code-box {
    background-color: var(--code-bg);
    color: #fff;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid var(--border-color);
    overflow-y: auto;
    flex-grow: 1;
    position: relative;
}
.lang-tag { position: absolute; top: 10px; left: 15px; color: #94a3b8; font-size: 13px; font-weight: bold; }
pre { margin: 0; font-size: 18px; direction: ltr; text-align: left; }
.line { display: block; padding: 2px 10px; border-radius: 4px; transition: 0.3s; }
.highlight { background-color: rgba(16, 185, 129, 0.3); border-left: 4px solid var(--primary); }

/* ==================== الأزرار والتحكم ==================== */
.controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 15px; flex-shrink: 0; }
.btn {
    flex: 1;
    min-width: 120px;
    background-color: var(--primary);
    color: white;
    text-decoration: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    border: none;
    cursor: pointer;
    transition: 0.3s;
    box-sizing: border-box;
    display: inline-block;
}
.btn:hover { background-color: var(--primary-hover); }
.btn-auto { background-color: #f59e0b; }
.btn-auto:hover { background-color: #d97706; }
.btn-reset { background-color: #64748b; }
.btn-reset:hover { background-color: #475569; }
.btn.disabled { background-color: var(--border-color); color: var(--text-muted); cursor: not-allowed; }
.block-btn { display: block; width: 100%; box-sizing: border-box; }

/* ==================== الجداول وشاشة المخرجات ==================== */
.auto-scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    background-color: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin-bottom: 15px;
}
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 400px; }
th, td { padding: 12px; text-align: center; border-bottom: 1px solid var(--border-color); }
.highlight-cell { background-color: rgba(16, 185, 129, 0.15); border: 2px solid var(--primary); box-shadow: inset 0 0 10px rgba(16,185,129,0.2); }

.fixed-height-console { flex-shrink: 0; height: 180px; display: flex; flex-direction: column; }
.output-screen {
    background-color: #000;
    flex-grow: 1;
    border-radius: 10px;
    padding: 15px;
    font-family: monospace;
    color: #10b981;
    font-size: 18px;
    direction: ltr;
    text-align: left;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

/* ==================== المؤشرات والنصوص التوضيحية ==================== */
.pointer-cursor { position: absolute; font-size: 28px; pointer-events: none; transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28); z-index: 9999; }
.text-green { color: var(--primary); font-weight: bold; }
.text-red { color: var(--danger); font-weight: bold; }
.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.02); } 100% { transform: scale(1); } }

/* ==================== لوحة القيادة (Dashboard) ==================== */
.dashboard-header { display: flex; gap: 20px; margin-bottom: 30px; }
.stat-box { background-color: var(--card-bg); border: 1px solid var(--border-color); padding: 20px; border-radius: 15px; flex: 1; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.stat-number { font-size: 36px; font-weight: bold; color: var(--primary); margin: 10px 0; }

/* تعديل شبكة عرض الدروس لتكون عمودين مثل الرئيسية */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* إجبار العرض كعمودين في الموبايل */
    gap: 15px;
    width: 100%;
    padding: 10px 0 30px 0;
}

/* تعديل كارت الدرس ليصبح مربعاً ومرتباً مثل الرئيسية */
.lesson-card {
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 20px 10px;
    text-align: center;
    transition: 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.lesson-card:hover {
    border-color: var(--primary);
    background: rgba(16, 185, 129, 0.05);
    transform: translateY(-5px);
}

/* تنسيق النصوص والزر داخل كارت الدرس الصغير */
.lesson-card h3 { font-size: 14px; font-weight: bold; margin: 10px 0 5px 0; line-height: 1.4; }
.lesson-card p { font-size: 11px; color: var(--text-muted); margin-bottom: 15px; }
.lesson-card .btn { width: 90%; padding: 8px; font-size: 12px; border-radius: 8px; margin: 0 auto; }
.lesson-card .status { position: absolute; top: 10px; left: 10px; font-size: 24px; }

/* ==================== النافذة المنبثقة (Modal/Quiz) ==================== */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); justify-content: center; align-items: center; z-index: 10000; }
.modal-content { background: var(--card-bg); padding: 30px; border-radius: 15px; width: 90%; max-width: 500px; text-align: center; border: 2px solid var(--primary); }
.quiz-option { display: block; width: 100%; padding: 12px; margin: 10px 0; background: var(--bg-color); border: 1px solid var(--border-color); color: var(--text-main); border-radius: 8px; cursor: pointer; transition: 0.3s; font-size: 16px; font-weight: bold; }
.quiz-option:hover { background: var(--primary); color: white; }

/* ==================== إضافات نظام التلعيب (Gamification) ==================== */
.level-bar-container { background: var(--border-color); border-radius: 10px; height: 20px; width: 100%; margin-top: 10px; overflow: hidden; }
.level-bar { background: linear-gradient(90deg, #f59e0b, #ef4444); height: 100%; width: 0%; transition: width 1s ease-in-out; }
.badge { display: inline-block; padding: 5px 10px; border-radius: 20px; font-size: 14px; font-weight: bold; margin-top: 5px; }
.badge-beginner { background: #3b82f6; color: white; }
.badge-pro { background: #8b5cf6; color: white; }
.badge-master { background: #f59e0b; color: white; }

/* ==================== تصميم لوحة الشرف (Leaderboard) ==================== */
.leaderboard-row { display: flex; justify-content: space-between; padding: 15px; background: var(--card-bg); border-bottom: 1px solid var(--border-color); align-items: center; font-size: 18px; }
.leaderboard-row:nth-child(1) { background: rgba(245, 158, 11, 0.1); border-left: 5px solid #f59e0b; font-size: 20px; font-weight: bold;}
.leaderboard-row:nth-child(2) { background: rgba(148, 163, 184, 0.1); border-left: 5px solid #94a3b8; }
.leaderboard-row:nth-child(3) { background: rgba(180, 83, 9, 0.1); border-left: 5px solid #b45309; }

/* ==================== تصميم الشهادة (Certificate) ==================== */
.certificate-box {
    border: 10px solid var(--primary);
    padding: 40px;
    text-align: center;
    background: url('https://www.transparenttextures.com/patterns/cubes.png'), var(--card-bg);
    border-radius: 15px;
    margin-top: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* ==================== إضافات الشاشة الرئيسية (Home) ==================== */
.home-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.splash-section { text-align: center; margin-top: 20px; margin-bottom: 30px; }
.splash-icon { font-size: 50px; color: var(--primary); background: rgba(16, 185, 129, 0.1); width: 100px; height: 100px; line-height: 100px; border-radius: 25px; display: inline-block; border: 2px solid var(--primary); margin-bottom: 10px; }
.splash-title { font-size: 24px; font-weight: bold; }
.splash-subtitle { color: var(--text-muted); font-size: 14px; margin-top: 5px; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; margin-bottom: 25px; }
.section-title { font-size: 20px; font-weight: bold; margin-bottom: 20px; text-align: center; width: 100%; }
.categories-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; width: 100%; margin-bottom: 30px; }
.category-card { background: var(--card-bg); border: 2px solid var(--border-color); border-radius: 20px; padding: 20px 10px; text-align: center; text-decoration: none; color: var(--text-main); transition: 0.3s; display: flex; flex-direction: column; align-items: center; }
.category-card:hover { border-color: var(--primary); background: rgba(16, 185, 129, 0.05); }
.cat-icon { font-size: 35px; margin-bottom: 10px; }
.cat-title { font-size: 15px; font-weight: bold; }
.cat-btn { background: var(--primary); color: white; padding: 5px 15px; border-radius: 8px; font-size: 12px; margin-top: 10px; text-decoration: none; }
.full-width-section { width: 100%; background: var(--card-bg); border-radius: 15px; padding: 20px; margin-bottom: 20px; box-sizing: border-box; border: 1px solid var(--border-color); }

/* ==================== الشريط السفلي وزر الرجوع ==================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--card-bg, #1e293b);
    border-top: 1px solid var(--border-color, #334155);
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    z-index: 1000;
}
.nav-item { color: var(--text-muted, #94a3b8); text-decoration: none; display: flex; flex-direction: column; align-items: center; font-size: 20px; }
.nav-item.active { color: var(--primary, #10b981); }
.nav-item span { font-size: 11px; margin-top: 5px; font-weight: bold; }
.theme-btn { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; padding: 0; display: flex; flex-direction: column; align-items: center;}
.theme-btn span {font-size: 11px; margin-top: 5px; font-weight: bold; font-family: 'Segoe UI', Tahoma, sans-serif;}

.back-btn { background: var(--card-bg, #1e293b); color: var(--text-main, #f8fafc); border: 1px solid var(--border-color, #334155); padding: 8px 15px; border-radius: 10px; cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; margin-bottom: 15px; margin-top: 10px; transition: 0.3s; font-family: inherit; }
.back-btn:hover { border-color: var(--primary, #10b981); color: var(--primary, #10b981); }


/* ==================== التجاوب مع شاشات الموبايل (Responsive) ==================== */
@media (max-width: 992px) {
    /* هنا السر: إجبار شاشة العمل لتكون عمودية في الموبايل */
    .app-workspace {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px;
    }
    .app-body { height: auto; overflow: auto; }
}

@media (max-width: 768px) {
    .dashboard-header { flex-direction: column; gap: 10px; }
    .navbar { flex-direction: column; gap: 10px; text-align: center; }
    .navbar .menu { flex-wrap: wrap; justify-content: center; }
    .controls { flex-direction: column; }
    .btn { width: 100%; margin-bottom: 5px;}
    .app-workspace { padding: 10px; }
    .certificate-box { padding: 20px; border-width: 5px;}
}

/* ==================== الذكاء الاصطناعي للشاشات والكمبيوتر ==================== */
@media (min-width: 768px) {
    body {
        padding-bottom: 0;
        padding-right: 90px;
    }
    /* هنا ترجع الكروت 4 أعمدة في الكمبيوتر عشان ما تخرب */
    .cards-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; }
    .home-container { max-width: 1100px; padding-right: 10px; padding-top: 40px; }
    .splash-section { display: flex; align-items: center; justify-content: center; gap: 20px; text-align: right; }
    .splash-icon { margin-bottom: 0; }
    .splash-subtitle { font-size: 16px; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 20px; }
    .categories-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; }

    .bottom-nav {
        top: 0;
        right: 0;
        left: auto;
        width: 90px;
        height: 100vh;
        flex-direction: column;
        justify-content: center;
        gap: 40px;
        border-top: none;
        border-left: 1px solid var(--border-color, #334155);
    }
}
/* ==================== اللمسات الاحترافية (Pro Upgrades) ==================== */

/* 1. تخصيص شريط التمرير (Scrollbar) ليناسب الوضع الليلي/النهاري */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* تخصيص سكرول صندوق الكود ليكون مميزاً */
.code-box::-webkit-scrollbar-thumb, .output-screen::-webkit-scrollbar-thumb {
    background: #334155;
}

/* 2. تأثير الزجاج (Glass Effect) للشريط السفلي والعلوي */
.bottom-nav {
    background: rgba(30, 41, 59, 0.85); /* لون شبه شفاف في الليلي */
    backdrop-filter: blur(12px); /* تأثير الضباب */
    -webkit-backdrop-filter: blur(12px);
}
body.light-mode .bottom-nav {
    background: rgba(255, 255, 255, 0.85); /* لون شبه شفاف في النهاري */
}

/* 3. تأثير "الطفو" الناعم للكروت عند المرور عليها (Smooth Float) */
.category-card, .lesson-card {
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.3s, box-shadow 0.3s;
}
.category-card:hover, .lesson-card:hover:not(.locked) {
    transform: translateY(-8px);
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.15);
}

/* 4. إضاءة خفيفة لأزرار التحكم (Glow Effect) */
.btn {
    transition: all 0.3s ease;
}
.btn:not(.disabled):hover {
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
    transform: translateY(-2px);
}
/* تحسينات الموبايل لشاشات الدخول */
@media (max-width: 768px) {
    .auth-container {
        width: 95% !important; /* يأخذ كامل عرض الشاشة تقريباً */
        padding: 20px !important;
        margin: 10px auto;
    }

    .auth-header h1 {
        font-size: 1.5rem !important; /* تصغير العنوان قليلاً */
    }

    input {
        font-size: 16px !important; /* لمنع الزوم التلقائي في الآيفون عند الكتابة */
        padding: 12px !important;
    }

    .btn-login {
        padding: 15px !important;
        font-size: 1.1rem !important;
    }
}

/* ستايل عام لجعل العناصر مرنة */
.container {
    max-width: 1200px;
}

img, table {
    max-width: 100%;
    height: auto;
}