/* --- PREMIUM DESIGN SYSTEM & VARIABLES --- */
:root {
    /* السمة المظلمة الافتراضية - Ultra Premium Dark Slate */
    --bg-app: #090d16;
    --bg-surface: rgba(20, 28, 47, 0.6);
    --bg-surface-hover: rgba(30, 41, 69, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(99, 102, 241, 0.4);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* التدرجات والألوان الرئيسية */
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    --accent-gradient: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --danger-gradient: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    
    --primary-glow: rgba(99, 102, 241, 0.15);
    --shadow-premium: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
    --blur-strength: 16px;
}

body.light-theme {
    /* السمة المضيئة - Minimalist Professional Light */
    --bg-app: #f4f6fa;
    --bg-surface: rgba(255, 255, 255, 0.75);
    --bg-surface-hover: rgba(255, 255, 255, 0.95);
    --border-color: rgba(0, 0, 0, 0.06);
    --border-hover: rgba(67, 97, 238, 0.4);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --primary-gradient: linear-gradient(135deg, #4361ee 0%, #3a53d0 100%);
    --primary-glow: rgba(67, 97, 238, 0.1);
    --shadow-premium: 0 20px 40px -20px rgba(0, 0, 0, 0.1);
}

/* --- SYSTEM RESETS & BASICS --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: 'Outfit', 'Tajawal', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.hidden { 
    display: none !important; 
}

/* --- AMBIENT GLOW BACKGROUND --- */
.ambient-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-blob {
    position: absolute;
    width: 45vw;
    height: 45vw;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.12;
    mix-blend-mode: screen;
    animation: floatAnimation 12s infinite alternate ease-in-out;
}
body.light-theme .glow-blob { opacity: 0.05; mix-blend-mode: multiply; filter: blur(80px); }

.blob-1 { top: -10%; left: -10%; background: #6366f1; }
.blob-2 { bottom: -10%; right: -10%; background: #a855f7; animation-delay: 3s; }

@keyframes floatAnimation {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(40px) scale(1.1); }
}

/* --- MAIN APPLICATION LAYOUT --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- PREMIUM SIDEBAR / BOTTOM BAR NAVIGATION --- */
.premium-nav {
    width: 260px;
    background: var(--bg-surface);
    backdrop-filter: blur(var(--blur-strength));
    -webkit-backdrop-filter: blur(var(--blur-strength));
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 99;
    box-shadow: var(--shadow-premium);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 3rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-gradient);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.4rem;
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
}

.nav-brand h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.nav-item {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 0.8rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    transition: all 0.25s ease;
}

.nav-item i { font-size: 1.3rem; }

.nav-item:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--border-color);
    transform: translateX(4px);
}

.nav-item.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.4);
}

.nav-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.action-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.8rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.25s ease;
}

.action-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

/* --- MAIN CONTENT WINDOW --- */
.main-content {
    flex-grow: 1;
    padding: 2rem 3rem;
    max-width: calc(100vw - 260px);
}

/* TOP BAR & HERO INTRO */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    gap: 2rem;
}

.greeting h2 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0.3rem;
}

.wave { display: inline-block; animation: waveAnim 2.5s infinite; transform-origin: 70% 70%; }
@keyframes waveAnim {
    0%, 100% { transform: rotate( 0deg) }
    10% { transform: rotate(14deg) }
    20% { transform: rotate(-8deg) }
    30% { transform: rotate(14deg) }
    40% { transform: rotate(-4deg) }
    50% { transform: rotate(10deg) }
}

.greeting p { color: var(--text-secondary); font-size: 0.95rem; }

/* HIGH-TECH PREMIUM SEARCH */
.search-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 420px;
}

.premium-search {
    width: 100%;
    padding: 0.9rem 1rem 0.9rem 2.8rem;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    outline: none;
    font-size: 0.95rem;
    backdrop-filter: blur(var(--blur-strength));
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.premium-search:focus {
    border-color: rgba(99, 102, 241, 0.8);
    background: var(--bg-surface-hover);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.search-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-secondary);
    font-size: 1.2rem;
    pointer-events: none;
}

.search-shortcut {
    position: absolute;
    right: 1rem;
    background: rgba(128,128,128,0.15);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* --- DASHBOARD CARDS & GRIDS --- */
.content-wrapper {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.chapter-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.8rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 200px;
    box-shadow: var(--shadow-premium);
    backdrop-filter: blur(var(--blur-strength));
    -webkit-backdrop-filter: blur(var(--blur-strength));
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chapter-card:hover {
    transform: translateY(-6px);
    border-color: var(--border-hover);
    background: var(--bg-surface-hover);
    box-shadow: 0 22px 40px -10px rgba(99, 102, 241, 0.15);
}

.chapter-card h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.4; }
.chapter-card p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.5rem; margin-bottom: 1.5rem; line-height: 1.5; }

/* PROGRESS BAR */
.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(128,128,128,0.12);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 10px;
    width: 0%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- STUDY SECTIONS AND ITEM CARDS --- */
.qa-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.8rem;
    margin-bottom: 1.2rem;
    backdrop-filter: blur(var(--blur-strength));
    box-shadow: var(--shadow-premium);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.8rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1.2rem;
}

.badge.tf { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.badge.mcq { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge.definition { background: rgba(168, 85, 247, 0.15); color: #c084fc; }
.badge.explain { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.badge.list { background: rgba(20, 184, 166, 0.15); color: #2dd4bf; }
.badge.memorize { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge.expected { background: rgba(244, 63, 94, 0.15); color: #fb7185; margin-left: 0.5rem; }

.qa-card h3 {
    font-size: 1.2rem;
    font-weight: 500;
    line-height: 1.5;
    margin-bottom: 1rem;
}

/* INTERACTIVE BUTTONS */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
}

.btn:active { transform: translateY(0); }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-primary); box-shadow: none; }
.btn-outline:hover { background: var(--bg-surface-hover); border-color: var(--border-hover); }

.answer-section {
    margin-top: 1.2rem;
    padding-top: 1.2rem;
    border-top: 1px dashed var(--border-color);
    animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* --- BILINGUAL (EN+AR) DISPLAY CONFIG --- */
.bilingual-text {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.text-en {
    direction: ltr;
    text-align: left;
    font-weight: 500;
}

.text-ar {
    direction: rtl;
    text-align: right;
    color: var(--text-secondary);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.95rem;
    padding-top: 0.6rem;
    border-top: 1px dotted var(--border-color);
}

/* HORIZONTAL SCROLL FILTERS (SWIPE-ABLE ON MOBILE) */
.filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }

.filter-btn {
    padding: 0.55rem 1.2rem;
    border-radius: 30px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    font-weight: 500;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.filter-btn:hover, .filter-btn.active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 8px 16px -4px rgba(99, 102, 241, 0.3);
}

.memorized-check {
    margin-top: 1.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: #10b981;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.15);
    transition: all 0.2s ease;
}
.memorized-check:hover { background: rgba(16, 185, 129, 0.15); }

/* --- HIGH-TECH IMMERSIVE STUDY MODAL --- */
.premium-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(4, 7, 13, 0.85);
    backdrop-filter: blur(10px);
}

.modal-dialog {
    position: relative;
    width: 100%;
    max-width: 680px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: var(--shadow-premium);
    overflow: hidden;
    z-index: 2;
    animation: modalScaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalScaleUp { from { transform: scale(0.9) translateY(10px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.modal-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.close-btn {
    background: rgba(128,128,128,0.1);
    border: none;
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: background 0.2s;
}
.close-btn:hover { background: rgba(128,128,128,0.2); }

.modal-body { padding: 2rem; max-height: 80vh; overflow-y: auto; }

/* FLASHCARDS UI/UX */
.flashcard-container {
    perspective: 1000px;
    margin: 1.5rem auto;
    width: 100%;
    height: 340px;
}

.flashcard {
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
    position: relative;
}

.flashcard.is-flipped { transform: rotateY(180deg); }

.flashcard-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2.5rem;
    text-align: center;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-premium);
    overflow-y: auto;
}

.flashcard-front {
    background: linear-gradient(145deg, rgba(30,41,59,0.9), rgba(15,23,42,0.9));
    color: #a5b4fc;
}

.flashcard-back {
    background: var(--primary-gradient);
    color: white;
    transform: rotateY(180deg);
}

/* --- إصلاح ألوان البطاقات (تباين النصوص والوضع المضيء) --- */
body.light-theme .flashcard-front {
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    color: var(--primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    border: 1px solid rgba(67, 97, 238, 0.2);
}

body.light-theme .flashcard-front .badge {
    background: rgba(67, 97, 238, 0.1) !important;
    color: var(--primary) !important;
}

.flashcard-back .text-ar,
.flashcard-back .text-en {
    color: #ffffff !important;
}

.flashcard-back .text-ar {
    border-top-color: rgba(255, 255, 255, 0.3) !important;
}

/* QUIZ INTERACTIVE FEEDBACK STYLES */
.quiz-options-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* --- DYNAMIC RTL SUPPORT BASED ON DIR ATTRIBUTE --- */
[dir="rtl"] {
    text-align: right;
}
[dir="rtl"] .premium-nav { border-right: none; border-left: 1px solid var(--border-color); }
[dir="rtl"] .nav-item { text-align: right; flex-direction: row-reverse; }
[dir="rtl"] .nav-brand { flex-direction: row-reverse; }
[dir="rtl"] .search-box input { padding: 0.6rem 2.8rem 0.6rem 1rem; }
[dir="rtl"] .search-icon { left: auto; right: 1rem; }
[dir="rtl"] .search-shortcut { right: auto; left: 1rem; }
[dir="rtl"] .badge.expected { margin-left: 0; margin-right: 0.5rem; }

/* --- RESPONSIVE MEDIA QUERIES (MOBILE OPTIMIZATION) --- */
@media (max-width: 992px) {
    .premium-nav { width: 80px; padding: 1.5rem 0.5rem; }
    .nav-brand h1, .nav-item span, .action-text { display: none; }
    .nav-brand { justify-content: center; margin-bottom: 2rem; }
    .nav-item { justify-content: center; padding: 1rem; }
    .action-btn { justify-content: center; padding: 1rem; border-radius: 50%; }
    .main-content { max-width: calc(100vw - 80px); padding: 2rem; }
}

@media (max-width: 768px) {
    /* تحويل الهيكل بالكامل ليتوافق مع أجهزة الجوال الفخمة */
    .app-layout { flex-direction: column; }
    
    /* الـ Navigation يتحول إلى شريط سفلي ذكي ومقاس آمن (Bottom Tab Bar) */
    .premium-nav {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        width: 100vw;
        height: auto; 
        min-height: 75px; 
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom, 0px)); 
        border-right: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -10px 30px rgba(0,0,0,0.3);
        border-radius: 20px 20px 0 0;
        background: var(--bg-surface);
        z-index: 1000;
    }
    
    .nav-brand { display: none; }
    
    .nav-menu { 
        flex-direction: row; 
        width: auto; 
        gap: 1rem; 
        justify-content: center; 
    }
    
    .nav-item { 
        flex-direction: column; 
        gap: 0.3rem; 
        font-size: 0.7rem; 
        padding: 0.5rem 1rem; 
        width: auto; 
        min-width: 70px;
        height: auto; 
        justify-content: center; 
        align-items: center;
        border-radius: 14px; 
    }
    
    .nav-item i { font-size: 1.4rem; margin: 0; }
    .nav-item span { display: block; font-size: 0.7rem; font-weight: 600; text-align: center; }
    
    .nav-actions { flex-direction: row; gap: 0.8rem; padding-top: 0; border-top: none; }
    .action-btn { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%; }
    
    /* تعديل منطقة المحتوى لتجنب التداخل مع الشريط السفلي */
    .main-content { max-width: 100vw; padding: 1.5rem 1rem 90px 1rem; }
    
    .top-bar { flex-direction: column; align-items: flex-start; gap: 1rem; margin-bottom: 2rem; }
    .search-container { max-width: 100%; }
    
    .grid-cards { grid-template-columns: 1fr; }
    
    .modal-dialog { width: 100%; max-height: 96vh; border-radius: 24px; }
    .modal-body { padding: 1.2rem; }
    
    .btn { width: 100%; } 
    .quiz-options-container .btn { width: 100%; margin-top: 0.5rem; }
}