/* ================================================
   علّمني عائد — التصميم الكامل
   تصميم RTL نظيف وأنيق
================================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
    background: #f7f8fc;
    color: #1a1a2e;
    line-height: 1.7;
    direction: rtl;
}

a { text-decoration: none; color: inherit; }

/* ================================================
   Navbar
================================================ */
.learn-navbar {
    background: #fff;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: 100;
}

.ln-right, .ln-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.ln-logo {
    font-size: 1.4rem;
    font-weight: 900;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.ln-logo-link { display: inline-block; }

.ln-user {
    color: #6b7280;
    font-size: 0.95rem;
}

.ln-left a {
    color: #6b7280;
    font-size: 0.92rem;
    transition: 0.2s;
    padding: 6px 12px;
    border-radius: 8px;
}

.ln-left a:hover {
    background: #f3f4f6;
    color: #1a1a2e;
}

.ln-logout {
    color: #ef4444 !important;
}
.ln-logout:hover {
    background: #fef2f2 !important;
}

.lesson-pos {
    color: #9ca3af;
    font-size: 0.88rem;
    background: #f3f4f6;
    padding: 6px 14px;
    border-radius: 20px;
}

/* ================================================
   Container
================================================ */
.learn-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
}

/* ================================================
   Welcome Card
================================================ */
.welcome-card {
    background: linear-gradient(135deg, #7c3aed 0%, #ec4899 100%);
    color: #fff;
    padding: 32px;
    border-radius: 20px;
    margin-bottom: 30px;
    box-shadow: 0 10px 40px rgba(124, 58, 237, 0.25);
}

.welcome-card h1 {
    font-size: 2rem;
    margin-bottom: 8px;
    font-weight: 900;
}

.welcome-card p {
    opacity: 0.95;
    margin-bottom: 24px;
}

.progress-bar-wrap {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 16px;
    backdrop-filter: blur(10px);
}

.progress-bar {
    background: rgba(255, 255, 255, 0.2);
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    background: #fff;
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.progress-stats strong {
    font-size: 1.2rem;
    font-weight: 900;
}

/* ================================================
   Levels & Lessons Grid
================================================ */
.level-section {
    margin-bottom: 36px;
}

.level-title {
    font-size: 1.4rem;
    margin-bottom: 16px;
    color: #1a1a2e;
    padding-bottom: 10px;
    border-bottom: 3px solid #ec4899;
    display: inline-block;
}

.lessons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.lesson-card {
    background: #fff;
    padding: 20px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: 0.25s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border: 2px solid transparent;
    cursor: pointer;
}

.lesson-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(124, 58, 237, 0.15);
    border-color: #ec4899;
}

.lesson-card.completed {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border-color: #10b981;
}

.lesson-card.in-progress {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
}

.lc-num {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 900;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.completed .lc-num {
    background: linear-gradient(135deg, #10b981, #059669);
}

.in-progress .lc-num {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.lc-content {
    flex: 1;
    min-width: 0;
}

.lc-content h3 {
    font-size: 1.05rem;
    margin-bottom: 4px;
    color: #1a1a2e;
}

.lc-content p {
    color: #6b7280;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.lc-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.78rem;
    color: #9ca3af;
}

.lc-badge-done {
    background: #10b981;
    color: #fff;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 700;
}

.lc-badge-progress {
    background: #f59e0b;
    color: #fff;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 700;
}

.lc-arrow {
    font-size: 1.5rem;
    color: #ec4899;
    transition: transform 0.2s;
}

.lesson-card:hover .lc-arrow {
    transform: translateX(-6px);
}

/* ================================================
   Lesson Page Layout
================================================ */
.lesson-page {
    background: #f7f8fc;
}

.lesson-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: calc(100vh - 64px);
}

.lesson-content {
    background: #fff;
    padding: 30px 36px;
    overflow-y: auto;
    border-left: 1px solid #e5e7eb;
}

.lesson-editor {
    background: #1e1e2f;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.back-link {
    color: #ec4899;
    font-size: 0.88rem;
    margin-bottom: 16px;
    display: inline-block;
    transition: 0.2s;
}

.back-link:hover {
    color: #7c3aed;
}

.lesson-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f3f4f6;
}

.lesson-level {
    display: inline-block;
    background: linear-gradient(135deg, #fce7f3, #fbcfe8);
    color: #be185d;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.lesson-header h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.lesson-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    color: #9ca3af;
    font-size: 0.88rem;
}

.badge-done {
    background: #10b981;
    color: #fff;
    padding: 3px 12px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.78rem;
}

/* محتوى الدرس */
.lesson-body {
    color: #374151;
    line-height: 1.9;
    font-size: 0.96rem;
}

.lesson-body h2 {
    color: #1a1a2e;
    font-size: 1.4rem;
    margin: 24px 0 12px;
    padding-right: 14px;
    border-right: 4px solid #ec4899;
}

.lesson-body h3 {
    color: #1a1a2e;
    font-size: 1.1rem;
    margin: 18px 0 10px;
}

.lesson-body p {
    margin-bottom: 12px;
}

.lesson-body ul, .lesson-body ol {
    margin-bottom: 14px;
    padding-right: 24px;
}

.lesson-body li {
    margin-bottom: 6px;
}

.lesson-body code {
    background: #f3f4f6;
    color: #be185d;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    direction: ltr;
    display: inline-block;
    unicode-bidi: embed;
    text-align: left;
}

/* علامة LTR غير مرئية تجبر الاتجاه LTR في بداية كل code */
.lesson-body code::before {
    content: "\200E";  /* LEFT-TO-RIGHT MARK */
}

.lesson-body pre {
    background: #1e1e2f;
    color: #fff;
    padding: 16px;
    border-radius: 10px;
    overflow-x: auto;
    margin: 14px 0;
    direction: ltr;
    text-align: left;
    unicode-bidi: embed;
}

.lesson-body pre::before {
    content: "\200E";
    display: block;
    height: 0;
    overflow: hidden;
}

.lesson-body pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: 0.88rem;
    display: block;
    unicode-bidi: embed;
    text-align: left;
}

.lesson-body pre code::before {
    content: "\200E";
}

.lesson-body strong {
    color: #1a1a2e;
    font-weight: 700;
}

.lesson-body em {
    color: #be185d;
    font-style: normal;
    font-weight: 700;
}

/* صناديق المحتوى */
.info-box {
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    padding: 14px 18px;
    border-radius: 10px;
    border-right: 4px solid #7c3aed;
    margin: 16px 0;
    color: #4c1d95;
}

.warning-box {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    padding: 14px 18px;
    border-radius: 10px;
    border-right: 4px solid #f59e0b;
    margin: 16px 0;
    color: #92400e;
}

.rules-box {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    padding: 14px 18px;
    border-radius: 10px;
    border-right: 4px solid #10b981;
    margin: 16px 0;
    color: #064e3b;
}

.flow-box {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    padding: 14px 18px;
    border-radius: 10px;
    border-right: 4px solid #3b82f6;
    margin: 16px 0;
    color: #1e3a8a;
}

/* العلامات (syntax tags) */
.syntax-tag {
    display: inline-block;
    background: #1a1a2e;
    color: #fbbf24;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    margin: 0 2px;
    direction: ltr;
}

/* جدول داخل الدرس */
.learn-table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.learn-table th {
    background: #1a1a2e;
    color: #fff;
    padding: 10px;
    font-weight: 700;
    text-align: center;
    font-size: 0.88rem;
}

.learn-table td {
    padding: 10px;
    border-bottom: 1px solid #f3f4f6;
    text-align: center;
    font-size: 0.88rem;
}

.learn-table tr:last-child td {
    border-bottom: none;
}

.learn-table tr:hover td {
    background: #fdf2f6;
}

/* ================================================
   Code Editor (Right Side)
================================================ */
.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    color: #fff;
}

.editor-header h3 {
    font-size: 1.05rem;
}

.editor-actions {
    display: flex;
    gap: 8px;
}

.btn-editor-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 14px;
    border-radius: 8px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.82rem;
    cursor: pointer;
    transition: 0.2s;
}

.btn-editor-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.CodeMirror {
    border-radius: 10px;
    font-size: 0.92rem;
    height: 400px !important;
}

.editor-footer {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.btn-check {
    flex: 2;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: 0.2s;
}

.btn-check:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-hint {
    flex: 1;
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 2px solid #fbbf24;
    padding: 14px;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

.btn-hint:hover {
    background: #fbbf24;
    color: #1a1a2e;
}

/* النتيجة */
.result-box {
    margin-top: 16px;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    border-radius: 10px;
}

.result-box.show {
    padding: 16px;
    max-height: 500px;
    overflow-y: auto;
}

.result-loading {
    color: #fbbf24;
    text-align: center;
    padding: 14px;
}

.result-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    padding: 18px;
    border-radius: 10px;
}

.result-success h3 {
    margin-bottom: 6px;
}

.result-error {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 2px solid #ef4444;
    padding: 18px;
    border-radius: 10px;
}

.result-error h3 {
    margin-bottom: 8px;
    color: #fca5a5;
}

.result-error ul {
    padding-right: 20px;
    margin-top: 8px;
}

.result-error li {
    margin-bottom: 4px;
}

.hint-available {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    padding: 8px 12px;
    border-radius: 8px;
    margin-top: 12px;
    font-size: 0.88rem;
}

/* صندوق التلميحات */
.hints-box {
    margin-top: 14px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.hints-box.show {
    max-height: 600px;
    overflow-y: auto;
}

.hint-card {
    background: rgba(251, 191, 36, 0.1);
    border-right: 4px solid #fbbf24;
    padding: 14px;
    border-radius: 10px;
    margin-bottom: 10px;
    color: #fff;
}

.hint-num {
    color: #fbbf24;
    font-weight: 700;
    margin-bottom: 6px;
    font-size: 0.88rem;
}

.hint-text {
    line-height: 1.7;
}

.hint-text code {
    background: #1a1a2e;
    color: #fbbf24;
    padding: 2px 6px;
    border-radius: 4px;
    direction: ltr;
    display: inline-block;
}

.hint-text pre {
    background: #1a1a2e;
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    direction: ltr;
    text-align: left;
}

.hint-locked {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    padding: 14px;
    border-radius: 10px;
    text-align: center;
}

/* التنقل بين الدروس */
.lesson-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    gap: 10px;
}

.nav-prev, .nav-next {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 12px;
    border-radius: 10px;
    text-align: center;
    transition: 0.2s;
    font-weight: 700;
}

.nav-prev:hover, .nav-next:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-next {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
}

.nav-next:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
}

.nav-next.disabled {
    background: rgba(255, 255, 255, 0.05) !important;
    color: rgba(255, 255, 255, 0.3) !important;
    cursor: not-allowed;
    pointer-events: none;
}

/* ================================================
   Auth Pages (Login)
================================================ */
.learn-auth-body {
    background: linear-gradient(135deg, #ede9fe 0%, #fce7f3 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.learn-auth-wrap {
    width: 100%;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.learn-auth-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
}

.learn-auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.learn-auth-icon {
    font-size: 3rem;
    margin-bottom: 8px;
}

.learn-auth-header h1 {
    font-size: 1.8rem;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.learn-auth-header p {
    color: #6b7280;
    font-size: 0.92rem;
}

.learn-auth-form .form-row {
    margin-bottom: 16px;
}

.learn-auth-form label {
    display: block;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 6px;
    font-size: 0.92rem;
}

.learn-auth-form input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.95rem;
    transition: 0.2s;
}

.learn-auth-form input:focus {
    outline: none;
    border-color: #ec4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.1);
}

.btn-learn-submit {
    width: 100%;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 8px;
    transition: 0.2s;
}

.btn-learn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35);
}

.learn-auth-footer {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #f3f4f6;
    color: #6b7280;
    font-size: 0.88rem;
    line-height: 1.7;
}

.learn-auth-footer a {
    color: #ec4899;
    font-weight: 700;
}

.learn-auth-footer a:hover {
    color: #7c3aed;
}

.learn-auth-back {
    text-align: center;
    margin-top: 14px;
}

.learn-auth-back a {
    color: #9ca3af;
    font-size: 0.85rem;
}

.learn-auth-back a:hover {
    color: #ec4899;
}

.learn-alert {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.92rem;
}

.learn-alert-error {
    background: #fef2f2;
    color: #dc2626;
    border-right: 4px solid #ef4444;
}

.learn-alert-success {
    background: #f0fdf4;
    color: #059669;
    border-right: 4px solid #10b981;
}

/* ================================================
   Install Page
================================================ */
.learn-install-wrap {
    min-height: 100vh;
    background: linear-gradient(135deg, #ede9fe 0%, #fce7f3 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.learn-install-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
}

.learn-install-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.learn-install-card h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.install-sub {
    color: #6b7280;
    margin-bottom: 24px;
}

.install-info-box {
    background: #f9fafb;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    text-align: right;
}

.install-info-box ul {
    padding-right: 20px;
    margin: 10px 0;
}

.install-info-box li {
    margin-bottom: 6px;
    color: #4b5563;
}

.install-info-box code {
    background: #1a1a2e;
    color: #fbbf24;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.install-note {
    background: #fef3c7;
    color: #92400e;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.88rem;
    margin-top: 14px;
}

.btn-install, .btn-start {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: #fff;
    border: none;
    padding: 14px 30px;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    transition: 0.2s;
    text-decoration: none;
    display: inline-block;
}

.btn-install:hover, .btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(124, 58, 237, 0.35);
}

.install-success-box {
    text-align: right;
}

.install-success-box h2 {
    color: #059669;
    margin-bottom: 14px;
    text-align: center;
}

.install-success-box ul {
    background: #f0fdf4;
    padding: 16px 30px;
    border-radius: 10px;
    margin: 14px 0;
}

.install-success-box li {
    color: #064e3b;
    margin-bottom: 6px;
}

.install-warn {
    background: #fef3c7;
    color: #92400e;
    padding: 12px 16px;
    border-radius: 10px;
    margin: 14px 0;
    font-size: 0.92rem;
    text-align: center;
}

/* ================================================
   Mobile Responsive
================================================ */
@media (max-width: 900px) {
    .lesson-layout {
        grid-template-columns: 1fr;
    }
    
    .lesson-content {
        border-left: none;
        border-bottom: 4px solid #f3f4f6;
    }
    
    .lessons-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .learn-navbar {
        padding: 12px 16px;
    }
    
    .ln-logo {
        font-size: 1.1rem;
    }
    
    .ln-user, .lesson-pos {
        display: none;
    }
    
    .lesson-content, .lesson-editor {
        padding: 18px;
    }
    
    .welcome-card h1 {
        font-size: 1.4rem;
    }
    
    .lesson-header h1 {
        font-size: 1.4rem;
    }
}

/* تحسينات للطباعة */
@media print {
    .learn-navbar, .lesson-editor, .lesson-nav {
        display: none;
    }
    .lesson-layout {
        grid-template-columns: 1fr;
    }
}
