/* ═══════════════════════════════════════════════════════════════
   🖋️ ديوان هديل — الأنماط الرئيسية
   ─────────────────────────────────────────────────────────────
   كل الأنماط تستعمل الرقائق من tokens.css (بلا أرقام مباشرة)
   قاعدة 60-30-10 · شبكة 8px · وضع ليلي مستقل
   ═══════════════════════════════════════════════════════════════ */

/* ═══ الأساس ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100vh;
  height: 100dvh;           /* viewport ثابت — لا تمرير للصفحة */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  overflow: hidden;         /* كل شاشة محصورة في الشاشة — التمرير داخلي فقط */
  animation: screenIn var(--dur-slow) var(--ease-out) both;
}
.screen.active { display: flex; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(var(--space-2)); }
  to   { opacity: 1; transform: none; }
}

/* ═══ الأزرار ═══ */
.btn-primary {
  background: var(--color-primary);
  color: var(--text-on-brand);
  border: none;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) ease,
              box-shadow var(--dur-fast) ease;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-primary:active { transform: translateY(0); box-shadow: none; }
.btn-primary:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--border-default);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur-fast) ease;
}
.btn-ghost:hover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.btn-ghost:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.btn-danger {
  background: var(--color-error);
  color: var(--paper-0);
  border: none;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur-fast) ease;
}
.btn-danger:hover { filter: brightness(1.08); transform: translateY(-1px); }

.btn-sm { padding: var(--space-2) var(--space-4); font-size: var(--text-sm); }

.btn-icon {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  cursor: pointer;
  transition: all var(--dur-fast) ease;
}
.btn-icon:hover { border-color: var(--border-accent); background: var(--color-accent-soft); transform: translateY(-1px); }
.btn-icon:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn-icon-sm { width: 32px; height: 32px; font-size: 1.1rem; border-radius: var(--radius-full); background: var(--color-primary); color: var(--text-on-brand); border: none; }
.btn-icon-sm:hover { background: var(--color-primary-hover); }

/* ═══ الشريط العلوي ═══ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  min-height: 64px;
}
.topbar-brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-icon {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--fab-bg);
  color: var(--fab-fg);
  border-radius: var(--radius-full);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  box-shadow: var(--shadow-gold);
}
.brand-text {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* ═══ شاشة البداية (Splash) ═══ */
#screen-splash {
  background: var(--screen-bg);
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: var(--space-5);
  transition: opacity 550ms ease;
}
#screen-splash.leaving { opacity: 0; }

/* نقشة هندسية خفيفة جداً — نفس هوية المكتبة */
#screen-splash::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: var(--pattern-op);
  background-image:
    repeating-linear-gradient(45deg, var(--pattern) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(-45deg, var(--pattern) 0 1px, transparent 1px 26px);
  mask-image: radial-gradient(70% 55% at 50% 45%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(70% 55% at 50% 45%, #000 0%, transparent 75%);
  pointer-events: none;
}

.splash-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* الشعار — الريشة المعتمدة (يُلوَّن بلون الثيم عبر mask) */
.splash-logo {
  width: clamp(112px, 22vh, 168px);
  height: clamp(112px, 22vh, 168px);
  background-color: var(--color-accent);
  -webkit-mask: url('../assets/logo-quill.png') no-repeat center / contain;
  mask: url('../assets/logo-quill.png') no-repeat center / contain;
  animation: splashRise 900ms var(--ease-out) both;
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.28));
}

/* عبارة الترحيب */
.splash-line {
  margin-top: clamp(22px, 4vh, 36px);
  font-family: var(--font-ui);
  font-weight: 300;
  font-size: clamp(19px, 4.6vw, 27px);
  line-height: 1.7;
  color: var(--text-primary);
  animation: splashRise 900ms 280ms var(--ease-out) both;
}
/* «مَدَوَّنة» — معالجة بصرية أنيقة: خط العناوين + لون مميّز + خيط رفيع */
.splash-line .mw {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-accent);
  position: relative;
  padding: 0 0.12em;
}
.splash-line .mw::after {
  content: '';
  position: absolute;
  bottom: -0.28em;
  right: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(to left, transparent, var(--rule), transparent);
}
.splash-line .nm { color: var(--text-heading); }

@keyframes splashRise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}

/* ═══ إذن الجهاز — صفحة الانتظار (pending / blocked) ═══
   نفس هوية Splash: الخلفية + النقشة + الشعار + خيط ذهبي رفيع.
   كل الألوان من Tokens → كلا الثيمين بلا أي قيمة مباشرة. ═══ */
#screen-gate {
  background: var(--screen-bg);
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: var(--space-5) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  transition: opacity 550ms ease;
}
#screen-gate.leaving { opacity: 0; }

/* نقشة هندسية خفيفة — نفس نقشة Splash */
#screen-gate::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: var(--pattern-op);
  background-image:
    repeating-linear-gradient(45deg, var(--pattern) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(-45deg, var(--pattern) 0 1px, transparent 1px 26px);
  mask-image: radial-gradient(70% 55% at 50% 45%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(70% 55% at 50% 45%, #000 0%, transparent 75%);
  pointer-events: none;
}

.gate-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 34rem;
}

.gate-title {
  margin-top: clamp(26px, 5vh, 40px);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(23px, 5.6vw, 32px);
  line-height: 1.5;
  color: var(--text-heading);
  animation: splashRise 900ms 200ms var(--ease-out) both;
}
/* خيط ذهبي رفيع — من هوية «مَدَوَّنة» */
.gate-title::after {
  content: '';
  display: block;
  width: min(190px, 46vw);
  height: 1px;
  margin: clamp(16px, 3vh, 22px) auto 0;
  background: linear-gradient(to left, transparent, var(--rule), transparent);
}

.gate-text {
  margin-top: clamp(16px, 3vh, 22px);
  font-family: var(--font-ui);
  font-weight: 300;
  font-size: clamp(16px, 4vw, 19px);
  line-height: 1.9;
  color: var(--text-secondary);
  max-width: 30ch;
  animation: splashRise 900ms 380ms var(--ease-out) both;
}

.gate-status {
  margin-top: clamp(24px, 4.5vh, 36px);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--panel);
  border: 1px solid var(--panel-b);
  border-radius: var(--radius-full);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-accent-text);
  animation: splashRise 900ms 560ms var(--ease-out) both;
}
.gate-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  animation: gateBreath 2.6s ease-in-out infinite;
}
#screen-gate[data-state="blocked"] .gate-status { color: var(--color-error); }
#screen-gate[data-state="blocked"] .gate-dot { background: var(--color-error); animation: none; }

.gate-note {
  margin-top: clamp(18px, 3.5vh, 26px);
  font-size: var(--text-xs);
  color: var(--text-dim);
  animation: splashRise 900ms 720ms var(--ease-out) both;
}
#screen-gate[data-state="blocked"] .gate-note { display: none; }

@keyframes gateBreath {
  0%, 100% { opacity: 0.45; transform: scale(0.82); }
  50%      { opacity: 1;    transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .gate-dot { animation: none; opacity: 0.9; }
}

/* ═══ المكتبة — Book Gallery (مرساة viewport ثابت) ═══ */
.ic { width: 20px; height: 20px; flex: none; display: block; }
.ic-sm { width: 16px; height: 16px; }
.ic-lg { width: 24px; height: 24px; }

#screen-home {
  background: var(--screen-bg);
  position: relative;
}
/* نقشة هندسية خفيفة — من هوية Splash */
#screen-home::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: var(--pattern-op);
  background-image:
    repeating-linear-gradient(45deg, var(--pattern) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(-45deg, var(--pattern) 0 1px, transparent 1px 26px);
  mask-image: radial-gradient(70% 55% at 50% 0%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(70% 55% at 50% 0%, #000 0%, transparent 75%);
  pointer-events: none;
}

.home {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: clamp(14px, 3vh, 36px) clamp(16px, 5vw, 72px) clamp(64px, 9vh, 92px);
}

/* ── صف الأدوات (ثابت في الأعلى) ── */
.home-top {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-bottom: clamp(10px, 2vh, 22px);
}
.home-top .btn-icon {
  background: var(--panel);
  border-color: var(--panel-b);
  color: var(--text-secondary);
}
.home-top .btn-icon:hover {
  border-color: var(--border-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
}
.home-top .btn-icon.is-admin { border-color: var(--border-accent); color: var(--color-accent-text); }

/* ── زر «المزيد»: أعلى اليسار (مقابل زر الإنشاء أسفل اليمين) ── */
.home-menu {
  position: absolute;
  top: clamp(10px, 2vh, 18px);
  inset-inline-end: clamp(12px, 2.5vw, 28px);
  z-index: 5;
  background: var(--panel);
  border-color: var(--panel-b);
  color: var(--text-secondary);
}
.home-menu:hover {
  border-color: var(--border-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
}

/* ── قائمة المزيد ── */
.more-list { display: flex; flex-direction: column; gap: 2px; }
.more-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 11px var(--space-3);
  background: none;
  border: 0;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--text-sm);
  text-align: start;
  cursor: pointer;
  transition: background var(--dur-fast) ease;
}
.more-item:hover { background: var(--color-primary-soft); }
.more-item .ic { width: 18px; height: 18px; color: var(--text-secondary); flex: none; }

/* ── الرأس: التهنئة (ثابتة) ── */
.home-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: clamp(16px, 3vw, 32px);
  flex-wrap: wrap;
  margin-top: 5mm; /* انزياح التحية عن الحافة العليا */
}

.greet .hi {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(17.5px, 1.65vw, 22px);
  color: var(--text-accent);
  margin-bottom: 8px;
}
.greet h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(41px, 7.3vw, 88px);
  line-height: 1.08;
  color: var(--text-heading);
  letter-spacing: -0.01em;
}
.greet h1 em { font-style: normal; color: var(--color-accent); }
.greet .meta {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(12px, 2vw, 26px);
  align-items: center;
  margin-top: clamp(10px, 1.8vh, 20px);
  color: var(--text-muted);
  font-size: clamp(14.5px, 1.4vw, 17px);
}
.greet .meta i {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--dot);
  margin-left: 8px;
  vertical-align: middle;
}

/* علبة البحث */
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  width: min(280px, 100%);
  border: 1px solid var(--panel-b);
  border-radius: 2px;
  background: var(--panel);
  color: var(--text-muted);
  transition: border-color var(--dur-base) ease;
}
.search:focus-within { border-color: var(--border-accent); }
.search .ic { opacity: 0.7; }
.search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text-primary);
  font-size: 14px;
}
.search input::placeholder { color: var(--text-muted); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* الخط الذهبي الرفيع (1px hairline) */
.rule {
  height: 1px;
  background: linear-gradient(to left, var(--rule), var(--rule-soft) 60%, transparent);
  margin-top: clamp(18px, 3.2vh, 40px);
}

/* ── الرفّ — منطقة التمرير الوحيدة ── */
.shelf {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: clamp(16px, 2.8vh, 36px);
}
.shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(12px, 1.8vh, 24px);
}
.shelf-head h2 {
  font-family: var(--font-display);
  font-size: clamp(20px, 2.4vw, 25px);
  font-weight: 700;
  color: var(--text-heading);
}
.shelf-head span {
  font-size: 12.5px;
  color: var(--text-dim);
  letter-spacing: 0.14em;
}

/* ⚠️ هذا هو المكان الوحيد القابل للتمرير في الصفحة الرئيسية */
.shelf-scroll {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
  -webkit-overflow-scrolling: touch;
}
.shelf-scroll::-webkit-scrollbar { width: 8px; }
.shelf-scroll::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 99px; }
.shelf-scroll::-webkit-scrollbar-track { background: transparent; }

.books {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  --gap: clamp(12px, 2vw, 30px);
  gap: var(--gap);
  align-items: end;
  padding-bottom: 2px;
}

.book {
  position: relative;
  max-width: 196px;
  justify-self: center;
  width: 100%;
  padding-bottom: 14px;
}
/* خشبة الرفّ الخشبية تحت كل كتاب */
.book::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: calc(-1 * var(--gap) / 2 - 1px);
  right: calc(-1 * var(--gap) / 2 - 1px);
  height: 6px;
  border-radius: 1px;
  background: linear-gradient(to bottom, var(--wood1), var(--wood2) 55%, var(--wood3));
  box-shadow: 0 12px 16px -10px var(--wood-shadow), 0 1px 0 var(--wood-hi);
}

.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 3px 7px 7px 3px;
  overflow: hidden;
  box-shadow: 0 18px 34px -14px var(--book-shadow), 0 3px 10px var(--book-shadow-2);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: clamp(12px, 2vw, 20px) clamp(10px, 1.6vw, 16px);
  cursor: pointer;
  transition: transform 380ms cubic-bezier(0.2, 0.7, 0.3, 1), box-shadow 380ms ease;
}
.book:hover .cover,
.book:focus-within .cover {
  transform: translateY(-13px);
  box-shadow: 0 34px 52px -18px var(--book-shadow), 0 0 0 1px var(--ring);
}
/* كعب الكتاب */
.cover::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 9px;
  background: linear-gradient(to left, var(--spine), rgba(255, 255, 255, 0.10) 60%, transparent);
}
/* إطار داخلي شعرة 1px */
.cover::after {
  content: '';
  position: absolute;
  inset: 9px 9px 9px 0;
  border: 1px solid var(--cover-line);
  border-radius: 2px;
  pointer-events: none;
}
.cover .ct {
  font-family: var(--font-display);
  font-size: clamp(15px, 2.2vw, 22px);
  line-height: 1.35;
  font-weight: 700;
  position: relative;
  z-index: 2;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cover .ca {
  font-size: clamp(10px, 1.2vw, 11.5px);
  letter-spacing: 0.16em;
  margin-top: 10px;
  opacity: 0.78;
  position: relative;
  z-index: 2;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cover .cd {
  position: absolute;
  bottom: clamp(10px, 1.6vh, 16px);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  opacity: 0.6;
  z-index: 2;
}
.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* أغلفة افتراضية (لكل كتاب بلا تصميم مخصّص) */
.cv-1 { background: var(--cv1); color: var(--cv1-ink); }
.cv-2 { background: var(--cv2); color: var(--cv2-ink); }
.cv-3 { background: var(--cv3); color: var(--cv3-ink); }
.cv-4 { background: var(--cv4); color: var(--cv4-ink); }
.cv-5 { background: var(--cv5); color: var(--cv5-ink); }

/* قائمة خيارات الكتاب (فتح / مشاركة / حذف) */
.book-menu-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 4;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  border: 1px solid var(--cover-line);
  background: rgba(0, 0, 0, 0.34);
  color: #f2ece2;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-base) ease, background var(--dur-fast) ease;
}
.book:hover .book-menu-btn,
.book:focus-within .book-menu-btn,
.book-menu-btn[aria-expanded="true"] { opacity: 1; }
.book-menu-btn:hover { background: rgba(0, 0, 0, 0.55); }
@media (hover: none) { .book-menu-btn { opacity: 0.9; } }

.book-menu {
  position: absolute;
  top: 42px;
  left: 8px;
  z-index: 6;
  display: none;
  min-width: 150px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.book-menu.open { display: block; }
.book-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: 0;
  color: var(--text-primary);
  font-size: 13.5px;
  text-align: start;
  cursor: pointer;
  transition: background var(--dur-fast) ease;
}
.book-menu button:hover { background: var(--bg-subtle); }
.book-menu button.danger { color: var(--color-error); }
.book.menu-open { z-index: 30; }   /* القائمة المفتوحة تعلو الجيران */

/* الحالة الفارغة */
.empty-state {
  display: none;
  text-align: center;
  padding: clamp(28px, 6vh, 64px) var(--space-5);
  color: var(--text-muted);
}
.empty-state.visible { display: block; }
.empty-state .ic {
  width: 52px;
  height: 52px;
  margin: 0 auto var(--space-4);
  color: var(--color-accent);
  opacity: 0.85;
}
.empty-title {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  color: var(--text-heading);
  margin-bottom: var(--space-2);
}
.empty-text { font-size: var(--text-sm); margin-bottom: var(--space-5); }

/* ── الأسفل: آخر ما كتبتِ + من دفترك (ثابت — لا يتحرك) ── */
.bottom {
  flex: none;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: clamp(20px, 4vw, 56px);
  margin-top: clamp(16px, 2.6vh, 34px);
}
.bottom h3 {
  font-family: var(--font-display);
  font-size: clamp(16px, 1.8vw, 19px);
  color: var(--h3);
  font-weight: 700;
  margin-bottom: 6px;
}

.row {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.4vw, 16px);
  padding: clamp(9px, 1.5vh, 15px) 6px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background var(--dur-base) ease;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--hover); }
.row .thumb {
  width: 32px;
  aspect-ratio: 2 / 3;
  border-radius: 2px;
  flex: none;
  box-shadow: 0 4px 8px var(--book-shadow-2);
}
.row .rt { flex: 1; min-width: 0; }
.row .rt b {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(15px, 1.5vw, 17px);
  color: var(--text-primary);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .rt span {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .rd {
  font-size: 12.5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  flex: none;
}

.side .note {
  border: 1px solid var(--note-b);
  padding: clamp(14px, 2vw, 22px);
  border-radius: 3px;
  background: var(--note-bg);
}
.side .note p {
  font-family: var(--font-display);
  font-size: clamp(15px, 1.6vw, 17.5px);
  line-height: 2;
  color: var(--note-fg);
}
.side .note small {
  display: block;
  margin-top: 12px;
  color: var(--note-small);
  font-size: 12px;
  letter-spacing: 0.2em;
}

/* ── زر «كتاب جديد» (ثابت أسفل اليمين) ── */
.fab {
  position: absolute;
  bottom: clamp(16px, 3vh, 30px);
  right: clamp(16px, 3vw, 34px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 24px;
  border-radius: var(--radius-full);
  border: 0;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  background: var(--fab-bg);
  color: var(--fab-fg);
  box-shadow: var(--fab-shadow);
  transition: transform 250ms ease, box-shadow 250ms ease;
}
.fab:hover { transform: translateY(-3px); box-shadow: var(--fab-shadow-h); }
.fab:active { transform: translateY(0); }
.fab .ic { width: 18px; height: 18px; }

/* ═══ المحرر ═══ */
.editor-layout { flex: 1; display: grid; grid-template-columns: 280px 1fr; overflow: hidden; }

.editor-sidebar {
  background: var(--bg-surface);
  border-inline-end: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.sidebar-header h3 { font-family: var(--font-display); font-size: var(--text-h3); }

.poem-list { flex: 1; overflow-y: auto; padding: var(--space-2); }
.poem-item {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1.5px solid transparent;
  margin-bottom: var(--space-1);
  transition: all var(--dur-fast) ease;
}
.poem-item:hover { background: var(--bg-subtle); }
.poem-item.active { background: var(--color-primary-soft); border-color: var(--color-primary); }
.poem-item-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.poem-item-count { font-size: var(--text-xs); color: var(--text-muted); }

.editor-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  overflow-y: auto;
  min-height: 0;
}
.poem-title-input {
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border-subtle);
  padding: var(--space-2) 0;
  transition: border-color var(--dur-fast) ease;
  min-height: 48px;
}
.poem-title-input::placeholder { color: var(--text-muted); font-weight: 400; }
.poem-title-input:focus { outline: none; border-bottom-color: var(--color-accent); }

.poem-body-input {
  flex: 1;
  min-height: 340px;
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: 2.1;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  resize: none;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.poem-body-input::placeholder { color: var(--text-muted); font-family: var(--font-ui); }
.poem-body-input:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-soft); }

.editor-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.save-indicator { color: var(--color-success); font-weight: 600; opacity: 0; transition: opacity var(--dur-base) ease; }
.save-indicator.visible { opacity: 1; }

/* ═══ المصمّم ═══ */
.designer-layout { flex: 1; display: grid; grid-template-columns: 1fr 340px; overflow: hidden; }

.designer-preview {
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--bg-subtle);
  overflow: auto;
}

.cover-preview {
  width: min(320px, 80vw);
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.cover-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-preview .cover-title-text { position: relative; z-index: 1; font-family: var(--font-display); font-weight: 700; line-height: 1.5; text-shadow: 0 2px 10px rgba(0,0,0,0.3); }
.cover-preview .cover-author { position: relative; z-index: 1; font-family: var(--font-display); opacity: 0.9; text-shadow: 0 1px 6px rgba(0,0,0,0.3); }

.page-preview {
  width: min(320px, 80vw);
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.page-preview .page-text { font-family: var(--font-body); font-size: var(--text-body); line-height: 2.1; white-space: pre-line; }
.page-preview .page-sample-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-h3); margin-bottom: var(--space-4); }

.designer-panel {
  background: var(--bg-surface);
  border-inline-start: 1px solid var(--border-subtle);
  padding: var(--space-5);
  overflow-y: auto;
}
.designer-panel h3 {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  color: var(--text-primary);
  padding-bottom: var(--space-2);
  margin: var(--space-5) 0 var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.designer-panel h3:first-child { margin-top: 0; }

.design-group { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-4); }

.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.color-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.color-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
}
.color-field input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  padding: 2px;
  cursor: pointer;
}

.design-group select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
}
.design-group select:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--shadow-focus); }

input[type="range"] { width: 100%; accent-color: var(--color-accent); }
input[type="range"] output { font-weight: 700; color: var(--color-accent-text); }

.file-input {
  font-size: var(--text-sm);
  border: 1.5px dashed var(--border-default);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--bg-subtle);
  cursor: pointer;
  width: 100%;
}

/* مبدّل */
.switch-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.switch-label input { position: absolute; opacity: 0; }
.switch {
  width: 42px; height: 24px;
  background: var(--border-default);
  border-radius: var(--radius-full);
  position: relative;
  transition: background var(--dur-fast) ease;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; inset-inline-start: 3px;
  width: 18px; height: 18px;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  transition: transform var(--dur-fast) var(--ease-spring);
  box-shadow: var(--shadow-xs);
}
.switch-label input:checked + .switch { background: var(--color-primary); }
.switch-label input:checked + .switch::after { transform: translateX(-18px); }
.switch-label input:focus-visible + .switch { box-shadow: var(--shadow-focus); }

/* ═══ القارئ ═══ */
.reader-main { flex: 1; display: flex; flex-direction: column; align-items: center; padding: var(--space-5); overflow: hidden; }

.reader-book {
  flex: 1;
  width: 100%;
  max-width: 720px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.reader-page {
  width: min(600px, 100%);
  min-height: 420px;
  max-height: 62vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: var(--space-7) var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-slow) ease;
}
.reader-page.flip-left { transform: translateX(-110%) rotateY(12deg); opacity: 0; }
.reader-page.flip-right { transform: translateX(110%) rotateY(-12deg); opacity: 0; }

.reader-poem-title {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  font-weight: 700;
  margin-bottom: var(--space-5);
}
.reader-poem-body {
  font-family: var(--font-body);
  font-size: 1.15rem;
  line-height: 2.3;
  white-space: pre-line;
}
.reader-page-num {
  position: absolute;
  bottom: var(--space-4);
  inset-inline-start: 50%;
  transform: translateX(50%);
  font-size: var(--text-xs);
  color: var(--text-muted);
  opacity: 0.7;
}

.reader-controls { display: flex; align-items: center; gap: var(--space-5); padding: var(--space-4) 0; }
.btn-nav {
  padding: var(--space-2) var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur-fast) ease;
}
.btn-nav:hover { background: var(--color-primary); color: var(--text-on-brand); border-color: var(--color-primary); }
.btn-nav:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-nav:disabled:hover { background: var(--bg-surface); color: inherit; border-color: var(--border-default); }
.reader-progress { font-size: var(--text-sm); color: var(--text-muted); min-width: 64px; text-align: center; }

/* وضع السرد المتصل */
.reader-book.scroll-mode { grid-auto-flow: row; grid-template-columns: none; overflow-y: auto; gap: var(--space-5); padding: var(--space-4); display: block; }
.reader-book.scroll-mode .reader-page { max-height: none; margin-bottom: var(--space-5); }

/* ═══ المودالات ═══ */
.modal { position: fixed; inset: 0; z-index: var(--z-modal); display: none; align-items: center; justify-content: center; padding: var(--space-5); }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(31, 28, 23, 0.55); backdrop-filter: blur(3px); animation: fadeIn var(--dur-fast) ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-xl);
  animation: modalIn var(--dur-base) var(--ease-spring) both;
}
.modal-card-sm { max-width: 360px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(var(--space-4)) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
.modal-card h3 { font-family: var(--font-display); font-size: var(--text-h3); margin-bottom: var(--space-4); }
.modal-card p { color: var(--text-secondary); font-size: var(--text-sm); line-height: 1.7; }
.modal-card input[type="text"] {
  width: 100%;
  padding: var(--space-3);
  background: var(--bg-app);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: var(--text-body);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.modal-card input[type="text"]:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; margin-top: var(--space-5); }

/* لوحة المدير */
.admin-user-list { max-height: 320px; overflow-y: auto; }
.admin-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.admin-user-item:last-child { border-bottom: none; }
.admin-user-name { font-weight: 600; }
.admin-user-role { font-size: var(--text-xs); color: var(--text-muted); }
.admin-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-success);
}

/* ═══ الإشعار ═══ */
.toast {
  position: fixed;
  bottom: var(--space-6);
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(120%);
  background: var(--ink-900);
  color: var(--paper-0);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  transition: transform var(--dur-base) var(--ease-spring), opacity var(--dur-base) ease;
  pointer-events: none;
  max-width: calc(100vw - var(--space-6));
}
.toast.show { transform: translateX(50%) translateY(0); opacity: 1; }
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-error); }


/* ═══ الاستجابة — Mobile-first ═══ */

/* المصمّم: لوحتا معاينة + لوحة على الهاتف */
@media (max-width: 900px) {
  .designer-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .designer-preview { padding: var(--space-4); min-height: 46vh; }
  .designer-panel { max-height: 42vh; border-inline-start: none; border-top: 1px solid var(--border-subtle); }
}

/* المحرر + عامة */
@media (max-width: 700px) {
  .editor-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .editor-sidebar { border-inline-end: none; border-bottom: 1px solid var(--border-subtle); max-height: 34vh; }
  .topbar { padding: var(--space-2) var(--space-4); min-height: 56px; }
  .brand-text { font-size: var(--text-body); }
  .btn-icon { width: 36px; height: 36px; }
  :root { --text-hero: 2.4rem; }

  /* المكتبة على الهاتف: البحث بعرض كامل، والأسفل مضغوط */
  .home { padding-inline: clamp(14px, 4.5vw, 24px); }
  .home-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .search { width: 100%; }
  .bottom { grid-template-columns: 1fr; gap: 10px; }
  .side { display: none; }              /* هاتف: نترك مساحة للكتب */
  .recent .row:nth-child(n + 3) { display: none; }   /* صفّان فقط على الهاتف */
  .recent .row { padding-top: 9px; padding-bottom: 9px; }
  .home { padding-bottom: 58px; }
  .fab { padding: 13px 20px; font-size: 14.5px; bottom: 14px; right: 14px; }
  .fab .ic { width: 16px; height: 16px; }
}

/* ── توزيع الكتب: ٢ ← ٣ ← ٤ ← ٥ ← ٦ في الصف حسب العرض ── */
@media (min-width: 400px) { .books { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 640px) { .books { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 900px) { .books { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1360px) { .books { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* شاشات قصيرة: نضغط الرأس والأسفل ليبقى الرفّ مريحاً */
@media (max-height: 800px) {
  .home { padding-bottom: clamp(56px, 8vh, 72px); }
  .home-top { margin-bottom: clamp(6px, 1.2vh, 14px); }
  .home-top .btn-icon { width: 34px; height: 34px; }
  .greet h1 { font-size: clamp(37px, min(6.1vw, 8.7vh), 65px); }
  .greet .hi { margin-bottom: 4px; }
  .greet .meta { margin-top: 8px; }
  .rule { margin-top: clamp(12px, 2vh, 24px); }
  .shelf { margin-top: clamp(10px, 1.8vh, 22px); }
  .shelf-head { margin-bottom: clamp(8px, 1.2vh, 16px); }
  .bottom { margin-top: clamp(10px, 1.6vh, 22px); }
  .bottom h3 { margin-bottom: 2px; }
  .recent .row:nth-child(n + 3) { display: none; }   /* صفّان على الشاشات القصيرة */
}
@media (max-height: 700px) {
  .recent .row:nth-child(n + 2) { display: none; }   /* صف واحد فقط */
  .recent .row { padding-top: 7px; padding-bottom: 7px; }
  .side { display: none; }
}
@media (max-height: 560px) {
  .bottom { display: none; }   /* أصغر من ذلك: نُخفي الأسفل لصالح الرفّ */
}

/* أجهزة صغيرة جداً */
@media (max-width: 420px) {
  .poem-body-input { font-size: 1.05rem; }
  .greet .meta { gap: 10px; }
  .shelf-head span { display: none; }
}

/* أجهزة كبيرة جداً: نمنع اتساع الأسطر */
@media (min-width: 1500px) {
  .home { max-width: 1360px; }
}

/* ═══ إمكانية الوصول ═══ */
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══ الطباعة ═══ */
@media print {
  .topbar, .reader-controls, .toast { display: none !important; }
  .reader-book { overflow: visible; max-width: none; }
  .reader-page { box-shadow: none; page-break-after: always; max-height: none; width: 100%; }
}
