/* ==========================================================================
   CSS Variables & Theme Setup (Premium Dark Mode)
   ========================================================================== */
:root {
    /* Colors */
    --bg-color: #0b0f19;
    --surface-color: rgba(30, 41, 59, 0.4);
    --surface-border: rgba(255, 255, 255, 0.08);
    --surface-hover: rgba(45, 60, 85, 0.6);
    
    --primary-color: #38bdf8;
    --primary-glow: rgba(56, 189, 248, 0.4);
    --accent-color: #818cf8;
    
    --success-color: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --success-border: rgba(16, 185, 129, 0.3);
    
    --danger-color: #f43f5e;
    --danger-bg: rgba(244, 63, 94, 0.15);
    --danger-border: rgba(244, 63, 94, 0.3);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Typography */
    --font-family-main: 'Tajawal', sans-serif;
    --font-family-num: 'Inter', 'Tajawal', sans-serif;
    
    /* Metrics */
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
    --border-radius-lg: 24px;
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   Global Reset & Base
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    font-family: var(--font-family-main);
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
    line-height: 1.6;
}

/* Background Ambient Glows */
.bg-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    z-index: -1;
    opacity: 0.5;
    pointer-events: none;
}
.bg-shape-1 {
    top: -10%;
    right: -5%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--accent-color), transparent 70%);
}
.bg-shape-2 {
    bottom: -10%;
    left: -10%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--primary-color), transparent 70%);
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--surface-color);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--surface-border);
    border-radius: var(--border-radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Typography Utilities */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.2; }
.accent-text { color: var(--primary-color); }
.danger-text { color: var(--danger-color); }
.subtitle { color: var(--text-muted); font-size: 1rem; margin-top: 8px; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-family-main);
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    text-decoration: none;
}
.btn-lg { padding: 14px 28px; font-size: 1.1rem; border-radius: var(--border-radius-md); }
.block { width: 100%; }

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: #fff;
    box-shadow: 0 4px 15px var(--primary-glow);
}
.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(129, 140, 248, 0.5);
}

.text-btn {
    background: transparent;
    color: var(--text-muted);
}
.text-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}
.text-btn.active {
    color: var(--primary-color);
    background: rgba(56, 189, 248, 0.1);
}

.danger-outline {
    background: transparent;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
}
.danger-outline:hover {
    background: var(--danger-color);
    color: #fff;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-main); }

/* ==========================================================================
   Layout
   ========================================================================== */
.container {
    max-width: 900px;
    margin: 40px auto 100px auto;
    padding: 0 20px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    margin: 20px;
    border-radius: var(--border-radius-lg);
    position: sticky;
    top: 20px;
    z-index: 100;
}
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
}
.logo i { color: var(--primary-color); width: 28px; height: 28px; }
.logo h1 { font-size: 1.5rem; letter-spacing: 0.5px; }

.nav-links { display: flex; gap: 10px; }

.section-header { margin-bottom: 24px; }
.badge {
    background: var(--primary-glow);
    color: var(--primary-color);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    vertical-align: middle;
    margin-right: 10px;
}

/* ==========================================================================
   Subjects View (Cards)
   ========================================================================== */
.branches-grid {
    display: grid;
    gap: 24px;
}
.branch-card {
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--border-radius-md);
    padding: 20px;
    border: 1px solid var(--surface-border);
}
.branch-card h3 {
    margin-bottom: 16px;
    color: var(--text-main);
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.subjects-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.subject-item {
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
    padding: 16px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.subject-item:hover {
    transform: translateY(-4px);
    border-color: var(--primary-color);
    background: var(--surface-hover);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
.subject-item strong { font-size: 1.1rem; }
.subject-item small { color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

/* Loader */
.loader-container {
    text-align: center;
    padding: 60px 0;
    color: var(--text-muted);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(56, 189, 248, 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Dashboard View
   ========================================================================== */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    margin-bottom: 30px;
}
.dashboard-title-wrapper { display: flex; align-items: center; gap: 16px; }

.dashboard-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 40px;
}
.stat-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 24px;
}
.stat-icon {
    width: 60px; height: 60px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.stat-icon i { width: 28px; height: 28px; }
.primary-bg { background: rgba(56, 189, 248, 0.15); color: var(--primary-color); }
.danger-bg { background: var(--danger-bg); color: var(--danger-color); }
.stat-info h3 { font-size: 1rem; color: var(--text-muted); font-weight: 500; }
.counter { font-size: 2.5rem; font-weight: 800; font-family: var(--font-family-num); line-height: 1; margin-top: 5px; }

.exam-modes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}
.mode-card {
    border: 1px solid var(--surface-border);
    padding: 24px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: var(--transition-smooth);
    text-align: right;
    display: flex; flex-direction: column; gap: 12px;
}
.mode-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    background: var(--surface-hover);
}
.mode-icon { color: var(--primary-color); }
.mode-icon i { width: 32px; height: 32px; }
.mode-card h3 { font-size: 1.2rem; margin: 0; color: var(--text-main); }
.mode-card p { font-size: 0.9rem; color: var(--text-muted); margin: 0; }

.mode-card.danger-glow:hover {
    border-color: var(--danger-color);
    box-shadow: 0 10px 25px rgba(244, 63, 94, 0.2);
}

/* ==========================================================================
   Exam View
   ========================================================================== */
.exam-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    margin-bottom: 24px;
}
.exam-progress-info {
    flex: 1;
    margin-left: 20px;
}
.progress-text { font-family: var(--font-family-num); font-weight: 600; font-size: 0.95rem; display: block; margin-bottom: 8px;}
.progress-bar-container {
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--primary-color));
    width: 0%;
    border-radius: 10px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.question-container {
    padding: 40px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}
.question-text {
    font-size: 1.6rem;
    line-height: 1.5;
    margin-bottom: 30px;
    color: var(--text-main);
}
.options-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: auto;
}
.option-btn {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--surface-border);
    padding: 18px 24px;
    border-radius: var(--border-radius-sm);
    color: var(--text-main);
    font-size: 1.1rem;
    font-family: inherit;
    text-align: right;
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}
.option-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.2);
    transform: translateX(-5px);
}
.option-btn:disabled { cursor: default; }

.option-btn.correct {
    background: var(--success-bg);
    border-color: var(--success-color);
    color: var(--success-color);
}
.option-btn.wrong {
    background: var(--danger-bg);
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.explanation-card {
    margin-top: 24px;
    padding: 20px;
    border-right: 4px solid var(--primary-color);
}
.explanation-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px;}
.explanation-card p { color: var(--text-muted); line-height: 1.7;}

.exam-footer { margin-top: 30px; display: flex; justify-content: flex-end; }

/* ==========================================================================
   Results View
   ========================================================================== */
.results-view {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}
.results-card {
    padding: 50px;
    text-align: center;
    max-width: 500px;
    width: 100%;
}
.results-icon {
    width: 80px; height: 80px;
    margin: 0 auto 20px;
    background: rgba(56, 189, 248, 0.1);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--primary-color);
}
.results-icon i { width: 40px; height: 40px; }

.score-circle {
    width: 150px;
    margin: 30px auto;
}
.circular-chart { display: block; margin: 0 auto; max-width: 80%; max-height: 250px; }
.circle-bg { fill: none; stroke: rgba(255,255,255,0.1); stroke-width: 2.5; }
.circle {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke: var(--primary-color);
    transition: stroke-dasharray 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.percentage {
    fill: var(--text-main);
    font-family: var(--font-family-num);
    font-size: 8px;
    font-weight: bold;
    text-anchor: middle;
}

.score-details {
    font-size: 2rem;
    font-family: var(--font-family-num);
    font-weight: 800;
    margin-bottom: 10px;
}
.score-divider { color: var(--text-muted); margin: 0 10px; font-weight: 400;}
.score-number.total { color: var(--text-muted); font-size: 1.5rem;}
.score-message { font-size: 1.2rem; color: var(--text-muted); margin-bottom: 30px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 768px) {
    .dashboard-stats { grid-template-columns: 1fr; }
    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .exam-top-bar { flex-direction: column; align-items: flex-start; gap: 15px;}
    .exam-progress-info { margin-left: 0; width: 100%; margin-bottom: 10px;}
    .question-container { padding: 25px; }
    .app-header { padding: 12px 20px; margin: 10px; flex-direction: column; gap: 15px; }
    .logo h1 { font-size: 1.2rem;}
    .btn { padding: 8px 16px; font-size: 0.95rem; }
    .results-card { padding: 30px 15px; }
    .bg-shape-1, .bg-shape-2 { width: 300px; height: 300px; filter: blur(80px); }
}
