/* ==========================================================================
   مكتبة بُرهان — styles.css
   - متغيرات CSS للثيمات (نهاري/ليلي)
   - تباين لوني يلبي WCAG AA (النصوص ≥ 4.5:1)
   - مؤشر تركيز واضح عبر :focus-visible لكل العناصر التفاعلية
   - احترام prefers-reduced-motion وتنسيقات طباعة
   ========================================================================== */

/* ---------- 1) المتغيرات ---------- */
:root {
  --paper:        #faf8f1;
  --surface:      #ffffff;
  --surface-2:    #f2efe4;
  --ink:          #1e2a23;
  --muted:        #4d5a52;
  --border:       #e0dcd0;

  --primary:        #14532d;
  --primary-hover:  #0e4023;
  --primary-ink:    #ffffff;
  --primary-soft:   #e7efe8;

  --accent:         #b45309;
  --accent-hover:   #92400e;
  --accent-ink:     #ffffff;

  --success:        #15803d;
  --danger:         #b91c1c;

  --gold:           #d4a24e;   /* زخرفي فقط، لا يُستخدم كنص صغير */
  --focus:          #b45309;

  --shadow-sm: 0 1px 2px rgba(20, 30, 24, .08), 0 2px 8px rgba(20, 30, 24, .06);
  --shadow-md: 0 6px 18px rgba(20, 30, 24, .14), 0 2px 6px rgba(20, 30, 24, .08);
  --shadow-lg: 0 24px 60px rgba(10, 20, 14, .35);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-display: "Amiri", "IBM Plex Sans Arabic", serif;
}

/* ---------- الوضع الليلي ---------- */
[data-theme="dark"] {
  --paper:        #0f1a13;
  --surface:      #16241c;
  --surface-2:    #1d2d23;
  --ink:          #ece9dd;
  --muted:        #a9b3a8;
  --border:       #2b3a30;

  --primary:        #1f7a43;
  --primary-hover:  #2a9253;
  --primary-ink:    #ffffff;
  --primary-soft:   #1c2f24;

  --accent:         #e8a33d;
  --accent-hover:   #f4c063;
  --accent-ink:     #241300;

  --success:        #4ade80;
  --danger:         #f87171;

  --focus:          #f6c453;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
}

/* ---------- 2) Reset خفيف ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.35; margin: 0 0 .5em; }
p { margin: 0 0 1em; }
[hidden] { display: none !important; }

/* نص مخفي بصريًا لكنه مسموع — أساسي لـ accessibility */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 3) مؤشر التركيز — لا يُزال أبدًا، فقط يُستبدل بأوضح منه ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
  box-shadow: 0 0 0 6px rgba(180, 83, 9, .18);
}
[data-theme="dark"] :focus-visible { box-shadow: 0 0 0 6px rgba(246, 196, 83, .22); }

/* رابط التخطي: مخفي حتى التركيز عليه */
.skip-link {
  position: absolute;
  inset-block-start: -100px;
  inset-inline-start: 1rem;
  z-index: 999;
  background: var(--primary);
  color: var(--primary-ink);
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-decoration: none;
  transition: inset-block-start .2s ease;
}
.skip-link:focus-visible { inset-block-start: 1rem; }

.container { width: min(1200px, 100% - 2.5rem); margin-inline: auto; }
.container-narrow { max-width: 860px; }

/* ==========================================================================
   4) الترويسة
   ========================================================================== */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; gap: 1.25rem;
  padding-block: .6rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; color: inherit; border-radius: var(--radius-sm); }
.brand-mark { flex: none; border-radius: 12px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 1.35rem; color: var(--ink); }
.brand-name strong { color: var(--primary); }
[data-theme="dark"] .brand-name strong { color: #7fd3a3; }
.brand-tagline { font-size: .68rem; color: var(--muted); letter-spacing: .01em; }

.main-nav ul { display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.main-nav a {
  display: inline-block; padding: .5rem .8rem; border-radius: 999px;
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: .95rem;
}
.main-nav a:hover { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .main-nav a:hover { color: #9fe0b8; }

.header-actions { display: flex; align-items: center; gap: .6rem; margin-inline-start: auto; }

/* زر رصيد التحميل */
.credits-pill {
  display: inline-flex; align-items: center; gap: .5rem;
  min-height: 44px; padding: .4rem .9rem;
  border-radius: 999px; border: 1.5px solid var(--primary);
  background: var(--primary-soft); color: var(--primary);
  font-family: inherit; font-weight: 700; cursor: pointer; font-size: .95rem;
  transition: background .15s ease, transform .15s ease;
}
.credits-pill:hover { background: #dce9de; }
[data-theme="dark"] .credits-pill { color: #9fe0b8; border-color: #2a9253; }
[data-theme="dark"] .credits-pill:hover { background: #213528; }
.credits-count {
  min-width: 2ch; text-align: center;
  background: var(--primary); color: var(--primary-ink);
  border-radius: 8px; padding: .1em .45em; font-variant-numeric: tabular-nums;
}
.credits-label { font-size: .8rem; font-weight: 600; }

/* زر أيقونة عام (الثيم، الإغلاق، …) */
.icon-button {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: background .15s ease;
}
.icon-button:hover { background: var(--surface-2); }

/* ==========================================================================
   5) الأزرار العامة
   ========================================================================== */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .55rem 1.15rem;
  border-radius: var(--radius-sm); border: 1.5px solid transparent;
  font-family: inherit; font-size: 1rem; font-weight: 700;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, color .15s ease;
}
.button:active { transform: translateY(1px) scale(.99); }
.button-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.button-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button-accent  { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.button-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-ghost   { background: transparent; color: var(--primary); border-color: var(--border); }
.button-ghost:hover { border-color: var(--primary); background: var(--primary-soft); }
[data-theme="dark"] .button-ghost { color: #9fe0b8; }
.button-large   { min-height: 52px; padding: .7rem 1.5rem; font-size: 1.05rem; border-radius: var(--radius-md); }

/* رقائق التصنيف (chips) */
.chip {
  display: inline-flex; align-items: center;
  font-size: .78rem; font-weight: 700; line-height: 1;
  padding: .38rem .7rem; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
}
[data-theme="dark"] .chip { color: #9fe0b8; }
.chip-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }

/* ==========================================================================
   6) الواجهة الترحيبية (Hero)
   ========================================================================== */
.hero {
  position: relative; overflow: hidden;
  color: #f5f2e7;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(212, 162, 78, .22), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(47, 143, 90, .25), transparent 55%),
    linear-gradient(150deg, #0c2b1c 0%, #10351f 55%, #0c2417 100%);
}
/* زخرفة هندسية إسلامية خفيفة (نجمة ثمانية) — عنصر زخرفي بحت */
.hero::after {
  content: ""; position: absolute; inset-inline-end: -80px; inset-block-start: -80px;
  width: 340px; height: 340px; opacity: .14; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%23f4c963' stroke-width='2'%3E%3Crect x='18' y='18' width='64' height='64'/%3E%3Crect x='18' y='18' width='64' height='64' transform='rotate(45 50 50)'/%3E%3Ccircle cx='50' cy='50' r='14'/%3E%3C/g%3E%3C/svg%3E");
  background-size: contain; background-repeat: no-repeat;
}
.hero-inner { position: relative; padding-block: 4.5rem 4rem; max-width: 980px; }
.hero-eyebrow {
  color: var(--gold); font-weight: 700; letter-spacing: .06em;
  font-size: .82rem; margin-bottom: .75rem;
}
.hero-title {
  font-size: clamp(2.3rem, 6vw, 3.9rem);
  line-height: 1.28; color: #fdfaf0; margin-bottom: 1.1rem;
}
.accent-text { color: #f4c963; }
.hero-subtitle {
  font-size: clamp(1.02rem, 1.6vw, 1.22rem);
  color: #cdd8cc; max-width: 52ch; margin-bottom: 1.75rem;
}
.hero-subtitle strong { color: #ffffff; }
.hero-cta { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 2.25rem; }
.hero .button-primary { background: #f4c963; border-color: #f4c963; color: #2a1e05; }
.hero .button-primary:hover { background: #ffd97a; border-color: #ffd97a; }
.hero .button-ghost { color: #eef3ec; border-color: rgba(255,255,255,.35); }
.hero .button-ghost:hover { background: rgba(255,255,255,.1); border-color: #fff; }

.hero-stats { display: flex; gap: 2rem; margin: 0; padding: 0; flex-wrap: wrap; border-top: 1px solid rgba(255,255,255,.18); padding-top: 1.5rem; }
.hero-stats div { display: flex; flex-direction: column; gap: .1rem; }
.hero-stats dt { order: 2; font-size: .8rem; color: #b9cbb9; }
.hero-stats dd { order: 1; margin: 0; font-size: 1.6rem; font-weight: 700; color: #fdfbf2; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   7) عناوين الأقسام والأدوات
   ========================================================================== */
.section-heading { margin-bottom: 1.5rem; }
.section-heading h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin-bottom: .25rem; }
.section-subtitle { color: var(--muted); margin: 0; }

.library-section { padding-block: 3.5rem 4rem; }
.how-section { padding-block: 3rem 3.5rem; background: var(--surface); border-block: 1px solid var(--border); }
.faq-section { padding-block: 3rem 4rem; }

/* شريط الأدوات */
.toolbar {
  display: flex; flex-direction: column; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  box-shadow: var(--shadow-sm); margin-bottom: .75rem;
}
.search-field {
  position: relative; display: flex; align-items: center;
  background: var(--paper); border: 1.5px solid var(--border);
  border-radius: var(--radius-md); min-height: 54px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(20, 83, 45, .15); }
.search-icon { position: absolute; inset-inline-start: 1rem; color: var(--muted); pointer-events: none; }
.search-field input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; background: transparent; color: var(--ink);
  font-family: inherit; font-size: 1.05rem;
  padding: .8rem 3rem .8rem 3rem;
}
.search-field input::placeholder { color: var(--muted); opacity: .85; }
.search-clear {
  position: absolute; inset-inline-end: .5rem;
  width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.search-clear:hover { background: var(--surface-2); color: var(--ink); }
/* إخفاء زر المسح الافتراضي في متصفحات WebKit لأن لدينا زرنا الخاص */
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.filter-chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.filter-chip {
  min-height: 44px; padding: .45rem 1rem;
  border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--paper); color: var(--ink);
  font-family: inherit; font-weight: 600; font-size: .92rem; cursor: pointer;
  transition: all .15s ease;
}
.filter-chip:hover { border-color: var(--primary); color: var(--primary); }
.filter-chip[aria-pressed="true"] {
  background: var(--primary); border-color: var(--primary); color: var(--primary-ink);
}
.filter-chip .count { font-variant-numeric: tabular-nums; font-size: .8em; font-weight: 600; }

.sort-field { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.sort-field label { font-weight: 600; color: var(--muted); font-size: .92rem; }
.sort-field select {
  min-height: 44px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink);
  font-family: inherit; font-size: .95rem; padding: .45rem .75rem; cursor: pointer;
}

.results-status { color: var(--muted); font-size: .92rem; margin: .25rem .1rem 1rem; min-height: 1.5em; }
.load-more-wrap { text-align: center; margin: 1.75rem auto 0; }

/* ==========================================================================
   8) شبكة الكتب والبطاقات
   ========================================================================== */
.books-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 1.4rem;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
}
.book-card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.book-card:focus-within { border-color: var(--primary); }

/* الغلاف المولّد بالكامل عبر CSS — لا صور خارجية، وأفضل alt عبر role=img */
.book-cover {
  position: relative; aspect-ratio: 16 / 10;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 1rem 1.1rem; color: #fdfcf6; overflow: hidden;
}
.book-cover::before { /* إطار داخلي زخرفي */
  content: ""; position: absolute; inset: .55rem;
  border: 1px solid rgba(255, 255, 255, .35); border-radius: 8px; pointer-events: none;
}
.book-cover::after { /* معيّن زخرفي */
  content: ""; position: absolute; top: .9rem; inset-inline-end: .9rem;
  width: 26px; height: 26px; transform: rotate(45deg);
  border: 2px solid rgba(255, 255, 255, .55); border-radius: 4px; pointer-events: none;
}
.book-cover-title {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.12rem; line-height: 1.55; color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-cover-author { font-size: .75rem; color: rgba(255, 255, 255, .85); margin-top: .25rem; }
.book-cover[data-category="الفلسفة"]       { background: linear-gradient(155deg, #10341f 0%, #1c5741 60%, #2a6b50 100%); }
.book-cover[data-category="علم الكلام"]    { background: linear-gradient(155deg, #141f36 0%, #233558 60%, #31456e 100%); }
.book-cover[data-category="مقارنة الأديان"]{ background: linear-gradient(155deg, #3d1f0e 0%, #6b3a1e 60%, #8a5630 100%); }
.book-cover[data-category="كتب نقدية"]     { background: linear-gradient(155deg, #241430 0%, #3e2a52 60%, #543d6b 100%); }
/* نفس التدرجات لغلاف نافذة المعاينة */
.preview-cover[data-category="الفلسفة"]       { background: linear-gradient(155deg, #10341f 0%, #1c5741 60%, #2a6b50 100%); }
.preview-cover[data-category="علم الكلام"]    { background: linear-gradient(155deg, #141f36 0%, #233558 60%, #31456e 100%); }
.preview-cover[data-category="مقارنة الأديان"]{ background: linear-gradient(155deg, #3d1f0e 0%, #6b3a1e 60%, #8a5630 100%); }
.preview-cover[data-category="كتب نقدية"]     { background: linear-gradient(155deg, #241430 0%, #3e2a52 60%, #543d6b 100%); }

.book-body { display: flex; flex-direction: column; gap: .35rem; padding: .9rem 1rem 1rem; flex: 1; }
.book-title { font-size: 1.08rem; margin: 0; font-family: var(--font-body); font-weight: 700; }
.book-title a { color: inherit; text-decoration: none; }
.book-title a:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
[data-theme="dark"] .book-title a:hover { color: #9fe0b8; }
.book-author { color: var(--muted); font-size: .88rem; margin: 0; }
.book-description {
  font-size: .88rem; color: var(--muted); margin: .15rem 0 .5rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.book-footer { margin-top: auto; display: flex; flex-direction: column; gap: .6rem; }
.book-chips { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.book-actions { display: flex; gap: .5rem; }
.book-actions .button { flex: 1; min-width: 0; padding-inline: .5rem; font-size: .92rem; }
.download-note { font-size: .72rem; color: var(--muted); text-align: center; }

/* حالات فارغة وخطأ */
.empty-state, .error-state {
  text-align: center; padding: 3rem 1.5rem;
  border: 1.5px dashed var(--border); border-radius: var(--radius-lg);
  color: var(--muted); background: var(--surface);
}
.empty-state h3, .error-state h3 { color: var(--ink); font-size: 1.3rem; }

/* ==========================================================================
   9) قسم «كيف يعمل»
   ========================================================================== */
.steps {
  list-style: none; margin: 0 0 1.25rem; padding: 0;
  display: grid; gap: 1.25rem; grid-template-columns: repeat(3, 1fr);
  counter-reset: step;
}
.step {
  background: var(--paper); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 1.5rem 1.25rem;
  position: relative;
}
.step-number {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--primary); color: #fff;
  font-size: 1.3rem; font-weight: 800; margin-bottom: .75rem;
  font-family: var(--font-body);
}
.step h3 { font-size: 1.15rem; margin-bottom: .35rem; }
.step p { color: var(--muted); margin: 0; font-size: .95rem; }
.how-note { text-align: center; color: var(--muted); font-size: .92rem; }
.how-cta { text-align: center; margin-top: 1.25rem; }

/* ==========================================================================
   10) الأسئلة الشائعة
   ========================================================================== */
.faq-section h2 { margin-bottom: 1rem; }
.faq-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 0 1.25rem; margin-bottom: .75rem;
}
.faq-item summary {
  cursor: pointer; font-weight: 700; padding: 1rem .25rem;
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  border-radius: var(--radius-sm);
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+"; font-size: 1.5rem; font-weight: 400; color: var(--primary);
  transition: transform .2s ease; line-height: 1;
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item p { padding: 0 .25rem 1.1rem; color: var(--muted); margin: 0; border-top: 1px dashed var(--border); padding-top: .75rem; }

/* ==========================================================================
   11) النوافذ المنبثقة (Modals)
   ========================================================================== */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: clamp(.75rem, 3vw, 2rem);
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 14, 10, .62);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fadeIn .18s ease;
}
.modal-panel {
  position: relative; width: min(620px, 100%);
  max-height: min(92vh, 900px); overflow: auto;
  background: var(--surface); color: var(--ink);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: panelIn .22s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-panel-wide { width: min(880px, 100%); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes panelIn { from { opacity: 0; transform: translateY(24px) scale(.97); } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .75rem 1.25rem 1.1rem; border-top: 1px solid var(--border); }
.channel-link { color: var(--primary); font-weight: 700; }
[data-theme="dark"] .channel-link { color: #9fe0b8; }

/* ---- معاينة الكتاب داخل النافذة ---- */
.preview-body { display: grid; grid-template-columns: 180px 1fr; gap: 1.25rem; align-items: start; }
.preview-cover {
  aspect-ratio: 3/4.4; border-radius: var(--radius-md);
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: .85rem; color: #fff; overflow: hidden; position: relative;
  background: linear-gradient(155deg, #10341f, #1c5741);
}
.preview-cover .book-cover-title { font-size: .95rem; -webkit-line-clamp: 4; }
.preview-cover .book-cover-author { font-size: .65rem; }
.preview-title { margin-bottom: .2rem; font-size: 1.35rem; }
.preview-author { color: var(--muted); font-weight: 600; margin-bottom: .5rem; }
.preview-chips { display: flex; gap: .4rem; margin-bottom: .65rem; }
.preview-description { color: var(--ink); }
.preview-translator { color: var(--muted); font-size: .85rem; }
.preview-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .75rem; }

.preview-embed-wrap { border-top: 1px solid var(--border); padding: 1rem 1.25rem 1.25rem; }
.preview-embed-heading { font-size: .95rem; color: var(--muted); margin-bottom: .5rem; }
.preview-embed { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }

/* ---- نافذة المشاهدة ---- */
.watch-pending { background: var(--primary-soft); border-radius: var(--radius-sm); padding: .5rem .8rem; }
.episode-fieldset { border: 1px solid var(--border); border-radius: var(--radius-md); padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
.episode-fieldset legend { font-weight: 700; padding-inline: .5rem; color: var(--muted); font-size: .9rem; }
.episode-list { display: flex; flex-direction: column; gap: .4rem; }
.episode-option {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .6rem .7rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.episode-option:hover { background: var(--surface-2); }
.episode-option:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); }
.episode-option input { margin-top: .3rem; accent-color: var(--primary); width: 1.1rem; height: 1.1rem; flex: none; }
.episode-option-title { font-weight: 600; line-height: 1.55; }
.episode-claimed { font-size: .72rem; color: var(--success); font-weight: 700; display: inline-flex; align-items: center; gap: .3rem; }

.player-wrap { margin-bottom: .5rem; }
.player-ratio { position: relative; aspect-ratio: 16/9; border-radius: var(--radius-md); overflow: hidden; background: #000; }
.yt-player, .player-ratio iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.watch-progress { margin-top: .85rem; }
.watch-progress-bar {
  height: 14px; border-radius: 999px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.watch-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), #2e8b57);
  transition: width .4s ease;
}
.watch-progress-text { font-size: .85rem; color: var(--muted); margin: .35rem .1rem 0; font-variant-numeric: tabular-nums; }
.watch-hint { font-size: .8rem; color: var(--muted); margin-top: .4rem; }

.player-error { background: #fef2f2; border: 1px solid #fecaca; color: #7f1d1d; border-radius: var(--radius-md); padding: 1rem; }
[data-theme="dark"] .player-error { background: #2a1616; border-color: #5b2626; color: #fca5a5; }

.watch-success { text-align: center; padding: 1.25rem .5rem .5rem; }
.success-icon { color: var(--success); margin-bottom: .5rem; }
.watch-success h3 { font-size: 1.4rem; margin-bottom: .25rem; }
.watch-success-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }

/* ==========================================================================
   12) منطقة الإشعارات (Toast) وزر الأعلى
   ========================================================================== */
.toast-region {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  z-index: 120; display: flex; flex-direction: column; gap: .5rem;
  width: min(560px, calc(100% - 2rem)); pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: #10241a; color: #eafff0;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: var(--radius-md); padding: .8rem 1.1rem;
  box-shadow: var(--shadow-md); font-size: .95rem; font-weight: 500;
  animation: toastIn .25s ease;
}
[data-theme="dark"] .toast { background: #eafff0; color: #10241a; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

.back-to-top {
  position: fixed; bottom: 1.25rem; inset-inline-end: 1.25rem; z-index: 60;
  width: 52px; height: 52px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--primary);
  cursor: pointer; box-shadow: var(--shadow-md); display: grid; place-items: center;
}
.back-to-top:hover { background: var(--primary-soft); }

/* ==========================================================================
   13) التذييل
   ========================================================================== */
.site-footer { background: #0d2417; color: #c9d6c9; border-top: 1px solid var(--border); }
.footer-inner { display: grid; grid-template-columns: 1.4fr 1fr; gap: 2.5rem; padding-block: 2.5rem; }
.footer-brand { font-size: 1.3rem; color: #fdfbf2; margin-bottom: .35rem; }
.footer-brand strong { color: #f4c963; }
.footer-note { font-size: .8rem; color: #8fa891; border-top: 1px solid rgba(255,255,255,.12); padding-top: .75rem; margin-top: .75rem; }
.footer-heading { font-size: .8rem; letter-spacing: .06em; color: #f4c963; margin-bottom: .5rem; font-family: var(--font-body); }
.footer-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.footer-nav a { color: #e7efe3; text-decoration: none; }
.footer-nav a:hover { text-decoration: underline; color: #fff; }
.footer-downloads { font-size: .8rem; color: #8fa891; margin-top: 1rem; font-variant-numeric: tabular-nums; }
.footer-bottom { border-top: 1px solid rgba(255,255,255,.12); padding-block: .9rem; font-size: .82rem; color: #8fa891; }
.footer-bottom p { margin: 0; }

.noscript-banner { background: #7f1d1d; color: #fff; padding: 1rem; text-align: center; font-weight: 700; }

/* ==========================================================================
   14) استجابة الشاشات الصغيرة
   ========================================================================== */
@media (max-width: 900px) {
  .steps { grid-template-columns: 1fr; }
  .footer-inner { grid-template-columns: 1fr; gap: 1.5rem; }
  .preview-body { grid-template-columns: 1fr; }
  .preview-cover { max-width: 220px; }
  .hero-inner { padding-block: 3rem 2.5rem; }
  .brand-tagline { display: none; }
  .credits-label { display: none; }
  .main-nav { order: 3; width: 100%; }
  .main-nav ul { justify-content: center; }
}
@media (max-width: 560px) {
  .books-grid { grid-template-columns: 1fr; }
  .book-actions { flex-direction: column; }
  .hero-stats { gap: 1.25rem; }
}

/* ==========================================================================
   15) احترام تفضيل تقليل الحركة
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .book-card:hover { transform: none; }
}

/* ==========================================================================
   16) الطباعة: اطبع قائمة كتب نظيفة
   ========================================================================== */
@media print {
  .site-header, .hero, .toolbar, .how-section, .faq-section,
  .site-footer, .toast-region, .back-to-top, .modal, .skip-link,
  .book-actions, .download-note { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .books-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .book-card { break-inside: avoid; border: 1px solid #999; box-shadow: none; }
  .book-cover { display: none; }
  .library-section { padding: 0; }
}
