/* ═══════════════════════════════════════════════════════════════
   Eid al-Adha — Premium E-Reader
   "Real book" aesthetic — velvet backdrop, two-page spread,
   refined typography, subtle page-flip animations
   ═══════════════════════════════════════════════════════════════ */

:root {
  --ink-deep:  #04080f;
  --ink:       #08101f;
  --ink-mid:   #0f1a30;
  --ink-rich:  #1a2549;

  --gold:        #d4af37;
  --gold-warm:   #c9a043;
  --gold-bright: #f0d27a;
  --gold-soft:   #b8923a;

  --cream:       #f5ecd9;
  --cream-warm:  #efe3c4;
  --paper:       #faf3e1;

  --serif: "Cormorant Garamond", "Georgia", "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --arabic: "Noto Naskh Arabic", "SF Arabic", "Geeza Pro", serif;

  --shadow-book:  0 60px 120px -30px rgba(0,0,0,0.85),
                   0 30px 60px -20px rgba(0,0,0,0.55),
                   0 10px 30px -10px rgba(0,0,0,0.4);
  --shadow-page:  0 4px 30px -6px rgba(0,0,0,0.45),
                   0 0 0 1px rgba(0,0,0,0.08) inset;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--sans);
  color: var(--cream);
  background: var(--ink-deep);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ───────── Backdrop: deep velvet with vignette ───────── */
.backdrop {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 100% 80% at 50% 40%, #1a2549 0%, #0a1428 45%, #04080f 100%);
}
.backdrop::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><g fill='none' stroke='%23d4af37' stroke-width='0.4' opacity='0.04'><path d='M50 0L58 18L78 18L62 32L68 50L50 40L32 50L38 32L22 18L42 18Z'/><circle cx='50' cy='50' r='22'/></g></svg>");
  background-size: 220px 220px;
  pointer-events: none;
  opacity: 0.6;
}

.grain-overlay {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.95 0 0 0 0 0.85 0 0 0 0 0.55 0 0 0 0.04 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
  opacity: 0.5;
}

.reader-progress {
  position: fixed; top: 0; left: 0;
  height: 2px; width: 0;
  background: linear-gradient(90deg, var(--gold-warm), var(--gold-bright));
  z-index: 50; transition: width 0.4s ease;
}

/* ───────── TOPBAR ───────── */
.topbar {
  position: relative; z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 28px;
  background: linear-gradient(180deg, rgba(8,16,31,0.92), rgba(8,16,31,0.75));
  border-bottom: 1px solid rgba(212, 175, 55, 0.18);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.topbar-left { display: flex; align-items: center; justify-content: flex-start; }
.topbar-center { display: flex; align-items: center; justify-content: center; }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }

.back-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 999px;
  color: var(--cream);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: all 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.back-btn:hover {
  background: rgba(212, 175, 55, 0.10);
  border-color: var(--gold);
  color: var(--gold-bright);
  transform: translateY(-1px);
}

.title-block { text-align: center; pointer-events: none; }
.book-title {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--cream);
  letter-spacing: 0.01em;
  line-height: 1;
}
.book-subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--gold-bright);
  letter-spacing: 0.05em;
  margin-top: 4px;
  opacity: 0.85;
}

.control-group {
  display: flex; align-items: center;
}
.select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(8, 16, 31, 0.6);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23d4af37' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 999px;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 8px 28px 8px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 120px;
}
.select:hover, .select:focus {
  background-color: rgba(212, 175, 55, 0.08);
  border-color: var(--gold);
  color: var(--gold-bright);
  outline: none;
}
.select option {
  background: var(--ink-rich);
  color: var(--cream);
}

.action-divider {
  width: 1px; height: 22px;
  background: rgba(212, 175, 55, 0.2);
  margin: 0 4px;
}

/* ───────── TABLE OF CONTENTS DRAWER ───────── */
.toc-drawer {
  position: fixed;
  top: 0; left: 0;
  width: 340px;
  height: 100vh;
  background: linear-gradient(180deg, rgba(8,16,31,0.98), rgba(4,8,15,0.98));
  border-right: 1px solid rgba(212, 175, 55, 0.25);
  box-shadow: 8px 0 40px rgba(0,0,0,0.5);
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(20px);
}
.toc-drawer.open { transform: translateX(0); }

.toc-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 26px 18px;
  border-bottom: 1px solid rgba(212, 175, 55, 0.18);
}
.toc-title {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--cream);
  letter-spacing: 0.04em;
}
.toc-close {
  width: 30px; height: 30px;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 175, 55, 0.35) transparent;
}
.toc-list::-webkit-scrollbar { width: 6px; }
.toc-list::-webkit-scrollbar-thumb { background: rgba(212, 175, 55, 0.3); border-radius: 3px; }

.toc-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 26px;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--cream);
  text-decoration: none;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.18s ease;
}
.toc-item:hover {
  background: rgba(212, 175, 55, 0.08);
  color: var(--gold-bright);
  border-left-color: var(--gold);
}
.toc-item.active {
  background: rgba(212, 175, 55, 0.12);
  color: var(--gold-bright);
  border-left-color: var(--gold-bright);
  font-weight: 500;
}
.toc-item-num {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: rgba(212, 175, 55, 0.55);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.toc-item.active .toc-item-num { color: var(--gold-bright); }

.toc-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.toc-backdrop.open { opacity: 1; pointer-events: auto; }

@media (max-width: 600px) {
  .toc-drawer { width: 88%; max-width: 320px; }
}

.edition-tag {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-bright);
  padding: 6px 14px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 999px;
  background: rgba(8, 16, 31, 0.4);
  font-weight: 500;
}

.icon-btn {
  background: transparent;
  border: 1px solid rgba(212, 175, 55, 0.22);
  color: var(--cream);
  width: 36px; height: 36px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}
.icon-btn:hover:not(:disabled) {
  background: rgba(212, 175, 55, 0.12);
  border-color: var(--gold);
  color: var(--gold-bright);
  transform: translateY(-1px);
}
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ───────── BOOK STAGE ───────── */
.book-stage {
  position: relative; z-index: 1;
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 40px 80px 100px;
  height: calc(100vh - 70px);
  overflow: hidden;
}

.book-frame {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  perspective: 2500px;
}

.book-shadow {
  position: absolute;
  bottom: -25px; left: 8%; right: 8%; height: 60px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.65) 0%, transparent 70%);
  filter: blur(20px);
  z-index: 0;
}

.book {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--ink-deep);
  border-radius: 4px;
  box-shadow: var(--shadow-book);
  transform-style: preserve-3d;
}

.page {
  position: relative;
  background: var(--paper);
  overflow: hidden;
  box-shadow: var(--shadow-page);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.page-left  { border-radius: 4px 0 0 4px; }
.page-right { border-radius: 0 4px 4px 0; }

/* Single-page mode (only right page shown) */
.book.single .page-left,
.book.single .book-binding { display: none; }
.book.single .page-right { border-radius: 4px; }

.page-canvas {
  display: block;
  max-width: 100%; max-height: 100%;
  border-radius: inherit;
}

/* Page corner curl hint */
.page-curl {
  position: absolute;
  width: 60px; height: 60px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.page-curl-left {
  bottom: 0; left: 0;
  background: linear-gradient(45deg, rgba(0,0,0,0.18) 0%, transparent 50%);
}
.page-curl-right {
  bottom: 0; right: 0;
  background: linear-gradient(-45deg, rgba(0,0,0,0.18) 0%, transparent 50%);
}
.book:hover .page-curl { opacity: 1; }

/* Center binding shadow — the "spine" between two open pages */
.book-binding {
  width: 14px;
  background:
    linear-gradient(90deg,
      transparent 0%,
      rgba(0,0,0,0.4) 30%,
      rgba(0,0,0,0.5) 50%,
      rgba(0,0,0,0.4) 70%,
      transparent 100%);
  flex-shrink: 0;
}

/* Page flip animation */
.page.turning-out {
  opacity: 0;
  transform: translateZ(8px) scale(0.985);
}
.page.turning-in {
  animation: page-fade-in 0.45s ease-out forwards;
}
@keyframes page-fade-in {
  from { opacity: 0; transform: translateZ(8px) scale(0.985); }
  to   { opacity: 1; transform: translateZ(0) scale(1); }
}

/* Loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(8, 16, 31, 0.85);
  backdrop-filter: blur(8px);
  z-index: 5;
  border-radius: 8px;
  transition: opacity 0.4s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-orb {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--gold-bright), var(--gold), var(--gold-soft));
  box-shadow: 0 0 30px rgba(212, 175, 55, 0.5);
  animation: loading-pulse 1.6s ease-in-out infinite;
}
@keyframes loading-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(0.85); opacity: 0.75; }
}
.loading-text {
  margin-top: 16px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--gold-bright);
  letter-spacing: 0.06em;
}

/* ───────── SIDE NAV ARROWS ───────── */
.side-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 56px; height: 56px;
  border-radius: 999px;
  background: rgba(8, 16, 31, 0.55);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(212, 175, 55, 0.25);
  color: var(--cream);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
  z-index: 20;
  opacity: 0.55;
}
.side-nav:hover:not(:disabled) {
  background: rgba(212, 175, 55, 0.18);
  border-color: var(--gold);
  color: var(--gold-bright);
  opacity: 1;
  transform: translateY(-50%) scale(1.08);
}
.side-nav:disabled { opacity: 0.18; cursor: not-allowed; }
.side-nav-prev { left: 28px; }
.side-nav-next { right: 28px; }

/* ───────── FOOTER ───────── */
.reader-footer {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
}
.footer-pill {
  display: flex; align-items: center;
  padding: 9px 18px;
  background: rgba(8, 16, 31, 0.78);
  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 999px;
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px -6px rgba(0,0,0,0.5);
}
.page-indicator {
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--cream);
  letter-spacing: 0.06em;
  display: inline-flex; align-items: center; gap: 8px;
}
.page-indicator strong { color: var(--gold-bright); font-weight: 600; }
.page-sep { color: rgba(212, 175, 55, 0.5); }

/* ───────── RTL ───────── */
[dir="rtl"] .topbar-left  { justify-content: flex-end; }
[dir="rtl"] .topbar-right { justify-content: flex-start; flex-direction: row-reverse; }
[dir="rtl"] .back-btn svg { transform: rotate(180deg); }
[dir="rtl"] .side-nav-prev { right: 28px; left: auto; }
[dir="rtl"] .side-nav-next { left: 28px; right: auto; }
[dir="rtl"] .side-nav-prev svg { transform: rotate(180deg); }
[dir="rtl"] .side-nav-next svg { transform: rotate(180deg); }
[dir="rtl"] .book-title,
[dir="rtl"] .book-subtitle { font-family: var(--arabic); }

/* ───────── RESPONSIVE ───────── */
@media (max-width: 1100px) {
  .book-stage { padding: 30px 50px 100px; }
  .book-title { font-size: 1.2rem; }
  .book-subtitle { font-size: 0.7rem; }
  .select { min-width: 110px; font-size: 0.75rem; padding: 7px 24px 7px 12px; }
}

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto 1fr auto; padding: 10px 14px; gap: 6px; }
  .topbar-center { display: none; }
  .topbar-right { gap: 4px; }
  .select { min-width: 100px; font-size: 0.72rem; padding: 6px 22px 6px 10px; }
  .action-divider { display: none; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn svg { width: 14px; height: 14px; }
  .back-label { display: none; }
  .back-btn { padding: 7px; }
  .edition-tag { font-size: 0.62rem; padding: 4px 10px; letter-spacing: 0.06em; white-space: nowrap; }
  .book-stage { padding: 18px 12px 100px; }
  .side-nav { width: 44px; height: 44px; }
  .side-nav-prev { left: 8px; }
  .side-nav-next { right: 8px; }
}

@media (max-width: 560px) {
  .edition-tag { display: none; }
  .topbar { padding: 10px 12px; gap: 4px; }
  .topbar-left { gap: 4px; }
  .topbar-right { gap: 2px; }
}

@media (max-width: 700px) {
  /* Force single-page mode on smaller screens */
  .book .page-left,
  .book .book-binding { display: none !important; }
  .book .page-right { border-radius: 4px !important; }
}

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

/* ───────── PRINT STYLESHEET ─────────
   When user hits Cmd+P, hide the chrome and direct them to download the PDF.
*/
@media print {
  body { background: white !important; color: black !important; }
  .backdrop, .grain-overlay, .topbar, .side-nav, .reader-footer,
  .toc-drawer, .toc-backdrop, .reader-progress, .book-shadow,
  .loading-overlay, .book-binding, .page-curl { display: none !important; }
  .book-stage { padding: 0 !important; height: auto !important; overflow: visible !important; }
  .book, .page { box-shadow: none !important; background: white !important; }
  .book::after {
    content: "For printing, please download the PDF using the Download button in the reader. This screen view is optimized for on-screen reading.";
    display: block !important;
    padding: 60px 40px !important;
    font-family: serif !important;
    font-size: 14pt !important;
    color: #333 !important;
    text-align: center !important;
    max-width: 500px !important;
    margin: 100px auto !important;
  }
}

/* ───────── PAGE JUMP INPUT ───────── */
.page-jump-input {
  width: 50px;
  background: transparent;
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 999px;
  color: var(--gold-bright);
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  padding: 4px 6px;
  margin: 0 4px;
  -moz-appearance: textfield;
  transition: all 0.2s ease;
}
.page-jump-input::-webkit-outer-spin-button,
.page-jump-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.page-jump-input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(212, 175, 55, 0.08);
}


/* v11.7 buy-pill styles in the reader topbar */
.icon-btn.buy-pill {
  width: auto;
  min-width: 0;
  padding: 0 14px;
  height: 36px;
  background: #FF9900;
  color: #111;
  border: 0;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;           /* keep "AMZN $2.99" on one line */
  flex-shrink: 0;                /* don't get squeezed by topbar flex */
  line-height: 1;
}
.icon-btn.buy-pill:hover { background: #ffb84d; transform: translateY(-1px); }
.icon-btn.buy-pill-gum  { background: #FF90E8; color: #111; }
.icon-btn.buy-pill-gum:hover { background: #ffadf0; }
@media (max-width: 900px) {
  /* On smaller viewports give a bit more breathing room and hide the price suffix */
  .icon-btn.buy-pill { padding: 0 10px; height: 32px; font-size: 10.5px; }
}
@media (max-width: 560px) {
  .icon-btn.buy-pill { padding: 0 8px; height: 30px; font-size: 9.5px; }
}
