/* ═══════════════════════════════════════════════════════════════════════════
   JS Brain — سمة «الكونسول الدافئ»
   فاتحة نهارًا بأصفر JavaScript (#F39C12)، داكنة ليلًا. الكونسول داكن دائمًا.
   كل لون يمرّ عبر متغيّر — الوضع الليلي يعيد تعريف المتغيّرات لا القواعد.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --color-bg: #fffdf7;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #fdf3dc;

    --color-primary: #f39c12;
    --color-primary-hover: #d9860b;
    --color-primary-soft: rgba(243, 156, 18, .14);
    --color-accent: #0ea5e9;
    --color-accent-soft: rgba(14, 165, 233, .1);

    --color-text: #1c1917;
    --color-text-secondary: #44403c;
    --color-text-muted: #a8a29e;

    --color-border: #f1e3bf;
    --color-success: #10b981;
    --color-error: #ef4444;

    /* المحرّر والكونسول داكنان في السمتين — كما في أدوات المطوّر الحقيقية */
    --editor-bg: #1e1e2e;
    --editor-fg: #e2e8f0;
    --console-bg: #0b1220;
    --console-fg: #d1fae5;
    --preview-bg: #ffffff;

    --font-sans: 'Cairo', system-ui, sans-serif;
    --font-mono: 'Fira Code', 'Courier New', monospace;

    --radius-sm: 0.4rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;

    --topbar-height: 64px;
    --nav-footer-height: 76px;
    --shadow-soft: 0 4px 20px -2px rgba(120, 80, 0, .08);
}

body.dark-mode {
    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #263449;
    --color-text: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #7c8aa5;
    --color-border: #334155;
    --color-primary-soft: rgba(243, 156, 18, .2);
    --color-accent: #38bdf8;
    --color-accent-soft: rgba(56, 189, 248, .12);
    --shadow-soft: 0 4px 20px -2px rgba(0, 0, 0, .35);
}

/* ─────────────────────────────────────────────────────────────────────────────
   RESET & BASE
   ───────────────────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    line-height: 1.7;
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
    transition: background-color .3s, color .3s;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    color: inherit;
}

a {
    color: var(--color-primary-hover);
    text-decoration: none;
}

kbd {
    font-family: var(--font-mono);
    font-size: .8em;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: .05rem .35rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   LANDING
   ───────────────────────────────────────────────────────────────────────────── */
.landing {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: 2rem 1rem 3rem;
    position: relative;
    overflow: hidden;
}

.landing__container {
    text-align: center;
    z-index: 10;
    max-width: 640px;
    width: 100%;
}

.landing__badge {
    background: var(--color-primary-soft);
    color: var(--color-primary-hover);
    border: 1px solid rgba(243, 156, 18, .35);
    padding: .45rem 1rem;
    border-radius: 99px;
    font-size: .9rem;
    font-weight: 600;
    margin-bottom: 1.75rem;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}

.landing__title {
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: .75rem;
    color: var(--color-text);
}

.landing__subtitle {
    font-size: 1.15rem;
    color: var(--color-text-secondary);
    margin-bottom: 2.25rem;
}

.landing__cta {
    background: linear-gradient(135deg, #f39c12, #f7c948);
    color: #1c1917;
    padding: .95rem 2.4rem;
    font-size: 1.15rem;
    font-weight: 800;
    border-radius: var(--radius-xl);
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    box-shadow: 0 10px 25px -8px rgba(243, 156, 18, .7);
    transition: transform .2s, box-shadow .2s;
}

.landing__cta:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px -8px rgba(243, 156, 18, .8);
}

.landing__stats {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    margin-bottom: 2.25rem;
    padding: 1.25rem 1.5rem;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.stat__number {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    color: var(--color-primary-hover);
    line-height: 1.1;
}

.stat__label {
    font-size: .85rem;
    color: var(--color-text-secondary);
}

.landing__continue {
    margin-top: 1.25rem;
}

.btn-link {
    color: var(--color-text-secondary);
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: .95rem;
    padding: .4rem .8rem;
    border-radius: var(--radius-md);
}

.btn-link:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.landing__decor {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: .35;
}

.blob--1 {
    width: 420px;
    height: 420px;
    background: #f9d977;
    top: -140px;
    right: -120px;
}

.blob--2 {
    width: 360px;
    height: 360px;
    background: #93d5f4;
    bottom: -140px;
    left: -100px;
}

body.dark-mode .blob {
    opacity: .16;
}

/* ─────────────────────────────────────────────────────────────────────────────
   COVER — CSS خالص
   ───────────────────────────────────────────────────────────────────────────── */
.landing__cover {
    margin: 0 auto 1.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .9rem;
}

.cover {
    --cover-w: 210px;
    --cover-h: 285px;
    position: relative;
    width: var(--cover-w);
    height: var(--cover-h);
    perspective: 1100px;
}

.cover__book {
    position: relative;
    width: 100%;
    height: 100%;
    transform: rotateY(16deg) rotateX(4deg);
    transform-style: preserve-3d;
    transition: transform .7s cubic-bezier(.22, 1, .36, 1);
}

.cover:hover .cover__book {
    transform: rotateY(0deg) rotateX(0deg) translateY(-6px);
}

.cover__spine {
    position: absolute;
    top: 0;
    right: -13px;
    width: 14px;
    height: 100%;
    border-radius: 0 5px 5px 0;
    background: linear-gradient(180deg, #b8720a, #8a5407 55%, #6a4005);
    box-shadow: inset 3px 0 6px rgba(0, 0, 0, .35);
}

.cover__face {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 12px 4px 4px 12px;
    background:
        radial-gradient(120% 90% at 15% 0%, rgba(255, 255, 255, .3), transparent 60%),
        linear-gradient(155deg, #f7c948 0%, #f39c12 55%, #d9860b 100%);
    box-shadow:
        0 22px 45px -12px rgba(140, 90, 0, .45),
        0 3px 10px rgba(15, 23, 42, .18),
        inset 0 0 0 1px rgba(255, 255, 255, .2);
    padding: .9rem 1rem;
    display: flex;
    flex-direction: column;
    color: #1c1917;
}

/* نقاط شبكة خفيفة — تلميح للدوائر المنطقية */
.cover__dots {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(0, 0, 0, .12) 1px, transparent 1.4px);
    background-size: 14px 14px;
    mask-image: radial-gradient(120% 80% at 80% 100%, #000, transparent 70%);
    -webkit-mask-image: radial-gradient(120% 80% at 80% 100%, #000, transparent 70%);
    pointer-events: none;
}

.cover__sheen {
    position: absolute;
    top: -60%;
    left: -70%;
    width: 55%;
    height: 220%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .4), transparent);
    transform: rotate(18deg);
    animation: cover-sheen 7s ease-in-out infinite;
    pointer-events: none;
}

@keyframes cover-sheen {
    0%, 62% { left: -70%; }
    88%, 100% { left: 130%; }
}

/* نافذة كونسول صغيرة */
.cover__term {
    background: #0b1220;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 20px -6px rgba(0, 0, 0, .5);
    margin-bottom: auto;
    direction: ltr;
    text-align: left;
    font-family: var(--font-mono);
    font-size: .66rem;
    position: relative;
    z-index: 1;
}

.cover__term-bar {
    display: flex;
    gap: .3rem;
    padding: .35rem .5rem;
    background: #1e293b;
}

.cover__term-bar span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #f87171;
}

.cover__term-bar span:nth-child(2) { background: #fbbf24; }
.cover__term-bar span:nth-child(3) { background: #34d399; }

.cover__term-body {
    padding: .5rem .6rem .55rem;
    color: #e2e8f0;
    line-height: 1.7;
}

.cover__p { color: #f7c948; }
.cover__s { color: #86efac; }
.cover__ln--out { color: #94a3b8; padding-left: .8rem; }

.cover__cursor {
    display: inline-block;
    width: 7px;
    height: .85em;
    background: #f7c948;
    vertical-align: -2px;
    animation: cover-blink 1s steps(1, end) infinite;
}

@keyframes cover-blink {
    50% { opacity: 0; }
}

.cover__title {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.15;
    margin: .6rem 0 .35rem;
    direction: ltr;
    text-align: left;
    letter-spacing: -.02em;
    text-shadow: 0 2px 10px rgba(120, 70, 0, .2);
    position: relative;
    z-index: 1;
}

.cover__tag {
    align-self: flex-start;
    font-family: var(--font-mono);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    padding: .2rem .6rem;
    border-radius: 999px;
    border: 1px solid rgba(28, 25, 23, .4);
    background: rgba(255, 255, 255, .22);
    direction: ltr;
    position: relative;
    z-index: 1;
}

.cover__shadow {
    position: absolute;
    bottom: -16px;
    left: 8%;
    width: 84%;
    height: 22px;
    border-radius: 50%;
    background: rgba(140, 90, 0, .3);
    filter: blur(13px);
    transition: transform .7s cubic-bezier(.22, 1, .36, 1), opacity .7s;
}

.cover:hover .cover__shadow {
    transform: scale(.92);
    opacity: .75;
}

.cover__note {
    font-size: .78rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: .4rem;
}

.cover__note i {
    color: var(--color-primary);
}

/* ─────────────────────────────────────────────────────────────────────────────
   READER
   ───────────────────────────────────────────────────────────────────────────── */
.reader {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    background: var(--color-bg-secondary);
    flex-shrink: 0;
}

.topbar__right,
.topbar__left {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.topbar__title {
    font-weight: 700;
    font-size: .95rem;
    color: var(--color-text);
    max-width: 40vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar__btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background .2s, color .2s;
}

.topbar__btn:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-primary-hover);
}

.topbar__center {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: .85rem;
    color: var(--color-text-secondary);
    background: var(--color-bg-tertiary);
    padding: .25rem .75rem;
    border-radius: 6px;
}

.progress-bar {
    height: 3px;
    background: var(--color-border);
    flex-shrink: 0;
}

.progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #f7c948);
    transition: width .4s ease;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem calc(var(--nav-footer-height) + 2rem);
}

.page {
    max-width: 860px;
    margin: 0 auto;
    animation: page-in .35s ease;
}

@keyframes page-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   TYPOGRAPHY
   ───────────────────────────────────────────────────────────────────────────── */
.page h1 {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1.25;
    margin-bottom: 1rem;
}

.page h2 {
    font-size: 1.7rem;
    font-weight: 800;
    margin: 2rem 0 1rem;
    padding-bottom: .5rem;
    border-bottom: 2px solid var(--color-border);
}

.page h2:first-child {
    margin-top: 0;
}

.page h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 1.5rem 0 .6rem;
    color: var(--color-primary-hover);
}

.page h4 {
    font-size: 1.05rem;
    margin: 1rem 0 .4rem;
}

.page p {
    font-size: 1.05rem;
    margin-bottom: 1.1rem;
    color: var(--color-text-secondary);
}

.page ul,
.page ol {
    margin: 1rem 0 1.25rem;
    padding-right: 1.5rem;
    color: var(--color-text-secondary);
}

.page li {
    margin-bottom: .5rem;
}

.page strong {
    color: var(--color-text);
}

.page code {
    background: var(--color-primary-soft);
    color: #9a5b00;
    padding: .15rem .4rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: .88em;
    unicode-bidi: isolate;
    direction: ltr;
    display: inline-block;
}

body.dark-mode .page code {
    color: #fcd34d;
}

.page pre {
    background: var(--editor-bg);
    color: var(--editor-fg);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin: 1rem 0 1.25rem;
    overflow-x: auto;
    font-size: .88rem;
    line-height: 1.65;
}

.page pre,
.page pre code {
    direction: ltr;
    text-align: left;
    unicode-bidi: isolate;
    white-space: pre;
}

.page pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: inherit;
    display: inline;
}

/* تلوين خفيف: k كلمة مفتاحية · s نصّ · n رقم · c تعليق · f دالة · o مخرَج */
.page pre .k { color: #c4b5fd; }
.page pre .s { color: #86efac; }
.page pre .n { color: #fdba74; }
.page pre .c { color: #94a3b8; font-style: italic; }
.page pre .f { color: #93c5fd; }
.page pre .o { color: #fcd34d; }
.page pre .x { color: #f87171; }

/* ─────────────────────────────────────────────────────────────────────────────
   صناديق ومكوّنات
   ───────────────────────────────────────────────────────────────────────────── */
.info-box,
.warning-box,
.success-box,
.tip-box {
    padding: 1.1rem 1.25rem;
    border-radius: var(--radius-md);
    margin: 1.5rem 0;
    border-right: 4px solid;
    background: var(--color-bg-secondary);
    box-shadow: var(--shadow-soft);
}

.info-box { border-color: var(--color-accent); }
.warning-box { border-color: var(--color-error); }
.success-box { border-color: var(--color-success); }
.tip-box { border-color: var(--color-primary); }

.info-box h4,
.success-box h4 {
    margin-top: 0;
}

.info-box p:last-child,
.tip-box p:last-child,
.success-box p:last-child,
.warning-box p:last-child {
    margin-bottom: 0;
}

.level-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .8rem;
    font-weight: 700;
    color: var(--color-accent);
    background: var(--color-accent-soft);
    padding: .3rem .8rem;
    border-radius: 999px;
    margin-bottom: 1rem;
}

.foryou {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 1.25rem 0 1.5rem;
}

.foryou__col {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
}

.foryou__col h4 {
    margin: 0 0 .6rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.foryou__col--yes h4 { color: var(--color-success); }
.foryou__col--no h4 { color: var(--color-text-muted); }

.foryou__col ul {
    margin: 0;
    padding-right: 1.1rem;
}

.foryou__col li {
    font-size: .95rem;
}

/* صناديق النطاق المتداخلة (درس let/const/var) */
.scope {
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-md);
    padding: .75rem .9rem .6rem;
    margin: .6rem 0;
    position: relative;
    background: var(--color-accent-soft);
    font-family: var(--font-mono);
    font-size: .84rem;
    direction: ltr;
    text-align: left;
}

.scope > .scope {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
}

.scope__name {
    position: absolute;
    top: -.75rem;
    left: .8rem;
    background: var(--color-bg-secondary);
    padding: 0 .5rem;
    font-size: .72rem;
    font-family: var(--font-sans);
    color: var(--color-text-secondary);
    border-radius: 4px;
}

.scope__var {
    display: inline-block;
    background: var(--color-bg-secondary);
    border-radius: 4px;
    padding: .1rem .45rem;
    margin: .15rem .2rem .15rem 0;
    color: var(--color-text);
}

.scope__var--leak {
    text-decoration: line-through;
    opacity: .6;
}

/* خط زمني (درس المؤقّتات) */
.timeline {
    display: grid;
    grid-template-columns: 70px 1fr;
    gap: .35rem 1rem;
    margin: 1.25rem 0;
    font-size: .92rem;
    align-items: center;
}

.timeline__t {
    font-family: var(--font-mono);
    font-size: .8rem;
    color: var(--color-text-muted);
    text-align: left;
    direction: ltr;
}

.timeline__e {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-right: 4px solid var(--color-accent);
    border-radius: var(--radius-sm);
    padding: .45rem .8rem;
}

.timeline__e--sync { border-right-color: var(--color-primary); }
.timeline__e--micro { border-right-color: #a78bfa; }

.timeline__e code {
    display: inline;
}

/* ─────────────────────────────────────────────────────────────────────────────
   CODE PLAYGROUND — المحرّر والكونسول
   ───────────────────────────────────────────────────────────────────────────── */
.code-playground {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    margin: 1.5rem 0 0;
    background: var(--color-bg-secondary);
    padding: .9rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-soft);
}

.playground-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
}

.playground-title {
    font-family: var(--font-mono);
    font-size: .85rem;
    color: var(--color-text-secondary);
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    direction: ltr;
}

.playground-title i {
    color: var(--color-primary);
}

.playground-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
}

.run-btn {
    background: var(--color-success);
    color: #fff;
    padding: .45rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    transition: filter .2s;
}

.run-btn:hover {
    filter: brightness(1.08);
}

.reset-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.reset-btn:hover {
    color: var(--color-error);
    border-color: var(--color-error);
}

.playground-grid {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: .75rem;
    height: 340px;
}

.playground-grid--tall {
    height: 460px;
}

.editor-wrapper,
.preview-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

.editor-label {
    font-size: .78rem;
    margin-bottom: .4rem;
    color: var(--color-text-muted);
}

.code-editor {
    flex: 1;
    background: var(--editor-bg);
    color: var(--editor-fg);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: .9rem 1rem;
    font-family: var(--font-mono);
    font-size: .86rem;
    line-height: 1.55;
    resize: none;
    outline: none;
    direction: ltr;
    text-align: left;
    tab-size: 4;
}

.code-editor:focus {
    border-color: var(--color-primary);
}

@media (max-width: 768px) {
    .playground-grid,
    .playground-grid--tall {
        grid-template-columns: 1fr;
        height: 560px;
    }
}

/* ─────────────────────────────────────────────────────────────────────────────
   NAV FOOTER
   ───────────────────────────────────────────────────────────────────────────── */
.nav-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-bg-secondary);
    height: var(--nav-footer-height);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    z-index: 50;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem 1.25rem;
    border-radius: var(--radius-md);
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    font-weight: 600;
    transition: all .2s;
}

.nav-btn:disabled {
    opacity: .4;
    cursor: default;
}

.nav-btn:not(:disabled):hover {
    border-color: var(--color-primary);
    color: var(--color-primary-hover);
}

.nav-btn--next {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #1c1917;
}

.nav-btn--next:not(:disabled):hover {
    background: var(--color-primary-hover);
    color: #fff;
}

.nav-dots {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 40vw;
}

.nav-dot {
    width: 7px;
    height: 7px;
    background: var(--color-border);
    border-radius: 50%;
    cursor: pointer;
    transition: transform .2s, background .2s;
}

.nav-dot.done {
    background: var(--color-success);
}

.nav-dot.active {
    background: var(--color-primary);
    transform: scale(1.4);
}

@media (max-width: 600px) {
    .nav-dots { display: none; }
    .nav-btn span { display: none; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   SIDE MENU
   ───────────────────────────────────────────────────────────────────────────── */
.side-menu {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    max-width: 90vw;
    height: 100%;
    background: var(--color-bg-secondary);
    border-left: 1px solid var(--color-border);
    z-index: 200;
    transition: right .3s ease;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.side-menu.open {
    right: 0;
}

.side-menu__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-border);
}

.side-menu__header h3 {
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.side-menu__close {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
}

.side-menu__close:hover {
    background: var(--color-bg-tertiary);
}

.side-menu__nav {
    overflow-y: auto;
    flex: 1;
}

.toc-item {
    padding: .6rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .92rem;
    transition: background .15s;
}

.toc-item > i:first-child {
    color: var(--color-text-muted);
    width: 1rem;
    text-align: center;
    font-size: .8rem;
}

.toc-item span {
    flex: 1;
}

.toc-item:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
}

.toc-item.active {
    background: var(--color-primary-soft);
    color: var(--color-primary-hover);
    font-weight: 700;
}

.toc-done {
    color: var(--color-success);
    opacity: 0;
    transition: opacity .2s;
}

.toc-done.on {
    opacity: 1;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: .3s;
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ─────────────────────────────────────────────────────────────────────────────
   شاشة المحتوى المقفل
   ───────────────────────────────────────────────────────────────────────────── */
.locked {
    text-align: center;
    padding: 4rem 1.5rem;
    max-width: 520px;
    margin: 0 auto;
}

.locked i {
    font-size: 2.5rem;
    color: var(--color-primary);
    opacity: .55;
    margin-bottom: 1.25rem;
    display: block;
}

.locked h3 {
    font-size: 1.35rem;
    margin-bottom: .75rem;
    color: var(--color-text);
}

.locked p {
    color: var(--color-text-secondary);
    line-height: 1.9;
}

/* ─────────────────────────────────────────────────────────────────────────────
   RESPONSIVE & MOTION
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .landing__title { font-size: 2rem; }
    .landing__stats { gap: 1.25rem; padding: 1rem; }
    .stat__number { font-size: 1.5rem; }
    .foryou { grid-template-columns: 1fr; }
    .page h1 { font-size: 1.7rem; }
    .page h2 { font-size: 1.35rem; }
    .cover { --cover-w: 170px; --cover-h: 230px; }
    .cover__title { font-size: 1.5rem; }
    .topbar__title { max-width: 32vw; font-size: .85rem; }
    .timeline { grid-template-columns: 56px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .cover__sheen,
    .cover__cursor,
    .page {
        animation: none !important;
    }
    .cover__book,
    .cover__shadow,
    .progress-bar__fill {
        transition: none !important;
    }
}

/* تشريح سطر كود: <div class="tag-anatomy"> أجزاء مع تسمياتها فوقها */
.tag-anatomy {
    background: var(--editor-bg);
    color: var(--editor-fg);
    border-radius: var(--radius-md);
    padding: 1.6rem 1.25rem 1rem;
    font-family: var(--font-mono);
    font-size: 1.05rem;
    direction: ltr;
    text-align: center;
    margin: 1.25rem 0;
    overflow-x: auto;
    white-space: nowrap;
}

.tag-anatomy__part {
    position: relative;
    display: inline-block;
    padding: .15rem .35rem;
    border-radius: 4px;
    margin: 1.2rem .1rem .2rem;
}

.tag-anatomy__part::before {
    content: attr(data-tag);
    position: absolute;
    top: -1.35rem;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-family: var(--font-sans);
    font-size: .68rem;
    direction: rtl;
    opacity: .85;
}

.tag-anatomy__part--tag { background: rgba(196, 181, 253, .18); color: #c4b5fd; }
.tag-anatomy__part--attr { background: rgba(147, 197, 253, .18); color: #93c5fd; }
.tag-anatomy__part--val { background: rgba(253, 186, 116, .18); color: #fdba74; }
.tag-anatomy__part--text { background: rgba(134, 239, 172, .15); color: #86efac; }

/* النصوص العربية داخل كتل الكود (سلاسل وتعليقات) تُعزل اتجاهيًا حتى لا تنقلب حول علامات الترقيم */
.page pre span {
    unicode-bidi: isolate;
}

/* ملاحظة عربية داخل صندوق نطاق (اتجاهه LTR) */
.scope__note {
    display: inline-block;
    direction: rtl;
    unicode-bidi: isolate;
    font-family: var(--font-sans);
    font-size: .78rem;
    color: var(--color-text-secondary);
    margin-inline-start: .5rem;
}
