/* ================================================================
   আর‑রাহীকুল মাখতূম — Reader Stylesheet
   Aesthetic: refined manuscript, parchment + deep teal, gold accents
   ================================================================ */

:root {
  /* — Light (Parchment) theme — */
  --bg: #f5ecda;                  /* warm parchment */
  --bg-elev: #fbf4e4;             /* paper card */
  --bg-deep: #ece1c8;             /* under shadow */
  --ink: #2a2418;                 /* near-black, slightly warm */
  --ink-soft: #57503d;            /* secondary text */
  --ink-faint: #8a8268;           /* muted */
  --rule: #d4c39a;                /* hairline rules */
  --teal: #1f6f6c;                /* deep teal — book cover */
  --teal-deep: #134948;
  --teal-soft: #4a9591;
  --gold: #b8884a;                /* warm gold accent */
  --gold-deep: #8e6633;
  --crimson: #8e2a2a;             /* for marker */
  --crimson-soft: #c4503e;
  --shadow-sm: 0 1px 3px rgba(60, 40, 10, 0.08);
  --shadow-md: 0 6px 24px rgba(60, 40, 10, 0.12);
  --shadow-lg: 0 24px 60px rgba(60, 40, 10, 0.18);

  /* fonts */
  --font-display: 'Cormorant Garamond', 'Iowan Old Style', 'Palatino', 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-latin: 'Cormorant Garamond', Georgia, serif;
}

/* — Dark (Night reading) theme — */
[data-theme="dark"] {
  --bg: #181614;
  --bg-elev: #221f1b;
  --bg-deep: #100e0c;
  --ink: #e8dfc8;
  --ink-soft: #b3a888;
  --ink-faint: #7a7259;
  --rule: #3d362a;
  --teal: #6cb5b1;
  --teal-deep: #4d8e8a;
  --teal-soft: #8fc9c5;
  --gold: #d4a766;
  --gold-deep: #b08544;
  --crimson: #d96a55;
  --crimson-soft: #b95040;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 6px 24px rgba(0,0,0,0.5);
  --shadow-lg: 0 24px 60px rgba(0,0,0,0.6);
}

/* ---------------- base ---------------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 8% 15%, rgba(184, 136, 74, 0.06) 0%, transparent 35%),
    radial-gradient(circle at 92% 85%, rgba(31, 111, 108, 0.05) 0%, transparent 40%);
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* ============================================================
   HOME PAGE
   ============================================================ */
.page-home { padding-bottom: 80px; }

.top-ornament {
  display: flex; justify-content: center; padding: 28px 16px 0;
  color: var(--gold);
}
.top-ornament svg { width: min(280px, 60vw); }

.hero {
  text-align: center;
  padding: 36px 20px 28px;
  max-width: 700px;
  margin: 0 auto;
}
.hero__eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin: 0 0 6px;
  font-weight: 500;
}
.hero__eyebrow--small { font-size: 0.72rem; opacity: 0.85; }

.hero__title {
  font-family: var(--font-display);
  font-size: clamp(3rem, 9vw, 5.6rem);
  font-weight: 500;
  line-height: 1.0;
  margin: 24px 0 18px;
  color: var(--teal-deep);
  letter-spacing: -0.015em;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.4);
  font-style: italic;
}
[data-theme="dark"] .hero__title {
  color: var(--teal);
  text-shadow: none;
}

.hero__author {
  font-size: 1.05rem;
  color: var(--ink);
  margin: 0 0 6px;
  font-weight: 500;
}
.hero__subtitle {
  font-family: var(--font-latin);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1rem;
  margin: 0;
}

/* ----- Resume card ----- */
.resume-card {
  margin: 36px auto 0;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 18px 22px;
  max-width: 460px;
  text-align: left;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.resume-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--gold) 0%, var(--teal) 100%);
}
.resume-card--hidden { display: none; }
.resume-card__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold-deep);
  font-weight: 600;
  margin-bottom: 6px;
}
.resume-card__info {
  font-size: 0.98rem;
  color: var(--ink);
  margin-bottom: 14px;
  line-height: 1.45;
}
.resume-card__info strong {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--teal-deep);
}
[data-theme="dark"] .resume-card__info strong { color: var(--teal); }

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--teal);
  background: var(--teal);
  color: var(--bg-elev);
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: var(--font-body);
  letter-spacing: 0.01em;
  transition: all 0.18s ease;
}
.btn--primary:hover {
  background: var(--teal-deep);
  border-color: var(--teal-deep);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
[data-theme="dark"] .btn--primary { color: var(--bg); }

/* ----- Container & TOC ----- */
.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px;
}
.section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.6rem;
  color: var(--teal-deep);
  text-align: center;
  margin: 32px 0 28px;
  position: relative;
}
[data-theme="dark"] .section-title { color: var(--teal); }
.section-title span {
  background: var(--bg);
  padding: 0 18px;
  position: relative; z-index: 2;
}
.section-title::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule) 25%, var(--rule) 75%, transparent);
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chapter-card {
  display: flex; align-items: baseline; gap: 16px;
  padding: 14px 18px;
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid transparent;
  transition: all 0.18s ease;
  position: relative;
}
.chapter-card:hover {
  background: var(--bg-elev);
  border-color: var(--rule);
  transform: translateX(2px);
}
.chapter-card__num {
  font-family: var(--font-latin);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--gold);
  font-style: italic;
  min-width: 38px;
  text-align: right;
  flex-shrink: 0;
  line-height: 1;
}
.chapter-card__title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--ink);
}
.chapter-card__pages {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-feature-settings: 'tnum';
  flex-shrink: 0;
  font-family: var(--font-latin);
  letter-spacing: 0.04em;
}

.chapter-card--front .chapter-card__title {
  font-style: italic;
  color: var(--ink-soft);
}

/* Section heading inside list */
.section-divider {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold-deep);
  font-weight: 600;
  padding: 24px 18px 6px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 4px;
}

/* ----- Footer ----- */
.site-footer {
  text-align: center;
  margin-top: 48px;
  padding: 24px 20px;
  font-size: 0.85rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--rule);
  font-family: var(--font-latin);
}
.site-footer p { margin: 4px 0; }
.site-footer__small { font-size: 0.78rem; opacity: 0.8; }

.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-faint);
  font-style: italic;
}

/* ============================================================
   READER PAGE
   ============================================================ */
.page-reader {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

/* Top bar */
.reader-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.reader-bar__home {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.15s;
}
.reader-bar__home:hover { background: var(--bg-deep); }

.reader-bar__center {
  flex: 1;
  text-align: center;
  min-width: 0;
}
.reader-bar__title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--teal-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
[data-theme="dark"] .reader-bar__title { color: var(--teal); }
.reader-bar__page {
  font-family: var(--font-latin);
  font-size: 0.82rem;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.reader-bar__actions {
  display: flex;
  gap: 4px;
}
.iconbtn {
  width: 36px; height: 36px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.iconbtn:hover {
  background: var(--bg-deep);
  color: var(--ink);
  border-color: var(--rule);
}

/* TOC drawer */
.toc-drawer {
  position: fixed;
  top: 0; right: 0;
  width: min(380px, 86vw);
  height: 100vh;
  background: var(--bg-elev);
  border-left: 1px solid var(--rule);
  z-index: 200;
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.toc-drawer--hidden { transform: translateX(100%); }
.toc-drawer__header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0;
  background: var(--bg-elev);
  z-index: 1;
}
.toc-drawer__header h2 {
  font-family: var(--font-display);
  font-weight: 400;
  margin: 0;
  font-size: 1.3rem;
  color: var(--teal-deep);
}
[data-theme="dark"] .toc-drawer__header h2 { color: var(--teal); }
.toc-drawer__list {
  padding: 8px 12px 32px;
  display: flex; flex-direction: column; gap: 2px;
}

.toc-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 14, 4, 0.45);
  backdrop-filter: blur(2px);
  z-index: 150;
  opacity: 1;
  transition: opacity 0.25s;
}
.toc-overlay--hidden { opacity: 0; pointer-events: none; }

/* Reader stage — image viewer */
.reader {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
}

.reader-stage {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 100px;
  position: relative;
  overflow-x: auto;
}

.page-frame {
  position: relative;
  background: white;
  box-shadow: var(--shadow-lg);
  border-radius: 2px;
  cursor: crosshair;
  transition: transform 0.25s ease, opacity 0.25s ease;
  user-select: none;
}
[data-theme="dark"] .page-frame {
  box-shadow: 0 24px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.05);
  filter: invert(0.9) hue-rotate(180deg);
}
.page-frame__img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  pointer-events: none;
}

/* Bookmark marker on page */
.page-marker {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 2px solid var(--crimson);
  pointer-events: none;
  z-index: 4;
  filter: drop-shadow(0 0 3px rgba(142, 42, 42, 0.4));
}
.page-marker::before {
  content: '';
  position: absolute;
  left: -10px; top: -8px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent var(--crimson);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}
.page-marker::after {
  content: 'Last read';
  position: absolute;
  right: 8px; top: -22px;
  font-size: 11px;
  font-family: var(--font-body);
  font-weight: 500;
  background: var(--crimson);
  color: white;
  padding: 3px 9px;
  border-radius: 2px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
[data-theme="dark"] .page-marker {
  /* Counteract the inversion filter on parent */
  border-top-color: var(--crimson);
}

/* Hover line preview */
.page-hover-line {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 1.5px dashed var(--teal);
  pointer-events: none;
  opacity: 0.7;
  z-index: 3;
}

/* Loading state */
.reader-loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-faint);
}
.reader-loading__rosette {
  color: var(--gold);
  animation: spin 4s linear infinite;
  display: inline-block;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Hint toast */
.hint-toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 18px 12px 18px;
  padding-right: 38px;
  border-radius: 6px;
  font-size: 0.86rem;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  line-height: 1.45;
  animation: hint-rise 0.4s ease;
}
@media (max-width: 600px) {
  .hint-toast {
    bottom: 170px;
    max-width: calc(100vw - 32px);
    margin: 0 16px;
    left: 0;
    right: 0;
    transform: none;
  }
}
.hint-toast--hidden { display: none; }
.hint-toast strong { color: var(--gold); margin-right: 4px; }
.hint-toast__close {
  position: absolute;
  right: 6px; top: 6px;
  background: transparent;
  border: none;
  color: var(--bg);
  font-size: 1.4rem;
  width: 26px; height: 26px;
  line-height: 1;
  border-radius: 3px;
  opacity: 0.7;
}
.hint-toast__close:hover { opacity: 1; background: rgba(255,255,255,0.1); }
@keyframes hint-rise {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Bookmark confirmation toast */
.bookmark-toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  background: var(--teal-deep);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  animation: toast-pop 0.3s ease;
}
[data-theme="dark"] .bookmark-toast {
  background: var(--teal);
  color: var(--bg);
}
.bookmark-toast--hidden { display: none; }
@keyframes toast-pop {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Bottom nav */
.reader-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-elev);
  border-top: 1px solid var(--rule);
  position: sticky;
  bottom: 0;
  z-index: 50;
}
.navbtn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  border-radius: 4px;
  font-size: 0.86rem;
  white-space: nowrap;
  transition: all 0.15s ease;
  font-family: var(--font-body);
}
.navbtn:hover:not(:disabled) {
  background: var(--bg-deep);
  border-color: var(--ink-soft);
}
.navbtn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.reader-foot__progress {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.reader-foot__sliderlabel {
  font-family: var(--font-latin);
  font-size: 0.74rem;
  text-align: center;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid var(--bg-elev);
  box-shadow: var(--shadow-sm);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid var(--bg-elev);
}

/* Responsive */
@media (max-width: 600px) {
  .hero__title { font-size: clamp(2.6rem, 14vw, 4rem); }
  .chapter-card { padding: 12px 14px; gap: 12px; }
  .chapter-card__num { font-size: 1.15rem; min-width: 30px; }
  .chapter-card__title { font-size: 0.98rem; }
  .chapter-card__pages { font-size: 0.7rem; }
  .reader-bar__title { font-size: 0.95rem; }
  .navbtn span { display: none; }
  .navbtn { padding: 8px 10px; }
  .reader-stage { padding: 14px 8px 90px; }
  .iconbtn { width: 34px; height: 34px; }
  .reader-bar { padding: 8px 10px; gap: 6px; }
  .resume-card { margin: 24px 16px 0; }
}

/* Print: hide UI chrome */
@media print {
  .reader-bar, .reader-foot, .toc-drawer, .toc-overlay, .hint-toast, .bookmark-toast { display: none !important; }
  .page-frame { box-shadow: none; }
}
