@font-face { font-family: "Plex Arabic"; src: url("../assets/fonts/ibm-plex-sans-arabic.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("../assets/fonts/ibm-plex-sans-arabic-semibold.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root { color-scheme: dark; --page: #11130f; --surface: #191c16; --ink: #f1f3e8; --muted: #a4ab99; --line: #34392d; --accent: #d5fa74; }
:root[data-theme="light"] { color-scheme: light; --page: #f2f2e9; --surface: #fafbf5; --ink: #242a1c; --muted: #5c6451; --line: #d4d8c8; }
:root[data-theme="midnight"] { --page: #0c1421; --surface: #141f30; --ink: #eaf0f7; --muted: #a2b2c9; --line: #2c3c53; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: "Plex Arabic", Tahoma, Arial, sans-serif; line-height: 1.8; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .35; cursor: default; }
button, a, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 5px; }
::selection { background: var(--accent); color: #11130f; }
.reader-header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 92px; margin-inline: clamp(20px, 5vw, 80px); border-bottom: 1px solid var(--line); gap: 16px; }
.reader-back { display: inline-flex; align-items: center; gap: 12px; width: fit-content; font-size: 14px; color: var(--muted); }
.reader-back:hover { color: var(--ink); }
.reader-back > span:first-child { font-size: 23px; }
.reader-brand { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; letter-spacing: 2px; }
.reader-brand > span:first-child { color: var(--accent); font-size: 30px; line-height: 1; }
:root[data-theme="light"] .reader-brand > span:first-child { color: var(--ink); }
.reader-theme { justify-self: end; display: flex; align-items: center; gap: 10px; padding: 8px 13px; border: 1px solid var(--line); background: transparent; border-radius: 100px; font-size: 12px; }
.reader-theme > span:first-child { font-size: 20px; line-height: 1; }
.reader-main { width: min(100% - 40px, 960px); margin: auto; }
.reader-intro { padding: 55px 0 36px; text-align: center; }
.reader-kicker { margin: 0 0 17px; display: flex; flex-wrap: wrap; justify-content: center; gap: 13px; font-size: 11px; color: var(--muted); }
.reader-kicker [lang="en"] { letter-spacing: 2px; }
.reader-intro h1 { margin: 0 auto; max-width: 850px; font-size: clamp(28px, 4.5vw, 48px); font-weight: 600; line-height: 1.55; letter-spacing: -1px; overflow-wrap: anywhere; }
.reader-subtitle { margin: 12px auto 0; max-width: 650px; color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.reader-meta { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 20px 0 0; }
.reader-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
:root[data-theme="light"] .reader-dot { background: var(--ink); }
.reader-workspace { position: relative; }
.reader-progress { height: 3px; background: var(--line); margin: 0 0 18px; overflow: hidden; }
.reader-progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .25s ease; }
:root[data-theme="light"] .reader-progress span { background: var(--ink); }
.reader-sheet { background: var(--surface); min-height: min(115vw, 680px); position: relative; border: 1px solid var(--line); box-shadow: 0 20px 70px #00000018; scroll-margin-top: 24px; }
.reader-sheet canvas { width: 100%; height: auto; display: block; background: white; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
.reader-sheet[aria-busy="true"] canvas, .reader-sheet.has-error canvas { visibility: hidden; }
.reader-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 25px; text-align: center; }
.state-symbol { font-size: 50px; font-weight: 400; color: var(--muted); }
.reader-state p { color: var(--muted); font-size: 14px; }
.reader-dock { position: sticky; bottom: 18px; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 20px; width: fit-content; max-width: 100%; margin: 24px auto 0; padding: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 35px #00000025; }
.page-turn { display: flex; align-items: center; gap: 10px; justify-content: center; background: transparent; border: 0; border-radius: 7px; padding: 10px 16px; min-height: 46px; font-size: 13px; }
.page-turn:hover:not(:disabled) { background: var(--accent); color: #11130f; }
.page-turn > span[aria-hidden] { font-size: 21px; line-height: 1; }
.page-jump { display: flex; align-items: center; gap: 9px; font-size: 12px; white-space: nowrap; }
.page-jump label, #page-total { color: var(--muted); }
.page-jump input { appearance: textfield; -moz-appearance: textfield; width: 56px; min-height: 42px; text-align: center; border: 1px solid var(--line); background: var(--page); color: var(--ink); border-radius: 6px; font-size: 14px; }
.page-jump input::-webkit-inner-spin-button, .page-jump input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.jump-button { border: 0; border-radius: 6px; background: transparent; width: 34px; min-height: 42px; font-size: 20px; }
.jump-button:hover { background: var(--page); }
.reader-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 20px 0 0; }
.reader-button { display: inline-flex; justify-content: center; align-items: center; gap: 10px; min-height: 46px; padding: 10px 22px; background: var(--accent); color: #11130f; border: 1px solid transparent; border-radius: 4px; font-size: 13px; font-weight: 600; }
/* نهاية المعاينة: بطاقة دعوة، لا حاشية. القارئ وصل هنا لأنّه مهتمّ. */
.reader-endnote { margin: 48px 0 0; padding: 0; display: block; }
.endnote-card { position: relative; overflow: hidden; max-width: 680px; margin-inline: auto; padding: clamp(28px, 5vw, 44px); text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.endnote-card::before { content: ""; position: absolute; inset-block-start: 0; inset-inline: 0; height: 3px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
.endnote-mark { display: block; font-size: 34px; line-height: 1; color: var(--accent); margin-bottom: 14px; }
.endnote-kicker { margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.reader-endnote h2 { margin: 0 0 12px; font-size: clamp(22px, 3.4vw, 30px); font-weight: 600; line-height: 1.3; }
.endnote-lede { margin: 0 auto 22px; max-width: 520px; font-size: 15px; color: var(--muted); }
.endnote-points { margin: 0 auto 26px; padding: 0; list-style: none; display: inline-grid; gap: 10px; text-align: start; font-size: 14.5px; }
.endnote-points li { display: flex; align-items: center; gap: 10px; }
.endnote-points span { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); font-size: 11px; font-weight: 700; }
.endnote-cta { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 13px 30px; background: #25d366; color: #06230f; border-radius: 999px; font-size: 15.5px; font-weight: 600; transition: transform .16s ease, box-shadow .16s ease; }
.endnote-cta:hover { transform: translateY(-2px); box-shadow: 0 10px 26px -8px rgba(37, 211, 102, .6); }
.endnote-cta svg { flex: none; }
.endnote-note { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.reader-empty { text-align: center; margin: 0 auto 70px; padding: 50px 20px; max-width: 700px; border: 1px solid var(--line); background: var(--surface); }
.reader-empty > span { font-size: 54px; color: var(--muted); }
.reader-empty h2 { font-size: 25px; font-weight: 600; }
.reader-empty p { color: var(--muted); font-size: 14px; margin-bottom: 25px; }
.reader-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 65px clamp(20px, 5vw, 80px) 0; padding: 24px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.reader-footer [lang="en"] { letter-spacing: 1px; }
.reader-announcement { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.reader-print-note { display: none; }
@media (max-width: 600px) {
    .reader-header { min-height: 76px; gap: 12px; }
    .reader-brand { font-size: 12px; gap: 6px; }
    .reader-brand > span:first-child { font-size: 25px; }
    .reader-theme { padding: 7px 10px; gap: 6px; }
    .reader-back { font-size: 12px; gap: 7px; }
    .reader-main { width: calc(100% - 24px); }
    .reader-intro { padding: 35px 10px 28px; }
    .reader-subtitle { font-size: 13px; }
    .reader-kicker { font-size: 10px; gap: 9px; }
    .reader-dock { bottom: 10px; gap: 4px; padding: 6px; }
    .page-turn { padding: 9px 14px; }
    .turn-label { display: none; }
    .page-jump { gap: 7px; }
    .endnote-card { padding-inline: 20px; border-radius: 14px; }
    .endnote-cta { width: 100%; }
    .reader-empty h2 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media print { body > * { display: none !important; } body { background: white; color: black; } body > .reader-print-note { display: block !important; padding: 40px; } }

/* ===== حواجز النسخ ===== */
/* الصفحة ما تنسحب ولا تنتخب ولا تُحفظ بالدوسة الطويلة بالموبايل */
.reader-sheet, .reader-sheet canvas {
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
}
.reader-sheet canvas { pointer-events: none; }

/* ستار يغطّي الصفحة لمّا تروح عن النافذة */
.reader-veil {
    position: absolute; inset: 0; z-index: 8;
    display: flex; align-items: center; justify-content: center;
    padding: 20px; text-align: center; line-height: 1.7;
    font-size: .9rem; color: #8b949e;
    background: #0d1117;
    border-radius: inherit;
}
.reader-veil[hidden] { display: none; }

/* الطباعة: لا تطلع الصفحة بالورقة ولا بـ PDF */
@media print {
    .reader-sheet, .reader-sheet canvas, .reader-dock { display: none !important; }
    body::after {
        content: 'هذا الكتاب محميّ — للحصول على نسخة تواصل مع الناشر.';
        display: block; padding: 40px; text-align: center; font-size: 14pt;
    }
}
