/* ─────────────────────────────────────────────────────────────────────────
   The library — the hall fills the viewport; everything else floats over
   it in smoked glass. Book text is Amiri, the Bulaq-press naskh; the
   honorific ligatures Amiri lacks come from a tiny Scheherazade subset.
   ───────────────────────────────────────────────────────────────────────── */
@font-face { font-family: 'Amiri'; font-style: normal; font-weight: 400; font-display: swap; src: url('/assets/fonts/Amiri-400.woff2') format('woff2'); }
@font-face { font-family: 'Amiri'; font-style: normal; font-weight: 700; font-display: swap; src: url('/assets/fonts/Amiri-700.woff2') format('woff2'); }
@font-face { font-family: 'Honorifics'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('/assets/fonts/Honorifics.woff2') format('woff2'); unicode-range: U+FD40-FD4F, U+FDCF, U+FDFA, U+FDFE-FDFF; }

:root {
  --font-book: 'Amiri', 'Honorifics', 'Noto Naskh Arabic', 'Scheherazade New', serif;
  --glass: rgba(10, 12, 16, 0.62);
  --glass-strong: rgba(9, 11, 15, 0.86);
  --glass-line: rgba(212, 169, 71, 0.16);
  --lib-ease: cubic-bezier(0.2, 0.75, 0.15, 1);
}

.lib-page { overflow: hidden; }
/* The hall is the page: it starts under the (transparent) nav rather than
   below it, so it is exactly one screen tall and nothing pinned to its
   bottom falls off the end. */
.lib-page main { padding-top: 0; }
.lib-page .footer { display: none; }
.lib-page .toasts { z-index: 400; }
.lib-page .nav { background: linear-gradient(to bottom, rgba(5, 4, 3, 0.78), rgba(5, 4, 3, 0)); border-bottom-color: transparent; }
.lib-page .nav.scrolled { background: linear-gradient(to bottom, rgba(5, 4, 3, 0.78), rgba(5, 4, 3, 0)); -webkit-backdrop-filter: none; backdrop-filter: none; }
html.rd-open .nav { visibility: hidden; }

/* clip, not hidden: a hidden box is still a scroll container, and a
   phone scrolls it sideways to show a focused input — shifting the hall. */
.lib { position: relative; height: 100dvh; overflow: hidden; overflow: clip; background: #050302; isolation: isolate; }
.lib-stage { position: absolute; inset: 0; }
.lib-canvas { position: absolute; inset: 0; display: block; touch-action: none; outline: none; }
.no-webgl .lib-stage { background: radial-gradient(120% 80% at 50% 0%, #2a1a0d 0%, #0a0705 60%, #050302 100%); }

/* ── the veil while the hall loads ──────────────────────────────────────── */
.lib-veil {
  position: absolute; inset: 0; z-index: 2; display: grid; place-items: center;
  background: radial-gradient(90% 70% at 50% 40%, #1c120a 0%, #080503 70%);
  transition: opacity 1.1s var(--lib-ease), visibility 1.1s;
}
.lib-veil.gone { opacity: 0; visibility: hidden; }
.lib-veil-in { display: grid; justify-items: center; gap: 22px; transform: translateY(-4vh); }
.lib-veil-mark {
  font-family: var(--font-book); font-weight: 700; font-size: clamp(56px, 9vw, 104px); line-height: 1.2;
  background: linear-gradient(180deg, #f6dc9a 0%, #d4a947 45%, #8a6424 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 28px rgba(212, 169, 71, 0.25));
  animation: lib-breathe 3.2s ease-in-out infinite;
}
.lib-veil-bar { width: 180px; height: 1px; background: rgba(212, 169, 71, 0.16); overflow: hidden; }
.lib-veil-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold-bright)); transform-origin: left; transform: scaleX(0); transition: transform 0.6s var(--lib-ease); }
[dir='rtl'] .lib-veil-bar span { transform-origin: right; }
.lib-veil-text { font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-3); }
[lang='ar'] .lib-veil-text { letter-spacing: 0; font-size: 14px; }
@keyframes lib-breathe { 0%, 100% { opacity: 0.82; } 50% { opacity: 1; } }

/* ── overlay layer ──────────────────────────────────────────────────────── */
.lib-ui { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.lib-ui > * { pointer-events: auto; }
/* Words over the hall let the pointer through to the books behind them. */
.lib-ui > .lib-head, .lib-ui > .lib-hint, .lib-ui > .lib-floors { pointer-events: none; }
.lib-head .lib-search, .lib-floors ol, .lib-floor { pointer-events: auto; }

.lib-head {
  position: absolute; top: calc(var(--nav-h) + clamp(8px, 3vh, 36px)); left: 50%; transform: translateX(-50%);
  width: min(720px, calc(100% - 2 * var(--gutter))); text-align: center;
  display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 12px;
  transition: top 0.7s var(--lib-ease);
}
.lib-head .eyebrow { justify-content: center; }
.lib-title {
  font-weight: 500; letter-spacing: -0.035em; line-height: 1.02; font-size: clamp(34px, 5vw, 64px);
  text-wrap: balance; text-shadow: 0 2px 30px rgba(0, 0, 0, 0.8);
  background: linear-gradient(180deg, #fffaf0 0%, #e9dcc0 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
}
[lang='ar'] .lib-title { font-family: var(--font-book); font-weight: 700; letter-spacing: 0; line-height: 1.25; }
.lib-lead { color: rgba(242, 239, 230, 0.78); font-size: clamp(15px, 1.25vw, 17.5px); max-width: 56ch; text-wrap: pretty; text-shadow: 0 1px 14px rgba(0, 0, 0, 0.9); }
.lib-title, .lib-lead, .lib-stats, .lib-head .eyebrow { transition: opacity 0.5s var(--lib-ease), transform 0.6s var(--lib-ease), max-height 0.6s var(--lib-ease); }

.lib-search {
  position: relative; width: 100%; margin-top: 6px;
  display: flex; align-items: center; gap: 4px; height: 58px; padding: 0 6px 0 16px;
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: var(--radius);
  -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
[dir='rtl'] .lib-search { padding: 0 16px 0 6px; }
.lib-search { z-index: 6; }
.lib-search:focus-within { border-color: var(--gold-40); box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.9), 0 0 0 4px rgba(212, 169, 71, 0.08), 0 0 40px -10px rgba(212, 169, 71, 0.35); }
.lib-search-icon { width: 18px; height: 18px; color: var(--gold); flex: none; }
.lib-search-input { flex: 1; width: 0; min-width: 0; text-overflow: ellipsis; height: 100%; background: none; border: 0; outline: none; font-size: 16.5px; color: var(--ink); padding: 0 8px; font-family: var(--font-ui); }
.lib-search-input::placeholder { color: rgba(155, 163, 174, 0.75); }
.lib-search-input:not(:placeholder-shown) { font-family: var(--font-book), var(--font-ui); font-size: 19px; }
.lib-search-go { height: 44px; padding: 0 22px; }
.lib-search-clear { color: var(--ink-3); }

.lib-suggest {
  position: absolute; top: calc(100% + 8px); inset-inline: 0; z-index: 5; text-align: start;
  background: #0b0d12; border: 1px solid var(--glass-line); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: 6px; max-height: min(66vh, 620px); overflow-y: auto; overscroll-behavior: contain;
  animation: lib-drop 0.22s var(--lib-ease);
}
@keyframes lib-drop { from { opacity: 0; transform: translateY(-6px); } }
.lib-sug { display: flex; align-items: baseline; gap: 12px; width: 100%; padding: 10px 12px; border-radius: var(--radius); text-align: start; transition: background 0.15s; }
.lib-sug:hover, .lib-sug.active { background: rgba(212, 169, 71, 0.09); }
.lib-sug-line { align-items: center; color: var(--ink); font-size: 14px; }
.lib-sug-line svg { width: 16px; height: 16px; color: var(--gold); flex: none; }
.lib-sug-line q { font-family: var(--font-book); font-size: 17px; color: var(--gold-bright); quotes: '«' '»'; }
.lib-sug-line .kbd { margin-inline-start: auto; }
.lib-sug-label { padding: 10px 12px 4px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.lib-sug-t { font-family: var(--font-book); font-size: 18px; color: var(--ink); }
.lib-sug-a { font-family: var(--font-book); font-size: 14px; color: var(--ink-3); margin-inline-start: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.lib-sug > svg { width: 16px; height: 16px; color: var(--gold); flex: none; align-self: center; }
.lib-sug-t small { font-size: 13px; color: var(--ink-3); font-weight: 400; }
.lib-sug-n { margin-inline-start: auto; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.lib-sug-label .num { color: var(--gold); margin-inline-start: 6px; letter-spacing: 0; }
.lib-sug-kws { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 8px 8px; }
.lib-kw { width: auto; display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 12px; border: 1px solid var(--stroke); border-radius: 16px; font-family: var(--font-book); font-size: 17px; color: var(--ink); }
.lib-kw .num { font-family: var(--font-ui); font-size: 11px; color: var(--ink-3); }
.lib-kw:hover, .lib-kw.active { border-color: var(--gold-40); background: var(--gold-8); }

.lib-stats { display: flex; justify-content: center; gap: clamp(18px, 3vw, 40px); margin-top: 4px; }
.lib-stats div { display: grid; gap: 2px; text-align: center; }
.lib-stats dt { order: 2; font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
[lang='ar'] .lib-stats dt { letter-spacing: 0; font-size: 12.5px; }
.lib-stats dd { margin: 0; font-size: clamp(17px, 1.6vw, 22px); font-weight: 500; color: var(--ink); letter-spacing: -0.02em; text-shadow: 0 1px 12px rgba(0, 0, 0, 0.9); }

/* Once the reader is in the hall, the heading steps aside for the search. */
.lib.compact .lib-head { top: calc(var(--nav-h) + 4px); }
.lib.compact .lib-title, .lib.compact .lib-lead, .lib.compact .lib-stats, .lib.compact .lib-head .eyebrow { opacity: 0; transform: translateY(-10px); pointer-events: none; max-height: 0; overflow: hidden; margin: 0; }
.lib.compact .lib-head { gap: 0; }

/* ── floors ─────────────────────────────────────────────────────────────── */
.lib-floors { position: absolute; inset-inline-start: var(--gutter); top: 50%; transform: translateY(-38%); display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; max-width: calc(100vw - 2 * var(--gutter)); }
.lib-floors ol { min-width: 0; }
.lib-floors-label { font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; padding-inline-start: 14px; }
[lang='ar'] .lib-floors-label { letter-spacing: 0; font-size: 12.5px; }
.lib-floors ol { display: grid; gap: 1px; }
.lib-floor {
  position: relative; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 12px;
  width: 238px; padding: 8px 14px; text-align: start; border-radius: var(--radius);
  color: var(--ink-2); transition: color 0.25s, background 0.25s;
  animation: lib-in 0.7s var(--lib-ease) both; animation-delay: calc(var(--i, 0) * 40ms + 200ms);
}
.lib-floor::before { content: ''; position: absolute; inset-inline-start: 0; top: 8px; bottom: 8px; width: 2px; background: var(--gold); transform: scaleY(0); transition: transform 0.35s var(--lib-ease); }
.lib-floor:hover { color: var(--ink); background: rgba(10, 12, 16, 0.45); }
.lib-floor[aria-current] { color: var(--ink); background: rgba(10, 12, 16, 0.55); }
.lib-floor[aria-current]::before { transform: scaleY(1); }
.lib-floor-n { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.lib-floor[aria-current] .lib-floor-n { color: var(--gold); }
.lib-floor-name { display: grid; line-height: 1.2; min-width: 0; }
.lib-floor-ar { font-family: var(--font-book); font-size: 18px; font-weight: 700; color: inherit; text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9); }
.lib-floor-en { font-size: 11.5px; color: var(--ink-3); letter-spacing: 0.02em; }
[lang='ar'] .lib-floor-en { display: none; }
.lib-floor-count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.lib-floors li:nth-child(1) .lib-floor { --i: 1; } .lib-floors li:nth-child(2) .lib-floor { --i: 2; } .lib-floors li:nth-child(3) .lib-floor { --i: 3; }
.lib-floors li:nth-child(4) .lib-floor { --i: 4; } .lib-floors li:nth-child(5) .lib-floor { --i: 5; } .lib-floors li:nth-child(6) .lib-floor { --i: 6; }
.lib-floors li:nth-child(7) .lib-floor { --i: 7; } .lib-floors li:nth-child(8) .lib-floor { --i: 8; } .lib-floors li:nth-child(9) .lib-floor { --i: 9; }
@keyframes lib-in { from { opacity: 0; transform: translateX(-12px); } }
[dir='rtl'] .lib-floor { animation-name: lib-in-rtl; }
@keyframes lib-in-rtl { from { opacity: 0; transform: translateX(12px); } }

.lib-hint { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); font-size: 12px; letter-spacing: 0.08em; color: rgba(242, 239, 230, 0.5); white-space: nowrap; transition: opacity 1s; pointer-events: none; text-shadow: 0 1px 8px #000; }
[lang='ar'] .lib-hint { letter-spacing: 0; font-size: 13px; }
.lib-hint-touch { display: none; }
@media (pointer: coarse) { .lib-hint-mouse { display: none; } .lib-hint-touch { display: inline; } }
.lib.moved .lib-hint { opacity: 0; }

.lib-corner { position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); inset-inline-end: var(--gutter); display: flex; gap: 8px; }
.lib-corner .btn { background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-color: var(--glass-line); }
.lib-corner .btn svg { width: 15px; height: 15px; }

/* Continue reading: the last book, under the search box. */
.lib-continue-slot:empty { display: none; }
.lib-continue { position: relative; display: inline-flex; align-items: baseline; gap: 10px; max-width: 100%; padding: 8px 14px 10px; border: 1px solid var(--glass-line); border-radius: var(--radius); background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); overflow: hidden; transition: border-color 0.2s; }
.lib-continue:hover { border-color: var(--gold-40); }
.lib-continue::after { content: ''; position: absolute; inset-inline-start: 0; bottom: 0; height: 2px; width: var(--pct); background: var(--gold); }
.lib-continue-k { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); font-weight: 600; white-space: nowrap; }
[lang='ar'] .lib-continue-k { letter-spacing: 0; font-size: 13px; }
.lib-continue-t { font-family: var(--font-book); font-size: 17px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.lib-continue-p { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.lib.compact .lib-continue-slot { display: none; }

/* The history panel. */
.lib-hist-list { display: grid; gap: 2px; }
.lib-hist { position: relative; display: flex; align-items: stretch; border-bottom: 1px solid var(--stroke-soft); }
.lib-hist > a { position: relative; flex: 1; min-width: 0; display: grid; grid-template-columns: 6px 1fr; column-gap: 12px; row-gap: 2px; padding: 12px 8px 14px; border-radius: var(--radius); transition: background 0.2s; }
.lib-hist > a:hover { background: rgba(255, 255, 255, 0.03); }
.lib-hist .lib-res-spine { grid-row: 1 / span 3; }
.lib-hist-t { font-family: var(--font-book); font-size: 18px; font-weight: 700; color: var(--ink); line-height: 1.4; }
.lib-hist-a { font-family: var(--font-book); font-size: 14.5px; color: var(--ink-2); }
.lib-hist-m { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-3); }
.lib-hist-bar { position: absolute; inset-inline-start: 26px; inset-inline-end: 8px; bottom: 6px; height: 2px; background: var(--stroke); }
.lib-hist-bar::after { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: var(--pct); background: var(--gold); }
.lib-hist-x { align-self: center; color: var(--ink-3); flex: none; }
.lib-hist-x:hover { color: var(--danger); }
.lib-hist-empty { padding: 24px 8px; color: var(--ink-2); font-size: 14px; line-height: 1.6; }

/* Phones: one word about the bigger screen. */
.lib-phone-note { position: absolute; z-index: 12; inset-inline: 12px; bottom: calc(146px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; background: rgba(12, 14, 19, 0.96); border: 1px solid var(--gold-24); border-radius: 12px; box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.9); animation: lib-sheet 0.45s var(--lib-ease); transition: opacity 0.35s, transform 0.35s; }
.lib-phone-note.out { opacity: 0; transform: translateY(12px); }
.lib-phone-note svg { width: 26px; height: 26px; flex: none; color: var(--gold); }
.lib-phone-note p { flex: 1; font-size: 13px; line-height: 1.5; color: var(--ink); }
.lib-phone-note .btn { flex: none; }

.lib-tip {
  position: absolute; top: 0; left: 0; z-index: 6; pointer-events: none; display: grid; gap: 3px;
  max-width: 300px; padding: 12px 14px; text-align: start;
  background: var(--glass-strong); border: 1px solid var(--glass-line); border-radius: var(--radius);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); box-shadow: var(--shadow-2);
  font-size: 13px; color: var(--ink-2); line-height: 1.45; will-change: transform;
}
.lib-tip strong { font-family: var(--font-book); font-size: 19px; font-weight: 700; color: var(--ink); line-height: 1.35; }
.lib-tip [lang='ar'] { font-family: var(--font-book); font-size: 15px; }
.lib-tip-ed { color: var(--ink-3); font-size: 13px !important; }
.lib-tip-meta { font-size: 11.5px; color: var(--gold); letter-spacing: 0.02em; margin-top: 2px; }

/* ── panels: results and the catalogue ──────────────────────────────────── */
.lib-panel {
  position: absolute; z-index: 8; top: calc(var(--nav-h) + 76px); bottom: 14px; inset-inline-end: 14px;
  width: min(540px, calc(100% - 28px)); display: flex; flex-direction: column;
  background: var(--glass-strong); border: 1px solid var(--glass-line); border-radius: var(--radius);
  -webkit-backdrop-filter: blur(24px) saturate(140%); backdrop-filter: blur(24px) saturate(140%);
  box-shadow: 0 40px 100px -30px rgba(0, 0, 0, 0.95);
  animation: lib-panel 0.5s var(--lib-ease);
}
@keyframes lib-panel { from { opacity: 0; transform: translateX(24px); } }
[dir='rtl'] .lib-panel { animation-name: lib-panel-rtl; }
@keyframes lib-panel-rtl { from { opacity: 0; transform: translateX(-24px); } }
.lib-panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--stroke-soft); }
.lib-panel-head h2 { flex: 1; font-size: 15px; font-weight: 600; }
.lib-res-q { flex: 1; }
.lib-res-q .input { height: 40px; width: 100%; font-family: var(--font-book), var(--font-ui); font-size: 17px; background: rgba(0, 0, 0, 0.25); }
.lib-panel-body { overflow-y: auto; padding: 8px 16px 20px; }
.lib-results { overflow-y: auto; }
.lib-results > * { flex-shrink: 0; }
.lib-res-status { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: var(--ink-2); font-size: 14px; }
.lib-res-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; flex-wrap: wrap; }
.lib-res-count { font-size: 14px; color: var(--ink); font-weight: 500; }
.lib-modes button { height: 30px; padding: 0 12px; font-size: 12.5px; color: var(--ink-2); border-radius: var(--radius); }
.lib-modes button.on { background: var(--gold-14); color: var(--gold-bright); }
.lib-facets { display: flex; gap: 6px; padding: 8px 16px 12px; overflow-x: auto; scrollbar-width: none; mask-image: linear-gradient(to right, #000 92%, transparent); }
[dir='rtl'] .lib-facets { mask-image: linear-gradient(to left, #000 92%, transparent); }
.lib-facets::-webkit-scrollbar { display: none; }
.lib-facets .chip { white-space: nowrap; height: 30px; padding: 0 12px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--stroke); border-radius: 15px; color: var(--ink-2); flex: none; transition: all 0.2s; }
.lib-facets .chip .num { color: var(--ink-3); font-size: 11.5px; }
.lib-facets .chip:hover { border-color: var(--stroke-strong); color: var(--ink); }
.lib-facets .chip.on { border-color: var(--gold-40); background: var(--gold-8); color: var(--gold-bright); }
.lib-res-list { padding: 0 8px; }
.lib-res { position: relative; padding: 12px 8px 14px; border-top: 1px solid var(--stroke-soft); animation: lib-up 0.45s var(--lib-ease) both; }
@keyframes lib-up { from { opacity: 0; transform: translateY(8px); } }
.lib-res-book { display: grid; grid-template-columns: 6px 1fr; column-gap: 12px; row-gap: 2px; padding: 4px 6px; border-radius: var(--radius); transition: background 0.2s; }
.lib-res-book:hover { background: rgba(255, 255, 255, 0.025); }
.lib-res-spine { grid-row: 1 / span 3; border-radius: 1px; background: linear-gradient(180deg, hsl(var(--h) 45% 28%), hsl(var(--h) 40% 18%)); box-shadow: inset 0 3px 0 rgba(212, 169, 71, 0.6), inset 0 -3px 0 rgba(212, 169, 71, 0.6); }
.lib-res-t { font-family: var(--font-book); font-size: 19px; font-weight: 700; color: var(--ink); line-height: 1.4; }
.lib-res-ed { font-weight: 400; font-size: 14px; color: var(--ink-3); }
.lib-res-a { font-family: var(--font-book); font-size: 15px; color: var(--ink-2); }
.lib-res-c { font-size: 12px; color: var(--ink-3); }
.lib-res.exact .lib-res-c::after { content: '✓'; margin-inline-start: 8px; color: var(--gold); font-weight: 700; }
.lib-res-snips { display: grid; gap: 6px; padding-inline-start: 24px; margin-top: 6px; }
.lib-snip { display: block; font-family: var(--font-book); font-size: 17px; line-height: 1.85; color: rgba(242, 239, 230, 0.8); padding: 6px 10px; border-inline-start: 1px solid var(--stroke); transition: border-color 0.2s, background 0.2s; }
.lib-snip:hover { border-color: var(--gold); background: rgba(212, 169, 71, 0.04); }
.lib-snip mark, .lib-res-line mark, .rd mark { background: rgba(212, 169, 71, 0.26); color: inherit; border-radius: 2px; box-shadow: 0 0 0 2px rgba(212, 169, 71, 0.26); }
.lib-snip-wait { display: block; height: 14px; width: 70%; border-radius: 2px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.03)); background-size: 200% 100%; animation: lib-shimmer 1.4s linear infinite; }
@keyframes lib-shimmer { to { background-position: -200% 0; } }
.lib-res-foot { display: grid; justify-items: center; gap: 10px; padding: 16px 16px 24px; text-align: center; }
.lib-res-end { height: 1px; }
.lib-sorts { display: flex; gap: 2px; padding: 4px 16px 6px; overflow-x: auto; scrollbar-width: none; }
.lib-sorts::-webkit-scrollbar { display: none; }
.lib-sorts button { height: 30px; padding: 0 12px; font-size: 12.5px; color: var(--ink-3); border-bottom: 2px solid transparent; white-space: nowrap; transition: color 0.2s, border-color 0.2s; }
.lib-sorts button:hover { color: var(--ink); }
.lib-sorts button[aria-selected='true'] { color: var(--gold-bright); border-bottom-color: var(--gold); }
.lib-res-sec { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 6px -8px 0; padding: 10px 16px 8px; background: rgba(9, 11, 15, 0.96); border-bottom: 1px solid var(--gold-24); font-size: 13px; font-weight: 600; color: var(--gold-bright); }
.lib-res-sec .num { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.lib-res-all { margin: 8px 0 0; margin-inline-start: 24px; font-size: 12.5px; color: var(--gold); border-bottom: 1px dashed var(--gold-40); padding-bottom: 1px; }
.lib-res-all:hover { color: var(--gold-bright); }
.lib-res-pages { margin: 8px 0 0; margin-inline-start: 24px; display: grid; gap: 2px; border-inline-start: 1px solid var(--stroke); }
.lib-res-pages a { display: grid; gap: 2px; padding: 6px 12px; border-radius: var(--radius); }
.lib-res-pages a:hover { background: rgba(212, 169, 71, 0.05); }
.lib-res-where { font-size: 11.5px; color: var(--gold); }
.lib-res-line { font-family: var(--font-book); font-size: 15.5px; line-height: 1.75; color: rgba(242, 239, 230, 0.75); min-height: 1.2em; }
.lib-res-pages-end { height: 1px; }
.lib-dym { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 4px 16px 10px; font-size: 13px; color: var(--ink-2); }
.lib-dym .chip { height: 30px; padding: 0 12px; border: 1px solid var(--gold-40); border-radius: 15px; font-family: var(--font-book); font-size: 16px; color: var(--gold-bright); }
.lib-list-title { flex: 1; font-family: var(--font-book); font-size: 19px; font-weight: 700; }
.lib-list-count { padding: 12px 16px 4px; }
.lib-list { padding: 0 12px 20px; }

.lib-shelf { padding: 14px 0; border-bottom: 1px solid var(--stroke-soft); }
.lib-shelf h3 { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.lib-shelf h3 [lang='ar'] { font-family: var(--font-book); font-size: 19px; }
.lib-shelf ul > li > button { display: flex; align-items: baseline; gap: 10px; width: 100%; padding: 7px 8px; text-align: start; border-radius: var(--radius); transition: background 0.2s; }
.lib-shelf ul > li > button:hover { background: rgba(255, 255, 255, 0.03); }
.lib-shelf ul > li > button [lang='ar'] { font-family: var(--font-book); font-size: 16.5px; }
.lib-shelf ul > li > button [lang='en'] { font-size: 12px; }
.lib-shelf ul > li > button .num { margin-inline-start: auto; font-size: 12px; }
[lang='ar'] .lib-shelf [lang='en'] { display: none; }
.lib-booklist { padding: 4px 0 10px; display: grid; }
.lib-bookrow { display: grid; padding: 6px 10px 6px 18px; border-inline-start: 1px solid var(--stroke); }
.lib-bookrow:hover { border-color: var(--gold); }
.lib-bookrow-t { font-family: var(--font-book); font-size: 16.5px; color: var(--ink); }
.lib-bookrow-a { font-family: var(--font-book); font-size: 13.5px; color: var(--ink-3); }

/* ── the reader ─────────────────────────────────────────────────────────── */
.lib-reader { position: fixed; inset: 0; z-index: 160; }
.rd-backdrop { position: absolute; inset: 0; background: rgba(4, 3, 2, 0.72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.rd {
  --rd-size: 21px;
  --rd-bg: #0e1015;
  --rd-ink: #ebe5d6;
  --rd-ink-2: #a49c8c;
  --rd-line: rgba(212, 169, 71, 0.14);
  position: absolute; inset: clamp(0px, 2.2vh, 22px) clamp(0px, 3vw, 44px);
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
  background: var(--rd-bg); color: var(--rd-ink); border: 1px solid var(--rd-line); border-radius: var(--radius);
  box-shadow: 0 50px 140px -30px rgba(0, 0, 0, 1);
}
.rd.paper { --rd-bg: #f2e9d6; --rd-ink: #2b2117; --rd-ink-2: #7a6a55; --rd-line: rgba(120, 90, 40, 0.22); color-scheme: light; }
.rd.paper mark { background: rgba(196, 140, 40, 0.28); box-shadow: 0 0 0 2px rgba(196, 140, 40, 0.28); }
.rd.paper .icon-btn { color: #5d4d39; }
.rd.paper .rd-bar, .rd.paper .rd-foot { background: rgba(242, 233, 214, 0.92); }
.rd.paper .rd-side { background: #ebe0c9; }
.rd.paper .input { background: #fff8ea; color: #2b2117; border-color: rgba(120, 90, 40, 0.25); }
.rd-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--rd-line); background: rgba(14, 16, 21, 0.94); min-width: 0; position: relative; z-index: 4; }
.rd-back { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px 0 8px; border: 1px solid var(--rd-line); border-radius: var(--radius); color: var(--rd-ink); font-size: 13.5px; font-weight: 500; flex: none; transition: border-color 0.2s, background 0.2s; }
[dir='rtl'] .rd-back { padding: 0 8px 0 12px; }
.rd-back svg { width: 18px; height: 18px; }
.rd-back:hover { border-color: var(--gold-40); background: rgba(212, 169, 71, 0.06); }
.rd-btn { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 11px; border-radius: var(--radius); color: var(--rd-ink); font-size: 13px; font-weight: 500; white-space: nowrap; border: 1px solid transparent; transition: background 0.2s, color 0.2s, border-color 0.2s; }
.rd-btn svg { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.rd-btn:hover { background: rgba(255, 255, 255, 0.05); border-color: var(--rd-line); }
.rd-btn.on, .rd-btn[aria-expanded='true'], .rd-btn[aria-pressed='true'] { color: var(--gold-bright); background: rgba(212, 169, 71, 0.1); border-color: var(--gold-24); }
.rd-btn-gold { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.rd-btn-gold:hover, .rd-btn-gold[aria-expanded='true'] { background: var(--gold-bright); color: var(--gold-ink); border-color: var(--gold-bright); }
.rd-size { display: inline-flex; border: 1px solid var(--rd-line); border-radius: var(--radius); overflow: hidden; flex: none; }
.rd-size button { direction: ltr; height: 38px; padding: 0 10px; color: var(--rd-ink); font-size: 13px; font-weight: 600; display: inline-flex; align-items: baseline; gap: 1px; transition: background 0.2s; }
.rd-size button + button { border-inline-start: 1px solid var(--rd-line); }
.rd-size button:hover { background: rgba(255, 255, 255, 0.05); }
.rd-a-small { font-size: 12px; } .rd-a-big { font-size: 16px; }
.rd-menu-wrap { position: relative; flex: none; }
.rd-menu { position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 20; width: 340px; padding: 6px; display: grid; gap: 2px; background: #12151c; border: 1px solid var(--glass-line); border-radius: var(--radius); box-shadow: 0 24px 60px -16px rgba(0, 0, 0, 0.85); animation: lib-drop 0.2s var(--lib-ease); text-align: start; }
.rd-menu > button, .rd-formats > button { display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 10px 12px; border-radius: var(--radius); text-align: start; color: var(--ink); transition: background 0.15s; }
.rd-menu > button:hover, .rd-formats > button:hover:not(:disabled) { background: rgba(212, 169, 71, 0.08); }
.rd-menu svg { width: 20px; height: 20px; flex: none; margin-top: 2px; color: var(--gold); }
.rd-menu b { display: block; font-size: 14px; font-weight: 600; }
.rd-menu small { display: block; font-size: 12px; color: var(--ink-3); line-height: 1.45; margin-top: 2px; }
.rd-menu small[data-rd-link-preview] { overflow-wrap: anywhere; direction: ltr; text-align: start; }
.rd-dl-menu { width: 380px; padding: 12px; gap: 10px; }
.rd-menu-title { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; padding: 2px 4px; }
[lang='ar'] .rd-menu-title { letter-spacing: 0; font-size: 13px; }
.rd-scope { display: flex; flex-wrap: wrap; gap: 6px; }
.rd-scope button { height: 32px; padding: 0 12px; border: 1px solid var(--stroke); border-radius: 16px; font-size: 12.5px; color: var(--ink-2); transition: all 0.15s; }
.rd-scope button[aria-checked='true'] { border-color: var(--gold-40); background: var(--gold-8); color: var(--gold-bright); }
.rd-range-in { display: flex; gap: 10px; }
.rd-range-in label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-3); flex: 1; }
.rd-range-in .input { height: 36px; width: 100%; }
.rd-scope-note { font-size: 12px; color: var(--gold); line-height: 1.45; padding: 0 4px; }
.rd-formats { display: grid; gap: 2px; border-top: 1px solid var(--stroke-soft); padding-top: 6px; }
.rd-formats > button:disabled { opacity: 0.38; cursor: not-allowed; }
.rd-formats svg { width: 22px; height: 22px; flex: none; margin-top: 1px; color: var(--gold); }
.rd.paper .rd-back, .rd.paper .rd-btn:not(.rd-btn-gold), .rd.paper .rd-size button { color: #3d2f1f; }
.rd.paper .rd-btn:hover { background: rgba(120, 90, 40, 0.08); }
.rd.paper .rd-btn.on, .rd.paper .rd-btn[aria-expanded='true']:not(.rd-btn-gold), .rd.paper .rd-btn[aria-pressed='true'] { color: #8a5a12; background: rgba(160, 110, 30, 0.12); border-color: rgba(160, 110, 30, 0.3); }
.rd.paper .rd-bar { background: rgba(236, 226, 205, 0.96); }
.rd-titles { flex: 1; min-width: 0; display: grid; }
.rd-title { font-family: var(--font-book); font-size: 21px; font-weight: 700; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-author { font-family: var(--font-book); font-size: 14.5px; color: var(--rd-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.rd-sep { width: 1px; height: 22px; background: var(--rd-line); margin: 0 4px; flex: none; }
/* Labels stay as long as there is room: the secondary ones go first. */
@media (max-width: 1140px) { .rd-tools .rd-more-item span:not(.rd-a-small):not(.rd-a-big), .rd-tools [data-rd-menu='share'] span { display: none; } }
@media (max-width: 980px) { .rd-tools .rd-btn:not(.rd-btn-gold) span { display: none; } .rd-tools .rd-btn:not(.rd-btn-gold) { padding: 0 10px; } }
.rd-main { position: relative; display: flex; min-height: 0; }
.rd-side { width: 340px; flex: none; border-inline-end: 1px solid var(--rd-line); background: #0b0d11; overflow: hidden; display: grid; min-height: 0; }
.rd-side-pane { overflow-y: auto; padding: 14px; min-height: 0; }
.rd-toc li a { display: flex; gap: 10px; align-items: baseline; padding: 6px 10px; padding-inline-start: calc(10px + var(--d, 0) * 14px); font-family: var(--font-book); font-size: 16px; line-height: 1.55; color: var(--rd-ink); border-radius: var(--radius); }
.rd-toc li a:hover { background: rgba(212, 169, 71, 0.07); }
.rd-toc li a .num { margin-inline-start: auto; font-size: 12px; font-family: var(--font-ui); }
.rd-toc li[style*='--d:0'] a { font-weight: 700; }
.rd-find .input { width: 100%; font-family: var(--font-book), var(--font-ui); font-size: 17px; }
.rd-find-count { font-size: 12.5px; margin: 12px 4px 6px; }
.rd-find-list a { display: grid; gap: 2px; padding: 8px 10px; border-radius: var(--radius); }
.rd-find-list a:hover { background: rgba(212, 169, 71, 0.07); }
.rd-find-where { font-size: 12px; color: var(--gold); font-family: var(--font-ui); }
.rd-find-snip { font-family: var(--font-book); font-size: 15.5px; line-height: 1.7; color: var(--rd-ink-2); }
.rd-card p { font-family: var(--font-book); font-size: 16px; line-height: 1.8; margin-bottom: 4px; }
.rd-card b { color: var(--gold); font-weight: 700; }
.rd-card-src { font-size: 12px; font-family: var(--font-ui); margin-top: 14px; }
.rd-none { color: var(--rd-ink-2); font-size: 14px; padding: 10px; }
.rd-failed { text-align: center; padding: 18vh 20px; font-family: var(--font-ui); }
.rd-scroll { flex: 1; min-width: 0; overflow-y: auto; overscroll-behavior: contain; outline: none; scroll-behavior: auto; }
.fn { font-family: var(--font-ui); font-size: 0.55em; vertical-align: super; line-height: 0; color: var(--gold); padding: 0 1px; }
.fn-n { display: inline-block; min-width: 1.4em; font-family: var(--font-ui); font-size: 0.8em; color: var(--gold); }
.rd.paper .fn, .rd.paper .fn-n { color: #8a5a12; }
.rd.paper .icon-btn:hover, .rd.paper .icon-btn:focus-visible { background: rgba(120, 90, 40, 0.1); color: #2b2117; }
.rd-pages { max-width: 780px; margin: 0 auto; padding: 28px clamp(18px, 4vw, 48px) 120px; font-family: var(--font-book); font-size: var(--rd-size); line-height: 2.05; text-align: justify; text-justify: inter-word; }
.rd-loading { display: grid; place-items: center; height: 40vh; }
.pg { padding: 6px 0 34px; }
.pg + .pg, .rd-chunk + .rd-chunk .pg:first-child { border-top: 1px solid var(--rd-line); }
.pg-head { display: flex; justify-content: center; margin: 14px 0 18px; }
.pg-head span { font-family: var(--font-ui); font-size: 11.5px; letter-spacing: 0.06em; color: var(--rd-ink-2); padding: 3px 10px; border: 1px solid var(--rd-line); border-radius: 12px; direction: ltr; unicode-bidi: plaintext; }
[lang='ar'] .pg-head span, .rd-pages .pg-head span { font-family: var(--font-arabic-ui); letter-spacing: 0; }
.pg-body p { margin: 0 0 0.35em; }
.pg-h { font-size: 1.12em; font-weight: 700; color: var(--gold); margin: 0.9em 0 0.4em; line-height: 1.6; text-align: start; }
.rd.paper .pg-h { color: #8a5a12; }
.pg-notes { margin-top: 1.2em; padding-top: 0.8em; border-top: 1px solid var(--rd-line); font-size: 0.78em; line-height: 1.9; color: var(--rd-ink-2); }
.pg-notes p { margin: 0 0 0.2em; }
.pg-empty { text-align: center; color: var(--rd-ink-2); }
.rd-foot { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--rd-line); background: rgba(14, 16, 21, 0.92); }
.rd-range { flex: 1; }
.rd-where { font-size: 12.5px; color: var(--rd-ink-2); white-space: nowrap; min-width: 150px; text-align: center; font-family: var(--font-ui); }
[lang='ar'] .rd-where { font-family: var(--font-arabic-ui); }
.rd-dl { position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--glass-strong); border: 1px solid var(--glass-line); border-radius: var(--radius); font-size: 13px; color: var(--ink); }
.rd-dl-bar { width: 140px; height: 2px; background: var(--stroke); overflow: hidden; }
.rd-dl-bar span { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); transition: transform 0.2s; }

/* ── small screens ──────────────────────────────────────────────────────── */
@media (max-width: 1240px) and (min-width: 861px) {
  .lib-floors { top: auto; bottom: 54px; transform: none; inset-inline: 0; padding: 0 var(--gutter); display: flex; justify-content: center; }
  .lib-floors-label { display: none; }
  .lib-floors ol { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
  .lib-floor { width: auto; grid-template-columns: auto auto; padding: 6px 12px; background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid var(--glass-line); }
  .lib-floor-n, .lib-floor-en { display: none; }
  .lib-floor::before { inset-inline-start: 10px; inset-inline-end: 10px; top: auto; bottom: 0; width: auto; height: 2px; transform: scaleX(0); }
  .lib-floor[aria-current]::before { transform: scaleX(1); }
  .lib-floor-ar { font-size: 15.5px; }
  .lib-corner { bottom: 100px; }
}
@media (max-width: 860px) {
  .lib-head { top: calc(var(--nav-h) + 2px); gap: 8px; }
  .lib-title { font-size: clamp(28px, 8vw, 40px); }
  .lib-lead { font-size: 14px; }
  .lib-stats { gap: 18px; }
  .lib-search { height: 52px; }
  .lib-search-input { font-size: 15px; }
  .lib-search-go { display: none; }
  .lib-floors { top: auto; bottom: 44px; transform: none; inset-inline: 0; padding: 0 var(--gutter); }
  .lib-floors-label { display: none; }
  .lib-floors ol { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x mandatory; padding-bottom: 2px; }
  .lib-floors li { flex: none; }
  .lib-floor-en { display: none; }
  .lib-floor-count { font-size: 11px; }
  .lib-floors ol::-webkit-scrollbar { display: none; }
  .lib-floor { width: auto; grid-template-columns: auto auto; padding: 6px 12px; background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid var(--glass-line); scroll-snap-align: start; white-space: nowrap; }
  .lib-floor-n { display: none; }
  .lib-floor::before { inset-inline-start: 10px; inset-inline-end: 10px; top: auto; bottom: 0; width: auto; height: 2px; transform: scaleX(0); }
  .lib-floor[aria-current]::before { transform: scaleX(1); }
  .lib-floor-ar { font-size: 15.5px; }
  .lib-hint { bottom: 16px; font-size: 11.5px; }
  .lib-corner { bottom: calc(92px + env(safe-area-inset-bottom)); }
  .lib-floors { bottom: calc(44px + env(safe-area-inset-bottom)); }
  .lib-hint { bottom: calc(16px + env(safe-area-inset-bottom)); }
  .lib-continue { padding: 7px 12px 9px; }
  .lib-continue-t { font-size: 16px; }
  .lib-panel { top: auto; bottom: 0; inset-inline: 0; width: 100%; height: min(74dvh, 680px); border-radius: 14px 14px 0 0; animation-name: lib-sheet; padding-bottom: env(safe-area-inset-bottom); }
  [dir='rtl'] .lib-panel { animation-name: lib-sheet; }
  .lib-tip { display: none; }
  .rd { inset: 0; border: 0; border-radius: 0; }
  .rd-side { position: absolute; inset: 0; z-index: 3; width: 100%; }
  .rd-bar { flex-wrap: wrap; row-gap: 6px; padding: 8px 10px; }
  .rd-back span { display: none; }
  .rd-back { padding: 0 8px; }
  .rd-titles { flex: 1 1 calc(100% - 60px); }
  .rd-tools { width: 100%; justify-content: space-between; gap: 2px; }
  .rd-sep { display: none; }
  .rd-btn-gold span { display: none; }
  .rd-btn-gold { padding: 0 12px; }
  .rd-menu, .rd-dl-menu { position: fixed; top: auto; bottom: 0; inset-inline: 0; width: auto; border-radius: 14px 14px 0 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); animation-name: lib-sheet; }
  .rd-title { font-size: 18px; }
  .rd-where { min-width: 0; font-size: 11.5px; }
}
@keyframes lib-sheet { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .lib *, .lib *::before { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
