/* ==========================================================
   BacOrbit - Production Stylesheet
   الملف الموحد النظيف بعد المراجعة التقنية وحل تعارضات التفاعل
   ========================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

html {
    scroll-behavior: smooth;
}

/* ---------- 1. متغيرات الألوان ---------- */

:root {
    --bg: #0d0d0d;
    --text: #ffffff;
    --text-secondary: #bdbdbd;
    --text-muted: #cfcfcf;
    --header-bg: #111111;
    --track-bg: #0a0a0a;
    --accent: #1aff66;
    --accent-soft: rgba(26, 255, 102, 0.5);
    --accent-glow: rgba(26, 255, 102, 0.4);
    --card-bg: #161616;
    --border: #1aff66;
    --empty-border: #333333;
    --empty-text: #666666;
    --footer-text: #888888;
    --featured-tint: #0f2b1a;
    --danger: #ff4d4d;
    --danger-bg: #2b0f0f;
    --gold: #ffd24d;
    --gold-dark: #c9a227;
    --bg-particle-dot: rgba(26, 255, 102, 0.5);
    --bg-particle-line: rgba(26, 255, 102, 0.4);
    --bg-grid: rgba(26, 255, 102, 0.045);
    --bg-glow-a: rgba(26, 255, 102, 0.08);
    --bg-glow-b: rgba(26, 255, 102, 0.05);
}

html[data-theme="light"] {
    --bg: #ffffff;
    --text: #181818;
    --text-secondary: #5c5c5c;
    --text-muted: #4a4a4a;
    --header-bg: #fff8f0;
    --track-bg: #ffe9d2;
    --accent: #ff8a1f;
    --accent-soft: rgba(255, 138, 31, 0.4);
    --accent-glow: rgba(255, 138, 31, 0.35);
    --card-bg: #fbf7f2;
    --border: #ff8a1f;
    --empty-border: #e4ded6;
    --empty-text: #a3a3a3;
    --footer-text: #8a8a8a;
    --featured-tint: #ffe6c9;
    --danger: #e04343;
    --danger-bg: #fdeaea;
    --gold: #ffc94d;
    --gold-dark: #b5860f;
    --bg-particle-dot: rgba(196, 148, 25, 0.8);
    --bg-particle-line: rgba(196, 148, 25, 0.45);
    --bg-grid: rgba(196, 148, 25, 0.075);
    --bg-glow-a: rgba(255, 138, 31, 0.09);
    --bg-glow-b: rgba(255, 201, 77, 0.10);
}

html, body {
    transition: background-color 0.4s ease, color 0.4s ease;
}

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    width: 100%;
}

/* ---------- 2. الشريط العلوي ---------- */

.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 25px;
    z-index: 1000;
    transition: transform 0.3s ease-in-out, background-color 0.35s ease, border-color 0.35s ease;
}

.top-bar.hide {
    transform: translateY(-100%);
}

.top-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.25s ease;
}

.top-link:hover {
    color: var(--text);
}

.notification-dot {
    width: 9px;
    height: 9px;
    background: var(--danger);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 10px var(--danger);
}

/* ---------- 3. زر تبديل الوضع (Switch) ---------- */

.theme-switch {
    direction: ltr;
    position: relative;
    width: 62px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--track-bg);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background-color 0.4s ease, border-color 0.4s ease, box-shadow 0.3s ease;
}

.theme-switch:hover {
    box-shadow: 0 0 14px var(--accent-glow);
}

.theme-switch:active .theme-switch-thumb {
    width: 30px;
}

.theme-switch-track {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 7px;
    pointer-events: none;
    z-index: 2;
}

.theme-switch-icon {
    font-size: 13px;
    line-height: 1;
    opacity: 0.4;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.theme-switch .moon {
    opacity: 1;
}

html[data-theme="light"] .theme-switch .sun {
    opacity: 1;
    transform: scale(1.1);
}

html[data-theme="light"] .theme-switch .moon {
    opacity: 0.4;
}

.theme-switch-thumb {
    position: absolute;
    top: 3px;
    left: 33px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease, width 0.15s ease;
    z-index: 3;
}

html[data-theme="light"] .theme-switch-thumb {
    left: 3px;
}

/* ---------- 4. الهيدر والشعار ---------- */

header.site-header {
    margin-top: 55px;
    text-align: center;
    padding: 30px;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.35s ease;
}

.logo {
    font-size: 40px;
    font-weight: bold;
    color: var(--accent);
    letter-spacing: 2px;
    transition: color 0.35s ease;
}

/* ---------- 5. قسم الهيرو ---------- */

.hero {
    text-align: center;
    padding: 70px 20px 40px;
}

.hero h1 {
    font-size: 44px;
    margin-bottom: 14px;
    color: var(--text);
}

.hero p {
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1.7;
}

/* ---------- 6. شبكة البطاقات (الصفحة الرئيسية) ---------- */

.branches {
    max-width: 1200px;
    margin: auto;
    padding: 30px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 25px;
}

.card {
    position: relative;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 35px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.35s ease, border-color 0.35s ease;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 0 25px var(--accent-soft);
}

.card h2 {
    color: var(--accent);
    margin-bottom: 15px;
    transition: color 0.35s ease;
}

.card p {
    color: var(--text-muted);
}

.card-featured {
    grid-column: 1 / -1;
    padding: 55px 35px;
    background: linear-gradient(135deg, var(--card-bg), var(--featured-tint));
    border-width: 3px;
}

.card-featured h2 {
    font-size: 30px;
}

.card-featured p {
    font-size: 16px;
    margin-top: 6px;
}

.card-empty {
    border-color: var(--empty-border);
    cursor: default;
    opacity: 0.65;
}

.card-empty:hover {
    transform: none;
    box-shadow: none;
}

.card-empty h2 {
    color: var(--empty-text);
}

/* ---------- 7. زر رجوع + فوتر ---------- */

.back {
    display: block;
    width: 260px;
    margin: 45px auto 40px;
    padding: 16px;
    text-align: center;
    background: var(--accent);
    color: #000;
    font-weight: bold;
    text-decoration: none;
    border-radius: 14px;
    transition: transform 0.25s ease, background-color 0.35s ease;
}

.back:hover {
    transform: scale(1.03);
}

footer {
    text-align: center;
    padding: 25px;
    color: var(--footer-text);
    transition: color 0.35s ease;
}

/* ---------- 8. عناصر لعبة "التذكير بالمكتسبات" ---------- */

.game-hero h1 {
    font-size: 40px;
    color: var(--accent);
}

.score-bar {
    max-width: 650px;
    margin: 0 auto 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: bold;
    flex-wrap: wrap;
    gap: 8px;
}

.score-bar span {
    color: var(--accent);
}

.progress-track {
    max-width: 650px;
    margin: 0 auto 25px;
    padding: 0 10px;
}

.progress-outer {
    height: 8px;
    background: var(--track-bg);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--empty-border);
}

.progress-inner {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.4s ease, background-color 0.35s ease;
}

.quiz-wrap {
    max-width: 650px;
    margin: auto;
    padding: 10px 20px 60px;
}

.quiz-card {
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 22px;
    padding: 35px;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.35s ease;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.3);
}

.quiz-card.shake {
    animation: shake 0.4s;
}

.quiz-card.flash-red {
    border-color: var(--danger);
    box-shadow: 0 0 30px rgba(224, 67, 67, 0.4);
}

.quiz-card.flash-green {
    border-color: var(--accent);
    box-shadow: 0 0 30px var(--accent-glow);
}

@keyframes shake {
    0% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-8px); }
    80% { transform: translateX(8px); }
    100% { transform: translateX(0); }
}

.badge {
    display: inline-block;
    background: var(--bg);
    border: 1px solid var(--accent);
    color: var(--accent);
    font-size: 13px;
    font-weight: bold;
    padding: 6px 16px;
    border-radius: 20px;
    margin-bottom: 18px;
    transition: border-color 0.35s ease, color 0.35s ease, background-color 0.35s ease;
}

.badge.review {
    border-color: var(--gold);
    color: var(--gold-dark);
}

.question-text {
    font-size: 21px;
    line-height: 1.85;
    margin-bottom: 28px;
    min-height: 60px;
    unicode-bidi: plaintext;
    letter-spacing: 0.2px;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.option-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg);
    border: 2px solid var(--empty-border);
    color: var(--text);
    padding: 14px 18px;
    border-radius: 14px;
    font-size: 17px;
    text-align: right;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease, background-color 0.35s ease, color 0.35s ease;
    font-family: inherit;
    width: 100%;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--accent);
    transform: translateY(-3px);
}

.option-btn:disabled {
    cursor: default;
}

.option-letter {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 2px solid var(--accent);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.option-text {
    flex: 1;
    unicode-bidi: plaintext;
    line-height: 1.6;
}

.option-btn.correct-answer {
    border-color: var(--accent);
    background: var(--featured-tint);
    color: var(--accent);
    font-weight: bold;
}

.option-btn.correct-answer .option-letter {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.option-btn.wrong-answer {
    border-color: var(--danger);
    background: var(--danger-bg);
    color: var(--danger);
    font-weight: bold;
}

.option-btn.wrong-answer .option-letter {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.banner-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 2000;
}

.banner {
    padding: 22px 45px;
    border-radius: 20px;
    font-size: 32px;
    font-weight: bold;
    text-align: center;
    opacity: 0;
    transform: scale(0.7);
    transition: transform 0.25s ease, opacity 0.25s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.banner.show {
    opacity: 1;
    transform: scale(1);
}

.banner.win {
    background: var(--featured-tint);
    border: 3px solid var(--accent);
    color: var(--accent);
}

.banner.lose {
    background: var(--danger-bg);
    border: 3px solid var(--danger);
    color: var(--danger);
}

.congrats, .stage-complete {
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 22px;
    padding: 35px 25px 40px;
    text-align: center;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.3);
}

.congrats-svg, .stage-complete-svg {
    width: 100%;
    height: auto;
    margin: 0 auto 10px;
    display: block;
}

.congrats-svg { max-width: 380px; }
.stage-complete-svg { max-width: 210px; }

.congrats h2, .stage-complete h2 {
    color: var(--accent);
    font-size: 26px;
    margin-bottom: 14px;
}

.congrats p, .stage-complete p {
    color: var(--text-muted);
    font-size: 17px;
    line-height: 1.8;
    margin-bottom: 26px;
}

.restart-btn {
    background: var(--accent);
    color: #000;
    border: none;
    padding: 15px 34px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.35s ease;
    font-family: inherit;
}

.restart-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--accent-glow);
}

.theme-fill {
    fill: var(--accent);
    transition: fill 0.35s ease;
}

.theme-stop {
    stop-color: var(--accent);
    transition: stop-color 0.35s ease;
}

.confetti {
    animation: floaty 3s ease-in-out infinite;
}

.confetti.c2, .confetti.c4, .confetti.c6 { animation-delay: 0.4s; }
.confetti.c3, .confetti.c5 { animation-delay: 0.8s; }

@keyframes floaty {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.sparkle {
    animation: twinkle 1.6s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}

.sparkle.s2 { animation-delay: 0.5s; }
.sparkle.s3 { animation-delay: 1s; }

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* ---------- 9. صفحات المواد والأكورديون (تم الإصلاح الشامل) ---------- */

.subjects {
    max-width: 1200px;
    margin: auto;
    padding: 30px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
    align-items: start;
}

.subjects .card {
    position: relative;
}

/* إصلاح مشكلة قفل النقر وحجب المحتوى داخل الأكورديون */
.subject-content {
    display: none;
    margin-top: 20px;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.35s ease, max-height 0.4s ease-out;
}

/* عند الفتح بـ JavaScript سواًء عبر تغيير display أو الكلاسات */
.subject-content[style*="display: block"],
.subject-content.open,
.subject-content.active {
    opacity: 1;
    max-height: 2000px;
    overflow: visible;
}

.mini-card {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 15px;
    padding: 15px;
    margin-top: 12px;
    color: var(--text);
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.35s ease, border-color 0.35s ease, color 0.35s ease;
}

.mini-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0 20px var(--accent-glow);
}

.mini-card.disabled-card {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.mini-card.disabled-card:hover {
    transform: none;
    box-shadow: none;
}

/* ---------- 10. صفحات الدروس ---------- */

.lessons {
    width: 100%;
    max-width: 1050px;
    margin: auto;
    padding: 20px;
}

.lesson {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 22px;
    overflow: hidden;
    margin-bottom: 45px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45);
    transition: transform 0.35s ease, box-shadow 0.35s ease, background-color 0.35s ease, border-color 0.35s ease;
}

.lesson:hover {
    transform: translateY(-6px);
    box-shadow: 0 0 35px var(--accent-glow);
}

.lesson img {
    width: var(--bac-lesson-zoom, 100%);
    max-width: 100%;
    display: block;
    margin: 0 auto;
    transition: width 0.15s ease;
}

.lesson iframe {
    width: 100%;
    height: 620px;
    border: none;
    display: block;
    background: #ffffff;
}

.lesson .topic-download-btn {
    margin: 14px 20px 20px;
}

/* ---------- 10ب. شريط التحكم بحجم صور الدروس (تكبير/تصغير فوري) ---------- */

.bac-zoom-bar {
    max-width: 1050px;
    margin: 0 auto 18px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    transition: background-color 0.35s ease, border-color 0.35s ease;
}

.bac-zoom-label {
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: bold;
    white-space: nowrap;
}

.bac-zoom-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1.5px solid var(--accent);
    background: var(--bg);
    color: var(--accent);
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    transition: background-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease, border-color 0.35s ease;
}

.bac-zoom-btn:hover {
    box-shadow: 0 0 14px var(--accent-glow);
}

.bac-zoom-range {
    width: 160px;
    max-width: 45vw;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ---------- 11. المنتدى (chat.html) وبوابة التسجيل الموحدة ---------- */

.wrap {
    max-width: 800px;
    margin: auto;
    padding: 0 20px 40px;
}

.auth-gate {
    max-width: 800px;
    margin: 0 auto 40px;
}

.auth-card {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 22px;
    padding: 38px 28px;
    text-align: center;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.25);
    animation: forumCardIn 0.45s ease both;
}

.auth-icon {
    width: 62px;
    height: 62px;
    margin: 0 auto 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    background: var(--featured-tint);
    border: 1px solid var(--accent);
    font-size: 28px;
}

.auth-card h2 {
    color: var(--accent);
    margin-bottom: 10px;
}

.auth-card p {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 22px;
}

.google-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 360px;
    padding: 14px 20px;
    border: 1px solid var(--accent);
    border-radius: 13px;
    background: var(--accent);
    color: #000;
    font: 700 15px Arial, sans-serif;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.25s ease, background-color 0.35s ease;
}

.google-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 22px var(--accent-glow);
}

.google-btn:disabled, .submit-btn:disabled {
    opacity: 0.65;
    cursor: wait;
    transform: none;
}

.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 auto 20px;
    max-width: 800px;
    padding: 12px 18px;
    border: 1px solid var(--empty-border);
    border-radius: 14px;
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 14px;
}

.user-bar strong {
    color: var(--accent);
}

.signout-link {
    color: var(--danger);
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
}

.signout-link:hover {
    text-decoration: underline;
    opacity: 0.85;
}

.new-post {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 25px;
    margin-bottom: 40px;
    transition: background-color 0.35s ease, border-color 0.35s ease;
}

.composer-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 16px;
}

.composer-title h3 {
    color: var(--accent);
    font-size: 20px;
    margin-bottom: 5px;
}

.composer-title p {
    color: var(--text-secondary);
    font-size: 13px;
}

.composer-badge {
    border: 1px solid var(--accent);
    color: var(--accent);
    background: var(--featured-tint);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: bold;
    white-space: nowrap;
}

.new-post input[type="text"],
.new-post textarea,
.reply-form input[type="text"],
.reply-form textarea {
    width: 100%;
    background: var(--bg);
    border: 2px solid var(--empty-border);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 14px;
    resize: vertical;
    transition: border-color 0.25s ease, background-color 0.35s ease, color 0.35s ease;
}

.new-post input[type="text"]:focus,
.new-post textarea:focus,
.reply-form input[type="text"]:focus,
.reply-form textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.new-post textarea { min-height: 100px; }

.file-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.file-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 2px dashed var(--accent);
    border-radius: 12px;
    padding: 10px 16px;
    color: var(--accent);
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.25s ease, border-color 0.35s ease;
}

.file-label:hover {
    background: var(--accent-glow);
}

.file-name {
    color: var(--text-secondary);
    font-size: 13px;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.clear-file-btn {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--danger);
    background: transparent;
    color: var(--danger);
    border-radius: 9px;
    padding: 7px 10px;
    cursor: pointer;
    font: 700 12px Arial, sans-serif;
}

.clear-file-btn:hover {
    background: var(--danger-bg);
}

.attachment-preview-wrap {
    margin: 0 0 14px;
    padding: 10px;
    border: 1px solid var(--empty-border);
    border-radius: 13px;
    background: var(--bg);
}

.img-preview {
    max-width: 220px;
    max-height: 220px;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid var(--border);
    display: none;
    margin-bottom: 14px;
}

.file-preview-card {
    display: none;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 58px;
    padding: 10px 12px;
    border-radius: 11px;
    background: var(--card-bg);
    border: 1px solid var(--empty-border);
    color: var(--text);
}

.file-preview-card strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 360px;
}

.file-preview-card small {
    display: block;
    color: var(--text-secondary);
    margin-top: 3px;
}

.file-preview-icon { font-size: 27px; }

.submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #000;
    font-weight: bold;
    font-size: 16px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.35s ease;
    font-family: inherit;
}

.submit-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(0, 0, 0, 0.25);
    border-top-color: #000;
    border-radius: 50%;
    animation: forumSpin 0.7s linear infinite;
}

.post {
    position: relative;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 20px;
    padding: 22px;
    margin-bottom: 25px;
    animation: forumCardIn 0.35s ease both;
    transition: box-shadow 0.3s ease, background-color 0.35s ease, border-color 0.35s ease;
}

.post:hover {
    box-shadow: 0 0 20px var(--accent-soft);
}

.post-mine {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--featured-tint), var(--card-bg) 65%);
    box-shadow: 0 0 0 1px var(--accent-soft), 0 8px 26px rgba(0, 0, 0, 0.18);
}

.post-mine::before {
    content: "";
    position: absolute;
    top: 12px;
    right: 12px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
}

.you-badge {
    display: inline-flex;
    align-items: center;
    margin-right: 5px;
    padding: 3px 7px;
    border-radius: 999px;
    background: var(--accent);
    color: #000;
    font-size: 10px;
    vertical-align: middle;
}

.post-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.post-author {
    color: var(--accent);
    font-weight: bold;
    font-size: 16px;
}

.post-date {
    color: var(--footer-text);
    font-size: 13px;
}

.post-text {
    color: var(--text);
    font-size: 15px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-bottom: 12px;
}

.post-img {
    max-width: 100%;
    border-radius: 14px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    display: block;
}

.attachment-image-link {
    display: block;
    width: max-content;
    max-width: 100%;
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 520px;
    margin: 0 0 13px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--empty-border);
    border-radius: 13px;
    color: var(--text);
    text-decoration: none;
    transition: transform 0.2s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.attachment-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.18);
}

.attachment-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    background: var(--featured-tint);
    font-size: 20px;
    flex: 0 0 auto;
}

.attachment-info {
    min-width: 0;
    flex: 1;
}

.attachment-info strong, .attachment-info small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-info small {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 11px;
}

.attachment-download {
    color: var(--accent);
    font-size: 22px;
    font-weight: bold;
}

.post-actions {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.action-btn {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 6px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: background-color 0.25s ease, border-color 0.35s ease, color 0.35s ease;
    font-family: inherit;
}

.action-btn:hover, .reply-btn:hover {
    background: var(--accent-glow);
}

.del-btn, .report-btn {
    border-color: var(--danger);
    color: var(--danger);
}

.del-btn:hover, .report-btn:hover {
    background: var(--danger-bg);
}

.replies {
    margin-top: 16px;
    padding-right: 22px;
    border-right: 2px solid var(--accent-soft);
}

.replies-title {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: bold;
    margin: 4px 0 8px;
}

.reply {
    background: var(--bg);
    border: 1px solid var(--empty-border);
    border-radius: 14px;
    padding: 14px 16px;
    margin-top: 12px;
}

.reply.post-mine {
    background: linear-gradient(135deg, var(--featured-tint), var(--bg) 70%);
}

.reply .attachment-card { max-width: 460px; }

.reply-form {
    display: none;
    margin-top: 14px;
    background: var(--bg);
    border: 1px solid var(--empty-border);
    border-radius: 14px;
    padding: 14px;
    overflow: hidden;
    animation: replyOpen 0.25s ease both;
}

.reply-form.open { display: block; }
.reply-form textarea { min-height: 70px; }

.empty-state {
    text-align: center;
    color: var(--footer-text);
    padding: 40px 20px;
    font-size: 16px;
}

.forum-error {
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid var(--danger);
    border-radius: 14px;
    background: var(--danger-bg);
    color: var(--danger);
    text-align: center;
    line-height: 1.7;
}

@keyframes forumCardIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes replyOpen {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes forumSpin {
    to { transform: rotate(360deg); }
}

/* ---------- 12. أزرار وتنسيق بطاقات المواضيع والتنزيل ---------- */

.topic-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    min-height: 168px;
    padding: 26px 22px;
    gap: 16px;
}

.topic-card h2 {
    width: 100%;
    font-size: 18px;
    line-height: 1.6;
    margin-bottom: 0;
}

.topic-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 0 16px var(--accent-soft);
}

.topic-download-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 145px;
    margin-top: auto;
    padding: 10px 18px;
    background: linear-gradient(135deg, var(--card-bg), var(--featured-tint));
    border: 1.5px solid var(--accent);
    color: var(--accent);
    border-radius: 10px;
    font-size: 13px;
    font-weight: bold;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    transition: background-color 0.25s ease, color 0.25s ease, transform 0.2s ease, box-shadow 0.25s ease, border-color 0.35s ease;
}

.topic-download-btn::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 25%, rgba(255, 255, 255, 0.16) 50%, transparent 75%);
    transform: translateX(-120%);
    transition: transform 0.55s ease;
    pointer-events: none;
}

.topic-download-btn:hover::after {
    transform: translateX(120%);
}

.topic-download-btn:hover {
    background: var(--accent);
    color: #000;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--accent-glow);
}

.topic-download-btn:active {
    transform: translateY(0);
}

.topic-download-btn.loading {
    cursor: wait;
    opacity: 0.9;
    transform: none;
}

.topic-download-btn.done {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    cursor: default;
    transform: none;
}

.topic-download-btn svg { flex-shrink: 0; }
.topic-download-btn span { line-height: 1; }

.download-all-section {
    max-width: 1050px;
    margin: 10px auto 45px;
    padding: 0 20px;
    text-align: center;
}

.download-all-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-width: 290px;
    max-width: 100%;
    padding: 17px 36px;
    background: var(--accent);
    color: #000;
    font-weight: bold;
    font-size: 16px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 8px 24px var(--accent-soft);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background-color 0.35s ease, opacity 0.25s ease;
}

.download-all-btn:hover:not(.loading):not(.done) {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 10px 30px var(--accent-glow);
}

.download-all-btn:active:not(.loading) {
    transform: translateY(0) scale(0.98);
}

.download-all-btn.loading {
    cursor: progress;
    opacity: 0.92;
}

.download-all-btn svg { flex-shrink: 0; }
.dl-label { line-height: 1.3; }

.dl-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2.5px solid rgba(0, 0, 0, 0.28);
    border-top-color: #000;
    animation: dlspin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes dlspin {
    to { transform: rotate(360deg); }
}

.dl-check {
    font-size: 19px;
    line-height: 1;
}

.download-hint {
    margin-top: 12px;
    font-size: 12.5px;
    color: var(--footer-text);
}

/* ---------- 13. أزرار عارض الصور (تكبير/تصغير وتنزيل جانبي) ---------- */

.bac-img-frame {
    position: relative;
    display: block;
    line-height: 0;
    isolation: isolate;
}

.bac-img-frame a {
    display: block;
    line-height: 0;
}

.bac-img-frame img {
    display: block;
    width: var(--bac-lesson-zoom, 100%);
    max-width: 100%;
    margin: 0 auto;
    transform-origin: center center;
    transition: transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1), box-shadow 0.35s ease, border-radius 0.35s ease, width 0.15s ease;
    backface-visibility: hidden;
    will-change: transform;
}

.bac-img-frame img {
    cursor: zoom-in;
}

.bac-img-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
}

.bac-side-download {
    pointer-events: auto;
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.bac-side-download:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.bac-side-download,
a.bac-side-download,
button.bac-side-download,
.topic-download-btn.bac-side-download {
    top: 12px;
    left: 12px;
    width: 44px;
    height: 44px;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 12px !important;
    background: var(--card-bg);
    border: 1.5px solid var(--accent);
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
    transition: transform 0.2s ease, box-shadow 0.25s ease, background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    z-index: 32;
    font-size: 0;
    line-height: 0;
    gap: 0;
    overflow: hidden;
}

.bac-side-download:hover,
.topic-download-btn.bac-side-download:hover {
    transform: translateY(-2px) scale(1.04);
    background: var(--featured-tint);
    box-shadow: 0 0 18px var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent);
}

.bac-side-download:active,
.topic-download-btn.bac-side-download:active {
    transform: translateY(0) scale(0.96);
}

.bac-side-download svg {
    width: 19px;
    height: 19px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.bac-hide-text { display: none !important; }
.topic-download-btn.bac-side-download::after { display: none; }

/* ---------- 13ب. المكبّر الموحّد لصور الدروس (عنصر واحد فقط لكل صفحة) ---------- */

.bac-image-viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 10500;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    padding: 40px 20px;
}

.bac-image-viewer-overlay.open {
    display: flex;
}

.bac-image-viewer-inner {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.bac-image-viewer-inner img {
    max-width: 92vw;
    max-height: 78vh;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: block;
    background: var(--card-bg);
}

.bac-image-viewer-close {
    position: absolute;
    top: -16px;
    left: -16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1.5px solid var(--accent);
    color: var(--accent);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, background-color 0.25s ease;
    font-family: inherit;
}

.bac-image-viewer-close:hover {
    transform: scale(1.08);
    background: var(--featured-tint);
}

.bac-image-viewer-download {
    width: auto;
    min-width: 160px;
}

/* ---------- 14. تموضع أساسي للبطاقات والأزرار (تُستخدمه عناصر أخرى مثل الشارات) ---------- */

.card, .mini-card, .topic-card, button {
    position: relative;
}


/* ---------- 15. الخلفية التفاعلية وتأثيرات النقر (Interactive Background & Click FX) ----------
   طبقتان Canvas فقط، بدون أي تأثير على تخطيط الصفحة أو قابلية النقر/التحديد:
   - bacBgCanvas: خلف كل المحتوى (z-index: -1)، شبكة جسيمات هادئة تتفاعل بنعومة مع الماوس.
   - bacClickFxCanvas: فوق كل شيء لكنها غير قابلة للنقر (pointer-events: none)، تعرض تأثير نقر بسيط.
   الألوان تُقرأ من متغيرات التصميم (--accent / --accent-soft) فتتكيف تلقائيًا مع الوضعين. */

#bacBgCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    display: block;
}

#bacClickFxCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    #bacBgCanvas,
    #bacClickFxCanvas {
        display: none !important;
    }
}

/* ---------- 16. قائمة التنقل المنسدلة (Hamburger Nav Menu) ----------
   زر ☰ واحد يستبدل رابطي «المنتدى» و«الدعم» المنفصلين سابقًا في الشريط
   العلوي. يعتمد بالكامل على متغيرات التصميم الحالية (--accent, --card-bg,
   --border...) ليتكيف تلقائيًا مع الوضعين الداكن والفاتح، ويتموضع كعنصر
   ابن لـ .top-bar فلا يحتاج أي تعديل في بنية الهيدر أو الشعار. */

.nav-menu-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.bac-nav-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.bac-nav-actions .bac-notif-btn,
.bac-nav-actions .bac-timer-btn {
    margin: 0;
}

.nav-menu-btn {
    position: relative;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--track-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.25s ease, transform 0.15s ease;
}

.nav-menu-btn:hover {
    box-shadow: 0 0 14px var(--accent-glow);
}

.nav-menu-btn:active {
    transform: scale(0.93);
}

.nav-menu-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.nav-menu-icon {
    position: relative;
    width: 20px;
    height: 15px;
    flex-shrink: 0;
}

.nav-menu-bar {
    position: absolute;
    right: 0;
    left: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, background-color 0.35s ease;
}

.nav-menu-bar:nth-child(1) { top: 0; }
.nav-menu-bar:nth-child(2) { top: 50%; transform: translateY(-50%); }
.nav-menu-bar:nth-child(3) { bottom: 0; }

.nav-menu-btn.open .nav-menu-bar:nth-child(1) {
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.nav-menu-btn.open .nav-menu-bar:nth-child(2) {
    opacity: 0;
    transform: translateY(-50%) scaleX(0);
}

.nav-menu-btn.open .nav-menu-bar:nth-child(3) {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%) rotate(-45deg);
}

.nav-menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 226px;
    background: var(--card-bg);
    border: 1.5px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.97);
    transform-origin: top right;
    transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.22s ease;
}

.nav-menu-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.nav-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    background: transparent;
    border: none;
    color: var(--text);
    text-decoration: none;
    font-size: 14.5px;
    font-weight: bold;
    font-family: inherit;
    text-align: right;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.nav-menu-item:hover {
    background: var(--accent-glow);
    color: var(--accent);
}

.nav-menu-item:active {
    transform: scale(0.98);
}

.nav-menu-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.nav-menu-item-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    width: 20px;
}

/* ---------- 17. تصميم متجاوب حقيقي للأجهزة اللوحية والهواتف ----------
   ملاحظة مهمة: في نسخة سابقة من هذا الملف تم عمدًا حذف كل قواعد @media
   الخاصة بالجوال بحيث يطابق الهاتف الحاسوب تمامًا في الأبعاد، مع تفعيل
   overflow-x: auto على body لامتصاص أي فائض عرضي بالتمرير الأفقي بدل
   إعادة الهيكلة. هذا بالضبط ما كان يسبب مشكلة العرض على الهاتف (بطاقات
   بعرض ثابت لا تلتف، عناصر أصغر من الطبيعي، ومساحة فارغة على جانب
   الشاشة) لأن بعض الشبكات (خصوصًا شبكة بطاقات الكتب في مكتبة الكتب،
   التي كانت تستخدم repeat(4, minmax(170px,1fr)) بعدد أعمدة ثابت لا
   يلتف) كانت تفرض عرضًا أدنى أكبر من عرض شاشة الهاتف، فيضطر المتصفح إلى
   تصغير الصفحة كاملة لتظهر بلا قطع. تم الآن استعادة overflow-x: hidden
   على body (انظر القسم 1) وإضافة استعلامات @media حقيقية هنا تعيد ترتيب
   الشبكات والمسافات والخطوط للشاشات الأصغر، دون أي تغيير على تصميم
   الحاسوب (كل القواعد هنا محصورة داخل max-width فلا تُفعَّل إلا تحت هذا
   العرض). الشبكات التي تستخدم أصلاً repeat(auto-fit, minmax(...)) (مثل
   .branches و.subjects و.teacher-grid و.resource-grid) كانت تلتف تلقائيًا
   من قبل ولم تُغيَّر هنا إلا لتحسين طفيف في القيم الدنيا على الشاشات
   الضيقة جدًا (320-430px). */

@media (max-width: 900px) {
    .branches,
    .subjects {
        grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
        gap: 18px;
        padding: 20px;
    }

    .hero {
        padding: 60px 18px 32px;
    }

    .hero h1 {
        font-size: 32px;
    }

    .hero p {
        font-size: 16px;
    }

    .quiz-wrap,
    .calc-wrap,
    .library-wrap,
    .guidance-wrap,
    .policy-wrap,
    .ii-wrap,
    .ip-wrap,
    .im-wrap,
    .is-wrap,
    .pe-wrap {
        padding-left: 16px;
        padding-right: 16px;
    }

    .lessons {
        padding: 16px;
    }

    .lesson iframe {
        height: 480px;
    }
}

@media (max-width: 480px) {
    .top-bar {
        padding: 10px 14px;
    }

    .logo {
        font-size: 30px;
    }

    header.site-header {
        padding: 22px 14px;
    }

    .hero {
        padding: 50px 14px 26px;
    }

    .hero h1 {
        font-size: 26px;
    }

    .hero p {
        font-size: 14.5px;
        line-height: 1.6;
    }

    .branches,
    .subjects {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 14px;
    }

    .card {
        padding: 24px 20px;
    }

    .card-featured {
        padding: 30px 20px;
    }

    .card-featured h2 {
        font-size: 24px;
    }

    .topic-card {
        min-height: 0;
        padding: 22px 18px;
    }

    .download-all-section {
        padding: 0 14px;
    }

    .download-all-btn {
        min-width: 0;
        width: 100%;
        padding: 15px 18px;
        font-size: 14.5px;
    }

    .nav-menu-panel {
        min-width: 200px;
    }

    .quiz-wrap {
        padding: 10px 14px 40px;
    }

    .quiz-card {
        padding: 22px 18px;
        border-radius: 18px;
    }

    .question-text {
        font-size: 17.5px;
        min-height: 0;
    }

    .option-btn {
        padding: 12px 14px;
        font-size: 15.5px;
    }

    .congrats,
    .stage-complete {
        padding: 26px 16px 30px;
    }

    .banner {
        font-size: 22px;
        padding: 16px 26px;
    }

    .lessons {
        padding: 12px;
    }

    .lesson iframe {
        height: 300px;
    }

    .bac-zoom-bar {
        padding: 10px 14px;
        gap: 10px;
    }

    .bac-zoom-range {
        width: 110px;
    }

    .calc-wrap {
        padding: 10px 14px 40px;
    }

    .calc-card {
        padding: 18px 14px;
    }

    .calc-table {
        min-width: 460px;
    }

    .calc-result-value {
        font-size: 32px;
    }

    .calc-actions {
        flex-direction: column;
    }

    .calc-btn {
        width: 100%;
        min-width: 0;
    }

    .guidance-section-head h2,
    .resource-card h3 {
        font-size: 20px;
    }

    .resource-card p {
        font-size: 14.5px;
    }

    .policy-card {
        padding: 22px 16px;
    }

    .new-post,
    .auth-card,
    .post {
        padding: 18px 16px;
    }

    .file-preview-card strong {
        max-width: 200px;
    }
}

/* ---------- 18. تمييز بطاقات المواضيع التي سبق للمستخدم الدخول إليها ----------
   تلوين أخضر هادئ وثابت (لا يتغيّر مع تبديل الوضع الداكن/الفاتح) خاص
   حصرًا ببطاقات المواضيع (.topic-card) التي تمت زيارتها من قبل، دون أي
   تأثير على بطاقات المواد أو "المكتسبات القبلية" أو أي عنصر آخر. الحالة
   تُضاف ديناميكيًا عبر class="topic-visited" من script.js، مع شارة "✓"
   حقيقية قابلة للنقر (.topic-visited-badge) تتيح للمستخدم إزالة العلامة
   يدويًا؛ عند إزالتها تعود البطاقة إلى مظهرها الأصلي كباقي البطاقات. */

.topic-card.topic-visited {
    border-color: rgba(34, 197, 94, 0.55);
    background: linear-gradient(135deg, var(--card-bg), rgba(34, 197, 94, 0.10));
}

.topic-visited-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    padding: 0;
    background: rgba(34, 197, 94, 0.9);
    color: #ffffff;
    font-size: 12px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    z-index: 3;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.topic-visited-badge:hover {
    background: rgba(224, 67, 67, 0.9);
    transform: scale(1.1);
}
/* ---------- 19. مؤقت الدراسة (Study Timer) ---------- */

.bac-timer-btn {
    position: relative;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--track-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    padding: 0;
    margin-right: 8px;
    flex-shrink: 0;
    color: var(--accent);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.25s ease, transform 0.15s ease;
}
.bac-timer-btn:hover { box-shadow: 0 0 14px var(--accent-glow); }
.bac-timer-btn:active { transform: scale(0.93); }
.bac-timer-btn svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bac-timer-btn.active { border-color: var(--accent); animation: bacTimerPulse 1.8s ease-in-out infinite; }

@keyframes bacTimerPulse {
    0%, 100% { box-shadow: 0 0 0 rgba(0,0,0,0); }
    50% { box-shadow: 0 0 14px var(--accent-glow); }
}

.bac-timer-badge {
    position: absolute;
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #000;
    font-size: 9.5px;
    font-weight: bold;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 999px;
    white-space: nowrap;
    direction: ltr;
    display: none;
}
.bac-timer-btn.active .bac-timer-badge { display: inline-block; }

.bac-timer-widget {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 4500;
    width: 250px;
    max-width: 92vw;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 10px 12px 12px;
    box-shadow: 0 14px 34px rgba(0,0,0,0.3);
    display: none;
    flex-direction: column;
    gap: 9px;
    opacity: 0;
    transform: translateY(10px) scale(0.97);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.4,0,0.2,1), left 0s, top 0s;
}
.bac-timer-widget.open { display: flex; opacity: 1; transform: translateY(0) scale(1); }
.bac-timer-widget.dragging { transition: none; box-shadow: 0 20px 44px rgba(0,0,0,0.42); }

.bac-timer-head {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: grab;
    user-select: none;
    touch-action: none;
}
.bac-timer-widget.dragging .bac-timer-head { cursor: grabbing; }
.bac-timer-drag-dots { color: var(--empty-text); font-size: 11px; letter-spacing: -2px; flex-shrink: 0; }
.bac-timer-title { flex: 1; font-size: 12.5px; font-weight: bold; color: var(--accent); }
.bac-timer-close {
    background: none; border: none; color: var(--footer-text); font-size: 13px;
    cursor: pointer; padding: 2px 5px; line-height: 1; font-family: inherit;
    border-radius: 6px; transition: background-color 0.2s ease, color 0.2s ease;
}
.bac-timer-close:hover { background: var(--danger-bg); color: var(--danger); }

.bac-timer-body {
    display: flex;
    align-items: center;
    gap: 8px;
}
.bac-timer-adjust-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 34px;
    background: var(--bg);
    border: 1.5px solid var(--empty-border);
    color: var(--text-secondary);
    border-radius: 9px;
    font-size: 12.5px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    direction: ltr;
    transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}
.bac-timer-adjust-btn:hover { border-color: var(--accent); color: var(--accent); }

.bac-timer-display-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 34px;
}
.bac-timer-display {
    font-size: 24px;
    font-weight: bold;
    color: var(--text);
    direction: ltr;
    letter-spacing: 0.5px;
    cursor: pointer;
    border-radius: 8px;
    padding: 2px 8px;
    transition: background-color 0.2s ease, color 0.2s ease;
}
.bac-timer-display:hover { background: var(--accent-glow); color: var(--accent); }
.bac-timer-display-hidden { display: none; }
.bac-timer-display-long { font-size: 19px; letter-spacing: 0; }
.bac-timer-edit-input.long { font-size: 17px; }

.bac-timer-edit-input {
    display: none;
    width: 100%;
    height: 34px;
    text-align: center;
    font-size: 22px;
    font-weight: bold;
    color: var(--text);
    background: var(--bg);
    border: 1.5px solid var(--accent);
    border-radius: 8px;
    font-family: inherit;
    direction: ltr;
}
.bac-timer-edit-input.show { display: block; }
.bac-timer-edit-input:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-glow); }

.bac-timer-controls { display: flex; gap: 8px; }
.bac-timer-primary-btn, .bac-timer-secondary-btn {
    padding: 8px 10px;
    border-radius: 9px;
    font-size: 12.5px;
    font-weight: bold;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: transform 0.2s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}
.bac-timer-primary-btn { flex: 1; background: var(--accent); color: #000; }
.bac-timer-primary-btn:hover { box-shadow: 0 0 14px var(--accent-glow); transform: translateY(-1px); }
.bac-timer-secondary-btn { flex: 0 0 40px; background: transparent; border: 1.5px solid var(--empty-border); color: var(--text-secondary); }
.bac-timer-secondary-btn:hover { border-color: var(--accent); color: var(--accent); }

.bac-timer-hint { font-size: 13px; font-weight: bold; color: var(--accent); text-align: center; line-height: 1.6; }

.bac-timer-finish-overlay {
    position: fixed; inset: 0; z-index: 10600; display: none;
    align-items: center; justify-content: center; background: rgba(0,0,0,0.75); padding: 20px;
}
.bac-timer-finish-overlay.show { display: flex; }
.bac-timer-finish-card {
    background: var(--card-bg); border: 3px solid var(--accent); border-radius: 22px;
    padding: 34px 26px; text-align: center; max-width: 340px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5); animation: forumCardIn 0.35s ease both;
}
.bac-timer-finish-icon { font-size: 46px; margin-bottom: 10px; }
.bac-timer-finish-card h3 { color: var(--accent); font-size: 21px; margin-bottom: 10px; }
.bac-timer-finish-card p { color: var(--text-muted); font-size: 14.5px; line-height: 1.8; margin-bottom: 22px; }

@media (max-width: 480px) {
    .bac-timer-widget { width: min(88vw, 250px); }
}
/* ---------- 20. العدّاد التنازلي لبكالوريا 2027 + حفظ شعبة المستخدم ----------
   يظهر عبر عنصر مشترك #bacFlipClock تديره initBacCountdown في script.js،
   في الصفحة الرئيسية (صفحة اختيار الشعب) وفي صفحات كل شعبة على حدة
   (Branches/1_*.html). القسم بأكمله يُفصل بصريًا عن بطاقات الصفحة بخط
   متقطع ومسافة كبيرة أعلاه (border-top + margin-top)، ليبقى عنصرًا
   ثانويًا واضحًا لكنه لا يشتت الطالب أثناء تصفّح الدروس والمواد. */

.bac-countdown-section {
    max-width: 720px;
    margin: 90px auto 30px;
    padding: 40px 20px 0;
    border-top: 1px dashed var(--empty-border);
    text-align: center;
    transition: border-color 0.35s ease;
}

.bac-countdown-title {
    color: var(--accent);
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 24px;
}

.bac-countdown-finished {
    color: var(--accent);
    font-size: 22px;
    font-weight: bold;
    padding: 32px 20px;
    background: var(--card-bg);
    border: 2px solid var(--accent);
    border-radius: 18px;
}

.bac-flip-clock {
    direction: ltr;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.bac-flip-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.bac-flip-digits {
    direction: ltr;
    display: flex;
    gap: 4px;
}

.bac-flip-card {
    position: relative;
    width: 38px;
    height: 54px;
    perspective: 300px;
    font-family: inherit;
}

.bac-flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.bac-flip-card-inner.bac-flip-rot {
    transform: rotateX(180deg);
}

.bac-flip-face {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--accent);
    font-size: 26px;
    font-weight: bold;
    direction: ltr;
    backface-visibility: hidden;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    transition: border-color 0.35s ease, background-color 0.35s ease, color 0.35s ease;
}

.bac-flip-face::after {
    content: "";
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 1px;
    background: rgba(0, 0, 0, 0.28);
    transform: translateY(-0.5px);
}

.bac-flip-face-back {
    transform: rotateX(180deg);
}

.bac-flip-label {
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: bold;
}

/* رابط "تغيير الشعبة" أسفل الأرقام — مسافة واضحة نسبيًا حتى لا يُقرأ
   كجزء من العدّاد نفسه، ويبقى تفصيلاً هادئًا وليس عنصرًا يجذب الانتباه. */
.bac-countdown-branch-action {
    margin-top: 34px;
    min-height: 1px;
}

.bac-branch-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.bac-change-branch-link {
    background: none;
    border: 1px solid var(--empty-border);
    color: var(--footer-text);
    font-size: 11.5px;
    font-weight: bold;
    cursor: pointer;
    font-family: inherit;
    padding: 4px 11px;
    line-height: 1.5;
    border-radius: 999px;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.bac-change-branch-link:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-glow);
}
.bac-save-branch-link {
    color: var(--accent);
    border-color: var(--accent-soft);
}

/* ══ نافذة "هل تريد حفظ شعبتك؟" ══ */
.bac-branch-modal-overlay {
    position: fixed; inset: 0; z-index: 6000; display: none;
    align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.7); padding: 20px;
}
.bac-branch-modal-overlay.open { display: flex; }
.bac-branch-modal {
    max-width: 380px; width: 100%;
    background: var(--card-bg);
    border: 2px solid var(--accent);
    border-radius: 20px;
    padding: 28px 24px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    animation: forumCardIn 0.3s ease both;
}
.bac-branch-modal-icon { font-size: 34px; margin-bottom: 10px; }
.bac-branch-modal h3 { color: var(--accent); font-size: 18px; margin-bottom: 10px; }
.bac-branch-modal p { color: var(--text-secondary); font-size: 13.5px; line-height: 1.8; margin-bottom: 22px; }
.bac-branch-modal-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.bac-branch-modal-btn {
    flex: 1; min-width: 120px;
    padding: 12px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    border: none;
    transition: transform 0.2s ease;
}
.bac-branch-modal-btn:hover { transform: translateY(-2px); }
.bac-branch-modal-save { background: var(--accent); color: #000; }
.bac-branch-modal-later { background: transparent; border: 1.5px solid var(--empty-border); color: var(--text-secondary); }

@media (max-width: 480px) {
    .bac-flip-card { width: 28px; height: 42px; }
    .bac-flip-face { font-size: 18px; border-radius: 8px; }
    .bac-flip-clock { gap: 9px; }
    .bac-flip-digits { gap: 3px; }
    .bac-countdown-title { font-size: 16.5px; }
    .bac-countdown-section { margin: 60px auto 20px; padding-top: 30px; }
}


/* ---------- 21. خلفية الموقع: ورق كراس مربّعات + توهّج هادئ ---------- */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse 60% 45% at 88% 0%, var(--bg-glow-a), transparent 70%),
        radial-gradient(ellipse 55% 40% at 4% 100%, var(--bg-glow-b), transparent 70%),
        linear-gradient(var(--bg-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
    background-size: auto, auto, 34px 34px, 34px 34px;
}

/* ---------- 22. دائرة العودة (التمرير للأسفل بعد نهاية الصفحة) ---------- */
.bac-home-ring {
    position: fixed;
    left: 50%;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    width: 64px;
    height: 64px;
    margin-left: -32px;
    z-index: 4600;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--empty-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(20px) scale(0.6);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.bac-home-ring.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; cursor: pointer; }
.bac-home-ring-svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.bac-home-ring-track { fill: none; stroke: var(--empty-border); stroke-width: 4; }
.bac-home-ring-bar { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset 0.08s linear; }
.bac-home-ring-icon { position: relative; display: flex; }
.bac-home-ring-icon svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bac-home-ring.done { animation: bacRingDone 0.3s ease forwards; box-shadow: 0 0 26px var(--accent-glow); }
.bac-home-ring.done .bac-home-ring-icon svg { fill: var(--accent-glow); }
@keyframes bacRingDone { 0% { transform: scale(1); } 60% { transform: scale(1.18); } 100% { transform: scale(1.08); } }


/* ---------- 23. تحسين سلاسة الحركة والانتقالات ----------
   إضافات خفيفة (opacity/transform فقط) لا تغيّر التصميم ولا الألوان، وتعمل
   في الوضعين الداكن والفاتح. fill-mode: backwards كي لا يُثبَّت transform
   النهائي فتتعطل حالات :hover. تُعطَّل عند prefers-reduced-motion. */

:root { --bac-ease: cubic-bezier(0.22, 0.61, 0.36, 1); }

button, a { -webkit-tap-highlight-color: transparent; }

.card {
    transition: transform 0.3s var(--bac-ease), box-shadow 0.3s var(--bac-ease), background-color 0.35s ease, border-color 0.35s ease;
}
.mini-card {
    transition: transform 0.3s var(--bac-ease), box-shadow 0.3s var(--bac-ease), background-color 0.35s ease, border-color 0.35s ease, color 0.35s ease;
}
.lesson {
    transition: transform 0.35s var(--bac-ease), box-shadow 0.35s var(--bac-ease), background-color 0.35s ease, border-color 0.35s ease;
}
.option-btn {
    transition: border-color 0.2s ease, transform 0.25s var(--bac-ease), background-color 0.35s ease, color 0.35s ease;
}
.back {
    transition: transform 0.25s var(--bac-ease), background-color 0.35s ease;
}

.card:active,
.mini-card:active,
.back:active,
.option-btn:not(:disabled):active,
.submit-btn:active,
.restart-btn:active,
.calc-btn:active { transform: scale(0.98); }

@keyframes bacFadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes bacFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.hero { animation: bacFadeUp 0.5s var(--bac-ease) backwards; }

.branches > .card,
.subjects > .card {
    animation: bacFadeUp 0.45s var(--bac-ease) backwards;
}
.branches > .card:nth-child(2), .subjects > .card:nth-child(2) { animation-delay: 0.04s; }
.branches > .card:nth-child(3), .subjects > .card:nth-child(3) { animation-delay: 0.08s; }
.branches > .card:nth-child(4), .subjects > .card:nth-child(4) { animation-delay: 0.12s; }
.branches > .card:nth-child(5), .subjects > .card:nth-child(5) { animation-delay: 0.16s; }
.branches > .card:nth-child(n+6), .subjects > .card:nth-child(n+6) { animation-delay: 0.2s; }

@keyframes bacSubjectOpen {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.subject-content[style*="display: block"],
.subject-content.open,
.subject-content.active {
    animation: bacSubjectOpen 0.3s var(--bac-ease) backwards;
}

.quiz-card, .stage-complete, .congrats {
    animation: bacFadeIn 0.35s ease backwards;
}

@media (prefers-reduced-motion: reduce) {
    .hero,
    .branches > .card,
    .subjects > .card,
    .subject-content,
    .quiz-card,
    .stage-complete,
    .congrats {
        animation: none !important;
    }
    html { scroll-behavior: auto; }
}
