:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --accent: #3b82f6;
    /* Modern blue */
    --accent-glow: rgba(59, 130, 246, 0.5);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --success: #10b981;
    --error: #ef4444;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', 'Cairo', sans-serif;
}

body[dir="rtl"] {
    font-family: 'Cairo', 'Outfit', sans-serif;
    direction: rtl;
    text-align: right;
}

body[dir="rtl"] .hero h2 {
    font-family: 'Cairo', sans-serif;
    line-height: 1.4;
}

body[dir="rtl"] .logo {
    flex-direction: row-reverse;
}

body[dir="rtl"] .option-btn {
    text-align: right;
}

body[dir="rtl"] .feedback {
    border-left: none;
    border-right: 4px solid var(--accent);
}

body[dir="rtl"] .feedback.correct {
    border-right-color: var(--success);
}

body[dir="rtl"] .feedback.incorrect {
    border-right-color: var(--error);
}

body[dir="rtl"] .nav-controls {
    flex-direction: row-reverse;
}

.text-btn {
    font-weight: 600;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    width: auto;
}

.nav-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Background Mesh Gradient */
.background-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background:
        radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.1) 0%, transparent 40%);
    pointer-events: none;
}

/* Glass Header */
.glass-header {
    width: 100%;
    max-width: 1200px;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.logo-icon {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

/* Theme Toggle Button */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    padding: 0.5rem;
    border-radius: 50%;
}

.icon-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

/* Main Container */
#app-container {
    width: 100%;
    max-width: 900px;
    padding: 2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Landing Section */
.hero {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInUp 0.6s ease-out;
}

.hero h2 {
    font-size: 3rem;
    margin-bottom: 1rem;
    background: linear-gradient(to right, var(--text-main), var(--accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Topic Grid */
.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    width: 100%;
    animation: fadeIn 0.8s ease-out 0.2s backwards;
}

.topic-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.topic-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.3);
    border-color: var(--accent);
}

.topic-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.topic-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.topic-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.03), transparent);
    transform: translateX(-100%);
    transition: 0.5s;
}

.topic-card:hover::before {
    transform: translateX(100%);
}

/* Random Quiz Card - Special Styling */
.random-quiz-card {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(59, 130, 246, 0.2));
    border: 2px solid rgba(139, 92, 246, 0.3);
    position: relative;
}

.random-quiz-card:hover {
    border-color: rgba(139, 92, 246, 0.6);
    box-shadow: 0 10px 40px -5px rgba(139, 92, 246, 0.4);
}

.random-quiz-card::after {
    content: '✨';
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    opacity: 0.6;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-content h2 {
    margin-bottom: 2rem;
    font-size: 1.8rem;
    text-align: center;
    background: linear-gradient(to right, var(--text-main), var(--accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.question-selector {
    margin-bottom: 2rem;
    text-align: center;
}

.question-selector label {
    display: block;
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 1rem;
}

.question-selector input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    margin-bottom: 1rem;
    -webkit-appearance: none;
    appearance: none;
}

.question-selector input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
    transition: var(--transition);
}

.question-selector input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--accent-glow);
}

.question-selector input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px var(--accent-glow);
    transition: var(--transition);
}

.question-selector input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px var(--accent-glow);
}

#question-count-display {
    display: inline-block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    min-width: 60px;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal-actions button {
    flex: 1;
    max-width: 200px;
}

.topics-selector-container {
    margin: 1.5rem 0;
    max-height: 200px;
    overflow-y: auto;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    text-align: left;
}

body[dir="rtl"] .topics-selector-container {
    text-align: right;
}

.topic-checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: var(--transition);
}

.topic-checkbox-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.topic-checkbox-item input {
    cursor: pointer;
    width: 1.2rem;
    height: 1.2rem;
    accent-color: var(--accent);
}

.topic-checkbox-item span {
    font-size: 0.95rem;
    color: var(--text-main);
}


/* Quiz Interface */
.hidden-section {
    display: none !important;
}

.active-section {
    display: flex;
    flex-direction: column;
    width: 100%;
    animation: fadeIn 0.5s ease-out;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 2rem;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.secondary-btn:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

.progress-bar-container {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin: 0 1.5rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.5s ease;
    box-shadow: 0 0 10px var(--accent-glow);
}

#question-count {
    font-weight: 600;
    color: var(--text-muted);
}

.question-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 2.5rem;
    width: 100%;
    margin-bottom: 2rem;
    box-shadow: var(--card-shadow);
}

.question-card h3 {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    line-height: 1.4;
}

.options-grid {
    display: grid;
    gap: 1rem;
}

.option-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    text-align: left;
    color: var(--text-main);
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
}

.option-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(5px);
}

.option-btn.selected {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.option-btn.correct {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.option-btn.incorrect {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.primary-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.quiz-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1rem;
    width: 100%;
}

.feedback {
    padding: 1rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    width: 100%;
    margin-bottom: 1rem;
    border-left: 4px solid var(--accent);
}

.feedback.correct {
    border-left-color: var(--success);
}

.feedback.incorrect {
    border-left-color: var(--error);
}

/* Results Section */
.result-card {
    text-align: center;
    padding: 4rem 2rem;
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.score-circle {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 0 auto 2rem;
}

.circular-chart {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    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: var(--accent);
    stroke-linecap: round;
    animation: progress 1.5s ease-out forwards;
}

#final-score {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    font-weight: 700;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes progress {
    0% {
        stroke-dasharray: 0 100;
    }
}

/* Study Bank Styles */
.section-header {
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
    padding: 1rem 0;
}

.bank-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 4rem;
}

.bank-topic-header {
    margin-top: 2rem;
    padding: 1rem;
    border-bottom: 2px solid var(--glass-border);
    color: var(--accent);
}

.bank-q-card {
    position: relative;
    padding: 2rem;
    text-align: left;
}

body[dir="rtl"] .bank-q-card {
    text-align: right;
}

.bank-q-num {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    opacity: 0.5;
}

body[dir="rtl"] .bank-q-num {
    right: auto;
    left: 1.5rem;
}

.bank-q-text {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.bank-options-container {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 0.8rem;
}

.bank-options-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 1rem;
}

body[dir="rtl"] .bank-options-list {
    margin: 0.5rem 1rem 0 0;
}

.bank-options-list li {
    padding: 0.4rem 0.8rem;
    margin: 0.2rem 0;
    border-radius: 0.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.bank-options-list li.correct-option {
    color: var(--success);
    background: rgba(16, 185, 129, 0.05);
    font-weight: 600;
}

.bank-answer {
    background: rgba(16, 185, 129, 0.1);
    border-radius: 0.8rem;
    padding: 1rem;
    margin-bottom: 1rem;
    border-left: 4px solid var(--success);
}

body[dir="rtl"] .bank-answer {
    border-left: none;
    border-right: 4px solid var(--success);
}

.correct-text {
    color: var(--success);
    font-weight: 700;
    margin-left: 0.5rem;
}

.bank-explanation {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0.8rem;
}

.bank-explanation strong {
    color: var(--accent);
    display: block;
    margin-bottom: 0.5rem;
}

.bank-explanation p {
    color: var(--text-muted);
    line-height: 1.5;
}

/* Utility */
.hidden {
    display: none;
}

/* Code Snippet Styles */
pre {
    background: #0f172a;
    /* Darker blue-black for better contrast */
    padding: 1.5rem;
    border-radius: 1rem;
    overflow-x: auto;
    margin: 1.5rem 0;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 1rem;
    border: 1px solid var(--glass-border);
    direction: ltr !important;
    /* Always Left-to-Right */
    text-align: left !important;
    /* Always aligned to the left */
    line-height: 1.6;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3);
    white-space: pre-wrap;
    /* Wrap lines to prevent overflow on mobile */
    word-break: break-all;
}

code {
    font-family: inherit;
    color: #60a5fa;
    /* Light blue color for code text */
}

/* Ensure code blocks in Arabic stay LTR */
body[dir="rtl"] pre {
    direction: ltr !important;
    text-align: left !important;
}

/* Responsiveness */
@media (max-width: 768px) {
    .hero h2 {
        font-size: 2rem;
    }

    .question-card {
        padding: 1.5rem;
    }

    .quiz-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .progress-bar-container {
        width: 100%;
        margin: 1rem 0;
    }
}

/* Confetti Canvas */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* Footer */
.glass-footer {
    width: 100%;
    margin-top: 2rem;
    padding: 2rem;
    text-align: center;
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.glass-footer p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

.footer-links a:hover {
    color: var(--text-main);
    text-decoration: underline;
}