/* ============================================================
   The reading room — قراءة مباشرة
   Full-screen e-reader chrome around a PDF.js canvas.
   Themes: paper (ivory) / sepia (manuscript) / dark (night).
   ============================================================ */
:root {
    --rd-gold: #C9A15C;
    --rd-gold-deep: #A8814A;
    --rd-green: #0f3d2e;
    --rd-bg: #efe9df;
    --rd-chrome: rgba(250, 248, 244, .88);
    --rd-chrome-tx: #123528;
    --rd-paper-shadow: 0 2px 6px rgba(20, 24, 20, .10), 0 14px 34px rgba(20, 24, 20, .14), 0 40px 90px rgba(20, 24, 20, .12);
    --rd-ease: cubic-bezier(.22, 1, .36, 1)}
* { box-sizing: border-box; margin: 0; padding: 0}
html, body { height: 100%}
body {
    font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif;
    background: var(--rd-bg);
    background-image: /* layered room light: warm top glow + corner shade + faint weave */
        radial-gradient(70% 55% at 50% 0%, rgba(255, 255, 255, .5), transparent 70%),
        radial-gradient(50% 40% at 100% 100%, rgba(201, 161, 92, .06), transparent 70%),
        radial-gradient(rgba(120, 100, 60, .05) 1px, transparent 1.5px);
    background-size: auto, auto, 26px 26px;
    color: var(--rd-chrome-tx);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent}

/* ---- themes ---- */
body.theme-sepia { --rd-bg: #e7dcc5; --rd-chrome: rgba(240, 231, 210, .9); --rd-chrome-tx: #4a3a22}
body.theme-sepia #rdCanvas { filter: sepia(.38) saturate(.9) contrast(.97)}
body.theme-dark { --rd-bg: #121815; --rd-chrome: rgba(20, 27, 23, .88); --rd-chrome-tx: #e7dfd0; background-image: radial-gradient(70% 55% at 50% 0%, rgba(201, 161, 92, .05), transparent 70%)}
body.theme-dark #rdCanvas { filter: invert(.93) hue-rotate(180deg) contrast(.92) brightness(1.02)}
body.theme-dark .rd-paper { box-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 14px 34px rgba(0, 0, 0, .4)}

/* ---- top gold reading progress ---- */
.rd-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 60; background: transparent}
.rd-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--rd-gold-deep), var(--rd-gold)); transition: width .4s var(--rd-ease)}

/* ---- chrome: floating glass cards, not full-width strips ---- */
.rd-top, .rd-bottom {
    position: fixed; z-index: 50;
    left: max(10px, env(safe-area-inset-left, 0px)); right: max(10px, env(safe-area-inset-right, 0px));
    display: flex; align-items: center; gap: .5rem;
    background: var(--rd-chrome);
    -webkit-backdrop-filter: blur(16px) saturate(150%); backdrop-filter: blur(16px) saturate(150%);
    border: 1px solid rgba(201, 161, 92, .3); border-radius: 16px;
    box-shadow: 0 2px 6px rgba(20, 24, 20, .08), 0 12px 32px rgba(20, 24, 20, .12);
    transition: transform .35s var(--rd-ease), opacity .35s ease}
.rd-top { top: calc(10px + env(safe-area-inset-top, 0px)); padding: .4rem .7rem}
.rd-bottom { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); padding: .4rem .7rem}
body.rd-idle .rd-top { transform: translateY(-130%); opacity: 0}
body.rd-idle .rd-bottom { transform: translateY(130%); opacity: 0}
body.rd-idle { cursor: none}
.rd-sep { flex: none; width: 1px; height: 22px; background: linear-gradient(rgba(201, 161, 92, 0), rgba(201, 161, 92, .55), rgba(201, 161, 92, 0)); margin: 0 .25rem}

.rd-title {
    flex: 1 1 auto; min-width: 0; font-size: .95rem; font-weight: 700; text-align: center;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap}
.rd-tools { display: flex; align-items: center; gap: .15rem}

.rd-btn {
    flex: none; display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent;
    color: inherit; cursor: pointer; text-decoration: none;
    transition: background .25s ease, filter .25s ease, transform .15s ease}
.rd-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round}
.rd-btn:hover { background: rgba(201, 161, 92, .14); filter: brightness(1.08)}
.rd-btn:active { transform: scale(.94)}
.rd-btn.on { color: var(--rd-gold-deep); background: rgba(201, 161, 92, .16)}
.rd-btn.on svg { fill: rgba(201, 161, 92, .35)}

/* ---- the page ---- */
.rd-stage {
    position: fixed; inset: 0; overflow: auto; display: grid;
    padding: calc(78px + env(safe-area-inset-top, 0px)) 14px calc(96px + env(safe-area-inset-bottom, 0px));
    scrollbar-width: thin}
.rd-paper {
    position: relative; border-radius: 10px; overflow: hidden;
    margin: auto; /* centers small pages; unlike place-items:center, tall pages stay scrollable from the top */
    background: #fbf8f1;
    box-shadow: /* five layers: contact → lift → mid → deep → ambient */
        0 1px 2px rgba(20, 24, 20, .08),
        0 4px 10px rgba(20, 24, 20, .08),
        0 14px 30px rgba(20, 24, 20, .10),
        0 36px 70px rgba(20, 24, 20, .10),
        0 8px 60px rgba(20, 24, 20, .05);
    transition: opacity .22s ease, transform .22s var(--rd-ease), box-shadow .22s ease; /* the paper is alive, barely */
}

.rd-paper.turning { opacity: 0; transform: translateX(-16px) translateY(-6px) scale(.994)}
.rd-paper.turning.back { transform: translateX(16px) translateY(-6px) scale(.994)}
#rdCanvas { display: block; max-width: 100%; height: auto}
.rd-paper::after { /* inner page edge light — the printed feel */
    content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: 10px;
    box-shadow: inset 0 0 0 1px rgba(120, 100, 60, .10), inset 0 1px 0 rgba(255, 255, 255, .5)}
.rd-skeleton {
    position: absolute; inset: 0; z-index: 1;
    background: linear-gradient(100deg, #efe9dd 40%, #f7f2e8 50%, #efe9dd 60%);
    background-size: 240% 100%;
    animation: rdShimmer 1.4s ease-in-out infinite}
.rd-skeleton.off { display: none}
@keyframes rdShimmer { from { background-position: 130% 0} to { background-position: -130% 0} }

/* golden bookmark ribbon slides in from the top of the page */
.rd-ribbon {
    position: absolute; top: -46px; inset-inline-start: 22px; width: 22px; height: 40px; z-index: 2;
    background: linear-gradient(180deg, var(--rd-gold), var(--rd-gold-deep));
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
    filter: drop-shadow(0 3px 5px rgba(20, 24, 20, .25));
    transition: top .45s var(--rd-ease)}
.rd-ribbon.in { top: -2px}

/* ---- bottom scrubber + reading meta ---- */
.rd-scrub { flex: 1 1 auto; display: flex; flex-direction: column; gap: .1rem; min-width: 0}
.rd-scrub__row { display: flex; align-items: center; gap: .9rem; min-width: 0}
.rd-pageinfo { flex: none; font-size: .85rem; font-weight: 700; color: var(--rd-chrome-tx); opacity: .85; direction: ltr}
#rdScrub { flex: 1 1 auto; min-width: 0; direction: rtl; accent-color: var(--rd-gold-deep); height: 4px; cursor: pointer}
.rd-meta { text-align: center; font-size: .72rem; opacity: .65; min-height: 1em}

/* keyboard focus is visible and golden */
.rd-btn:focus-visible, #rdScrub:focus-visible, .rd-item:focus-visible { outline: 2px solid var(--rd-gold-deep); outline-offset: 2px}

/* the chapter you are inside right now */
.rd-item.now { background: rgba(201, 161, 92, .16)}
.rd-item.now::before { content: "◈ "; color: var(--rd-gold-deep)}

/* ---- drawer (TOC / bookmarks / search) ---- */
.rd-drawer {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(360px, 92vw); z-index: 70;
    display: flex; flex-direction: column;
    background: var(--rd-chrome);
    -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%);
    border-inline-end: 1px solid rgba(201, 161, 92, .3);
    box-shadow: 12px 0 40px rgba(20, 24, 20, .18);
    transform: translateX(105%);
    transition: transform .4s var(--rd-ease);
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px)}
.rd-drawer.open { transform: translateX(0)}
.rd-drawer__head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.1rem .6rem}
.rd-drawer__title { font-size: 1.05rem; font-weight: 800}
.rd-drawer__search { padding: 0 1.1rem .6rem}
.rd-drawer__search input {
    width: 100%; padding: .6rem .9rem; border-radius: 12px; border: 1px solid rgba(201, 161, 92, .4);
    background: rgba(255, 255, 255, .55); color: inherit; font: inherit; outline: none}
body.theme-dark .rd-drawer__search input { background: rgba(0, 0, 0, .25)}
.rd-drawer__hint { font-size: .78rem; opacity: .7; margin-top: .35rem; min-height: 1em}
.rd-drawer__body { flex: 1 1 auto; overflow-y: auto; padding: .3rem .6rem 1rem; scrollbar-width: thin}
.rd-item {
    display: block; width: 100%; text-align: start; border: 0; background: transparent; color: inherit;
    font: inherit; padding: .6rem .7rem; border-radius: 10px; cursor: pointer;
    transition: background .2s ease}
.rd-item:hover { background: rgba(201, 161, 92, .13)}
.rd-item .pg { color: var(--rd-gold-deep); font-weight: 700; font-size: .8rem; margin-inline-start: .5rem; white-space: nowrap}
.rd-item .sn { display: block; font-size: .82rem; opacity: .75; margin-top: .15rem; line-height: 1.6}
.rd-item.lvl2 { padding-inline-start: 1.6rem; font-size: .92rem}
.rd-item.lvl3 { padding-inline-start: 2.5rem; font-size: .88rem; opacity: .9}
.rd-empty { padding: 1.2rem; text-align: center; opacity: .7; font-size: .9rem}
.rd-scrim { position: fixed; inset: 0; z-index: 65; background: rgba(15, 22, 18, .35); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px)}

/* theme picker rows */
.rd-theme-row { display: flex; gap: .6rem; padding: .5rem .7rem}
.rd-theme-opt {
    flex: 1; border: 2px solid transparent; border-radius: 12px; padding: .9rem .4rem; cursor: pointer;
    text-align: center; font: inherit; font-size: .85rem; font-weight: 700;
    transition: border-color .25s ease, transform .2s ease}
.rd-theme-opt:active { transform: scale(.96)}
.rd-theme-opt.on { border-color: var(--rd-gold-deep)}
.rd-theme-opt[data-theme="paper"] { background: #faf6ec; color: #123528}
.rd-theme-opt[data-theme="sepia"] { background: #e9dcc0; color: #4a3a22}
.rd-theme-opt[data-theme="dark"] { background: #16201b; color: #e7dfd0}

/* ---- toast ---- */
.rd-toast {
    position: fixed; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); left: 50%; z-index: 80;
    transform: translate(-50%, 14px); opacity: 0; pointer-events: none;
    background: rgba(18, 26, 21, .88); color: #f3eee2; font-size: .88rem; font-weight: 600;
    padding: .55rem 1.1rem; border-radius: 99px; border: 1px solid rgba(201, 161, 92, .4);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    transition: opacity .3s ease, transform .3s var(--rd-ease);
    max-width: 92vw; text-align: center}
.rd-toast.show { opacity: 1; transform: translate(-50%, 0)}

/* ---- responsive ---- */
@media (max-width: 767.98px) {
    .rd-desktop-only { display: none}
    .rd-title { font-size: .85rem}
    .rd-btn { width: 38px; height: 38px}
    .rd-stage { padding-left: 8px; padding-right: 8px}
}
@media (prefers-reduced-motion: reduce) {
    .rd-paper, .rd-top, .rd-bottom, .rd-drawer, .rd-ribbon, .rd-progress span { transition: none}
    .rd-skeleton, .rd-paper { animation: none}
}
