/* ═══════════════════════════════════════════════════════════════════════════
   CSS STYLING BOOK - The Palette Theme
   Aesthetically pleasing, colorful, and clean.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────────
   CSS VARIABLES
   ───────────────────────────────────────────────────────────────────────────── */
:root {
    /* Theme Colors - The Canvas */
    --color-bg: #f8fafc;
    /* Slate 50 */
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #f1f5f9;
    /* Slate 100 */

    /* Palette Colors */
    --color-primary: #ec4899;
    /* Pink 500 */
    --color-primary-hover: #db2777;
    --color-accent: #8b5cf6;
    /* Violet 500 */
    --color-secondary-accent: #06b6d4;
    /* Cyan 500 */

    --color-text: #1e293b;
    /* Slate 800 */
    --color-text-secondary: #475569;
    --color-text-muted: #94a3b8;

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

    /* Code Editor Specifics - Light Mode Default for this book */
    --editor-bg: #ffffff;
    --editor-fg: #1e293b;
    --preview-bg: #ffffff;

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

    /* Metrics */
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;

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

body.dark-mode {
    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-text: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-border: #334155;
    --editor-bg: #0d1117;
    --editor-fg: #c9d1d9;
}

/* ─────────────────────────────────────────────────────────────────────────────
   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 0.3s, color 0.3s;
}

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

a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

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

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

.landing__badge {
    background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
    color: white;
    padding: 0.5rem 1.2rem;
    border-radius: 99px;
    font-size: 0.9rem;
    margin-bottom: 2rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 10px rgba(236, 72, 153, 0.3);
}

.landing__title {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 1rem;
    color: var(--color-text);
    background: linear-gradient(to right, #ec4899, #8b5cf6, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.landing__cta {
    /* كان var(--color-text) فيصير الزر أبيضَ على أبيض في الوضع الليلي */
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: white;
    padding: 1.2rem 3rem;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: var(--radius-xl);
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.landing__cta:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 30px -10px rgba(0, 0, 0, 0.15);
}

.landing__stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 3rem;
    padding: 2rem;
    background: var(--color-bg-secondary);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
}

.stat__number {
    display: block;
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to bottom right, #ec4899, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* DECORATIVE BLOBS */
.landing__decor {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: drift 20s infinite alternate;
}

.blob--1 {
    width: 500px;
    height: 500px;
    bg: #ec4899;
    top: -100px;
    right: -100px;
    background: rgba(236, 72, 153, 0.2);
}

.blob--2 {
    width: 400px;
    height: 400px;
    bg: #8b5cf6;
    bottom: -50px;
    left: -50px;
    background: rgba(139, 92, 246, 0.2);
    animation-delay: -5s;
}

.blob--3 {
    width: 300px;
    height: 300px;
    bg: #06b6d4;
    top: 40%;
    left: 40%;
    background: rgba(6, 182, 212, 0.2);
    animation-delay: -10s;
}

@keyframes drift {
    from {
        transform: translate(0, 0);
    }

    to {
        transform: translate(50px, 50px);
    }
}

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

/* TOPBAR */
.topbar {
    height: var(--topbar-height);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    z-index: 50;
}

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

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

.topbar__center {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--color-text);
    background: var(--color-bg-tertiary);
    padding: 0.4rem 1rem;
    border-radius: 99px;
    letter-spacing: 1px;
}

/* CREDIT CARD STYLE PROGRESS BAR */
.progress-bar {
    height: 3px;
    background: var(--color-bg-tertiary);
    width: 100%;
}

.progress-bar__fill {
    height: 100%;
    background: linear-gradient(to right, #ec4899, #8b5cf6, #06b6d4);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 0 99px 99px 0;
}

/* CONTENT */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 3rem 1.5rem 8rem 1.5rem;
}

.page {
    max-width: 800px;
    margin: 0 auto;
    background: var(--color-bg-secondary);
    padding: 3rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-soft);
}

.page h2 {
    font-size: 2.25rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px dashed var(--color-border);
    color: var(--color-text);
}

.page p {
    font-size: 1.15rem;
    line-height: 1.8;
    margin-bottom: 1.5rem;
    color: var(--color-text-secondary);
}

.page code {
    background: var(--color-bg-tertiary);
    color: var(--color-primary);
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.9em;
}

/* INFO BOXES - ART THEMED */
.info-box,
.warning-box,
.success-box,
.tip-box {
    padding: 2rem;
    border-radius: var(--radius-lg);
    margin: 2.5rem 0;
    position: relative;
    overflow: hidden;
}

.info-box {
    background: #eff6ff;
    color: #1e40af;
    border-left: 5px solid #3b82f6;
}

/* Blue */
.tip-box {
    background: #fdf2f8;
    color: #9d174d;
    border-left: 5px solid #ec4899;
}

/* Pink */
.success-box {
    background: #ecfdf5;
    color: #065f46;
    border-left: 5px solid #10b981;
}

/* Green */

/* ─────────────────────────────────────────────────────────────────────────────
   CODE PLAYGROUND - The Artists Easel
   ───────────────────────────────────────────────────────────────────────────── */
.code-playground {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 3rem -1rem;
    /* Break out of container slightly */
    background: var(--color-text);
    /* Dark background frame */
    padding: 1.5rem;
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.3);
}

.playground-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.playground-title {
    font-family: var(--font-mono);
    color: white;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.run-btn {
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-lg);
    font-weight: 700;
}

.playground-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: 450px;
}

.editor-wrapper {
    display: flex;
    flex-direction: column;
}

.editor-label {
    color: #94a3b8;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.code-editor {
    flex: 1;
    background: var(--editor-bg);
    color: var(--editor-fg);
    border: none;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    font-family: var(--font-mono);
    resize: none;
    outline: none;
    font-size: 0.95rem;
    line-height: 1.6;

    /* LTR Support */
    direction: ltr;
    text-align: left;
}

.preview-frame {
    flex: 1;
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    height: 100%;
    border: none;
}

/* ─────────────────────────────────────────────────────────────────────────────
   NAV FOOTER
   ───────────────────────────────────────────────────────────────────────────── */
.nav-footer {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(16px);
    padding: 1rem 1.5rem;
    border-radius: 99px;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.nav-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--color-bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    color: var(--color-text);
}

.nav-btn--next {
    background: var(--color-text);
    color: white;
    width: auto;
    padding: 0 2rem;
    border-radius: 99px;
}

.nav-btn span {
    font-weight: 700;
    margin-right: 0.5rem;
}

.nav-btn:hover {
    transform: scale(1.05);
}

/* ─────────────────────────────────────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .playground-grid {
        grid-template-columns: 1fr;
        height: 600px;
    }

    .page {
        padding: 1.5rem;
    }

    .landing__title {
        font-size: 2.5rem;
    }
}
/* ═══════════════════════════════════════════════════════════════════════════
   الفهرس الجانبي والحجاب
   كانت هذه القواعد ناقصة تمامًا من الملف، فكان الفهرس يُرسم داخل تدفّق الصفحة
   ويضغط منطقة المحتوى إلى ثلث ارتفاعها. هذا إصلاح لخلل قائم قبل التطوير.
   ═══════════════════════════════════════════════════════════════════════════ */
.side-menu {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100%;
    background: var(--color-bg-secondary);
    border-left: 1px solid var(--color-border);
    box-shadow: -8px 0 30px rgba(15, 23, 42, .08);
    z-index: 200;
    transition: right .3s ease;
    padding: 1.25rem;
    overflow-y: auto;
}

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

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

.side-menu__header h3 {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--color-primary);
}

.side-menu__close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: .3rem;
    border-radius: var(--radius-sm);
}

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

.side-menu__nav {
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

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

.toc-item i:first-child {
    font-size: .78rem;
    color: var(--color-text-muted);
}

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

.toc-item.active {
    background: rgba(236, 72, 153, .1);
    color: var(--color-primary);
    font-weight: 700;
}

.toc-item.active i:first-child {
    color: var(--color-primary);
}

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

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

.nav-dots {
    display: none;
}

@media (max-width: 520px) {
    .side-menu {
        width: 86%;
        right: -90%;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   كتل الكود
   لم يكن للملف أي تنسيق لـ pre، فكانت أمثلة الكود تُعرض من اليمين لليسار
   وتظهر الأقواس والفواصل المنقوطة في غير مواضعها. إصلاح لخلل قائم.
   ═══════════════════════════════════════════════════════════════════════════ */
.page pre {
    direction: ltr;
    text-align: left;
    background: #0d1117;
    color: #c9d1d9;
    padding: 1rem 1.15rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 1.25rem 0;
    font-size: .86rem;
    line-height: 1.85;
    unicode-bidi: isolate;
}

.page pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-family: var(--font-mono);
    font-size: inherit;
    white-space: pre;
}

.page code {
    unicode-bidi: isolate;
}

@media (max-width: 620px) {
    .page h2 {
        font-size: 1.5rem;
        margin-bottom: 1.25rem;
        padding-bottom: 1rem;
    }

    .page p {
        font-size: 1rem;
    }

    .page {
        padding: 1.25rem;
    }

    .content {
        padding: 1.5rem 1rem 7rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   الغلاف — CSS خالص
   لا صورة ولا SVG. كل ما تراه: تدرّجات، ظلال، تحويل ثلاثي الأبعاد،
   حركة @keyframes، ومتغيّرات — وهي بالضبط دروس هذا الكتاب.
   ═══════════════════════════════════════════════════════════════════════════ */
.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, #9d1f5f, #6b1746 55%, #4a1030);
    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, .22), transparent 60%),
        linear-gradient(150deg, #ec4899 0%, #a855f7 55%, #6366f1 100%);
    box-shadow:
        0 22px 45px -12px rgba(76, 5, 60, .45),
        0 3px 10px rgba(15, 23, 42, .18),
        inset 0 0 0 1px rgba(255, 255, 255, .18);
    padding: 1.1rem 1rem;
    display: flex;
    flex-direction: column;
    color: #fff;
}

/* شبكة خفيفة في الخلفية — تلميح لتخطيط Grid */
.cover__grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .13) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .13) 1px, transparent 1px);
    background-size: 26px 26px;
    mask-image: radial-gradient(120% 80% at 20% 100%, #000, transparent 70%);
    -webkit-mask-image: radial-gradient(120% 80% at 20% 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, .38), 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__swatches {
    display: flex;
    gap: .35rem;
    margin-bottom: auto;
}

.cover__swatches span {
    width: 15px;
    height: 15px;
    border-radius: 5px;
    background: rgba(255, 255, 255, .85);
    animation: cover-pop 3.2s ease-in-out infinite;
}

.cover__swatches span:nth-child(2) {
    animation-delay: .25s;
    opacity: .72;
}

.cover__swatches span:nth-child(3) {
    animation-delay: .5s;
    opacity: .5;
}

@keyframes cover-pop {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.32);
    }
}

/* العنوان */
.cover__title {
    font-size: 1.85rem;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: -.02em;
    margin: 0 0 .35rem;
    text-shadow: 0 2px 12px rgba(60, 5, 45, .3);
}

.cover__tag {
    align-self: flex-start;
    font-family: var(--font-mono);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .18em;
    padding: .2rem .6rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .5);
    background: rgba(255, 255, 255, .14);
    margin-bottom: .85rem;
}

/* قاعدة CSS مصغّرة في أسفل الغلاف */
.cover__rule {
    direction: ltr;
    text-align: left;
    font-family: var(--font-mono);
    font-size: .66rem;
    line-height: 1.7;
    padding: .5rem .6rem;
    border-radius: 8px;
    background: rgba(15, 23, 42, .3);
    border: 1px solid rgba(255, 255, 255, .16);
    backdrop-filter: blur(2px);
}

.cover__rule .s {
    color: #ffe9a8;
}

.cover__rule .k {
    color: #b8f5d0;
}

.cover__decl {
    padding-inline-start: .8rem;
    display: flex;
    align-items: center;
    gap: .25rem;
}

/* المربّع الذي يبدّل لونه — يشرح فكرة «القيمة» بلا كلمة واحدة */
.cover__chip {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    display: inline-block;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .45);
    animation: cover-hue 8s steps(1, end) infinite;
}

@keyframes cover-hue {
    0% {
        background: #fde047;
    }

    25% {
        background: #4ade80;
    }

    50% {
        background: #38bdf8;
    }

    75% {
        background: #fb7185;
    }
}

/* الظل الأرضي */
.cover__shadow {
    position: absolute;
    bottom: -16px;
    left: 8%;
    width: 84%;
    height: 22px;
    border-radius: 50%;
    background: rgba(76, 5, 60, .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);
}

/* احترام تفضيل تقليل الحركة */
@media (prefers-reduced-motion: reduce) {

    .cover__sheen,
    .cover__swatches span,
    .cover__chip {
        animation: none;
    }

    .cover__book {
        transition: none;
    }
}

@media (max-width: 520px) {
    .cover {
        --cover-w: 172px;
        --cover-h: 234px;
    }

    .cover__title {
        font-size: 1.5rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   شاشة الفصل المقفل — يعرضها api.php حين لا يملك القارئ صلاحية
   ═══════════════════════════════════════════════════════════════════════════ */
.locked {
    text-align: center;
    padding: 3rem 1.5rem;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-secondary);
}

.locked i {
    font-size: 2rem;
    color: var(--color-primary);
    margin-bottom: 1rem;
    display: block;
}

.locked h3 {
    margin: 0 0 .5rem;
    color: var(--color-text);
}

.locked p {
    color: var(--color-text-secondary);
    margin: 0;
}
