html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* الشريط العلوي */
.bar { flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 6px; background: var(--bg); }
.logo img { height: 36px; display: block; }
.date-btn { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 6px; background: none; border: 0;
  color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer; padding: 6px 4px; }
.date-btn > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.date-btn small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.date-btn svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }

/* الأقسام */
.chips { flex-shrink: 0; display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 10px; background: var(--bg); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); border-radius: 999px; padding: 7px 13px; font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .2s, border-color .2s; }
.chip small { font-family: "Montserrat", sans-serif; font-weight: 600; font-size: 11px; color: var(--muted); }
.chip.on { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); color: #fff; }
.chip.on small { color: rgba(255,255,255,.8); }

/* الكتاب */
.area { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: radial-gradient(ellipse at 50% 45%, #221F27 0%, #141217 55%, var(--bg) 100%); cursor: grab; }
.area.zoomed { cursor: move; }
.zoom { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.zoom.anim { transition: transform .22s ease-out; }
.book { position: absolute; perspective: 2400px; }
.slot, .leaf { position: absolute; top: 0; width: var(--pw); height: 100%; }
.slot { background: #fff; box-shadow: 0 12px 34px rgba(0,0,0,.5); }
.slot.empty { visibility: hidden; }
.slot img, .face img { display: block; width: 100%; height: 100%; background: #fff; pointer-events: none; -webkit-touch-callout: none; }
.spine { position: absolute; top: 0; bottom: 0; width: 70px; left: calc(var(--pw) - 35px); z-index: 2; pointer-events: none;
  background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,.16) 45%, rgba(0,0,0,.22) 50%, rgba(0,0,0,.16) 55%, rgba(0,0,0,0)); }
.leaf { z-index: 3; transform-style: preserve-3d; will-change: transform; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: #fff; overflow: hidden; }
.face.back { transform: rotateY(180deg); }
.face.blank { background: #F3F1EC; }
.face.blank img { visibility: hidden; }
.face .shade { position: absolute; inset: 0; opacity: 0; pointer-events: none; }

.v-nav { position: absolute; top: 50%; z-index: 5; width: 44px; height: 64px; margin-top: -32px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: rgba(33,30,37,.8); color: #fff; cursor: pointer; }
.v-nav svg { width: 24px; height: 24px; }
.v-next { left: 12px; }
.v-prev { right: 12px; }
.v-nav:disabled { opacity: 0; pointer-events: none; }
.v-zoom { position: absolute; bottom: 14px; left: 14px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.v-zoom .icon-btn { background: rgba(33,30,37,.85); }
@media (hover: none) { .v-nav, .v-zoom { display: none; } }
.v-hint { position: absolute; bottom: 14px; inset-inline: 0; margin: 0 auto; width: max-content; max-width: 90%; z-index: 5;
  background: rgba(33,30,37,.9); border-radius: 999px; padding: 7px 14px; font-size: 13px; pointer-events: none; }

/* الشريط السفلي */
.pager { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); }
.pager .icon-btn { width: 40px; height: 40px; }
.pager .icon-btn:disabled { opacity: .35; cursor: default; }
.pager-mid { flex: 1; min-width: 0; display: grid; gap: 2px; }
.pager-label { text-align: center; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pager-label b { color: var(--text); margin-inline-end: 6px; }
#slider { width: 100%; margin: 0; accent-color: var(--accent); height: 22px; }

/* وضع القراءة: كبسة بنص الصفحة بتخفي الشرائط */
body.focus .bar, body.focus .chips, body.focus .pager { display: none; }

.empty { flex: 1; display: grid; place-content: center; text-align: center; gap: 4px; padding: 24px; }
.empty img { width: 140px; margin: 0 auto 10px; }
.empty h1 { font-size: 20px; margin: 0; }
.empty p { color: var(--muted); margin: 0; }

/* القوائم */
.sheet-dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 0;
  width: min(560px, calc(100% - 24px)); max-height: min(82vh, 720px); }
.sheet-dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 1; }
.idx-sec { padding: 12px 16px 4px; font-weight: 800; }
.idx-sec::before { content: ""; display: inline-block; width: 5px; height: 16px; border-radius: 3px; background: var(--c); margin-inline-end: 8px; vertical-align: -2px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; padding: 8px 16px 14px; }
.thumb { display: grid; gap: 4px; padding: 0; border: 0; background: none; color: var(--text); text-decoration: none; font-size: 12px; text-align: center; cursor: pointer; }
.thumb img { width: 100%; aspect-ratio: .61; object-fit: cover; object-position: top; border-radius: 6px; background: #fff; border: 2px solid transparent; }
.thumb.cur img { border-color: var(--accent); }
.thumb b { font-weight: 700; }

/* التثبيت والحفظ */
.install-btn { display: inline-flex; align-items: center; gap: 5px; height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--accent);
  background: rgba(0,157,223,.12); color: var(--accent-2); font-weight: 700; font-size: 14px; cursor: pointer; }
.install-btn svg { width: 18px; height: 18px; }
@media (max-width: 420px) { .install-btn { width: 42px; padding: 0; justify-content: center; } .install-btn span { display: none; } }
.save-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px 0; }
.save-row .btn svg { width: 16px; height: 16px; }
.save-row .btn.done { border-color: var(--ok); color: var(--ok); }
.steps { margin: 0; padding: 16px 40px 20px 20px; display: grid; gap: 14px; line-height: 1.8; }
.steps svg { width: 22px; height: 22px; vertical-align: -5px; color: var(--accent-2); margin: 0 4px; }
#bellBtn svg { width: 16px; height: 16px; }
#bellBtn.on { border-color: var(--accent); color: var(--accent-2); }
.ask { position: fixed; inset-inline: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 40; max-width: 520px; margin: 0 auto;
  display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; padding: 14px 16px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.5); animation: askIn .3s ease-out; }
.ask > svg { width: 30px; height: 30px; color: var(--accent); }
.ask-text b { display: block; font-size: 15px; }
.ask-text span { color: var(--muted); font-size: 13px; }
.ask-acts { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
@keyframes askIn { from { opacity: 0; transform: translateY(16px); } }
.toast.link { pointer-events: auto; cursor: pointer; border-color: var(--accent); }
.offline-badge { position: fixed; bottom: calc(72px + env(safe-area-inset-bottom)); inset-inline: 0; margin: 0 auto; width: max-content; z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--muted); }
