/* ==========================================================================
   Invisible Islam – PDF reader
   ========================================================================== */

:root {
    --rd-bg: #0b1020;
    --rd-bg-2: #111832;
    --rd-panel: rgb(15 20 40 / .72);
    --rd-line: rgb(255 255 255 / .08);
    --rd-text: #e6e8f2;
    --rd-muted: #9aa3c0;
    --rd-accent: #6366f1;
    --rd-accent-2: #818cf8;
    --rd-gold: #d4af5a;
    --rd-toolbar-h: 60px;
    --rd-sidebar-w: 176px;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
.rd-body {
    font-family: 'Inter', system-ui, sans-serif;
    color: var(--rd-text);
    background:
        radial-gradient(900px 500px at 85% -10%, rgb(99 102 241 / .16), transparent 60%),
        radial-gradient(700px 500px at -10% 110%, rgb(212 175 90 / .10), transparent 60%),
        var(--rd-bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.rd { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Toolbar ------------------------------------------------------- */
.rd-toolbar {
    position: relative; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    min-height: var(--rd-toolbar-h);
    padding: .5rem max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left));
    background: var(--rd-panel);
    backdrop-filter: blur(16px) saturate(150%);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    border-bottom: 1px solid var(--rd-line);
}
.rd-group { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.rd-group--start { flex: 1 1 0; }
.rd-group--end { flex: 1 1 0; justify-content: flex-end; }

.rd-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    min-width: 40px; height: 40px; padding: 0 .6rem;
    border: 0; border-radius: 12px;
    background: transparent; color: var(--rd-text);
    font: inherit; font-size: .875rem; font-weight: 600; text-decoration: none;
    cursor: pointer;
    transition: background-color .18s, color .18s, transform .12s;
}
.rd-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.rd-btn:hover { background: rgb(255 255 255 / .08); }
.rd-btn:active { transform: scale(.94); }
.rd-btn:focus-visible, .rd-zoom-label:focus-visible, .rd-pagebox input:focus-visible, .rd-viewer:focus-visible, .rd-thumb:focus-visible {
    outline: 2px solid var(--rd-accent-2); outline-offset: 2px;
}
.rd-btn[aria-pressed="true"] { background: rgb(99 102 241 / .22); color: #c7d2fe; }
.rd-btn:disabled { opacity: .35; cursor: default; }
.rd-btn--accent { background: linear-gradient(135deg, var(--rd-accent), #4f46e5); box-shadow: 0 6px 18px -8px rgb(99 102 241 / .9); }
.rd-btn--accent:hover { background: linear-gradient(135deg, #4f46e5, #4338ca); }

.rd-title { display: flex; flex-direction: column; min-width: 0; margin-inline-start: .35rem; }
.rd-title-main {
    font-family: 'Noto Nastaliq Urdu', 'Inter', serif; font-weight: 700; font-size: 1rem; line-height: 1.9;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext;
}
.rd-title-sub { font-size: .75rem; color: var(--rd-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -.2rem; }

.rd-pagebox {
    display: inline-flex; align-items: center; gap: .4rem;
    height: 40px; padding: 0 .65rem; border-radius: 12px;
    background: rgb(255 255 255 / .06); border: 1px solid var(--rd-line);
    font-size: .875rem; color: var(--rd-muted);
}
.rd-pagebox input {
    width: 3.4ch; min-width: 2.5rem; border: 0; background: transparent; color: var(--rd-text);
    font: inherit; font-weight: 700; text-align: center; border-radius: 6px;
    -moz-appearance: textfield; appearance: textfield;
}
.rd-pagebox input::-webkit-outer-spin-button, .rd-pagebox input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Urdu books read right-to-left: "next" sits on the left and arrows mirror */
.rd[data-dir="rtl"] .rd-pager { flex-direction: row-reverse; }
.rd[data-dir="rtl"] .rd-flip svg { transform: scaleX(-1); }

.rd-zoom { display: inline-flex; align-items: center; border-radius: 12px; background: rgb(255 255 255 / .05); border: 1px solid var(--rd-line); }
.rd-zoom .rd-btn { min-width: 36px; height: 38px; }
.rd-zoom-label {
    min-width: 3.6rem; height: 38px; border: 0; background: transparent; color: var(--rd-text);
    font: inherit; font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; border-radius: 8px;
}
.rd-zoom-label:hover { color: #c7d2fe; }

/* ---------- Progress ------------------------------------------------------ */
.rd-progress { position: relative; z-index: 21; height: 3px; margin-top: -3px; overflow: hidden; }
.rd-progress span {
    display: block; height: 100%; width: 0;
    background: linear-gradient(90deg, var(--rd-accent), var(--rd-gold));
    box-shadow: 0 0 12px rgb(129 140 248 / .8);
    transition: width .25s ease, opacity .4s ease .3s;
}
.rd-progress.is-done span { opacity: 0; }

/* ---------- Layout -------------------------------------------------------- */
.rd-main { position: relative; flex: 1; display: flex; min-height: 0; }
.rd[data-dir="rtl"] .rd-main { flex-direction: row-reverse; }   /* thumbnails on the right for Urdu */

.rd-viewer { position: relative; flex: 1; overflow: auto; overscroll-behavior: contain; scroll-behavior: auto; outline: none; }
.rd-pages {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 18px;
    padding: 24px 12px 32px;
    min-width: min-content;
}

.rd-page {
    position: relative; flex-shrink: 0;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 1px 0 rgb(255 255 255 / .04) inset, 0 10px 30px -12px rgb(0 0 0 / .7), 0 2px 6px rgb(0 0 0 / .35);
    overflow: hidden;
}
.rd-page::before {              /* shimmer while the page renders */
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(100deg, #f1f2f6 30%, #fafbfd 50%, #f1f2f6 70%);
    background-size: 300% 100%;
    animation: rd-shimmer 1.4s linear infinite;
}
.rd-page.is-rendered::before { display: none; }
.rd-page canvas { position: relative; display: block; width: 100%; height: 100%; }
.rd-page-num {
    position: absolute; inset-block-end: 8px; inset-inline-end: 10px; z-index: 1;
    padding: 2px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 600; color: #475569; background: rgb(255 255 255 / .85);
    opacity: 0; transition: opacity .2s;
}
.rd-page:hover .rd-page-num { opacity: 1; }

@keyframes rd-shimmer { from { background-position: 100% 0; } to { background-position: -200% 0; } }

/* Night mode: invert paper while keeping image hues sensible */
.rd.is-night .rd-page { background: #111; }
.rd.is-night .rd-page canvas, .rd.is-night .rd-thumb canvas { filter: invert(.9) hue-rotate(180deg) contrast(.95); }

/* ---------- Status / errors ---------------------------------------------- */
.rd-status {
    position: absolute; inset: 0; z-index: 2;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
    color: var(--rd-muted); text-align: center; padding: 2rem;
}
.rd-status p { margin: 0; font-size: .95rem; }
.rd-status a { color: #a5b4fc; }
.rd-spinner {
    width: 44px; height: 44px; border-radius: 50%;
    border: 3px solid rgb(255 255 255 / .1); border-top-color: var(--rd-accent-2);
    animation: rd-spin .9s linear infinite;
}
.rd-status.is-error .rd-spinner { display: none; }
@keyframes rd-spin { to { transform: rotate(360deg); } }

/* ---------- Thumbnails sidebar ------------------------------------------- */
.rd-sidebar {
    width: var(--rd-sidebar-w); flex-shrink: 0;
    overflow-y: auto; overscroll-behavior: contain;
    background: rgb(10 14 30 / .6);
    border-inline-end: 1px solid var(--rd-line);
    scrollbar-width: thin; scrollbar-color: rgb(255 255 255 / .15) transparent;
}
.rd[data-dir="rtl"] .rd-sidebar { border-inline-end: 0; border-inline-start: 1px solid var(--rd-line); }
.rd-thumbs { list-style: none; margin: 0; padding: 14px 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.rd-thumb {
    display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; text-align: center;
    color: var(--rd-muted); font: inherit; font-size: 11px; font-weight: 600; border-radius: 6px;
}
.rd-thumb-img {
    position: relative; display: block; width: 100%;
    background: #e9ebf1; border-radius: 4px; overflow: hidden;
    outline: 2px solid transparent; outline-offset: 3px;
    box-shadow: 0 4px 14px -6px rgb(0 0 0 / .7);
    transition: outline-color .2s, transform .2s;
}
.rd-thumb canvas { display: block; width: 100%; height: 100%; }
.rd-thumb:hover .rd-thumb-img { transform: translateY(-2px); }
.rd-thumb.is-current .rd-thumb-img { outline-color: var(--rd-accent-2); }
.rd-thumb.is-current { color: #c7d2fe; }
.rd-thumb-label { display: block; margin-top: 6px; }

.rd-scrim { position: absolute; inset: 0; z-index: 9; background: rgb(0 0 0 / .5); }

/* ---------- End card ------------------------------------------------------ */
.rd-end {
    max-width: 520px; margin: 8px auto 64px; padding: 2rem 1.5rem;
    text-align: center; border-radius: 20px;
    background: linear-gradient(160deg, rgb(99 102 241 / .16), rgb(212 175 90 / .08));
    border: 1px solid var(--rd-line);
}
.rd-end-kicker { margin: 0; font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--rd-gold); }
.rd-end-title { margin: .5rem 0 1.25rem; font-size: 1.4rem; }
.rd-cta {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .8rem 1.4rem; border-radius: 14px;
    color: #fff; font-weight: 700; text-decoration: none;
    background: linear-gradient(135deg, var(--rd-accent), #4338ca);
    box-shadow: 0 10px 24px -10px rgb(99 102 241 / .9);
    transition: transform .15s, box-shadow .2s;
}
.rd-cta:hover { transform: translateY(-1px); box-shadow: 0 14px 30px -12px rgb(99 102 241 / 1); }
.rd-cta svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.rd[data-dir="rtl"] .rd-cta svg { transform: scaleX(-1); }
.rd-end-link { display: inline-block; margin-top: 1rem; color: var(--rd-muted); font-size: .875rem; text-decoration: none; }
.rd-end-link:hover { color: var(--rd-text); }

/* ---------- Toast --------------------------------------------------------- */
.rd-toast {
    position: fixed; z-index: 30; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem .75rem .65rem 1rem; border-radius: 14px;
    background: rgb(20 26 50 / .92); border: 1px solid var(--rd-line);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 16px 40px -12px rgb(0 0 0 / .8);
    font-size: .875rem; white-space: nowrap;
    animation: rd-toast-in .35s cubic-bezier(.2, .8, .2, 1);
}
.rd-toast button {
    border: 0; border-radius: 10px; padding: .4rem .75rem; cursor: pointer;
    background: rgb(255 255 255 / .1); color: #c7d2fe; font: inherit; font-weight: 600;
}
.rd-toast button:hover { background: rgb(255 255 255 / .16); }
@keyframes rd-toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- Scrollbars ---------------------------------------------------- */
.rd-viewer { scrollbar-width: thin; scrollbar-color: rgb(255 255 255 / .2) transparent; }

/* ---------- Responsive ---------------------------------------------------- */
@media (max-width: 899px) {
    .rd-sidebar {
        position: absolute; z-index: 10; inset-block: 0; inset-inline-start: 0;
        box-shadow: 20px 0 40px -20px rgb(0 0 0 / .8);
        background: rgb(10 14 30 / .96);
    }
    .rd[data-dir="rtl"] .rd-sidebar { inset-inline-start: auto; inset-inline-end: 0; }
}
@media (max-width: 760px) {
    :root { --rd-toolbar-h: auto; }
    .rd-toolbar { flex-wrap: wrap; row-gap: .4rem; }
    .rd-group--start { flex: 1 1 100%; order: 0; }
    .rd-pager { order: 1; }
    .rd-group--end { flex: 1 1 auto; order: 2; }
    .rd-hide-sm { display: none; }
    .rd-zoom-label { min-width: 3rem; }
    .rd-pages { padding: 14px 6px 24px; gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    .rd-page::before, .rd-spinner { animation: none; }
    .rd-toast { animation: none; }
}
