/* ==========================================================================
   MATH CHAPTER SYSTEM & LEARNING STUDIO STYLESHEET
   math-chapter-system.css
   Eye-comfortable, classic modern dark glassmorphic design
   ========================================================================== */

:root {
    --ch-bg-dark: #090e17;
    --ch-surface: #0f172a;
    --ch-surface-card: #141f36;
    --ch-surface-hover: #1e293b;
    --ch-border: rgba(56, 189, 248, 0.18);
    --ch-border-glow: rgba(56, 189, 248, 0.45);
    --ch-primary: #38bdf8;
    --ch-primary-dark: #0284c7;
    --ch-purple: #a855f7;
    --ch-emerald: #10b981;
    --ch-amber: #f59e0b;
    --ch-rose: #f43f5e;
    --ch-text-main: #f8fafc;
    --ch-text-muted: #94a3b8;
}

/* Modal Overlay */
.math-ch-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(4, 7, 15, 0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    direction: rtl;
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Cairo', 'Tajawal', sans-serif;
}

.math-ch-overlay.active {
    opacity: 1;
    visibility: visible;
}

.math-ch-modal {
    background: var(--ch-surface);
    border: 1.5px solid var(--ch-border);
    border-radius: 20px;
    width: 100%;
    max-width: 1280px;
    height: 95vh;
    max-height: 940px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.85), 0 0 40px rgba(56, 189, 248, 0.15);
    transform: scale(0.96) translateY(12px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.math-ch-overlay.active .math-ch-modal {
    transform: scale(1) translateY(0);
}

/* Header */
.math-ch-header {
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.math-ch-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.math-ch-header-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--ch-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 800;
}

.math-ch-header-title {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    color: var(--ch-text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-header-subtitle {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: var(--ch-text-muted);
}

.math-ch-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-close-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--ch-text-muted);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s ease;
}

.math-ch-close-btn:hover {
    background: rgba(244, 63, 94, 0.2);
    border-color: var(--ch-rose);
    color: #ffffff;
}

/* Body container with scrollbar on RIGHT side matching dashboard */
.math-ch-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: radial-gradient(circle at top right, rgba(56, 189, 248, 0.05), transparent 45%),
                radial-gradient(circle at bottom left, rgba(168, 85, 247, 0.04), transparent 45%),
                var(--ch-bg-dark);
    direction: ltr !important; /* Moves vertical scrollbar to the RIGHT edge */
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.6) rgba(15, 23, 42, 0.6);
}

.math-ch-body > * {
    direction: rtl !important; /* Preserves natural RTL reading flow for Arabic */
}

/* Custom Scrollbars aligned to the right */
.math-ch-body::-webkit-scrollbar,
.math-ch-slide-card::-webkit-scrollbar,
.math-ch-theory-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.math-ch-body::-webkit-scrollbar-track,
.math-ch-slide-card::-webkit-scrollbar-track,
.math-ch-theory-container::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 9999px;
}
.math-ch-body::-webkit-scrollbar-thumb,
.math-ch-slide-card::-webkit-scrollbar-thumb,
.math-ch-theory-container::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 9999px;
}
.math-ch-body::-webkit-scrollbar-thumb:hover,
.math-ch-slide-card::-webkit-scrollbar-thumb:hover,
.math-ch-theory-container::-webkit-scrollbar-thumb:hover {
    background: var(--ch-primary);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.8);
}

/* Floating Scroll Down Pill Button on the RIGHT side */
.math-ch-scroll-pill-btn {
    position: fixed;
    bottom: 36px;
    right: calc(50% - 510px + 28px);
    z-index: 999999;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.9);
    border: 1.5px solid var(--ch-border-glow);
    color: var(--ch-primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 12px rgba(56, 189, 248, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 800;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0.9;
}
.math-ch-scroll-pill-btn:hover {
    background: var(--ch-primary);
    color: #0f172a;
    transform: translateY(2px) scale(1.08);
    box-shadow: 0 6px 22px rgba(56, 189, 248, 0.55);
    opacity: 1;
}
@media (max-width: 1120px) {
    .math-ch-scroll-pill-btn {
        right: 28px;
    }
}

/* TOPICS VIEW */
.math-ch-topics-view {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.math-ch-hero-banner {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.2), rgba(15, 23, 42, 0.7));
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 16px;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.math-ch-hero-stats {
    display: flex;
    gap: 24px;
    align-items: center;
}

.math-ch-stat-box {
    text-align: center;
}

.math-ch-stat-val {
    font-size: 22px;
    font-weight: 800;
    color: var(--ch-primary);
}

.math-ch-stat-lbl {
    font-size: 11.5px;
    color: var(--ch-text-muted);
}

.math-ch-topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.math-ch-topic-card {
    background: var(--ch-surface-card);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.math-ch-topic-card:hover:not(.locked) {
    border-color: var(--ch-primary);
    transform: translateY(-3px);
    box-shadow: 0 12px 28px -8px rgba(56, 189, 248, 0.25);
}

.math-ch-topic-card.locked {
    opacity: 0.55;
    filter: grayscale(0.4);
    cursor: not-allowed;
}

.math-ch-topic-card.completed {
    border-color: rgba(16, 185, 129, 0.35);
}

.math-ch-topic-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.math-ch-topic-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(56, 189, 248, 0.1);
    color: var(--ch-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.math-ch-status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
}

.math-ch-status-badge.completed {
    background: rgba(16, 185, 129, 0.18);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.35);
}

.math-ch-status-badge.active {
    background: rgba(56, 189, 248, 0.18);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.math-ch-status-badge.locked {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ch-text-muted);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.math-ch-topic-title {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: var(--ch-text-main);
    line-height: 1.4;
}

.math-ch-topic-desc {
    margin: 0;
    font-size: 12px;
    color: var(--ch-text-muted);
    line-height: 1.5;
}

.math-ch-topic-action-btn {
    width: 100%;
    padding: 11px 16px;
    border-radius: 10px;
    border: none;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    margin-top: auto;
}

.math-ch-topic-action-btn.primary {
    background: linear-gradient(135deg, var(--ch-primary-dark), #0369a1);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);
}
.math-ch-topic-action-btn.primary:hover {
    background: linear-gradient(135deg, #38bdf8, var(--ch-primary-dark));
    box-shadow: 0 6px 16px rgba(56, 189, 248, 0.45);
}

.math-ch-topic-action-btn.success {
    background: rgba(16, 185, 129, 0.16);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.35);
}
.math-ch-topic-action-btn.success:hover {
    background: rgba(16, 185, 129, 0.25);
}

/* Chapter Final Exam Banner Card */
.math-ch-final-exam-card {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(15, 23, 42, 0.85));
    border: 1.5px solid rgba(168, 85, 247, 0.3);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-top: 8px;
    position: relative;
    overflow: hidden;
}

.math-ch-final-exam-card.locked {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.6);
    opacity: 0.65;
}

.math-ch-exam-info h3 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 800;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-exam-info p {
    margin: 0;
    font-size: 13px;
    color: var(--ch-text-muted);
}

.math-ch-exam-gate-tag {
    display: none; /* مخفي في الوضع الأساسي للدروس المشروحة، يظهر فقط في وضع التحدي */
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbbf24;
    font-size: 12px;
    font-weight: 700;
    margin-top: 10px;
}

body.challenge-mode .math-ch-exam-gate-tag,
.challenge-mode .math-ch-exam-gate-tag {
    display: inline-flex;
}

.math-ch-exam-btn {
    padding: 13px 26px;
    border-radius: 12px;
    border: none;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4);
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    transition: all 0.25s ease;
}

.math-ch-exam-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(168, 85, 247, 0.55);
}

.math-ch-exam-btn:disabled {
    background: rgba(255, 255, 255, 0.1);
    color: var(--ch-text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

/* STUDIO VIEW */
.math-ch-studio-view {
    display: flex;
    flex-direction: column;
    gap: 18px;
    height: 100%;
}

.math-ch-studio-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--ch-surface-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 10px 16px;
}

.math-ch-tabs {
    display: flex;
    gap: 8px;
}

.math-ch-tab-btn {
    background: transparent;
    border: none;
    color: var(--ch-text-muted);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.math-ch-tab-btn.active {
    background: rgba(56, 189, 248, 0.15);
    color: var(--ch-primary);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.math-ch-studio-back-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--ch-text-muted);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.math-ch-studio-back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* Theory Container */
.math-ch-theory-container {
    background: var(--ch-surface-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 24px;
    overflow-y: auto;
    direction: ltr !important; /* Moves scrollbar to RIGHT */
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.math-ch-theory-container > * {
    direction: rtl !important;
}

.math-ch-rule-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.math-ch-rule-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--ch-primary);
    margin: 0;
}

.math-ch-rule-math {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    direction: ltr;
    font-family: 'Cambria Math', 'KaTeX_Math', serif;
    font-size: 18px;
    color: #ffffff;
}

.math-ch-rule-desc {
    margin: 0;
    font-size: 13.5px;
    color: var(--ch-text-main);
    line-height: 1.6;
}

.math-ch-golden-tip {
    background: rgba(245, 158, 11, 0.1);
    border-right: 3px solid var(--ch-amber);
    border-radius: 0 8px 8px 0;
    padding: 8px 14px;
    font-size: 12.5px;
    color: #fde68a;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Slide Deck Styles */
.math-ch-slide-deck {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

.math-ch-slide-card {
    background: var(--ch-surface-card);
    border: 1.5px solid rgba(56, 189, 248, 0.22);
    border-radius: 18px;
    padding: 26px 32px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    direction: ltr !important; /* Moves scrollbar to RIGHT */
    box-shadow: 0 14px 35px -10px rgba(0, 0, 0, 0.5);
    position: relative;
    animation: fadeInSlide 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.math-ch-slide-card > * {
    direction: rtl !important;
}

@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.math-ch-slide-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.math-ch-slide-counter {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ch-text-muted);
}

.math-ch-diff-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 6px;
}

.math-ch-diff-badge.easy {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34d399;
}

.math-ch-diff-badge.medium {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbbf24;
}

.math-ch-diff-badge.hard {
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: #f87171;
}

.math-ch-slide-qtext {
    font-size: 18px;
    font-weight: 800;
    color: #ffffff;
    line-height: 1.6;
    margin: 0 0 14px;
}

.math-ch-slide-math-box {
    background: rgba(0, 0, 0, 0.4);
    border: 1.5px solid rgba(56, 189, 248, 0.3);
    border-radius: 14px;
    padding: 14px 22px;
    min-height: 60px;
    text-align: center;
    direction: ltr;
    font-family: 'Cambria Math', 'KaTeX_Math', serif;
    font-size: 22px;
    color: #38bdf8;
    margin-bottom: 14px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible !important;
}

/* 5 Steps Display */
.math-ch-steps-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 22px;
}

.math-ch-step-row {
    background: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 18px 22px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
}

.math-ch-step-row:hover {
    border-color: rgba(56, 189, 248, 0.3);
    background: rgba(15, 23, 42, 0.85);
}

.math-ch-step-num {
    background: rgba(56, 189, 248, 0.15);
    color: var(--ch-primary);
    border: 1px solid rgba(56, 189, 248, 0.35);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    flex-shrink: 0;
    margin-top: 2px;
}

.math-ch-step-content {
    flex: 1;
}

.math-ch-step-name {
    font-size: 14.5px;
    font-weight: 800;
    color: var(--ch-primary);
    margin-bottom: 4px;
}

.math-ch-step-text {
    font-size: 14.5px;
    color: var(--ch-text-main);
    line-height: 1.6;
    margin: 0;
}

/* Hint Box */
.math-ch-hint-toggle {
    background: rgba(245, 158, 11, 0.08);
    border: 1px dashed rgba(245, 158, 11, 0.3);
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: #fde68a;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    user-select: none;
    transition: all 0.2s ease;
}
.math-ch-hint-toggle:hover {
    background: rgba(245, 158, 11, 0.15);
}

.math-ch-hint-content {
    padding: 10px 14px 4px;
    font-size: 13px;
    color: var(--ch-text-muted);
    line-height: 1.5;
    display: none;
}
.math-ch-hint-content.show {
    display: block;
}

/* Continue ("متابعة") Button & Slide Controls */
.math-ch-slide-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 8px;
    flex-shrink: 0;
}

.math-ch-continue-btn {
    flex: 1;
    padding: 14px 28px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.4);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.math-ch-continue-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 26px rgba(56, 189, 248, 0.55);
    background: linear-gradient(135deg, #0369a1, #0284c7);
}

.math-ch-continue-btn.finish-btn {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    box-shadow: 0 6px 22px rgba(236, 72, 153, 0.45);
    animation: pulseGlow 1.8s infinite;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 6px 22px rgba(236, 72, 153, 0.45);
    }
    50% {
        box-shadow: 0 8px 30px rgba(236, 72, 153, 0.75);
    }
}

.math-ch-nav-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--ch-surface-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--ch-text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.math-ch-nav-icon-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--ch-primary);
}

.math-ch-nav-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Indicator Dots */
.math-ch-dots-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 6px 0;
}

.math-ch-dot {
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.25s ease;
    cursor: pointer;
}

.math-ch-dot.active {
    width: 24px;
    background: var(--ch-primary);
}

/* QUIZ & FINAL EXAM ENGINE */
.math-ch-quiz-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
}

/* Quiz Slide Question: strictly NO scrollbar, all content visible at once */
.math-ch-body:has(.math-ch-quiz-slide-layout),
.math-ch-body.math-ch-quiz-active {
    padding: 8px 16px !important;
    overflow-y: hidden !important;
    overflow-x: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    scrollbar-width: none !important;
}

.math-ch-body:has(.math-ch-quiz-slide-layout)::-webkit-scrollbar,
.math-ch-body.math-ch-quiz-active::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
}

/* Results error report allows scrolling */
.math-ch-body:has(.math-ch-quiz-container:not(.math-ch-quiz-slide-layout)),
.math-ch-body.math-ch-results-active {
    padding: 24px 20px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    display: block !important;
    direction: ltr !important;
}

.math-ch-modal:has(.math-ch-quiz-slide-layout) .math-ch-scroll-pill-btn,
.math-ch-modal:has(.math-ch-quiz-slide-card) .math-ch-scroll-pill-btn,
.math-ch-modal.math-ch-quiz-active-modal .math-ch-scroll-pill-btn {
    display: none !important;
}

.math-ch-quiz-slide-layout {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden !important;
}

.math-ch-quiz-slide-top {
    background: var(--ch-surface-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.math-ch-quiz-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.math-ch-quiz-meta-right, .math-ch-quiz-meta-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.math-ch-slide-counter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    font-size: 12.5px;
    font-weight: 700;
    border: 1px solid rgba(56, 189, 248, 0.25);
}

.math-ch-qstatus-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
}

.math-ch-qstatus-badge.answered {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.math-ch-qstatus-badge.pending {
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.math-ch-quiz-answered-count {
    font-size: 13px;
    color: var(--ch-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.math-ch-pass-badge {
    font-size: 11.5px;
    font-weight: 700;
    color: #fbbf24;
    padding: 3px 10px;
    border-radius: 6px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.25);
}

.math-ch-quiz-stepper-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.math-ch-quiz-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.math-ch-dot-pill.answered {
    border-color: rgba(56, 189, 248, 0.5);
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    position: relative;
}

.math-ch-dot-pill.answered::after {
    content: "✓";
    position: absolute;
    top: -5px;
    right: -4px;
    font-size: 9px;
    background: #10b981;
    color: #04070f;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    line-height: 1;
}

.math-ch-dot-pill.purple-theme.active {
    background: #a855f7 !important;
    color: #ffffff !important;
    border-color: #a855f7 !important;
    box-shadow: 0 0 14px rgba(168, 85, 247, 0.6);
}

.math-ch-dot-pill.purple-theme.answered {
    border-color: rgba(168, 85, 247, 0.5);
    background: rgba(168, 85, 247, 0.15);
    color: #c084fc;
}

.math-ch-quiz-slide-card {
    background: var(--ch-surface-card);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 10px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    flex: 1;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    justify-content: flex-start !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    animation: mathChQuizSlideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    scrollbar-width: thin !important;
    scrollbar-color: rgba(56, 189, 248, 0.35) rgba(15, 23, 42, 0.3);
}

.math-ch-quiz-slide-card::-webkit-scrollbar {
    display: block !important;
    width: 5px !important;
}

.math-ch-quiz-slide-card::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.35) !important;
    border-radius: 10px !important;
}

.math-ch-quiz-slide-card .math-ch-slide-math-box {
    margin: 4px 0 10px !important;
    padding: 14px 22px !important;
    min-height: 58px !important;
    flex-shrink: 0 !important;
    overflow: visible !important;
}

.math-ch-quiz-slide-card .math-ch-slide-math-box .katex-display,
.math-ch-quiz-slide-card .math-ch-slide-math-box .math-display-wrapper {
    margin: 2px 0 !important;
    padding: 4px 8px !important;
    overflow-y: visible !important;
    overflow-x: auto !important;
}

.math-ch-quiz-slide-card .math-ch-choices-list {
    display: flex !important;
    flex-direction: column !important;
    flex-shrink: 0 !important;
    margin-top: 6px !important;
    gap: 10px !important;
    width: 100% !important;
}

.math-ch-quiz-slide-card .math-ch-choice-item {
    min-height: 52px !important;
    padding: 10px 16px !important;
    flex-shrink: 0 !important;
    overflow: visible !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

@media (max-height: 820px) {
    .math-ch-quiz-slide-top {
        padding: 5px 12px !important;
        gap: 4px !important;
    }
    .math-ch-quiz-slide-layout {
        gap: 5px !important;
    }
    .math-ch-quiz-slide-card {
        padding: 8px 14px !important;
        gap: 5px !important;
    }
    .math-ch-quiz-slide-card .math-ch-slide-math-box {
        padding: 10px 16px !important;
        margin: 3px 0 6px !important;
        font-size: 18px !important;
        min-height: 50px !important;
        overflow: visible !important;
    }
    .math-ch-quiz-slide-card .math-ch-choice-item {
        min-height: 48px !important;
        padding: 8px 12px !important;
        overflow: visible !important;
    }
}

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

.math-ch-quiz-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.math-ch-quiz-card-qtag {
    font-size: 12px;
    font-weight: 800;
    color: var(--ch-primary);
    background: rgba(56, 189, 248, 0.12);
    padding: 3px 10px;
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.25);
}

.math-ch-quiz-slide-prompt {
    margin: 0 0 6px 0 !important;
    font-size: 16px !important;
    color: #ffffff !important;
    line-height: 1.75 !important;
    font-weight: 700 !important;
    padding: 3px 2px !important;
    overflow: visible !important;
}

.math-prompt-formula {
    display: inline-block !important;
    vertical-align: middle !important;
    line-height: normal !important;
    padding: 2px 6px !important;
    overflow: visible !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
}

.math-prompt-formula .katex {
    overflow: visible !important;
    line-height: normal !important;
}

.math-ch-quiz-nav-strip {
    background: var(--ch-surface-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.math-ch-quiz-nav-center {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.math-ch-nav-indicator {
    font-size: 13px;
    font-weight: 700;
    color: #cbd5e1;
}

.math-ch-status-pill-ok {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 700;
    color: #34d399;
    background: rgba(16, 185, 129, 0.12);
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.math-ch-status-pill-warn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 700;
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.1);
    padding: 3px 10px;
    border-radius: 999px;
}

.math-ch-quick-submit-top-btn {
    background: linear-gradient(135deg, #059669, #10b981);
    border: 1px solid rgba(52, 211, 153, 0.5);
    color: #ffffff;
    padding: 7px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.math-ch-quick-submit-top-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
}

.math-ch-quick-submit-top-btn.purple-theme {
    background: linear-gradient(135deg, #7c3aed, #9333ea);
    border-color: rgba(192, 132, 252, 0.5);
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.25);
}

.math-ch-quiz-all-done-banner {
    background: rgba(16, 185, 129, 0.08);
    border: 1.5px solid rgba(16, 185, 129, 0.3);
    border-radius: 14px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13.5px;
    color: #e2e8f0;
    animation: mathChQuizSlideIn 0.25s ease;
}

.math-ch-quick-submit-banner-btn {
    background: linear-gradient(135deg, #059669, #10b981);
    border: 1px solid rgba(52, 211, 153, 0.5);
    color: #ffffff;
    padding: 8px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.math-ch-quick-submit-banner-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
}

.math-ch-quiz-header {
    background: var(--ch-surface-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.math-ch-quiz-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}

.math-ch-quiz-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0284c7, #38bdf8);
    transition: width 0.3s ease;
}

.math-ch-qcard {
    background: var(--ch-surface-card);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.math-ch-choices-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

@media (max-width: 640px) {
    .math-ch-choices-list {
        grid-template-columns: 1fr;
    }
}

.math-ch-choice-item {
    background: rgba(15, 23, 42, 0.65);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-right: 5px solid #475569;
    border-radius: 12px;
    padding: 10px 16px;
    min-height: 54px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    overflow: visible;
}

.math-ch-choice-item:hover {
    border-color: rgba(56, 189, 248, 0.5);
    border-right-color: #38bdf8;
    background: rgba(56, 189, 248, 0.09);
    transform: translateX(-3px);
}

.math-ch-choice-item.selected {
    border-color: #38bdf8 !important;
    border-right: 6px solid #0284c7 !important;
    background: rgba(14, 165, 233, 0.18) !important;
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.22) !important;
}

.math-ch-choice-item.correct {
    border-color: #22c55e !important;
    border-right: 6px solid #16a34a !important;
    background: rgba(34, 197, 94, 0.2) !important;
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.2) !important;
}

.math-ch-choice-item.wrong {
    border-color: #f43f5e !important;
    border-right: 6px solid #e11d48 !important;
    background: rgba(244, 63, 94, 0.2) !important;
    box-shadow: 0 4px 16px rgba(244, 63, 94, 0.18) !important;
}

.math-ch-choice-badge {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    color: var(--ch-text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.math-ch-choice-item.selected .math-ch-choice-badge {
    background: #0284c7 !important;
    border-color: #38bdf8 !important;
    color: #ffffff !important;
    transform: scale(1.06);
}

.math-ch-choice-text {
    font-size: 17.5px;
    color: var(--ch-text-main);
    direction: rtl;
    text-align: right;
    flex: 1;
    display: block;
    line-height: 1.5;
    unicode-bidi: plaintext;
}

/* Diagnostic Error Report View */
.math-ch-report-card {
    background: var(--ch-surface-card);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.math-ch-score-banner {
    border-radius: 14px;
    padding: 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.math-ch-score-banner.pass {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(5, 150, 105, 0.1));
    border: 1.5px solid rgba(16, 185, 129, 0.35);
}

.math-ch-score-banner.fail {
    background: linear-gradient(135deg, rgba(244, 63, 94, 0.18), rgba(190, 18, 60, 0.1));
    border: 1.5px solid rgba(244, 63, 94, 0.35);
}

.math-ch-score-pct {
    font-size: 48px;
    font-weight: 900;
}
.math-ch-score-banner.pass .math-ch-score-pct {
    color: #34d399;
}
.math-ch-score-banner.fail .math-ch-score-pct {
    color: #f87171;
}

.math-ch-error-item {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(244, 63, 94, 0.25);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.math-ch-error-item.math-ch-correct-item {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(6, 40, 28, 0.55);
}

.math-ch-error-title {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    color: #fca5a5;
    display: flex;
    align-items: center;
    gap: 8px;
}
.math-ch-correct-item .math-ch-error-title {
    color: #6ee7b7 !important;
}

.math-ch-error-answers {
    display: flex;
    gap: 16px;
    font-size: 13px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
}

.math-ch-error-concept {
    font-size: 13px;
    color: #fde68a;
    background: rgba(245, 158, 11, 0.1);
    padding: 8px 12px;
    border-radius: 8px;
    border-right: 3px solid #f59e0b;
}

.math-ch-show-solution-btn {
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.4);
    color: #38bdf8;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    white-space: nowrap;
}

.math-ch-show-solution-btn:hover {
    background: rgba(56, 189, 248, 0.3);
    border-color: #38bdf8;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.25);
}

.math-ch-error-solution-box {
    animation: fadeInSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.math-ch-diff-badge.ministerial {
    background: rgba(234, 179, 8, 0.2) !important;
    border: 1px solid #eab308 !important;
    color: #fde047 !important;
}

/* Dashboard Lock Overlay for Chapter Cards */

.dashboard-chapter-card.locked-card {
    position: relative;
    opacity: 0.65;
    filter: grayscale(0.25);
}

.dashboard-chapter-card.locked-card .dashboard-chapter-btn {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #94a3b8 !important;
    box-shadow: none !important;
    cursor: not-allowed !important;
}

.dashboard-chapter-card.unlocked-celebrate {
    border-color: rgba(168, 85, 247, 0.8) !important;
    animation: glowPulse 2s infinite alternate;
}

@keyframes glowPulse {
    from {
        box-shadow: 0 0 15px rgba(168, 85, 247, 0.2);
    }
    to {
        box-shadow: 0 0 30px rgba(168, 85, 247, 0.55);
    }
}

/* ==========================================================================
   MATHEMATICAL TYPOGRAPHY & DIRECTION ISOLATION
   Ensures roots, exponents, powers, and equations NEVER reverse in RTL
   ========================================================================== */
.katex,
.katex-display,
.katex-html,
.math-ch-slide-math-box,
.math-ch-rule-math,
.math-ch-step-math,
.math-token-ltr,
.math-inline-ltr,
.math-expr-ltr,
.math-display-wrapper,
bdi.math-token-ltr {
    direction: ltr !important;
    unicode-bidi: isolate !important;
}

.math-display-wrapper {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    max-width: 100% !important;
    padding: 6px 12px !important;
    -webkit-overflow-scrolling: touch !important;
}

.katex-display {
    text-align: center !important;
    margin: 0.4em 0 !important;
    display: block !important;
    font-size: clamp(1.15rem, 2.2vw, 1.45rem) !important;
    overflow: visible !important;
}

.katex {
    display: inline-block !important;
    white-space: nowrap !important;
    text-rendering: geometricPrecision !important;
    color: #f8fafc !important;
    overflow: visible !important;
}

.katex-html {
    overflow: visible !important;
}

/* Explicit protection for radical signs and square roots */
.katex .sqrt {
    display: inline-block !important;
    direction: ltr !important;
}

.katex .sqrt > .vlist-t {
    direction: ltr !important;
}

.katex .sqrt-sign {
    direction: ltr !important;
}

/* Explicit protection for exponents and superscripts: preserve pure TeX metrics without shifting */
.katex .msupsub {
    direction: ltr !important;
    text-align: left !important;
    overflow: visible !important;
}

.katex .msupsub .vlist-t,
.katex .msupsub .vlist-r,
.katex .msupsub .vlist {
    overflow: visible !important;
}

/* Numerals and characters in exponents: crisp contrast while strictly preserving KaTeX font sizing & vertical alignment */
.katex .msupsub .mtight,
.katex .msupsub .sizing.reset-size6.size3.mtight,
.katex .msupsub .mord.mtight {
    color: #ffffff !important;
    letter-spacing: 0.02em !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    text-rendering: geometricPrecision !important;
}

.katex .msupsub .mtight .mord,
.katex .msupsub .mord.mtight {
    font-feature-settings: "tnum" 1, "lnum" 1 !important;
}

/* Authentic LaTeX fraction vinculum: pure KaTeX metrics preserved */
.katex .frac-line {
    border-bottom-color: currentColor !important;
}

/* =========================================================
   MATHEMATICAL COLLISION PREVENTION (Fractions, Roots, Powers)
   Guarantees generous clearance so powers never collide with vinculum or fraction line
   ========================================================= */
.katex .mfrac {
    vertical-align: middle !important;
}

/* Numerator bottom clearance from fraction line */
.katex .mfrac .vlist-t > .vlist-r:first-child .vlist,
.katex .mfrac .vlist-t2 > .vlist-r:first-child .vlist {
    padding-bottom: 2.5px !important;
}

/* Denominator top clearance from fraction line */
.katex .mfrac .vlist-t > .vlist-r:last-child .vlist,
.katex .mfrac .vlist-t2 > .vlist-r:last-child .vlist {
    padding-top: 2.5px !important;
}

/* Radical ceiling clearance: ensures exponents inside roots never touch radical roof */
.katex .sqrt > .vlist-t > .vlist-r:first-child .vlist,
.katex .sqrt > .vlist-t2 > .vlist-r:first-child .vlist {
    padding-top: 2.5px !important;
}

.katex .sqrt .sqrt-sign {
    padding-top: 1px !important;
}

/* Superscripts spacing protection */
.katex .msupsub {
    margin-left: 0.04em !important;
}

/* Large and prominent fraction rendering inside MCQ Choice buttons */
.math-ch-choice-text .katex .mfrac {
    font-size: 1.15em !important;
    margin: 0 4px !important;
}

.math-ch-choice-text .math-frac {
    font-size: 1.05em !important;
    margin: 0 4px !important;
}

/* HTML fallback fractions root clearance & high contrast */
.math-frac {
    display: inline-flex !important;
    flex-direction: column !important;
    vertical-align: middle !important;
    text-align: center !important;
    padding: 0 4px !important;
    margin: 0 2px !important;
    font-size: 0.95em !important;
    line-height: 1 !important;
    min-width: 1.35em !important;
}

.math-frac-num {
    border-bottom: 2.2px solid var(--ch-amber, #f59e0b) !important;
    padding-bottom: 5px !important;
    margin-bottom: 3px !important;
    display: block !important;
    box-shadow: 0 1px 4px rgba(245, 158, 11, 0.35) !important;
}

.math-frac-den {
    padding-top: 5px !important;
    margin-top: 2px !important;
    display: block !important;
}

.math-frac-den:has(.math-radical),
.math-frac-den:has(.math-sqrt),
.math-frac-den .math-radical,
.math-frac-den .math-sqrt {
    padding-top: 7px !important;
    margin-top: 3px !important;
}

/* ==========================================================================
   SCALABLE PARENTHESES & DELIMITERS
   ========================================================================== */
.katex .delimsizing,
.katex .delimsizing.size1,
.katex .delimsizing.size2,
.katex .delimsizing.size3,
.katex .delimsizing.size4 {
    font-weight: 600 !important;
    color: #e2e8f0 !important;
}

/* ==========================================================================
   MATH OPERATORS SPACING & HIGH CONTRAST (+, −, ×, ÷, =, ·)
   ========================================================================== */
.katex .mbin,
.katex .mrel,
.katex .math-op-accent,
.math-op-accent {
    margin: 0 0.32em !important;
    color: #F59E0B !important;
    font-weight: 800 !important;
}

/* Ensure internal composite overlays (like \not and \rlap) NEVER have margins that displace the slash */
.katex .mrel .mrel,
.katex .mrel .rlap,
.katex .rlap,
.katex .rlap .inner,
.katex .rlap .inner .mrel {
    margin: 0 !important;
    padding: 0 !important;
}

/* Unified, mathematically centered not-equal operator glyph */
.katex .math-neq-symbol,
.math-neq-symbol {
    font-family: 'KaTeX_Main', 'Cambria Math', 'Times New Roman', 'Cairo', serif !important;
    font-style: normal !important;
    font-weight: 800 !important;
    display: inline-block !important;
    text-align: center !important;
    margin: 0 0.32em !important;
    color: #F59E0B !important;
    vertical-align: baseline !important;
    line-height: 1 !important;
}

.katex .mbin {
    color: #F59E0B !important;
    font-size: 1.05em !important;
}

.katex .mrel {
    color: #F59E0B !important;
}

/* Inline math tokens inside Arabic text */
.math-inline-katex,
.math-token-ltr,
.math-inline-ltr,
bdi.math-token-ltr {
    display: inline-block !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    font-family: 'KaTeX_Main', 'Cambria Math', 'Times New Roman', serif;
    font-size: 1.05em;
    padding: 0 3px;
    vertical-align: baseline;
    font-style: normal;
}

/* Choice text with math tokens */
.math-ch-choice-text {
    flex: 1;
    font-size: 17.5px;
    font-weight: 600;
    color: var(--ch-text-main);
    line-height: 1.5;
    direction: rtl;
    text-align: right;
}

.math-ch-choice-text bdi.math-token-ltr,
.math-ch-choice-text .math-inline-ltr,
.math-ch-choice-text .math-inline-katex,
.math-ch-choice-text .katex {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block !important;
}

/* ==========================================================================
   VARIABLE X COLOR HIGHLIGHT (PRESERVING BRAND CYAN)
   ========================================================================== */
.math-var-x {
    font-family: 'KaTeX_Math', 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif !important;
    font-style: italic !important;
    font-weight: 700 !important;
    color: #38bdf8 !important; /* Bright cyan for algebraic variable x */
    padding: 0 1.5px;
}

.math-op-mult {
    color: #fbbf24 !important; /* Distinct gold/amber for standalone multiplication symbol */
    margin: 0 4px;
    display: inline-block;
    font-size: 1.1em;
    vertical-align: middle;
}

/* ==========================================================================
   VERTICAL STEP-BY-STEP CALCULATION STACK (LTR, LINE-BY-LINE)
   ========================================================================== */
.math-ch-vertical-calc {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    direction: ltr !important;
    text-align: left !important;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(56, 189, 248, 0.22);
    border-radius: 10px;
    padding: 12px 18px;
    margin: 10px 0;
    font-family: 'Cambria Math', 'STIX Two Math', 'KaTeX_Math', monospace, serif;
    font-size: 15px;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.math-calc-line {
    display: flex;
    align-items: center;
    gap: 8px;
    direction: ltr !important;
    line-height: 1.6;
}

.math-calc-line.indent-1,
.math-calc-line.indent-2,
.math-calc-line.indent-3,
.math-calc-line.indent-4 {
    padding-left: 0 !important;
}

.math-calc-eq {
    color: #f59e0b;
    font-weight: 700;
    font-size: 16px;
}

.math-calc-term {
    color: #f1f5f9;
    font-weight: 600;
}

/* ==========================================================================
   COORDINATE PLANE TABLES (JADAWIL AS IN TEXTBOOK PP. 81-83)
   ========================================================================== */
.math-ch-table-wrap {
    overflow-x: auto;
    margin: 12px 0;
    border-radius: 12px;
    border: 1.5px solid rgba(56, 189, 248, 0.3);
    background: rgba(15, 23, 42, 0.85);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.math-ch-table {
    width: 100%;
    border-collapse: collapse;
    text-align: center;
    direction: rtl;
    font-size: 13.5px;
}

.math-ch-table th {
    background: rgba(56, 189, 248, 0.16);
    color: #38bdf8;
    font-weight: 800;
    padding: 10px 14px;
    border-bottom: 2px solid rgba(56, 189, 248, 0.35);
    font-size: 13px;
    letter-spacing: 0.3px;
}

.math-ch-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
    font-size: 13.5px;
}

.math-ch-table tr:hover {
    background: rgba(56, 189, 248, 0.06);
}

/* ==========================================================================
   COORDINATE PLANE GRAPHICAL DIAGRAM (ASHKAL & RUSOOM)
   ========================================================================== */
.math-ch-graph-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 14px 0;
    padding: 14px;
    background: rgba(11, 19, 36, 0.92);
    border: 1.5px solid rgba(56, 189, 248, 0.35);
    border-radius: 14px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.3);
}

.math-ch-graph-svg {
    border-radius: 8px;
    max-width: 100%;
    height: auto;
}

.math-ch-graph-caption {
    margin-top: 10px;
    font-size: 13px;
    color: #94a3b8;
    text-align: center;
    font-weight: 700;
}

.math-ch-step-text {
    font-size: 13.5px;
    color: var(--ch-text-main);
    line-height: 1.7;
    margin: 0;
    white-space: normal;
}

/* ==========================================================================
   FUNDAMENTAL RULES & BASICS BOX (THEORY USED IN EXAMPLE)
   ========================================================================== */
.math-ch-basics-box {
    margin: 14px 0 16px 0;
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.3) 0%, rgba(15, 23, 42, 0.8) 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.math-ch-basics-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 14.5px;
    font-weight: 800;
    color: #38bdf8;
}

.math-ch-basics-content {
    font-size: 13.5px;
    line-height: 1.7;
    color: #cbd5e1;
}

.math-ch-basics-list {
    margin: 6px 0 0 0;
    padding-right: 20px;
}

.math-ch-basics-list li {
    margin-bottom: 4px;
}

/* ==========================================================================
   STEP TEXT INSTRUCTION & PRACTICAL NUMERICAL APPLICATION
   ========================================================================== */
.math-ch-step-instruction {
    font-size: 14px;
    line-height: 1.75;
    color: #f8fafc;
    font-weight: 600;
    margin-bottom: 8px;
}

.math-ch-step-app-box {
    background: rgba(15, 23, 42, 0.85);
    border: 1.5px solid rgba(56, 189, 248, 0.3);
    border-radius: 10px;
    padding: 12px 18px;
    margin: 8px 0 12px 0;
    direction: ltr !important;
    text-align: left !important;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
    overflow-x: auto;
    scrollbar-width: thin;
}

/* ==========================================================================
   COORDINATE GRAPH TOOLBAR & ZOOM MODAL
   ========================================================================== */
.math-ch-graph-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.math-ch-graph-tag {
    font-size: 12px;
    font-weight: 700;
    color: #94a3b8;
}

.math-ch-zoom-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(56, 189, 248, 0.16);
    border: 1.5px solid rgba(56, 189, 248, 0.5);
    color: #38bdf8;
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.math-ch-zoom-btn:hover {
    background: #38bdf8;
    color: #0f172a;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
    transform: translateY(-1px);
}

.math-ch-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: mathFadeIn 0.25s ease;
}

.math-ch-modal-dialog {
    background: #0f172a;
    border: 2px solid #38bdf8;
    border-radius: 18px;
    max-width: 680px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.25);
    direction: rtl;
}

.math-ch-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.math-ch-modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-ch-modal-close {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #f1f5f9;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.math-ch-modal-close:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
}

@keyframes mathFadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   FULL-PAGE LUXURY LESSON STUDIO & 3-COLUMN HORIZONTAL TRIPTYCH LAYOUT
   Design System: Dark Glassmorphic, Neon Glows, Zero-Vertical-Scroll Architecture
   Order: [1. نص المسألة الرياضية] -> [2. القواعد والأساسيات المنهجية] -> [3. حل المسألة]
   ========================================================================== */

/* Fullscreen mode for lesson studio */
body.lesson-studio-page {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    background-color: #070B14;
    background-image: 
        radial-gradient(circle at 85% 15%, rgba(99, 102, 241, 0.14) 0%, transparent 45%),
        radial-gradient(circle at 15% 85%, rgba(6, 182, 212, 0.12) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.06) 0%, transparent 60%);
    background-attachment: fixed;
}

body.lesson-studio-page .math-ch-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: 1 !important;
    visibility: visible !important;
    display: flex;
    overflow: hidden;
    z-index: 10;
}

body.lesson-studio-page .math-ch-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    transform: none !important;
    background: rgba(7, 11, 20, 0.94);
    display: flex;
    flex-direction: column;
}

body.lesson-studio-page .math-ch-scroll-pill-btn {
    display: none !important;
}

/* Header Refinement */
.math-ch-header {
    background: rgba(13, 19, 33, 0.96);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 24px;
    height: 64px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 20;
}

.math-ch-studio-back-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #E2E8F0;
    padding: 7px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
}

.math-ch-studio-back-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.5);
    color: #FFFFFF;
    transform: translateX(3px);
}

.math-ch-tab-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #94A3B8;
    padding: 7px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.math-ch-tab-btn:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.08);
}

.math-ch-tab-btn.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(56, 189, 248, 0.2));
    border-color: rgba(56, 189, 248, 0.5);
    color: #38BDF8;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.2);
}

/* Studio Body View */
.math-ch-body {
    flex: 1;
    overflow: hidden;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
}

.math-ch-studio-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.math-ch-studio-workspace {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    gap: 12px;
}

/* Slide Top Strip */
.math-ch-slide-strip-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-shrink: 0;
    padding: 2px 4px;
}

.math-ch-strip-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.math-ch-slide-counter-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: #38BDF8;
    padding: 5px 14px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 700;
}

.math-ch-strip-topic-badge {
    font-size: 13px;
    font-weight: 700;
    color: #94A3B8;
}

.math-ch-strip-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-diff-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 700;
}

.math-ch-diff-badge.ministerial {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.16), rgba(217, 119, 6, 0.22));
    border: 1px solid rgba(245, 158, 11, 0.45);
    color: #FBBF24;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.2);
}

.math-ch-diff-badge.easy {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #34D399;
}

.math-ch-diff-badge.medium {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #FBBF24;
}

.math-ch-diff-badge.hard {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #F87171;
}

.math-ch-dot-diff {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
}

/* ==========================================================================
   VERTICAL FLOW LAYOUT: [1. نص المسألة] -> [2. القواعد والأساسيات] -> [3. حل المسألة]
   ========================================================================== */
.math-ch-vertical-flow {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 12px 24px 12px;
    direction: ltr !important; /* Positions vertical scrollbar on the right */
}

.math-ch-vertical-flow > * {
    direction: rtl !important; /* Preserves natural RTL reading flow */
}

.math-ch-vertical-flow::-webkit-scrollbar {
    width: 6px;
}
.math-ch-vertical-flow::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.4);
    border-radius: 10px;
}
.math-ch-vertical-flow::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.25);
    border-radius: 10px;
}
.math-ch-vertical-flow::-webkit-scrollbar-thumb:hover {
    background: rgba(56, 189, 248, 0.5);
}

/* Individual Section Card (Full Width Vertical Blocks) */
.math-ch-section-card,
.math-ch-triptych-col {
    background: rgba(15, 23, 42, 0.72);
    border: 1.5px solid rgba(148, 163, 184, 0.14);
    border-radius: 18px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.math-ch-section-card:hover,
.math-ch-triptych-col:hover {
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45);
}

.math-ch-section-card.col-problem,
.math-ch-triptych-col.col-problem {
    border-color: rgba(56, 189, 248, 0.28);
}
.math-ch-section-card.col-problem:hover,
.math-ch-triptych-col.col-problem:hover {
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45), 0 0 20px rgba(56, 189, 248, 0.12);
}

.math-ch-section-card.col-basics,
.math-ch-triptych-col.col-basics {
    border-color: rgba(99, 102, 241, 0.3);
}
.math-ch-section-card.col-basics:hover,
.math-ch-triptych-col.col-basics:hover {
    border-color: rgba(99, 102, 241, 0.55);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45), 0 0 20px rgba(99, 102, 241, 0.12);
}

.math-ch-section-card.col-solution,
.math-ch-triptych-col.col-solution {
    border-color: rgba(16, 185, 129, 0.3);
}
.math-ch-section-card.col-solution:hover,
.math-ch-triptych-col.col-solution:hover {
    border-color: rgba(16, 185, 129, 0.55);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.45), 0 0 20px rgba(16, 185, 129, 0.12);
}

/* Column Header */
.math-ch-col-header {
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(15, 23, 42, 0.55);
    flex-shrink: 0;
}

.math-ch-col-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-col-icon-badge {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.math-ch-col-icon-badge.cyan {
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.35);
    color: #38BDF8;
}

.math-ch-col-icon-badge.indigo {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: #818CF8;
}

.math-ch-col-icon-badge.emerald {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #34D399;
}

.math-ch-col-title {
    margin: 0;
    font-size: 14.5px;
    font-weight: 800;
    color: #FFFFFF;
    line-height: 1.3;
}

.math-ch-col-subtitle {
    display: block;
    font-size: 11px;
    color: #94A3B8;
    margin-top: 1px;
}

.math-ch-header-badges-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.math-ch-ex-pill,
.math-ch-page-pill,
.math-ch-tag-pill,
.math-ch-steps-count-pill {
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11.5px;
    font-weight: 800;
}

.math-ch-ex-pill {
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: #38BDF8;
}

.math-ch-page-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #FBBF24;
}

.math-ch-page-pill i,
.math-ch-page-pill svg {
    width: 12px;
    height: 12px;
}

.math-ch-problem-meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.math-ch-book-ref-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    background: rgba(245, 158, 11, 0.10);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: #FCD34D;
}

.math-ch-book-ref-pill i,
.math-ch-book-ref-pill svg {
    width: 12px;
    height: 12px;
}

.math-ch-tag-pill {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #818CF8;
}

.math-ch-steps-count-pill {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34D399;
}

/* Section Body (Spacious, full height, seamless vertical flow) */
.math-ch-section-body,
.math-ch-col-scrollable {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: visible;
}

/* Custom Scrollbars inside columns */
.math-ch-col-scrollable::-webkit-scrollbar {
    width: 5px;
}
.math-ch-col-scrollable::-webkit-scrollbar-track {
    background: transparent;
}
.math-ch-col-scrollable::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.2);
    border-radius: 10px;
}
.math-ch-col-scrollable::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.4);
}

/* ==========================================================================
   COLUMN 1: PROBLEM DETAILS
   ========================================================================== */
.math-ch-problem-card {
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.math-ch-qtitle-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(56, 189, 248, 0.1);
    color: #38BDF8;
    border: 1px solid rgba(56, 189, 248, 0.2);
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 11.5px;
    font-weight: 700;
    width: fit-content;
}

.math-ch-problem-text {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
    color: #FFFFFF;
    line-height: 1.8;
}

.math-ch-formula-focus-card {
    background: radial-gradient(circle at center, rgba(56, 189, 248, 0.08) 0%, rgba(15, 23, 42, 0.85) 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.3);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: inset 0 0 20px rgba(56, 189, 248, 0.05);
}

.math-ch-formula-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: #38BDF8;
}

.math-ch-formula-display {
    padding: 12px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: auto;
    font-size: 18px;
}

.math-ch-req-list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
}

.math-ch-req-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
}

.math-ch-req-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    flex-shrink: 0;
}

.math-ch-req-text {
    font-size: 14px;
    font-weight: 600;
    color: #e2e8f0;
    line-height: 1.5;
}

.math-ch-req-text-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-ch-req-verbal-goal {
    font-size: 14.5px;
    font-weight: 600;
    color: #38bdf8;
    line-height: 1.6;
    background: rgba(56, 189, 248, 0.08);
    border-right: 3px solid #38bdf8;
    padding: 8px 12px;
    border-radius: 6px;
}


/* ==========================================================================
   COLUMN 2: METHODOLOGICAL BASICS & RULES
   ========================================================================== */
.math-ch-basics-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.math-ch-rule-card-refined {
    background: rgba(30, 41, 59, 0.45);
    border: 1.5px solid rgba(99, 102, 241, 0.25);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.math-ch-rule-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.math-ch-rule-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-ch-mini-badge {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.math-ch-mini-badge.indigo {
    background: rgba(99, 102, 241, 0.2);
    color: #818CF8;
}

.math-ch-rule-title {
    margin: 0;
    font-size: 14px;
    font-weight: 800;
    color: #FFFFFF;
}

.math-ch-rule-formula-box {
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.1) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-ch-formula-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    color: #818CF8;
}

.math-ch-formula-render {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 0 !important;
    font-size: 16px;
    min-height: 76px !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
}

.math-ch-formula-render .katex-display {
    margin: 8px 0 !important;
    padding: 6px 0 !important;
    line-height: 2 !important;
    overflow-y: visible !important;
}

.katex .mord.text,
.katex .cjk_fallback,
.arabic-math-text {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
    font-size: 1.05em !important;
    line-height: normal !important;
}

/* Specialized styling for overset annotations to ensure vertical clearance */
.katex .mover,
.katex .op-limits {
    overflow: visible !important;
}

.katex .mover > .vlist-t > .vlist-r:first-child .mord.text,
.katex .op-limits > .vlist-t > .vlist-r:first-child .mord.text {
    font-size: 0.78em !important;
    line-height: 1.15 !important;
    display: inline-block !important;
    padding-bottom: 5px !important;
}

/* Ensure rule formula boxes provide generous vertical room for overset formulas */
.math-ch-formula-render,
.math-ch-theory-formula-render,
.math-ch-rule-formula-box .math-ch-formula-render {
    min-height: 88px !important;
    padding: 18px 0 !important;
}

.math-ch-formula-render .katex-display,
.math-ch-theory-formula-render .katex-display {
    margin: 10px 0 !important;
    padding: 8px 0 !important;
    line-height: 2.2 !important;
    overflow-y: visible !important;
}


.math-ch-rule-explanation-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-explanation-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 700;
    color: #CBD5E1;
}

.math-ch-rule-desc {
    margin: 0;
    font-size: 13px;
    color: #94A3B8;
    line-height: 1.7;
}

.math-ch-golden-tip-refined {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-tip-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 800;
    color: #FBBF24;
}

.math-ch-golden-tip-body {
    font-size: 12.5px;
    color: #FDE68A;
    line-height: 1.6;
}

.math-ch-smart-hint-card {
    background: rgba(14, 165, 233, 0.08);
    border: 1px solid rgba(14, 165, 233, 0.28);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-hint-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.math-ch-hint-icon {
    color: #38BDF8;
}

.math-ch-hint-label {
    font-size: 12px;
    font-weight: 800;
    color: #38BDF8;
}

.math-ch-hint-text {
    font-size: 12.5px;
    color: #BAE6FD;
    line-height: 1.6;
}

/* ==========================================================================
   DETAILED MOTION-BY-MOTION EXPLANATION (الشرح المفصل حركة بحركة)
   ========================================================================== */
.math-ch-motion-card {
    background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.09) 0%, rgba(15, 23, 42, 0.88) 100%);
    border: 1.5px solid rgba(16, 185, 129, 0.35);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.math-ch-motion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(16, 185, 129, 0.2);
}

.math-ch-motion-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-motion-title {
    font-size: 15px;
    font-weight: 700;
    color: #34d399;
    margin: 0;
}

.math-ch-motion-subtitle {
    font-size: 12px;
    color: #94a3b8;
    display: block;
    margin-top: 2px;
}

.math-ch-motion-tag {
    font-size: 11.5px;
    font-weight: 700;
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 3px 8px;
    border-radius: 6px;
}

.math-ch-motion-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.math-ch-motion-item {
    background: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-motion-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-ch-motion-item-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, #059669, #10b981);
    color: #ffffff;
    font-size: 11.5px;
    font-weight: 800;
    border-radius: 6px;
    flex-shrink: 0;
}

.math-ch-motion-item-title {
    font-size: 13.5px;
    font-weight: 700;
    color: #a7f3d0;
}

.math-ch-motion-item-desc {
    font-size: 14px;
    line-height: 1.8;
    color: #e2e8f0;
}

/* ==========================================================================
   COLUMN 3: STEP-BY-STEP SOLUTION
   ========================================================================== */
.math-ch-steps-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.math-ch-step-row {
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 18px 22px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 4px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.math-ch-step-row:hover {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(52, 211, 153, 0.35);
    transform: translateY(-1px);
}

.math-ch-step-row.final-step {
    background: radial-gradient(circle at 10% 20%, rgba(16, 185, 129, 0.12) 0%, rgba(15, 23, 42, 0.75) 100%);
    border-color: rgba(52, 211, 153, 0.45);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.15);
}

.math-ch-step-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.math-ch-step-num {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(6, 182, 212, 0.25));
    border: 1.5px solid rgba(52, 211, 153, 0.45);
    color: #34D399;
    font-size: 13px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.2);
}

.math-ch-step-row.final-step .math-ch-step-num {
    background: linear-gradient(135deg, #10B981, #059669);
    border-color: #34D399;
    color: #FFFFFF;
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.4);
}

.math-ch-step-line {
    width: 2px;
    height: 24px;
    background: rgba(148, 163, 184, 0.16);
    margin-top: 6px;
}

.math-ch-step-main {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-step-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.math-ch-step-name {
    font-size: 14.5px;
    font-weight: 800;
    color: #FFFFFF;
}

.math-ch-final-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.45);
    color: #34D399;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
}

.math-ch-step-text {
    font-size: 13.5px;
    color: #CBD5E1;
    line-height: 1.7;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
}

/* ==========================================================================
   SLIDE BOTTOM CONTROLS & PAGINATION
   ========================================================================== */
.math-ch-slide-strip-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    padding: 6px 4px 2px;
}

.math-ch-nav-icon-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    color: #E2E8F0;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 13.5px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
}

.math-ch-nav-icon-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    color: #FFFFFF;
    transform: translateY(-1px);
}

.math-ch-nav-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.math-ch-dots-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 4px 8px;
    border-radius: 9999px;
}

.math-ch-dot-pill {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: #94A3B8;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.math-ch-dot-pill:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.08);
}

.math-ch-dot-pill.active {
    background: #38BDF8;
    color: #070B14;
    border-color: #38BDF8;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
    font-weight: 800;
}

.math-ch-continue-btn {
    background: linear-gradient(135deg, #0284C7, #0369A1);
    border: 1.5px solid rgba(56, 189, 248, 0.5);
    color: #FFFFFF;
    padding: 10px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
    box-shadow: 0 4px 16px rgba(2, 132, 199, 0.35);
}

.math-ch-continue-btn:hover {
    background: linear-gradient(135deg, #38BDF8, #0284C7);
    box-shadow: 0 6px 22px rgba(56, 189, 248, 0.5);
    transform: translateY(-2px);
}

.math-ch-continue-btn.finish-btn {
    background: linear-gradient(135deg, #059669, #047857);
    border-color: rgba(52, 211, 153, 0.6);
    box-shadow: 0 4px 18px rgba(16, 185, 129, 0.4);
}

.math-ch-continue-btn.finish-btn:hover {
    background: linear-gradient(135deg, #10B981, #059669);
    box-shadow: 0 6px 24px rgba(16, 185, 129, 0.55);
}

.math-ch-continue-btn.finish-btn.pending-answers {
    background: linear-gradient(135deg, #0d9488, #059669) !important;
    cursor: pointer !important;
    opacity: 0.95;
}

.math-ch-continue-btn.finish-btn.pending-answers:hover {
    background: linear-gradient(135deg, #14b8a6, #10b981) !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 22px rgba(20, 184, 166, 0.5) !important;
}


/* ==========================================================================
   THEORY TAB STYLES
   ========================================================================== */
.math-ch-theory-container {
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    padding: 8px 4px 20px;
    height: 100%;
}

.math-ch-theory-hero {
    background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15), rgba(15, 23, 42, 0.7));
    border: 1px solid rgba(99, 102, 241, 0.28);
    border-radius: 16px;
    padding: 20px 24px;
}

.math-ch-theory-hero-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 800;
    color: #FFFFFF;
}

.math-ch-theory-hero-desc {
    margin: 0;
    font-size: 13.5px;
    color: #CBD5E1;
    line-height: 1.7;
}

.math-ch-theory-rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

.math-ch-rule-card {
    background: rgba(15, 23, 42, 0.75);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.25s ease;
}

.math-ch-rule-card:hover {
    border-color: rgba(99, 102, 241, 0.45);
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.math-ch-rule-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.math-ch-rule-counter {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #818CF8;
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
}

.math-ch-rule-math {
    background: rgba(10, 15, 29, 0.85);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    overflow-x: auto;
}

.math-ch-golden-tip {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.28);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.math-ch-tip-header-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 800;
    color: #FBBF24;
}

.math-ch-tip-text {
    font-size: 12.5px;
    color: #FDE68A;
    line-height: 1.6;
}

/* ==========================================================================
   THEORY SLIDE CAROUSEL SYSTEM
   Renders one rule per slide completely visible without scrolling
   ========================================================================== */
.math-ch-theory-slide-workspace {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    gap: 12px;
}

.math-ch-theory-single-slide {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6px 14px;
    overflow-y: auto;
}

.math-ch-theory-slide-card {
    background: rgba(15, 23, 42, 0.85);
    border: 1.5px solid rgba(99, 102, 241, 0.3);
    border-radius: 20px;
    padding: 22px 28px;
    width: 100%;
    max-width: 960px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), 0 0 25px rgba(99, 102, 241, 0.12);
    animation: mathFadeIn 0.25s ease-out;
}

.math-ch-theory-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.math-ch-theory-slide-title {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    color: #FFFFFF;
    line-height: 1.4;
}

.math-ch-theory-formula-box {
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.14) 0%, rgba(10, 15, 29, 0.95) 100%);
    border: 1.5px solid rgba(99, 102, 241, 0.4);
    border-radius: 14px;
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: inset 0 0 20px rgba(99, 102, 241, 0.08);
}

.math-ch-theory-formula-render {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 0;
    min-height: 72px;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    overflow-x: auto;
    overflow-y: visible !important;
}

.math-ch-theory-formula-render .math-display-wrapper {
    margin: 0 !important;
    padding: 8px 0 !important;
    width: 100% !important;
    justify-content: center !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

.math-ch-theory-formula-render .math-display-wrapper::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.math-ch-theory-formula-render .katex-display {
    margin: 8px 0 !important;
    font-size: clamp(1rem, 1.45vw, 1.25rem) !important;
    line-height: 2 !important;
    overflow-y: visible !important;
}

.math-ch-theory-formula-render .katex .mord.text {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
    font-size: 0.95em !important;
}


.math-ch-theory-explanation-box {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-theory-desc {
    margin: 0;
    font-size: 13.5px;
    color: #CBD5E1;
    line-height: 1.7;
    direction: rtl;
    unicode-bidi: isolate;
}

.math-ch-theory-tip-box {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-theory-tip-text {
    font-size: 13px;
    color: #FDE68A;
    line-height: 1.7;
    direction: rtl;
    unicode-bidi: isolate;
}

/* ==========================================================================
   RESPONSIVE DESIGN BREAKPOINTS
   ========================================================================== */
@media (max-width: 768px) {
    .math-ch-vertical-flow {
        padding: 4px 6px 16px 6px;
        gap: 16px;
    }
    .math-ch-section-body,
    .math-ch-col-scrollable {
        padding: 14px 16px;
        gap: 12px;
    }
    .math-ch-col-header {
        padding: 12px 16px;
    }
}

/* ==========================================================================
   MATHEMATICAL RADICAL SYSTEM — VINCULUM ROOF & MULTI-CHAR SCALING
   Connects √ checkmark to a horizontal overline roof covering the radicand.
   Scales up size for 2+ digits/letters. Prevents collisions with letters/digits.
   ========================================================================== */
.math-radical {
    display: inline-flex !important;
    align-items: stretch !important;
    vertical-align: -0.06em !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    margin: 0 0.25em !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    position: relative !important;
    font-style: normal !important;
}

.math-radical .rad-index {
    font-size: 0.62em !important;
    line-height: 1 !important;
    font-weight: 800 !important;
    position: relative !important;
    top: -0.38em !important;
    margin-right: -0.22em !important;
    color: inherit !important;
}

.math-radical .rad-surd {
    font-family: 'KaTeX_Main', 'Cambria Math', 'STIX Two Math', 'DejaVu Sans', serif !important;
    font-size: 1.18em !important;
    line-height: 0.95 !important;
    margin-right: -0.5px !important;
    font-style: normal !important;
    color: inherit !important;
    user-select: none !important;
    display: inline-block !important;
    transform: translateY(1px) !important;
}

.math-radical .rad-radicand {
    border-top: 1.8px solid currentColor !important;
    padding-top: 1.5px !important;
    padding-left: 2px !important;
    padding-right: 3px !important;
    margin-left: -0.5px !important;
    display: inline-flex !important;
    align-items: center !important;
    line-height: 1.15 !important;
    font-style: normal !important;
    font-family: inherit !important;
}

/* Enlarge root size when radicand has 2 or more characters (e.g. √14, √125, √28, √2ab) */
.math-radical.rad-large {
    margin: 0 0.35em !important;
    vertical-align: -0.10em !important;
}

.math-radical.rad-large .rad-surd {
    font-size: 1.40em !important;
    font-weight: 700 !important;
    line-height: 0.88 !important;
    transform: translateY(1.5px) !important;
}

.math-radical.rad-large .rad-radicand {
    border-top-width: 2.2px !important;
    padding-top: 2px !important;
    padding-left: 3px !important;
    padding-right: 4.5px !important;
    font-size: 1.05em !important;
}

/* KaTeX .sqrt: authentic LaTeX vinculum and clean SVG rendering */
.katex .sqrt {
    margin: 0 0.15em !important;
}

.katex .sqrt svg {
    overflow: visible !important;
}

/* Backwards-compatibility for .math-sqrt */
.math-sqrt {
    display: inline-flex !important;
    align-items: stretch !important;
    vertical-align: -0.06em !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    margin: 0 0.25em !important;
    line-height: 1 !important;
    white-space: nowrap !important;
}

.math-rad-index {
    font-size: 0.62em !important;
    line-height: 1 !important;
    font-weight: 800 !important;
    position: relative !important;
    top: -0.38em !important;
    margin-right: -0.22em !important;
    color: inherit !important;
}

.math-rad-surd {
    font-family: 'KaTeX_Main', 'Cambria Math', 'STIX Two Math', 'DejaVu Sans', serif !important;
    font-size: 1.18em !important;
    line-height: 0.95 !important;
    margin-right: -0.5px !important;
    color: inherit !important;
    display: inline-block !important;
    transform: translateY(1px) !important;
}

.math-rad-body {
    border-top: 1.8px solid currentColor !important;
    padding-top: 1.5px !important;
    padding-left: 2px !important;
    padding-right: 3px !important;
    margin-left: -0.5px !important;
    display: inline-flex !important;
    align-items: center !important;
    line-height: 1.15 !important;
}

.math-sqrt.rad-large {
    margin: 0 0.35em !important;
}

.math-sqrt.rad-large .math-rad-surd {
    font-size: 1.40em !important;
    font-weight: 700 !important;
    transform: translateY(1.5px) !important;
}

.math-sqrt.rad-large .math-rad-body {
    border-top-width: 2.2px !important;
    padding-top: 2px !important;
    padding-left: 3px !important;
    padding-right: 4.5px !important;
    font-size: 1.05em !important;
}

/* ==========================================================================
   MODE SELECTION MODAL & CHALLENGE SYSTEM
   ========================================================================== */

.math-mode-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: rgba(4, 7, 15, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    direction: rtl;
    font-family: 'Cairo', sans-serif;
}

.math-mode-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.math-mode-modal {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.96) 0%, rgba(9, 14, 23, 0.99) 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.35);
    border-radius: 24px;
    width: 100%;
    max-width: 820px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9), 0 0 50px rgba(56, 189, 248, 0.18);
    transform: scale(0.92) translateY(18px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 28px;
    position: relative;
}

.math-mode-modal-overlay.active .math-mode-modal {
    transform: scale(1) translateY(0);
}

.math-mode-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.math-mode-header-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.math-mode-chapter-badge {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: rgba(56, 189, 248, 0.12);
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.25);
    flex-shrink: 0;
}

.math-mode-header-tag {
    font-size: 12px;
    font-weight: 800;
    color: #38bdf8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.math-mode-chapter-title {
    margin: 0;
    font-size: 20px;
    font-weight: 900;
    color: #ffffff;
    line-height: 1.3;
}

.math-mode-close-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.math-mode-close-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
    transform: rotate(90deg);
}

.math-mode-intro {
    font-size: 14.5px;
    color: #cbd5e1;
    margin-bottom: 24px;
    line-height: 1.6;
    text-align: center;
}

.math-mode-cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 12px;
}

@media (max-width: 680px) {
    .math-mode-cards-grid {
        grid-template-columns: 1fr;
    }
}

.math-mode-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.math-mode-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.math-mode-card.basic-mode:hover {
    transform: translateY(-6px);
    border-color: rgba(56, 189, 248, 0.5);
    background: rgba(30, 41, 59, 0.75);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45), 0 0 30px rgba(56, 189, 248, 0.2);
}

.math-mode-card.basic-mode::before {
    background: linear-gradient(90deg, #0284c7, #38bdf8);
}

.math-mode-card.basic-mode:hover::before {
    opacity: 1;
}

.math-mode-card.challenge-mode:hover {
    transform: translateY(-6px);
    border-color: rgba(245, 158, 11, 0.5);
    background: rgba(30, 41, 59, 0.75);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45), 0 0 30px rgba(245, 158, 11, 0.25);
}

.math-mode-card.challenge-mode::before {
    background: linear-gradient(90deg, #ea580c, #f59e0b);
}

.math-mode-card.challenge-mode:hover::before {
    opacity: 1;
}

.math-mode-pill-badge {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 11.5px;
    font-weight: 800;
    margin-bottom: 16px;
}

.math-mode-pill-badge.basic-pill {
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.35);
    color: #38bdf8;
}

.math-mode-pill-badge.challenge-pill {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #fbbf24;
}

.math-mode-card-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.math-mode-icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.basic-mode .math-mode-icon-circle {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.2), rgba(56, 189, 248, 0.25));
    border: 1.5px solid rgba(56, 189, 248, 0.4);
    color: #38bdf8;
}

.challenge-mode .math-mode-icon-circle {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.2), rgba(245, 158, 11, 0.25));
    border: 1.5px solid rgba(245, 158, 11, 0.4);
    color: #fbbf24;
}

.math-mode-name {
    font-size: 19px;
    font-weight: 900;
    color: #ffffff;
    margin: 0 0 3px;
}

.math-mode-tagline {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 600;
}

.math-mode-detail {
    font-size: 13px;
    color: #cbd5e1;
    line-height: 1.6;
    margin-bottom: 16px;
    flex-grow: 1;
}

.math-mode-checklist {
    list-style: none;
    padding: 0;
    margin: 0 0 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.math-mode-checklist li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #94a3b8;
    font-weight: 600;
}

.math-mode-checklist li .chk-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.math-mode-action-btn {
    width: 100%;
    padding: 12px 18px;
    border-radius: 12px;
    border: none;
    font-size: 14px;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.25s ease;
}

.math-mode-action-btn.basic-btn {
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    color: #ffffff;
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.35);
}

.math-mode-action-btn.basic-btn:hover {
    background: linear-gradient(135deg, #0369a1, #0284c7);
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(2, 132, 199, 0.5);
}

.math-mode-action-btn.challenge-btn {
    background: linear-gradient(135deg, #d97706, #f59e0b);
    color: #ffffff;
    box-shadow: 0 6px 18px rgba(217, 119, 6, 0.35);
}

.math-mode-action-btn.challenge-btn:hover {
    background: linear-gradient(135deg, #b45309, #d97706);
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(217, 119, 6, 0.5);
}

/* Challenge Locked View inside Modal */
.math-challenge-locked-view {
    text-align: center;
    padding: 20px 10px;
}

.math-challenge-lock-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.15);
    border: 2px solid rgba(245, 158, 11, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    margin: 0 auto 16px;
    box-shadow: 0 0 30px rgba(245, 158, 11, 0.25);
    animation: lockPulse 2s infinite ease-in-out;
}

@keyframes lockPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.math-challenge-locked-title {
    font-size: 22px;
    font-weight: 900;
    color: #ffffff;
    margin-bottom: 10px;
}

.math-challenge-locked-msg {
    font-size: 14.5px;
    color: #cbd5e1;
    max-width: 520px;
    margin: 0 auto 26px;
    line-height: 1.6;
}

.math-challenge-locked-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
    margin: 0 auto;
}

/* Locked Card in Chapter Pages */
.lesson-node-card.challenge-locked-card {
    opacity: 0.60 !important;
    filter: grayscale(0.4) !important;
    cursor: not-allowed !important;
}

.lesson-node-card.challenge-locked-card:hover {
    transform: none !important;
}

.lesson-node-card.challenge-locked-card .node-circle-wrap {
    cursor: not-allowed !important;
}

.lesson-node-card.challenge-locked-card .node-action-pill {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
    color: #64748b !important;
    box-shadow: none !important;
    cursor: not-allowed !important;
}

.lesson-node-card.challenge-locked-card .node-subaction-pill {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}

/* Floating Chapter Mode Banner */
.chapter-mode-banner-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 0 auto 24px;
    flex-wrap: wrap;
    position: relative;
    z-index: 20;
}

.chapter-mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px;
    border-radius: 9999px;
    backdrop-filter: blur(10px);
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.chapter-mode-pill.challenge {
    background: rgba(245, 158, 11, 0.14);
    border: 1.5px solid rgba(245, 158, 11, 0.45);
    color: #fbbf24;
}

.chapter-mode-pill.basic {
    background: rgba(56, 189, 248, 0.14);
    border: 1.5px solid rgba(56, 189, 248, 0.45);
    color: #38bdf8;
}

.chapter-mode-switch-btn {
    padding: 6px 14px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chapter-mode-switch-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

/* ==========================================================================
   INTERACTIVE ANIMATED WALKTHROUGH (الحل التفاعلي المتحرك للمهارة)
   ========================================================================== */
.col-interactive-walkthrough {
    border: 1.5px solid rgba(168, 85, 247, 0.4) !important;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 27, 75, 0.75)) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 20px rgba(168, 85, 247, 0.15) !important;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 20px;
}

.math-ch-iw-pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d946ef;
    box-shadow: 0 0 8px #d946ef;
    animation: iwPulse 1.8s infinite;
}

@keyframes iwPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.6; }
}

.math-ch-iw-timeline {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 12px;
    margin-bottom: 16px;
    scrollbar-width: thin;
}

.math-ch-iw-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 20px;
    color: #cbd5e1;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.math-ch-iw-pill:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(168, 85, 247, 0.5);
    color: #ffffff;
}

.math-ch-iw-pill.active {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    border-color: #d946ef;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(168, 85, 247, 0.4);
    font-weight: 700;
}

.math-ch-iw-pill-num {
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 800;
}

.math-ch-iw-stage {
    background: rgba(11, 19, 43, 0.85);
    border: 1.5px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    padding: 24px 20px;
    margin-bottom: 16px;
    box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.4);
}

.math-ch-iw-formula-display {
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    direction: ltr !important;
    text-align: center;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.math-ch-iw-note-card {
    margin-top: 18px;
    padding: 12px 16px;
    background: rgba(30, 41, 59, 0.6);
    border-right: 4px solid #a855f7;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.math-ch-iw-note-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #e9d5ff;
    font-weight: 800;
    font-size: 14px;
}

.math-ch-iw-note-desc {
    margin: 0;
    color: #cbd5e1;
    font-size: 13.5px;
    line-height: 1.6;
}

.math-ch-iw-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 6px;
}

.math-ch-iw-controls-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.math-ch-iw-ctrl-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.math-ch-iw-ctrl-btn:hover {
    background: rgba(51, 65, 85, 0.9);
    border-color: #38bdf8;
    color: #ffffff;
}

.math-ch-iw-play-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 20px;
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    border-radius: 8px;
    color: #ffffff;
    font-size: 14px;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
    transition: all 0.2s ease;
}

.math-ch-iw-play-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.5);
    filter: brightness(1.1);
}

.math-ch-iw-speed-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(15, 23, 42, 0.6);
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.math-ch-iw-speed-label {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 600;
}

.math-ch-iw-speed-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #94a3b8;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.math-ch-iw-speed-btn.active {
    background: rgba(56, 189, 248, 0.2);
    border-color: #38bdf8;
    color: #38bdf8;
}





/* ==========================================================================
   5-LEVEL INTERACTIVE VIDEO SCAFFOLD (Ø§Ù„ÙÙŠØ¯ÙŠÙˆ Ø§Ù„Ø±ÙŠØ§Ø¶ÙŠ Ø§Ù„ØªÙØ§Ø¹Ù„ÙŠ Ø¨Ø®Ù…Ø³Ø© Ù…Ø³ØªÙˆÙŠØ§Øª)
   Strict gating, cumulative permanent board, tiered hints, and rich aesthetics
   ========================================================================== */

.col-scaffold-player {
    background: rgba(15, 23, 42, 0.82) !important;
    border: 1.5px solid rgba(168, 85, 247, 0.38) !important;
    border-radius: 18px !important;
    overflow: hidden;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4), 0 0 24px rgba(168, 85, 247, 0.12) !important;
    margin-bottom: 22px;
    animation: scaffoldSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.scaffold-tag-pill {
    background: rgba(168, 85, 247, 0.18);
    border: 1px solid rgba(168, 85, 247, 0.45);
    color: #e9d5ff;
    padding: 5px 14px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 10px rgba(168, 85, 247, 0.2);
}

.scaffold-pulse-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c084fc;
    box-shadow: 0 0 10px #c084fc;
    animation: scaffoldPulse 1.6s infinite ease-in-out;
}

@keyframes scaffoldPulse {
    0%, 100% {
        transform: scale(0.9);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.3);
        opacity: 1;
        box-shadow: 0 0 14px #e879f9;
    }
}

/* 5 Progressive Mastery Levels Track */
.scaffold-levels-track {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

@media (max-width: 900px) {
    .scaffold-levels-track {
        grid-template-columns: 1fr;
    }
}

.scaffold-lvl-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    position: relative;
    overflow: hidden;
}

.scaffold-lvl-pill .scaffold-lvl-num {
    font-size: 12px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 6px;
    margin-left: 6px;
}

.scaffold-lvl-pill .scaffold-lvl-name {
    flex: 1;
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scaffold-lvl-pill .scaffold-lvl-status-icon {
    font-size: 13px;
    margin-right: 4px;
}

.scaffold-lvl-pill.active {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.28), rgba(99, 102, 241, 0.28));
    border: 1.5px solid #a855f7;
    color: #ffffff;
    box-shadow: 0 0 16px rgba(168, 85, 247, 0.35);
    transform: translateY(-2px);
}

.scaffold-lvl-pill.active .scaffold-lvl-num {
    background: #a855f7;
    color: #ffffff;
}

.scaffold-lvl-pill.completed {
    background: rgba(16, 185, 129, 0.16);
    border: 1.5px solid rgba(16, 185, 129, 0.45);
    color: #6ee7b7;
}

.scaffold-lvl-pill.completed .scaffold-lvl-num {
    background: rgba(16, 185, 129, 0.3);
    color: #a7f3d0;
}

.scaffold-lvl-pill.locked {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #64748b;
    opacity: 0.65;
}

.scaffold-lvl-pill.locked .scaffold-lvl-num {
    background: rgba(255, 255, 255, 0.06);
    color: #94a3b8;
}

/* Transition Condition Banner */
.scaffold-condition-banner {
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.14), rgba(99, 102, 241, 0.1));
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-right: 5px solid #38bdf8;
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 22px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.scaffold-condition-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13.5px;
    font-weight: 800;
    color: #38bdf8;
    white-space: nowrap;
}

.scaffold-condition-text {
    font-size: 14px;
    font-weight: 700;
    color: #f1f5f9;
}

/* Two-Zone Arena: [Interactive Challenge Zone] + [Cumulative Solution Board] */
.scaffold-arena-grid {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 20px;
    align-items: start;
}

@media (max-width: 980px) {
    .scaffold-arena-grid {
        grid-template-columns: 1fr;
    }
}

/* Left Zone: Interactive Challenge Card */
.scaffold-challenge-zone {
    background: rgba(15, 23, 42, 0.65);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease;
}

.scaffold-challenge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.scaffold-challenge-level-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 800;
    color: #c084fc;
    background: rgba(168, 85, 247, 0.16);
    padding: 5px 14px;
    border-radius: 8px;
    border: 1px solid rgba(168, 85, 247, 0.35);
}

.scaffold-challenge-subtag {
    font-size: 12.5px;
    color: #94a3b8;
    font-weight: 600;
}

.scaffold-prompt-box {
    font-size: 16px;
    line-height: 1.85;
    color: #f8fafc;
    background: rgba(30, 41, 59, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.2);
}

.scaffold-options-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.scaffold-opt-btn {
    width: 100%;
    background: rgba(30, 41, 59, 0.7);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-right: 4px solid #64748b;
    border-radius: 12px;
    padding: 12px 18px;
    color: #f1f5f9;
    font-family: inherit;
    font-size: 15.5px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: right;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.scaffold-opt-btn:hover {
    background: rgba(99, 102, 241, 0.16);
    border-color: rgba(168, 85, 247, 0.55);
    border-right-color: #a855f7;
    transform: translateX(-4px);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.22);
}

.scaffold-opt-badge {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #38bdf8;
    font-weight: 800;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.scaffold-opt-btn:hover .scaffold-opt-badge {
    background: #a855f7;
    border-color: #c084fc;
    color: #ffffff;
    transform: scale(1.08);
}

.scaffold-opt-content {
    flex: 1;
    font-weight: 600;
}

/* Tiered Feedback Boxes */
.scaffold-feedback-box {
    padding: 14px 18px;
    border-radius: 12px;
    animation: scaffoldSlideIn 0.25s ease;
}

.scaffold-feedback-box.success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.12));
    border: 1.5px solid #10b981;
    color: #a7f3d0;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

.scaffold-feedback-box.warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.12));
    border: 1.5px solid #f59e0b;
    color: #fde68a;
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.25);
}

.scaffold-feedback-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14.5px;
    font-weight: 800;
    margin-bottom: 6px;
}

.scaffold-feedback-msg {
    margin: 0;
    font-size: 14px;
    line-height: 1.65;
    font-weight: 600;
}

/* Error Shake Animation */
.scaffold-shake {
    animation: scaffoldShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes scaffoldShake {
    10%, 90% { transform: translate3d(-3px, 0, 0); }
    20%, 80% { transform: translate3d(5px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Right Zone: Cumulative Solution Board */
.scaffold-cumulative-zone {
    background: rgba(15, 23, 42, 0.7);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.scaffold-cum-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.scaffold-cum-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 800;
    color: #e2e8f0;
}

.scaffold-cum-tag {
    font-size: 11.5px;
    font-weight: 700;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.15);
    padding: 3px 9px;
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.scaffold-cumulative-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 480px;
    overflow-y: auto;
    padding-right: 2px;
}

.scaffold-cumulative-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 36px 18px;
    color: #64748b;
    font-size: 13.5px;
    font-weight: 600;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1.5px dashed rgba(255, 255, 255, 0.08);
    border-radius: 12px;
}

.scaffold-cum-row {
    background: rgba(30, 41, 59, 0.6);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    gap: 16px;
    align-items: flex-start;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    animation: scaffoldFadeInUp 0.35s ease;
}

.scaffold-cum-row.latest-step {
    border-color: #a855f7 !important;
    background: linear-gradient(135deg, rgba(88, 28, 135, 0.35), rgba(30, 41, 59, 0.75)) !important;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.3) !important;
    transform: scale(1.01);
}

.scaffold-cum-badge-col {
    position: relative;
    flex-shrink: 0;
}

.scaffold-cum-step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: rgba(168, 85, 247, 0.2);
    border: 1.5px solid #a855f7;
    color: #e9d5ff;
    font-size: 13px;
    font-weight: 800;
}

.scaffold-cum-pulse-ring {
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 12px;
    border: 2px solid #c084fc;
    animation: scaffoldPulse 1.4s infinite;
    pointer-events: none;
}

.scaffold-cum-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.scaffold-cum-math {
    font-size: 17.5px;
    color: #ffffff;
    font-weight: 700;
    direction: ltr !important;
    text-align: left;
    padding: 4px 0;
}

.scaffold-cum-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12.5px;
}

.scaffold-cum-rule-title {
    font-weight: 800;
    color: #38bdf8;
}

.scaffold-cum-rule-desc {
    color: #cbd5e1;
    line-height: 1.5;
}

/* Victory State */
.scaffold-victory-card {
    text-align: center;
    padding: 36px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    background: linear-gradient(135deg, rgba(88, 28, 135, 0.3), rgba(15, 23, 42, 0.7));
    border-radius: 14px;
    border: 1.5px solid rgba(168, 85, 247, 0.4);
    animation: scaffoldFadeInUp 0.4s ease;
}

.scaffold-victory-badge {
    display: inline-block;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #ffffff;
    padding: 6px 18px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
}

.scaffold-victory-title {
    margin: 0;
    font-size: 19px;
    font-weight: 900;
    color: #f5f3ff;
    line-height: 1.6;
}

.scaffold-victory-desc {
    margin: 0;
    font-size: 14.5px;
    color: #cbd5e1;
    max-width: 480px;
    line-height: 1.7;
}

.scaffold-restart-btn {
    background: linear-gradient(135deg, #a855f7, #6366f1);
    border: 1px solid rgba(192, 132, 252, 0.5);
    color: #ffffff;
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.22s ease;
    box-shadow: 0 4px 16px rgba(168, 85, 247, 0.35);
    margin-top: 6px;
}

.scaffold-restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(168, 85, 247, 0.5);
    filter: brightness(1.1);
}

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

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

/* ==========================================================================
   GENEROUS MATHEMATICAL DERIVATION & STEP ROW SPACING (Eye Comfort & Clarity)
   Eliminates crowding between stacked fraction numerators, denominators & steps
   ========================================================================== */
.math-display-wrapper {
    margin: 14px 0 !important;
    padding: 14px 0 !important;
    overflow-x: auto;
    overflow-y: visible !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

.math-display-wrapper::-webkit-scrollbar,
.katex-display::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.katex-display {
    margin: 14px 0 !important;
    padding: 10px 0 !important;
    overflow-x: auto;
    overflow-y: visible !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

.math-ch-step-app-box {
    margin: 14px 0 !important;
    padding: 18px 24px !important;
    line-height: 2.3 !important;
    border-radius: 12px !important;
}

/* ==========================================================================
   CHAPTER 3 LESSON 7 & GLOBAL STEPS 1-5 MATHEMATICAL SYMBOL ENLARGEMENT
   Enlarges mathematical symbols and formulas in Steps 1-5 ONLY.
   Arabic explanation texts remain standard size (14.5px).
   Step 6 (.final-step) remains completely untouched.
   ========================================================================== */
.math-ch-step-row:not(.final-step) .math-ch-step-app-box {
    font-size: 21px !important;
    padding: 16px 24px !important;
    line-height: 2.3 !important;
    letter-spacing: 0.5px !important;
}

.math-ch-step-row:not(.final-step) .math-ch-step-app-box .katex {
    font-size: 1.25em !important;
}

.math-ch-step-row:not(.final-step) .math-inline-katex {
    font-size: 1.2em !important;
}

.math-ch-step-row:not(.final-step) .math-token-ltr {
    font-size: 1.18em !important;
}

.math-ch-step-instruction {
    margin-bottom: 8px !important;
    line-height: 1.8 !important;
    font-size: 14.5px !important;
}

.math-ch-step-row:not(.final-step) .math-ch-step-instruction {
    font-size: 14.5px !important;
    line-height: 1.8 !important;
}

.math-ch-step-text {
    line-height: 1.85 !important;
}

/* Vertical spacing clearance for KaTeX tables and multiline aligned environments */
.katex .mtable .vertical-separator {
    min-height: 16px !important;
}


/* Add ample clearance between stacked fractions */
.katex .mfrac {
    padding-top: 0.35em !important;
    margin-top: 0.2em !important;
    margin-bottom: 0.2em !important;
}

.katex,
.katex-html,
.katex .vlist-t,
.katex .vlist-t2,
.katex .vlist-r,
.katex .vlist {
    overflow: visible !important;
    overflow-y: visible !important;
}

/* ==========================================================================
   BIDI ISOLATION & KATEX TYPOGRAPHY PERFECTION
   Prevents punctuation jumping, dot misalignment, and unwanted horizontal scroll
   ========================================================================== */
bdi.math-bdi-wrapper {
    display: inline-block;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    vertical-align: middle;
}

.math-inline-katex {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block;
    vertical-align: middle;
}

.math-ch-step-app-box,
.math-display-wrapper {
    overflow-x: auto !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    scrollbar-width: thin;
}

.math-ch-step-app-box .katex-display,
.math-display-wrapper .katex-display,
.math-ch-step-text .katex-display {
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    margin: 8px 0 !important;
}

.math-ch-step-app-box::-webkit-scrollbar,
.math-display-wrapper::-webkit-scrollbar {
    height: 4px;
}
.math-ch-step-app-box::-webkit-scrollbar-thumb,
.math-display-wrapper::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 4px;
}

/* LTR Requirements Container in Arabic Question Prompts (e.g. i) sin A  ii) cos A) */
.ltr-req {
    direction: ltr !important;
    unicode-bidi: isolate !important;
    display: inline-block !important;
    margin: 0 4px !important;
    font-family: inherit;
    vertical-align: middle;
}