/* ═══════════════════════════════════════════════════════════
   فضل القضية في الحاكمية | Design System
   Classic manuscript meets modern web · RTL · Arabic-first
   ═══════════════════════════════════════════════════════════ */

/* Fonts moved to <link rel="preconnect"> + <link rel="stylesheet"> in index.html
   so they download in parallel with CSS parsing instead of blocking it. */

:root {
  /* Colors, dark mode (default): sampled from the cover image
     Background: #080808 / #101010 / #181818 (warm near-black)
     Gold dominant: #b09050  Gold deep: #907040  Gold highlight: #f0c95e
     "teal" vars repurposed as warm-black scale; variable names kept so
     the rest of the cascade still reads cleanly. */
  --teal-900: #000000;
  --teal-800: #080806;
  --teal-700: #101008;
  --teal-600: #181610;
  --teal-500: #221d14;
  --teal-50:  #6b5520;

  --gold-700: #6b5520;
  --gold-600: #907040;
  --gold-500: #b09050;
  --gold-400: #c9a55a;
  --gold-300: #d9b86b;
  --gold-100: #e6c87a;
  --gold-50:  #f0c95e;

  --cream-50:  #14110a;
  --cream-100: #0c0a07;
  --cream-200: #1c1810;
  --cream-300: #2a2418;
  --cream-400: #3a3122;

  --ink-900: #ecd9a5;
  --ink-700: #c9b283;
  --ink-500: #9a8862;
  --ink-400: #6b5e44;

  --surface:    #14110a;
  --surface-2:  #1c1810;
  --line:       rgba(176, 144, 80, 0.14);
  --line-strong: rgba(176, 144, 80, 0.28);
  --gold-line:  rgba(176, 144, 80, 0.45);

  --shadow-glow: 0 0 30px rgba(176,144,80,0.25);
  --hero-grad:  radial-gradient(120% 80% at 50% 0%, rgba(176,144,80,0.18), transparent 60%),
                linear-gradient(180deg, var(--teal-700), var(--teal-900));
  --thumb-audio: radial-gradient(70% 100% at 50% 50%, rgba(176,144,80,0.2), transparent 60%),
                 linear-gradient(135deg, var(--teal-700), var(--teal-900));
  --thumb-video: radial-gradient(80% 120% at 50% 0%, rgba(176,144,80,0.15), transparent 60%),
                 linear-gradient(135deg, var(--ink-900), var(--teal-900));

  /* Type — defaults; overridden by --ff-body-pref / --ff-display-pref
     when the reader picks a different Arabic font. */
  --ff-display: var(--ff-display-pref, 'Amiri', 'Scheherazade New', 'Noto Naskh Arabic', serif);
  --ff-body:    var(--ff-body-pref,    'Noto Naskh Arabic', 'Amiri', serif);
  --ff-num:     'Markazi Text', 'Amiri', serif;

  /* Geometry */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 26px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4), 0 1px 0 rgba(176,144,80,0.10) inset;
  --shadow-md: 0 4px 14px -6px rgba(0,0,0,0.6), 0 1px 0 rgba(176,144,80,0.14) inset;
  --shadow-lg: 0 18px 40px -22px rgba(0,0,0,0.8), 0 1px 0 rgba(176,144,80,0.18) inset;

  --sidebar-w: 304px;

  /* Reader-controlled tokens (overridden by JS via :root inline styles).
     Keeping defaults here means everything renders correctly even before
     the settings panel mounts. */
  --reader-scale: 1;             /* 0.9 / 1 / 1.12 / 1.25 */
  --reader-leading: 1.85;        /* 1.65 / 1.85 / 2.05 */
  --ff-body-pref: 'Noto Naskh Arabic', 'Amiri', serif;
  --ff-display-pref: 'Amiri', 'Scheherazade New', 'Noto Naskh Arabic', serif;

  /* Text-on-surface gold token. Used wherever gold appears as TEXT on a
     page surface (cream/cards in light, near-black in dark). gold-300/500
     are still used as text on the dark hero/sidebar/modal-stage where
     they have plenty of contrast. */
  --gold-text:        #e6c87a;   /* dark mode: bright enough on near-black */
  --gold-text-muted:  #c9a55a;

  /* Semantic surface tokens — named so light mode can re-theme each
     surface by overriding ONE variable instead of re-pinning every
     component. These values reproduce the existing dark-mode look.
     NOTE: hero/sidebar are DARK surfaces in dark mode, so their "ink"
     (body text) must be LIGHT here — the original literal colors. */
  --hero-ink:        rgba(252, 249, 241, 0.86);
  --hero-accent:     var(--gold-300);
  --hero-accent-2:   var(--gold-100);
  --hero-border:     rgba(176,144,80,0.22);
  --hero-title-shadow: 0 0 40px rgba(176,144,80,0.18);

  --sidebar-bg:           linear-gradient(180deg, var(--teal-800) 0%, var(--teal-900) 100%);
  --sidebar-ink:          rgba(252, 249, 241, 0.78);
  --sidebar-muted:        rgba(243, 230, 184, 0.55);
  --sidebar-accent:       var(--gold-500);
  --sidebar-accent-strong:var(--gold-300);
  --sidebar-border:       rgba(176,144,80,0.18);
  --sidebar-pattern-opacity: 0.35;

  --accent-pill-bg:  var(--teal-700);
  --accent-pill-ink: var(--gold-300);

  /* Numeral disc (chapter number circle, scholar seal): a numeral on a
     small --cream disc. The disc is dark in dark mode, so the numeral
     must be a brighter gold here to stay legible (gold-700 was ~2.5:1). */
  --num-disc-ink: var(--gold-300);

  /* Media-thumbnail chrome (icon disc + corner tags). Dark-mode values
     reproduce the original look: bright gold on dark thumbs. */
  --thumb-icon-bg:     rgba(252, 249, 241, 0.08);
  --thumb-icon-border: var(--gold-500);
  --thumb-icon-color:  var(--gold-300);
  --thumb-tag-bg:      rgba(0,0,0,0.74);
  --thumb-tag-color:   var(--gold-100);
  --thumb-tag-border:  rgba(176,144,80,0.4);

  --stage-bg:  #0a0805;
  --stage-ink: var(--gold-300);

  /* "Colophon" card (about-meta-card): a dark info panel in both themes,
     so its ink is light in both. */
  --colophon-ink: #ecd9a5;
  --colophon-bg:  linear-gradient(180deg, var(--teal-700), var(--teal-800));

  --tab-active-ink: var(--gold-300);
}

/* ───────── Light mode — true "parchment" theme ─────────
   A cohesive light palette, NOT a recoloured dark theme. Hero, sidebar
   and cards are all genuinely light; depth comes from wider surface
   luminance steps + warmer/deeper shadows; the gold identity is carried
   by engraved bronze + serif type rather than glow (glow needs a dark
   backdrop). The only deliberate warm-dark accents are the small
   "accent pills" (scholar chapter numbers) — manuscript character at a
   size where dark-on-light still reads as an ornament, not a patch.

   Semantic tokens below (--sidebar-*, --hero-*, --accent-pill-*,
   --tab-active-ink, --stage-*) let the component cascade stay clean:
   each surface is DERIVED from a token instead of being re-pinned by a
   per-component override. Dark mode (:root) defines the same tokens. */
body.is-light {
  /* warm-black scale flips to a warm-white scale (names kept) */
  --teal-900: #e7dcc2;
  --teal-800: #efe7d4;
  --teal-700: #fbf7ee;
  --teal-600: #ffffff;
  --teal-500: #ffffff;
  --teal-50:  #6b5520;

  --cream-50:  #fbf6ea;
  --cream-100: #efe7d4;   /* page */
  --cream-200: #e6dcc4;
  --cream-300: #dbcfb0;
  --cream-400: #c9b98f;

  --ink-900: #241b10;     /* near-black warm brown — body text */
  --ink-700: #473a26;
  --ink-500: #6f6049;
  --ink-400: #8c7d63;

  --surface:    #fbf7ee;  /* cards — clearly lighter than the page */
  --surface-2:  #f1e8d4;  /* elevated */
  --line:        rgba(60, 46, 24, 0.14);
  --line-strong: rgba(60, 46, 24, 0.26);
  --gold-line:   rgba(140, 112, 52, 0.55);

  /* Warmer, deeper shadows so cards actually lift off the parchment */
  --shadow-sm: 0 1px 2px rgba(60,46,24,0.10), 0 1px 0 rgba(255,255,255,0.70) inset;
  --shadow-md: 0 6px 18px -8px rgba(60,46,24,0.26), 0 1px 0 rgba(255,255,255,0.80) inset;
  --shadow-lg: 0 22px 48px -22px rgba(60,46,24,0.40), 0 1px 0 rgba(255,255,255,0.85) inset;
  --shadow-glow: 0 0 0 rgba(0,0,0,0);  /* no glow on light surfaces */

  /* Hero is LIGHT parchment; identity = ornament + serif + bronze. */
  --hero-grad:  radial-gradient(120% 90% at 50% 0%, rgba(176,144,80,0.20), transparent 62%),
                linear-gradient(180deg, #f6edd7 0%, #ecdfc2 100%);
  --hero-ink:        #3a2c14;   /* hero body/subtitle text */
  --hero-accent:     #6e4f17;   /* hero title / eyebrow — engraved bronze */
  --hero-accent-2:   #654c14;   /* byline label/honorific — passes AA on parchment */
  --hero-border:     rgba(140,112,52,0.40);
  --hero-title-shadow: 0 1px 0 rgba(255,255,255,0.6);

  /* Media thumbnails: all light parchment in light mode (the real video
     still plays cinema-dark in the modal stage). */
  --thumb-audio: radial-gradient(70% 100% at 50% 50%, rgba(176,144,80,0.16), transparent 60%),
                 linear-gradient(135deg, #f3ead4, #e3d6b8);
  --thumb-video: radial-gradient(80% 120% at 50% 0%, rgba(176,144,80,0.16), transparent 60%),
                 linear-gradient(135deg, #f3ead4, #e3d6b8);

  /* Thumbnail chrome on light parchment: bronze icon on a near-white
     disc, dark-bronze corner tags. */
  --thumb-icon-bg:     rgba(255, 255, 255, 0.55);
  --thumb-icon-border: var(--gold-600);
  --thumb-icon-color:  #6e4f17;
  --thumb-tag-bg:      rgba(255, 250, 238, 0.85);
  --thumb-tag-color:   #5c4310;
  --thumb-tag-border:  rgba(140, 112, 52, 0.45);

  /* Brand sidebar — light ivory panel (was a dark island before).
     Muted/accent text tuned against the DARKER gradient end (#e7dabd)
     so it passes AA at the bottom of the sidebar too. */
  --sidebar-bg:           linear-gradient(180deg, #f3ead4 0%, #e7dabd 100%);
  --sidebar-ink:          #3a2c14;
  --sidebar-muted:        rgba(48,36,16,0.82);
  --sidebar-accent:       #6e4f17;   /* marks, dividers, active rail */
  --sidebar-accent-strong:#5a3f12;   /* brand title, active item */
  --sidebar-border:       rgba(140,112,52,0.30);
  --sidebar-pattern-opacity: 0.16;

  /* Small warm-dark accent (scholar number pills, detail num). Gold-on-
     dark glow survives here because the swatch is tiny. */
  --accent-pill-bg:  linear-gradient(180deg, #2a2014, #161208);
  --accent-pill-ink: #e6c87a;

  /* Numeral disc: dark-bronze numeral on the light cream disc. */
  --num-disc-ink: var(--gold-700);

  /* Cinema stages (modal video/audio) stay dark on purpose. */
  --stage-bg:  #1a160e;
  --stage-ink: #ecd9a5;

  /* Colophon card: deliberate warm-dark info panel on the light page. */
  --colophon-bg:  linear-gradient(180deg, #1a160e, #060503);
  --colophon-ink: #ecd9a5;

  /* Active pill/tab text on light surfaces (gold-300 would fail AA). */
  --tab-active-ink: var(--gold-text);

  /* Small gold "chip" (scholar badge): lighter, more opaque fill so the
     bronze --gold-text reads against it (the translucent-gold default
     muddied to ~3:1 over parchment). */
  --chip-bg: rgba(255,250,238,0.92);

  /* Engraved bronze for gold-as-text on parchment (passes WCAG AA). */
  --gold-text:        #5c4310;
  --gold-text-muted:  #7a5c1e;
}

/* ───────── High-contrast mode (opt-in via reader settings) — pushes
   muted/decorative text to full strength. */
body.is-high-contrast {
  --ink-500: #f3e6b8;
  --ink-700: #f7eed2;
  --gold-text: #ffd97a;
  --gold-text-muted: #f0c95e;
}
body.is-light.is-high-contrast {
  --ink-500: #2a2418;
  --ink-700: #1c1610;
  --gold-text: #4a3712;
  --gold-text-muted: #5a4418;
}
@media (prefers-contrast: more) {
  body:not(.is-no-auto-contrast) {
    --ink-500: #f3e6b8;
    --ink-700: #f7eed2;
    --gold-text: #ffd97a;
    --gold-text-muted: #f0c95e;
  }
  body.is-light:not(.is-no-auto-contrast) {
    --ink-500: #2a2418;
    --ink-700: #1c1610;
    --gold-text: #4a3712;
    --gold-text-muted: #5a4418;
  }
}

/* Reduce motion — opt-in or prefers-reduced-motion */
body.is-reduce-motion *,
body.is-reduce-motion *::before,
body.is-reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}
@media (prefers-reduced-motion: reduce) {
  body:not(.is-allow-motion) *,
  body:not(.is-allow-motion) *::before,
  body:not(.is-allow-motion) *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Universal focus-visible ring — keyboard users get a clear gold ring */
:focus-visible {
  outline: 2px solid var(--gold-300);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold-300);
  outline-offset: 2px;
}
/* Light-mode page background — warmer radial wash on the parchment.
   Everything else (hero, sidebar, cards, pills, stages) is themed via
   the semantic tokens in the body.is-light block above, so there are
   no longer any per-component dark-pinning overrides here. */
body.is-light {
  background: var(--cream-100);
  color: var(--ink-900);
  background-image:
    radial-gradient(1100px 700px at 100% -10%, rgba(176,144,80,0.10), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(144,112,64,0.06), transparent 60%);
}

/* ───────── Base ───────── */
* { box-sizing: border-box; }
html {
  font-size: calc(17px * var(--reader-scale));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  margin: 0; padding: 0;
  background: var(--cream-100);
  color: var(--ink-900);
  font-family: var(--ff-body);
  font-size: 1rem;
  line-height: var(--reader-leading);
}
body {
  min-height: 100vh;
  background-image:
    radial-gradient(1100px 700px at 100% -10%, rgba(176,144,80,0.06), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(176,144,80,0.03), transparent 60%);
  transition: background-color 220ms ease, color 220ms ease;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img, svg { display: block; max-width: 100%; }

/* ───────── Scroll progress ───────── */
.scroll-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: transparent;
  z-index: 1000;
  pointer-events: none;
}
.scroll-progress::after {
  content: '';
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: linear-gradient(90deg, var(--gold-500), var(--gold-300));
  box-shadow: 0 0 12px rgba(176,144,80,0.5);
  transition: width 80ms linear;
}

/* ═══════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════ */
.app {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  min-height: 100vh;
}

/* ───────── Sidebar (right side in RTL) ───────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  border-inline-start: 1px solid var(--sidebar-border);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
}
.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'><g fill='none' stroke='%23b09050' stroke-width='0.6' opacity='0.18'><path d='M60 6 L92 24 L92 60 L60 78 L28 60 L28 24 Z'/><path d='M60 24 L78 33 L78 51 L60 60 L42 51 L42 33 Z'/><circle cx='60' cy='42' r='10'/></g></svg>");
  background-size: 160px 160px;
  background-position: center;
  opacity: var(--sidebar-pattern-opacity);
  pointer-events: none;
  mask-image: linear-gradient(180deg, transparent 0, black 30%, black 80%, transparent 100%);
}
.sidebar > * { position: relative; z-index: 1; }

.brand {
  padding: 32px 28px 24px;
  border-bottom: 1px solid rgba(176,144,80,0.18);
}
.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
  border: 1px solid var(--sidebar-accent);
  border-radius: 50%;
  color: var(--sidebar-accent);
  background: rgba(176,144,80,0.08);
}
.brand-mark svg { width: 32px; height: 32px; }
.brand-title {
  font-family: var(--ff-display);
  font-size: 24px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--sidebar-accent-strong);
  margin: 0;
}
.brand-subtitle {
  font-family: var(--ff-display);
  font-size: 13.5px;
  color: var(--sidebar-muted);
  margin-top: 6px;
  letter-spacing: 0.02em;
}
.brand-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  color: var(--gold-500);
  opacity: 0.7;
}
.brand-divider::before, .brand-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-500), transparent);
}
.brand-divider svg { width: 14px; height: 14px; }
.brand-library {
  font-family: var(--ff-display);
  font-size: 12px;
  text-align: center;
  letter-spacing: 0.18em;
  color: var(--sidebar-accent);
  margin-top: 12px;
}

.nav {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  color: var(--sidebar-ink);
  border-radius: var(--r-md);
  text-align: start;
  width: 100%;
  font-family: var(--ff-body);
  font-size: 16px;
  font-weight: 500;
  position: relative;
  transition: all 180ms ease;
}
.nav-item:hover {
  background: rgba(176,144,80,0.10);
  color: var(--sidebar-accent-strong);
}
.nav-item.is-active {
  background: linear-gradient(90deg, rgba(176,144,80,0.18), rgba(176,144,80,0.04));
  color: var(--sidebar-accent-strong);
}
.nav-item.is-active::before {
  content: '';
  position: absolute;
  inset-inline-end: 0;
  top: 22%;
  bottom: 22%;
  width: 3px;
  background: var(--gold-500);
  border-radius: 3px;
  box-shadow: 0 0 10px rgba(176,144,80,0.6);
}
.nav-item .ico {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--sidebar-accent);
  opacity: 0.85;
}
.nav-item.is-active .ico { opacity: 1; }
.nav-section {
  margin-top: 14px;
  padding: 10px 16px 6px;
  font-size: 11.5px;
  letter-spacing: 0.18em;
  color: rgba(176,144,80,0.6);
}

.nav-buy {
  color: var(--gold-text);
  font-weight: 700;
  text-decoration: none;
}
.nav-buy .ico { color: var(--gold-700); opacity: 1; }
.nav-buy:hover { background: rgba(176,144,80,0.10); color: var(--gold-text); }

.nav-lang {
  border-top: 1px dashed rgba(176,144,80,0.18);
  border-bottom: 1px dashed rgba(176,144,80,0.18);
  margin: 4px 0;
  padding-top: 14px !important;
  padding-bottom: 14px !important;
}
.nav-theme {
  border-top: 1px dashed rgba(176,144,80,0.18);
  margin: 4px 0;
  padding-top: 14px !important;
  padding-bottom: 14px !important;
}
.lang-pill {
  font-family: var(--ff-display);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--gold-500);
  color: #1a130a;          /* dark ink reads on gold in BOTH themes */
  min-width: 32px;
  text-align: center;
  margin-inline-start: auto;
}
.nav-lock {
  opacity: 0.65;
  font-size: 14px !important;
}
.nav-lock:hover { opacity: 1; }

/* LTR mode (English) */
body.is-ltr {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
body.is-ltr .brand-title,
body.is-ltr .hero-title,
body.is-ltr .page-title,
body.is-ltr .chapter-title,
body.is-ltr .chapter-detail h1,
body.is-ltr .modal-title,
body.is-ltr .media-title,
body.is-ltr .about-text h3,
body.is-ltr .section-head h2 {
  font-family: 'Cormorant Garamond', 'Playfair Display', Georgia, serif;
  letter-spacing: -0.01em;
}
body.is-ltr .eyebrow,
body.is-ltr .hero-eyebrow,
body.is-ltr .brand-library,
body.is-ltr .brand-subtitle,
body.is-ltr .stat-label,
body.is-ltr .modal-eyebrow,
body.is-ltr .chapter-ordinal,
body.is-ltr .chapter-ordinal-lg {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
}
body.is-ltr .hero-eyebrow { font-size: 13px; }
body.is-ltr .brand-subtitle { letter-spacing: 0.04em; text-transform: none; font-size: 13px; }
body.is-ltr .bismillah { font-size: 22px; font-style: italic; letter-spacing: 0.02em; }
body.is-ltr .stat-value { font-family: 'Cormorant Garamond', Georgia, serif; }
body.is-ltr .chapter-num { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 17px; }
body.is-ltr .chapter-num-lg { font-family: 'Cormorant Garamond', Georgia, serif; }
body.is-ltr .scholar-seal { font-family: 'Cormorant Garamond', Georgia, serif; }
body.is-ltr { font-size: 16px; line-height: 1.7; }
body.is-ltr .page-lede { line-height: 1.7; }
body.is-ltr .chapter-body { line-height: 1.85; }

.sidebar-footer {
  padding: 18px 24px 24px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 12.5px;
  color: var(--sidebar-muted);
  text-align: center;
  font-family: var(--ff-display);
}

/* mobile sidebar trigger */
.sidebar-trigger {
  display: none;
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  inset-inline-end: 16px;
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--teal-800);
  color: var(--gold-300);
  border: 1px solid var(--gold-500);
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px -4px rgba(0,0,0,0.4);
}

/* ───────── Main content ───────── */
.main {
  min-width: 0;
  padding: 0;
}
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 56px 64px 96px;
  animation: pageIn 480ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   COMMON ELEMENTS
   ═══════════════════════════════════════════════════════════ */

/* Section eyebrow */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--ff-display);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--gold-text);
  text-transform: none;
  margin-bottom: 14px;
}
.eyebrow::before, .eyebrow::after {
  content: '';
  width: 28px;
  height: 1px;
  background: var(--gold-500);
}
.page-title {
  font-family: var(--ff-display);
  font-size: 44px;
  line-height: 1.25;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--ink-900);
}
.page-lede {
  font-size: 17.5px;
  line-height: 2.0;
  color: var(--ink-500);
  max-width: 64ch;
  margin: 6px 0 0;
}

.section-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 56px 0;
  color: var(--gold-500);
}
.section-divider::before, .section-divider::after {
  content: '';
  height: 1px;
  flex: 1;
  max-width: 200px;
  background: linear-gradient(90deg, transparent, var(--gold-500), transparent);
}
.section-divider svg { width: 22px; height: 22px; opacity: 0.85; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--ff-body);
  font-weight: 600;
  font-size: 15px;
  transition: all 180ms ease;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn > span > svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.btn-primary {
  background: var(--accent-pill-bg);
  color: var(--accent-pill-ink);
  border-color: var(--gold-line);
}
.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px -10px rgba(0,0,0,0.45);
}
.btn-gold {
  background: linear-gradient(180deg, var(--gold-500), var(--gold-600));
  color: #1a130a;          /* dark ink reads on gold in BOTH themes (was --cream-50, which flips near-white in light) */
  box-shadow: 0 4px 14px -6px rgba(176,144,80,0.55);
}
.btn-gold:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}
.btn-ghost {
  background: transparent;
  color: var(--gold-text);
  border-color: var(--gold-line);
  font-weight: 700;
}
.btn-ghost:hover {
  background: rgba(176,144,80,0.10);
  border-color: var(--gold-500);
  color: var(--gold-text);
}

/* ═══════════════════════════════════════════════════════════
   HOME
   ═══════════════════════════════════════════════════════════ */
.hero {
  position: relative;
  border-radius: var(--r-xl);
  overflow: hidden;
  background: var(--hero-grad);
  color: var(--hero-ink);
  padding: 64px 56px 72px;
  margin-bottom: 56px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--hero-border);
}
@media (min-width: 1024px) {
  .hero {
    min-height: calc(100vh - 112px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 56px;
    padding-bottom: 56px;
  }
}
.hero::before, .hero::after {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  inset-inline-end: 0;
  height: 64px;
  pointer-events: none;
  background-repeat: repeat-x;
  background-size: 64px 64px;
  opacity: 0.5;
}
.hero::before {
  top: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'><g fill='none' stroke='%23b09050' stroke-width='0.7' opacity='0.5'><path d='M0 32 L16 16 L32 32 L48 16 L64 32'/><path d='M0 48 L16 32 L32 48 L48 32 L64 48'/></g></svg>");
  -webkit-mask-image: linear-gradient(90deg, transparent 0, black 80px, black calc(100% - 80px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, black 80px, black calc(100% - 80px), transparent 100%);
}
.hero::after {
  bottom: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'><g fill='none' stroke='%23b09050' stroke-width='0.7' opacity='0.5'><path d='M0 32 L16 16 L32 32 L48 16 L64 32'/><path d='M0 16 L16 32 L32 16 L48 32 L64 16'/></g></svg>");
  -webkit-mask-image: linear-gradient(90deg, transparent 0, black 80px, black calc(100% - 80px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, black 80px, black calc(100% - 80px), transparent 100%);
}
.bismillah {
  text-align: center;
  font-family: 'Amiri', serif;
  font-size: 38px;
  line-height: 1.6;
  color: var(--hero-accent);
  margin: 0 0 36px;
  text-shadow: var(--hero-title-shadow);
  position: relative;
  z-index: 1;
}
.hero-inner {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 760px;
  margin: 0 auto;
}
.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--ff-display);
  font-size: 13px;
  letter-spacing: 0.28em;
  color: var(--hero-accent);
  margin-bottom: 18px;
  opacity: 0.9;
}
.hero-eyebrow::before, .hero-eyebrow::after {
  content: '';
  width: 36px;
  height: 1px;
  background: var(--hero-accent);
  opacity: 0.6;
}
.hero-title {
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: 76px;
  line-height: 1.18;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--hero-accent);
  text-shadow: var(--hero-title-shadow);
}
.hero-subtitle {
  font-family: var(--ff-display);
  font-size: 22px;
  line-height: 1.7;
  color: var(--hero-ink);
  margin: 18px auto 0;
  max-width: 56ch;
  font-weight: 400;
}
.hero-byline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}
.hero-byline-label {
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--hero-accent-2);
  opacity: 0.92;
  font-family: var(--ff-display);
}
.hero-byline-name {
  font-family: var(--ff-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--hero-accent);
  letter-spacing: 0.02em;
}
.hero-byline-honorific {
  font-family: var(--ff-display);
  font-size: 13px;
  color: var(--hero-accent-2);
  opacity: 0.85;
  letter-spacing: 0.04em;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 32px;
}
.hero-actions .btn-primary {
  background: linear-gradient(180deg, var(--gold-400), var(--gold-600));
  border-color: var(--gold-600);
  color: #1a130a;          /* dark ink reads on gold in BOTH themes */
  font-weight: 700;
}
.hero-actions .btn-primary:hover {
  background: linear-gradient(180deg, var(--gold-300), var(--gold-500));
  border-color: var(--gold-500);
}
.hero-actions .btn-ghost {
  border-color: var(--gold-line);
  color: var(--hero-accent);
}
.hero-actions .btn-ghost:hover {
  background: rgba(176,144,80,0.1);
}

/* Stats strip */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 48px;
  padding: 28px 0 0;
  border-top: 1px solid rgba(176,144,80,0.28);
  position: relative;
  z-index: 1;
}
.stat {
  text-align: center;
  position: relative;
  padding: 0 16px;
}
.stat + .stat::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 18%;
  bottom: 18%;
  width: 1px;
  background: rgba(176,144,80,0.28);
}
.stat-value {
  font-family: var(--ff-display);
  font-size: 48px;
  font-weight: 700;
  color: var(--hero-accent);
  line-height: 1;
}
.stat-label {
  font-family: var(--ff-display);
  font-size: 15px;
  color: var(--hero-ink);
  opacity: 0.72;
  margin-top: 8px;
}

/* Chapter grid */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}
.chapter-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  margin: 0;
  padding: 26px 24px 22px;
  transition: all 200ms ease;
  cursor: pointer;
  text-align: start;
  width: 100%;
  font-family: inherit;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.chapter-card::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline-start: 22px;
  inset-inline-end: 22px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-500), transparent);
  opacity: 0;
  transition: opacity 200ms ease;
}
.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--gold-line);
}
.chapter-card:hover::before { opacity: 1; }
.chapter-card.is-scholar {
  background: linear-gradient(180deg, var(--surface) 0%, var(--cream-50) 100%);
  border-color: rgba(176,144,80,0.22);
}
.chapter-card.is-preface {
  background: linear-gradient(180deg, var(--cream-200), var(--cream-100));
  border-color: var(--gold-line);
  border-style: dashed;
}
.chapter-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--gold-line);
  background: var(--cream-50);
  color: var(--num-disc-ink);
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 14px;
  padding: 0 10px;
}
.chapter-card.is-scholar .chapter-num {
  background: var(--accent-pill-bg);
  color: var(--accent-pill-ink);
  border-color: transparent;
}
.chapter-card.is-preface .chapter-num {
  background: transparent;
  font-size: 22px;
  letter-spacing: -0.02em;
  width: 38px;
  min-width: 38px;
  padding: 0;
}
.chapter-ordinal {
  font-family: var(--ff-display);
  font-size: 14px;
  color: var(--gold-text);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
.chapter-title {
  font-family: var(--ff-display);
  font-size: 21px;
  line-height: 1.55;
  font-weight: 700;
  color: var(--ink-900);
  margin: 0;
}
.chapter-meta {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
  color: var(--ink-500);
  font-family: var(--ff-display);
}
.scholar-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--chip-bg, rgba(176,144,80,0.20));
  color: var(--gold-text);
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--ff-display);
}
.scholar-badge svg { width: 12px; height: 12px; }

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.section-head h2 {
  font-family: var(--ff-display);
  font-size: 32px;
  font-weight: 700;
  margin: 0;
  color: var(--ink-900);
}
.section-head .eyebrow { margin-bottom: 6px; }

/* ═══════════════════════════════════════════════════════════
   CHAPTERS PAGE
   ═══════════════════════════════════════════════════════════ */
.chapter-tabs {
  display: inline-flex;
  background: var(--cream-200);
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: 999px;
  margin-bottom: 28px;
  gap: 2px;
}
.chapter-tabs button {
  padding: 8px 18px;
  border: 0;
  background: transparent;
  color: var(--ink-700);
  border-radius: 999px;
  font-weight: 500;
  font-family: var(--ff-display);
  font-size: 15px;
  transition: all 160ms ease;
}
.chapter-tabs button.is-active {
  background: var(--surface);
  color: var(--tab-active-ink);
  box-shadow: var(--shadow-sm);
}

/* Chapter detail view */
.chapter-detail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 56px 64px;
  position: relative;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.chapter-detail .chapter-body,
.chapter-detail .chapter-summary { max-width: 70ch; }
.chapter-detail::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  inset-inline-end: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, var(--gold-500), transparent);
}
.chapter-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--gold-text);
  font-family: var(--ff-display);
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 24px;
  border: 0;
  background: transparent;
  padding: 6px 4px;
  border-radius: var(--r-sm);
}
.chapter-back svg { flex-shrink: 0; width: 16px; height: 16px; }
.chapter-back:hover { color: var(--gold-text-muted); }
.chapter-detail .chapter-num-lg {
  display: inline-flex;
  margin-inline-start: 16px;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-pill-bg);
  color: var(--accent-pill-ink);
  font-family: var(--ff-display);
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 20px;
}
.chapter-detail .chapter-ordinal-lg {
  font-family: var(--ff-display);
  font-size: 16px;
  letter-spacing: 0.18em;
  color: var(--gold-text);
  font-weight: 600;
  margin-bottom: 8px;
}
.chapter-detail h1 {
  font-family: var(--ff-display);
  font-size: 42px;
  line-height: 1.35;
  margin: 0 0 16px;
  color: var(--ink-900);
}
.chapter-scholar-line {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--cream-200);
  border: 1px solid var(--gold-line);
  font-family: var(--ff-display);
  font-size: 19px;
  color: var(--ink-700);
  margin-top: 10px;
  line-height: 1.4;
}
.chapter-scholar-line svg { flex-shrink: 0; align-self: center; width: 18px; height: 18px; color: var(--gold-700); }
.chapter-scholar-line .honorific {
  color: var(--ink-500);
  font-size: 14px;
  padding-inline-start: 10px;
  border-inline-start: 1px solid var(--gold-line);
}
.chapter-body {
  margin-top: 36px;
  padding-top: 36px;
  border-top: 1px dashed var(--gold-line);
  font-size: 17px;
  line-height: 2.1;
  color: var(--ink-700);
}
.chapter-body p { margin: 0 0 18px; }

.chapter-media-list {
  margin-top: 36px;
}
.chapter-media-list h3 {
  font-family: var(--ff-display);
  font-size: 22px;
  margin: 0 0 16px;
  color: var(--gold-text);
}
.media-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--cream-50);
  margin-bottom: 10px;
  transition: all 160ms ease;
}
.media-row:hover {
  border-color: var(--gold-line);
  background: var(--surface);
}
.media-row .play-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--teal-700);
  color: var(--gold-300);
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.media-row .play-btn:hover { background: var(--teal-800); }
.media-row .meta { flex: 1; min-width: 0; }
.media-row .meta-title {
  font-family: var(--ff-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-900);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-row .meta-sub {
  font-size: 13px;
  color: var(--ink-500);
  font-family: var(--ff-display);
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 40px;
  padding-top: 28px;
  border-top: 1px dashed var(--gold-line);
}
.chapter-nav button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 18px;
  font-family: var(--ff-body);
  text-align: start;
  color: var(--ink-700);
  flex: 1;
  max-width: 48%;
  transition: all 160ms ease;
}
.chapter-nav button:hover {
  border-color: var(--gold-line);
  background: var(--cream-50);
}
.chapter-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
.chapter-nav .label {
  font-family: var(--ff-display);
  font-size: 13px;
  color: var(--gold-text);
  font-weight: 600;
  letter-spacing: 0.1em;
}
.chapter-nav .target {
  font-family: var(--ff-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-900);
  line-height: 1.4;
}
.chapter-nav .next-btn { text-align: end; align-items: flex-end; }

/* ═══════════════════════════════════════════════════════════
   MEDIA LIBRARY
   ═══════════════════════════════════════════════════════════ */
.media-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-top: 28px;
  margin-bottom: 28px;
}
.media-tabs {
  display: inline-flex;
  background: var(--cream-200);
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: 999px;
  gap: 2px;
}
.media-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: 0;
  background: transparent;
  color: var(--ink-700);
  border-radius: 999px;
  font-family: var(--ff-display);
  font-size: 15px;
  font-weight: 500;
  transition: all 160ms ease;
}
.media-tabs button:hover { color: var(--ink-700); }
.media-tabs button.is-active {
  background: var(--surface);
  color: var(--tab-active-ink);
  box-shadow: var(--shadow-sm);
}
.media-tabs button .count {
  font-size: 12.5px;
  background: var(--cream-300);
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--ink-700);
}
.media-tabs button.is-active .count {
  background: var(--gold-100);
  color: #4a3712;        /* dark bronze reads on the light-gold pill */
}

.media-search {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 360px;
}
.media-search input {
  width: 100%;
  padding: 11px 44px 11px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-family: var(--ff-body);
  font-size: 15px;
  background: var(--surface);
  color: var(--ink-900);
  transition: all 160ms ease;
}
.media-search input:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(176,144,80,0.18);
}
.media-search svg {
  position: absolute;
  inset-inline-end: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--ink-400);
  pointer-events: none;
}

/* Media grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}
.media-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  isolation: isolate;
  transform: translateZ(0);
  transition: all 200ms ease;
  cursor: pointer;
  text-align: start;
  font-family: inherit;
  width: 100%;
  padding: 0;
  margin: 0;
  box-shadow: var(--shadow-sm);
}
.media-card > .media-thumb:first-child { border-radius: 0; }
.media-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold-line);
  box-shadow: var(--shadow-md);
}
.media-thumb {
  height: 140px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--teal-800);
}
.media-thumb.t-audio {
  background: var(--thumb-audio);
}
.media-thumb.t-video {
  background: var(--thumb-video);
}
.media-thumb.t-page {
  background:
    repeating-linear-gradient(
      0deg,
      var(--cream-100) 0,
      var(--cream-100) 26px,
      rgba(176,144,80,0.06) 26px,
      rgba(176,144,80,0.06) 27px
    ),
    var(--cream-50);
}
.media-thumb.t-page .media-thumb-icon { color: var(--gold-700); background: var(--cream-50); border-color: var(--gold-line); }
.media-thumb-pattern {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'><g fill='none' stroke='%23b09050' stroke-width='0.5' opacity='0.25'><circle cx='40' cy='40' r='20'/><circle cx='40' cy='40' r='30'/><path d='M40 10 L62 40 L40 70 L18 40 Z'/></g></svg>");
  background-size: 100px 100px;
  opacity: 0.6;
  pointer-events: none;
}
.media-thumb-icon {
  position: relative;
  z-index: 1;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--thumb-icon-bg);
  border: 1px solid var(--thumb-icon-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--thumb-icon-color);
  transition: transform 240ms cubic-bezier(0.2, 0.7, 0.2, 1);
  backdrop-filter: blur(2px);
}
.media-card:hover .media-thumb-icon { transform: scale(1.08); }
.media-thumb-icon svg { width: 28px; height: 28px; }
.media-thumb-tag {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  z-index: 2;
  font-family: var(--ff-display);
  font-size: 12px;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--thumb-tag-color);
  background: var(--thumb-tag-bg);
  border: 1px solid var(--thumb-tag-border);
  backdrop-filter: blur(4px);
}
.media-page-tag {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  z-index: 2;
  font-family: var(--ff-display);
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--thumb-tag-bg);
  color: var(--thumb-tag-color);
  border: 1px solid var(--thumb-tag-border);
  backdrop-filter: blur(4px);
}

.media-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}
.media-title {
  font-family: var(--ff-display);
  font-size: 18px;
  line-height: 1.55;
  font-weight: 600;
  color: var(--ink-900);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.media-scholar {
  font-family: var(--ff-display);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--gold-text);
}
.media-episode-info {
  font-family: var(--ff-display);
  font-size: 13px;
  color: var(--ink-500);
  line-height: 1.5;
}
.media-timestamp-badge {
  position: absolute;
  bottom: 10px;
  inset-inline-end: 10px;
  z-index: 2;
  font-family: var(--ff-display);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--gold-500);
  color: #1a1008;
  letter-spacing: 0.04em;
}
.media-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-500);
  font-family: var(--ff-display);
  gap: 8px;
}
.media-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--gold-text);
  font-weight: 700;
}
.media-card:hover .media-cta { color: var(--gold-text-muted); }

/* Empty state */
.empty {
  text-align: center;
  padding: 80px 24px;
  color: var(--ink-500);
}
.empty svg { width: 48px; height: 48px; color: var(--gold-500); opacity: 0.6; margin-bottom: 12px; }
.empty p { margin: 0; font-family: var(--ff-display); }

/* ═══════════════════════════════════════════════════════════
   MEDIA MODAL PLAYER
   ═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 12, 8, 0.78);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  animation: overlayIn 260ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
@keyframes overlayIn {
  from { opacity: 0; -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); }
  to   { opacity: 1; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1px solid var(--gold-line);
  width: 100%;
  max-width: 880px;
  max-height: 90vh;
  /* Don't scroll the whole modal — the video stage stays pinned at the
     top and only .modal-body scrolls (see below). This keeps the video
     visible while the user reads the meta, and keeps the scrollbar from
     running alongside the video. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px -30px rgba(0,0,0,0.6);
  animation: modalIn 260ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
  position: relative;
  contain: layout paint;
}
@keyframes modalIn {
  from { opacity: 0; transform: translate3d(0, 8px, 0) scale(0.985); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  body:not(.is-allow-motion) .modal-overlay { animation: fadeIn 120ms ease both; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
  body:not(.is-allow-motion) .modal { animation: fadeIn 120ms ease both; }
}
body.is-reduce-motion .modal-overlay { animation: fadeIn 120ms ease both; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
body.is-reduce-motion .modal { animation: fadeIn 120ms ease both; }
.modal-close {
  position: absolute;
  top: 16px;
  inset-inline-start: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cream-200);
  border: 1px solid var(--line);
  color: var(--ink-700);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.modal-close:hover { background: var(--cream-300); }
.modal-stage {
  /* Hard-coded dark — --ink-900 flips to cream in dark mode, which used
     to bleed around the video when the player didn't fill the stage. */
  background: #0a0805;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  flex: 0 0 auto;
}
.modal-stage video {
  width: 100%;
  max-height: 60vh;
  display: block;
  background: #000;
}
/* When the stage hosts the custom video player, it must hug the player
   exactly — no min-height padding above/below that could expose the
   modal surface behind it. */
.modal-stage:has(> .mplayer.is-video) {
  padding: 0;
  background: #000;
}
.modal-stage > .mplayer.is-video { width: 100%; }
.modal-stage.audio {
  padding: 56px 32px;
  background:
    radial-gradient(70% 100% at 50% 50%, rgba(176,144,80,0.18), transparent 60%),
    linear-gradient(135deg, var(--stage-bg), #060503);
  color: var(--stage-ink);
  flex-direction: column;
  gap: 24px;
}
.audio-art {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid var(--gold-500);
  background: rgba(252, 249, 241, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-300);
  position: relative;
}
.audio-art svg { width: 48px; height: 48px; }
.audio-art::before, .audio-art::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid rgba(176,144,80,0.3);
  animation: ripple 3s ease-out infinite;
  animation-play-state: paused;
}
.audio-art::after { animation-delay: 1.5s; }
body.media-playing .audio-art::before,
body.media-playing .audio-art::after { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
  body:not(.is-allow-motion) .audio-art::before,
  body:not(.is-allow-motion) .audio-art::after { animation: none; }
}
body.is-reduce-motion .audio-art::before,
body.is-reduce-motion .audio-art::after { animation: none; }
@keyframes ripple {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.4); opacity: 0; }
}
.modal-stage.audio audio {
  width: 100%;
  max-width: 560px;
}
.modal-body {
  padding: 28px 36px 36px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.modal-eyebrow {
  font-family: var(--ff-display);
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--gold-text);
  font-weight: 600;
  margin-bottom: 8px;
}
.modal-title {
  font-family: var(--ff-display);
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 14px;
  line-height: 1.4;
  color: var(--ink-900);
}
.modal-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, auto));
  gap: 14px 20px;
  padding: 18px 20px;
  background: var(--cream-100);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-top: 8px;
}
.modal-meta-grid dt {
  font-size: 12px;
  color: var(--ink-500);
  font-family: var(--ff-display);
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}
.modal-meta-grid dd {
  margin: 0;
  font-family: var(--ff-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-900);
  word-break: break-word;
  white-space: normal;
}
.modal-meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.modal-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--ff-display);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
}
.modal-pill-time {
  background: var(--gold-500);
  color: #1a1008;
}
.modal-pill-time .pill-icon {
  display: inline-flex;
  width: 12px;
  height: 12px;
}
.modal-pill-ep {
  background: var(--accent-pill-bg);
  color: var(--accent-pill-ink);
  border: 1px solid rgba(176,144,80,0.3);
}
.modal-pill-series {
  background: var(--cream-100);
  color: var(--ink-700);
  border: 1px solid var(--line);
  font-weight: 400;
  max-width: 48ch;
  white-space: normal;
  line-height: 1.4;
}
.modal-context-quote {
  margin: 14px 0 0;
  padding: 14px 18px;
  border-inline-start: 3px solid var(--gold-500);
  background: var(--cream-100);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-family: var(--ff-display);
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink-700);
  font-style: italic;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.modal-format-warn {
  margin-top: 14px;
  padding: 14px 16px;
  border-inline-start: 3px solid var(--gold-500);
  background: rgba(176,144,80,0.08);
  color: var(--ink-900);
  border-radius: var(--r-sm);
  font-size: 14.5px;
  color: var(--ink-700);
  line-height: 1.7;
}
.modal-page-stage {
  padding: 56px 32px;
  background:
    repeating-linear-gradient(
      0deg,
      var(--cream-100) 0,
      var(--cream-100) 30px,
      rgba(176,144,80,0.06) 30px,
      rgba(176,144,80,0.06) 31px
    ),
    var(--cream-50);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.modal-page-stage svg { width: 56px; height: 56px; color: var(--gold-700); }
.modal-page-stage .url {
  font-family: monospace;
  direction: ltr;
  font-size: 13px;
  color: var(--ink-500);
  background: var(--cream-200);
  padding: 6px 12px;
  border-radius: 999px;
  word-break: break-all;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════
   ABOUT
   ═══════════════════════════════════════════════════════════ */
.about-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 32px;
  margin-top: 24px;
}
@media (max-width: 920px) { .about-grid { grid-template-columns: 1fr; } }

.about-text {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 40px 44px;
  font-size: 17px;
  line-height: 2.1;
  color: var(--ink-700);
  position: relative;
  box-shadow: var(--shadow-sm);
}
.about-text::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline-start: 40px;
  width: 60px;
  height: 3px;
  background: var(--gold-500);
}
.about-text h3 {
  font-family: var(--ff-display);
  font-size: 26px;
  margin: 0 0 16px;
  color: var(--gold-text);
}
.about-text p { margin: 0 0 16px; }
.about-text .first-letter {
  float: right;
  font-family: var(--ff-display);
  font-size: 64px;
  line-height: 0.9;
  margin: 6px 0 0 14px;
  color: var(--gold-600);
  font-weight: 700;
}

.about-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.about-meta-card {
  /* Warm-dark "colophon" card — a deliberate accent surface in both
     themes, driven by its own --colophon-* tokens. */
  background: var(--colophon-bg);
  color: var(--colophon-ink);
  border-radius: var(--r-xl);
  padding: 28px;
  position: relative;
  overflow: hidden;
}
.about-meta-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'><g fill='none' stroke='%23b09050' stroke-width='0.5' opacity='0.25'><path d='M30 4 L46 14 L46 32 L30 42 L14 32 L14 14 Z'/><path d='M30 14 L38 19 L38 28 L30 33 L22 28 L22 19 Z'/></g></svg>");
  background-size: 100px 100px;
  opacity: 0.6;
  pointer-events: none;
}
.about-meta-card > * { position: relative; z-index: 1; }
.about-meta-card h4 {
  font-family: var(--ff-display);
  font-size: 18px;
  color: var(--gold-300);
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.about-meta-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px dashed rgba(176,144,80,0.25);
  font-family: var(--ff-display);
  font-size: 15px;
}
.about-meta-row:first-of-type { border-top: 0; padding-top: 0; }
.about-meta-row .k { color: rgba(252,249,241,0.65); }
.about-meta-row .v { color: var(--gold-300); font-weight: 600; }

.about-note {
  padding: 18px 20px;
  background: rgba(176,144,80,0.08);
  color: var(--ink-900);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  font-family: var(--ff-display);
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink-700);
  display: flex;
  gap: 12px;
}
.about-note svg { flex-shrink: 0; width: 22px; height: 22px; color: var(--gold-700); margin-top: 2px; }

/* Buy block */
.about-buy {
  margin-top: 20px;
  padding: 20px;
  background: linear-gradient(180deg, rgba(176,144,80,0.14), rgba(176,144,80,0.06));
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
}
.about-buy-heading {
  font-family: var(--ff-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-text);
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.about-buy-ico {
  display: inline-flex;
  width: 18px;
  height: 18px;
  color: var(--gold-700);
}
.about-buy-ico svg { width: 18px; height: 18px; }
.about-buy-note {
  font-size: 13px;
  color: var(--ink-500);
  margin: 0 0 14px;
  line-height: 1.7;
}
.about-buy-cta {
  width: 100%;
}

/* Contact block */
.about-contact {
  margin-top: 20px;
  padding: 18px 20px;
  background: rgba(176,144,80,0.06);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
}
.about-contact-heading {
  font-family: var(--ff-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--gold-text);
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.about-contact-note {
  font-size: 13px;
  color: var(--ink-500);
  margin: 0 0 14px;
  line-height: 1.6;
}
.about-contact-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-top: 1px solid var(--gold-line);
  text-decoration: none;
  gap: 12px;
  transition: opacity 0.15s;
}
.about-contact-row:hover { opacity: 0.75; }
.about-contact-row .k {
  font-size: 13px;
  color: var(--ink-500);
  flex-shrink: 0;
}
.about-contact-row .v {
  font-size: 13px;
  color: var(--gold-text);
  font-weight: 700;
  direction: ltr;
  text-align: end;
  word-break: break-all;
}

/* Scholars grid */
.scholars-section {
  margin-top: 64px;
}
.scholars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 24px;
}
.scholar-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all 180ms ease;
}
.scholar-tile:hover {
  border-color: var(--gold-line);
  background: var(--cream-50);
  transform: translateY(-1px);
}
.scholar-seal {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--cream-200);
  border: 1px solid var(--gold-line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--num-disc-ink);
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: 14px;
}
.scholar-tile .name {
  font-family: var(--ff-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-900);
  line-height: 1.4;
}
.scholar-tile .honorific {
  font-family: var(--ff-display);
  font-size: 12.5px;
  color: var(--ink-500);
  margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════════
   ADMIN
   ═══════════════════════════════════════════════════════════ */
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 24px;
}
@media (max-width: 980px) { .admin-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 32px 36px;
  box-shadow: var(--shadow-sm);
}
.panel h3 {
  font-family: var(--ff-display);
  font-size: 22px;
  margin: 0 0 6px;
  color: var(--gold-text);
}
.panel .panel-sub {
  font-size: 14px;
  color: var(--ink-500);
  margin-bottom: 24px;
}

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-family: var(--ff-display);
  font-size: 14px;
  color: var(--ink-700);
  margin-bottom: 6px;
  font-weight: 600;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-family: var(--ff-body);
  font-size: 15px;
  background: var(--cream-50);
  color: var(--ink-900);
  transition: all 160ms ease;
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.7; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(176,144,80,0.18);
  background: var(--surface);
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--line);
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--cream-50);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.admin-row .type-badge {
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  background: var(--cream-200);
}
.admin-row.t-audio .type-badge { background: rgba(176,144,80,0.10); color: var(--gold-300); }
.admin-row.t-video .type-badge { background: rgba(176,144,80,0.18); color: var(--gold-700); }
.admin-row.t-page  .type-badge { background: var(--cream-300); color: var(--ink-700); }
.admin-row .info { flex: 1; min-width: 0; }
.admin-row .t {
  font-family: var(--ff-display);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.admin-row .s {
  font-size: 12.5px;
  color: var(--ink-500);
  font-family: var(--ff-display);
}
.admin-row .x-btn {
  background: transparent;
  border: 0;
  color: var(--ink-400);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.admin-row .x-btn:hover { background: rgba(190,30,30,0.08); color: #b22; }

.admin-toast {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 24px;
  background: var(--teal-800);
  color: var(--gold-300);
  padding: 12px 20px;
  border-radius: 999px;
  font-family: var(--ff-display);
  font-size: 15px;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,0.3);
  border: 1px solid var(--gold-500);
  animation: toastIn 240ms ease;
  z-index: 300;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .page { padding: 40px 36px 80px; }
  .hero { padding: 48px 32px 56px; }
  .hero-title { font-size: 56px; }
  .chapter-detail { padding: 40px 36px; }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    inset-inline-end: 0;
    bottom: 0;
    width: 84vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 280ms cubic-bezier(0.2,0.7,0.2,1);
    box-shadow: -20px 0 60px -20px rgba(0,0,0,0.4);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  [dir="ltr"] .sidebar { transform: translateX(100%); }
  .sidebar.is-open,
  [dir="ltr"] .sidebar.is-open { transform: translateX(0); }
  .sidebar-trigger { display: flex; }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(16,12,8,0.5);
    z-index: 49;
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }
  .sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }
  .page { padding: 80px 20px 60px; }
  .hero { padding: 40px 22px 48px; }
  .bismillah { font-size: 28px; }
  .hero-title { font-size: 40px; }
  .hero-subtitle { font-size: 17px; }
  .stats { grid-template-columns: 1fr; gap: 20px; }
  .stat + .stat::before { display: none; }
  .stat + .stat { padding-top: 20px; border-top: 1px dashed rgba(176,144,80,0.28); }
  .page-title { font-size: 32px; }
  .chapter-detail { padding: 28px 22px; }
  .chapter-detail h1 { font-size: 28px; }
  .modal-overlay { padding: 12px; }
  .modal-body { padding: 22px; }
  .modal-title { font-size: 22px; }
  .field-row { grid-template-columns: 1fr; }

  /* Media library: prevent horizontal overflow of the page */
  .media-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .media-tabs {
    display: flex;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .media-tabs::-webkit-scrollbar { display: none; }
  .media-tabs button {
    flex: 0 0 auto;
    padding: 8px 14px;
    font-size: 14px;
    gap: 6px;
  }
  .media-search {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .media-grid { grid-template-columns: 1fr; gap: 14px; }

  /* Media modal: tighter spacing, no horizontal overflow inside the modal */
  .modal-stage.audio { padding: 32px 16px; gap: 18px; }
  .modal-stage.audio audio { max-width: 100%; }
  .audio-art { width: 96px; height: 96px; }
  .audio-art svg { width: 40px; height: 40px; }
  .modal-page-stage { padding: 36px 18px; }
  .modal-page-stage .url { max-width: 100%; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
  .modal-meta-grid { padding: 14px 16px; grid-template-columns: 1fr 1fr; }
}

/* Defensive: never let a stray-wide child shift the whole document.
   overflow-x:clip (not hidden) so sticky children keep their scroll context. */
html, body { overflow-x: clip; }

/* ───────── New: chapter summary, page range ───────── */
.chapter-page-range {
  font-family: var(--ff-num);
  color: var(--ink-500);
  font-size: 15px;
  margin: 4px 0 16px;
  letter-spacing: 0.02em;
}
.chapter-summary-eyebrow {
  font-family: var(--ff-display);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-text);
  margin: 14px 0 6px;
}
.chapter-summary {
  font-family: var(--ff-body);
  color: var(--ink-700);
  line-height: 1.95;
  font-size: 17px;
  margin: 0 0 14px;
}

/* ───────── New: admin tabs and panels ───────── */
.admin-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin: 18px 0 24px;
  flex-wrap: wrap;
}
.admin-tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-500);
  font-family: var(--ff-display);
  font-size: 16px;
  padding: 10px 16px;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease;
}
.admin-tab:hover { color: var(--ink-900); }
.admin-tab.is-active {
  color: var(--gold-500);
  border-bottom-color: var(--gold-500);
}
.admin-body { display: block; }

.admin-row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-500);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 160ms ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover {
  color: var(--ink-900);
  border-color: var(--gold-line);
}
.icon-btn.x-btn:hover { color: #d8665a; border-color: rgba(216,102,90,0.3); }

/* honorific text adjacent to scholar tile */
.scholar-tile .honorific {
  color: var(--ink-500);
  font-size: 13px;
  margin-top: 2px;
}

/* media-row chapter summary block respects RTL */
[dir="rtl"] .chapter-page-range { text-align: right; }
[dir="ltr"] .chapter-page-range { text-align: left; }

/* ═══════════════════════════════════════════════════════════
   READER SETTINGS PANEL
   ═══════════════════════════════════════════════════════════ */
.reader-popover {
  position: fixed;
  z-index: 220;
  inset-inline-end: 24px;
  bottom: 24px;
  width: min(360px, calc(100vw - 32px));
  max-height: min(80vh, 640px);
  overflow-y: auto;
  background: var(--surface);
  color: var(--ink-900);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.55);
  padding: 22px 22px 18px;
  font-family: var(--ff-body);
  animation: readerIn 200ms cubic-bezier(0.2,0.7,0.2,1);
}
@keyframes readerIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.reader-popover h3 {
  margin: 0 0 4px;
  font-family: var(--ff-display);
  font-size: 19px;
  color: var(--gold-text);
}
.reader-popover .reader-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--ink-500);
}
.reader-popover .reader-section {
  padding: 14px 0;
  border-top: 1px dashed var(--line-strong);
}
.reader-popover .reader-section:first-of-type { border-top: 0; padding-top: 4px; }
.reader-popover .reader-label {
  font-family: var(--ff-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-700);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  letter-spacing: 0.04em;
}
.reader-popover .reader-label .reader-value {
  font-size: 12px;
  color: var(--gold-text);
  font-weight: 600;
}
.reader-popover .reader-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.reader-popover .reader-options button {
  flex: 1 1 auto;
  min-width: 56px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-700);
  font-family: var(--ff-display);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 140ms ease;
}
.reader-popover .reader-options button:hover {
  border-color: var(--gold-line);
  color: var(--ink-900);
}
.reader-popover .reader-options button.is-active {
  border-color: var(--gold-500);
  background: rgba(176,144,80,0.22);
  color: var(--gold-text);
  font-weight: 700;
}
.reader-popover .reader-font-list { display: grid; gap: 6px; }
.reader-popover .reader-font-list button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-900);
  cursor: pointer;
  text-align: start;
  transition: all 140ms ease;
}
.reader-popover .reader-font-list button:hover { border-color: var(--gold-line); }
.reader-popover .reader-font-list button.is-active {
  border-color: var(--gold-500);
  background: rgba(176,144,80,0.10);
}
.reader-popover .reader-font-list .font-name {
  font-size: 18px;
  line-height: 1.2;
}
.reader-popover .reader-font-list .font-tag {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-700);
  font-family: var(--ff-display);
  font-weight: 600;
  text-transform: uppercase;
}
.reader-popover .reader-toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reader-popover .reader-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
  color: var(--ink-700);
}
.reader-popover .reader-toggle .reader-toggle-label {
  font-weight: 600;
  color: var(--ink-900);
}
.reader-popover .reader-toggle .reader-toggle-sub {
  font-size: 12px;
  color: var(--ink-500);
  margin-top: 2px;
}
.reader-switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--line-strong);
  border: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 160ms ease;
}
.reader-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 160ms cubic-bezier(0.2,0.7,0.2,1);
}
[dir="ltr"] .reader-switch.is-on::after { transform: translateX(18px); }
[dir="rtl"] .reader-switch.is-on::after { transform: translateX(-18px); }
.reader-switch.is-on { background: var(--gold-500); }
.reader-popover .reader-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line-strong);
}
.reader-popover .reader-reset {
  background: transparent;
  border: 0;
  color: var(--ink-500);
  font-family: var(--ff-display);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--r-sm);
}
.reader-popover .reader-reset:hover { color: var(--ink-900); background: rgba(176,144,80,0.08); }
.reader-popover .reader-close {
  background: var(--gold-500);
  color: #1a160e;
  border: 0;
  font-family: var(--ff-display);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.reader-popover .reader-close:hover { background: var(--gold-400); }

/* Reader popover backdrop (mobile only — desktop floats free) */
@media (max-width: 720px) {
  .reader-popover {
    inset-inline-end: 16px;
    inset-inline-start: 16px;
    width: auto;
    bottom: 16px;
  }
  .reader-backdrop {
    position: fixed; inset: 0;
    background: rgba(16,12,8,0.4);
    z-index: 219;
    animation: fadeIn 180ms ease;
  }
}

/* ═══════════════════════════════════════════════════════════
   THEMED SCROLLBARS
   Cross-browser, gold-accented, rounded — matches manuscript vibe.
   - Firefox: scrollbar-color / scrollbar-width
   - WebKit/Blink (Chrome, Edge, Safari, Opera, iOS Safari): ::-webkit-scrollbar
   iOS Safari ignores ::-webkit-scrollbar on page scroll (uses native flick
   indicator that auto-hides — already on-theme), but applies it to scrollable
   children. Firefox-only props are no-ops elsewhere; safe to ship.
   ═══════════════════════════════════════════════════════════ */
:root {
  --scroll-track: rgba(176, 144, 80, 0.08);
  --scroll-thumb: linear-gradient(180deg, #b09050, #907040);
  --scroll-thumb-hover: linear-gradient(180deg, #c9a55a, #b09050);
  --scroll-thumb-solid: #907040;
}
body.is-light {
  --scroll-track: rgba(28, 22, 16, 0.06);
  --scroll-thumb: linear-gradient(180deg, #b09050, #6b5520);
  --scroll-thumb-hover: linear-gradient(180deg, #c9a55a, #907040);
  --scroll-thumb-solid: #907040;
}

/* Firefox */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb-solid) transparent;
}
* {
  scrollbar-color: var(--scroll-thumb-solid) transparent;
}

/* WebKit / Blink */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(176, 144, 80, 0.35);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}
/* Slimmer scrollbars inside modal & reader popover so they read as accents */
.modal::-webkit-scrollbar,
.reader-popover::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.modal::-webkit-scrollbar-thumb,
.reader-popover::-webkit-scrollbar-thumb {
  border-width: 2px;
}

/* ═══════════════════════════════════════════════════════════
   LIGHT-MODE CONTRAST & PARITY POLISH
   These cover small surfaces where the dark→light token map left
   gold-on-cream readability gaps or kept references to literal dark
   colors (--gold-300, --gold-100) used as TEXT on light surfaces.
   ═══════════════════════════════════════════════════════════ */

/* Body bg/color — re-stated with higher specificity so plain `body`
   rules later in the cascade cannot win the shorthand. */
body.is-light {
  background-color: var(--cream-100);
  color: var(--ink-900);
}

/* Media-row surface in light (uses light tokens; not a dark-pin). */
body.is-light .media-row { background: var(--surface); }
body.is-light .media-row:hover { background: var(--cream-200); }

/* NOTE: tab active-state, chapter-num-lg, modal-stage (video+audio) and
   modal-pill-ep no longer need light overrides — they read from the
   --tab-active-ink / --accent-pill-* / --stage-* tokens, which carry the
   correct value in each theme. Their old dark-pin overrides were removed. */

/* Admin badges: gold-300 on near-white reads poorly */
body.is-light .admin-row.t-audio .type-badge { color: var(--gold-text); }
body.is-light .admin-row.t-video .type-badge { color: var(--gold-text); }

/* Admin toast keeps dark surface */
body.is-light .admin-toast {
  background: #1a160e;
  color: var(--gold-300);
  border-color: var(--gold-500);
}

/* Chapter-tabs/media-tabs container bg subtle in light */
body.is-light .chapter-tabs,
body.is-light .media-tabs {
  background: var(--cream-200);
}

/* Reader-popover stays light-themed in light mode (uses --surface/--ink-* ✓) */

/* ═══════════════════════════════════════════════════════════
   CUSTOM MEDIA PLAYER (audio + video)
   Replaces the native <audio controls> chrome with a themed shell so
   the timeline, play button and time read-out match the manuscript
   palette across every OS (Win/Mac/Linux/iOS/Android). Native
   <video controls> are kept for video so fullscreen / PiP / keyboard
   a11y stay browser-native; we wrap them in a themed frame instead.
   ═══════════════════════════════════════════════════════════ */
.mplayer {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 560px;
}
.mplayer.is-video {
  max-width: 100%;
}
.mplayer-video-wrap {
  position: relative;
  width: 100%;
  /* Reserve 16:9 box on mount so the player has its final size before
     <video> metadata loads — eliminates the layout snap / loading flash. */
  aspect-ratio: 16 / 9;
  max-height: 60vh;
  background: #000;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid rgba(176, 144, 80, 0.35);
  box-shadow: 0 8px 24px -10px rgba(0, 0, 0, 0.6);
}
.mplayer-video-wrap video {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* contain = no crop; the wrap adopts the video's real aspect-ratio at
     loadedmetadata so contain & cover render identically with no bars. */
  object-fit: contain;
  background: #000;
}
.mplayer audio {
  /* Hide the native audio element entirely; we drive it via the shell */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.mplayer-shell {
  /* Force LTR for the player chrome — play sits at the visual start,
     volume at the visual end, timeline fills left→right. This matches
     universal media-player conventions (YouTube, Spotify, Apple Music)
     regardless of the page's RTL/LTR direction. */
  direction: ltr;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(28, 22, 16, 0.85), rgba(12, 10, 7, 0.92));
  border: 1px solid rgba(176, 144, 80, 0.32);
  border-radius: 999px;
  box-shadow: 0 6px 20px -10px rgba(0, 0, 0, 0.45),
              inset 0 1px 0 rgba(255, 255, 255, 0.04);
  color: #ecd9a5;
  font-family: var(--ff-display);
}
/* Desktop: flatten the ctrls wrapper into the same flex row as the
   timeline via display:contents, then use `order` to restore the
   classic single-row layout:
     [back10] [play] [fwd10] [time] [track] [speed] [vol] [pip] [fs] */
.mplayer-ctrls { display: contents; }
.mplayer-shell > .mplayer-ctrls > .mplayer-btn.is-skip:first-child { order: 1; }
.mplayer-shell > .mplayer-ctrls > .mplayer-btn.is-play { order: 2; }
.mplayer-shell > .mplayer-ctrls > .mplayer-btn.is-skip:nth-child(3) { order: 3; }
.mplayer-shell > .mplayer-time { order: 4; }
.mplayer-shell > .mplayer-track { order: 5; }
.mplayer-shell > .mplayer-ctrls > .mplayer-rate { order: 6; }
.mplayer-shell > .mplayer-ctrls > .mplayer-vol { order: 7; }
.mplayer-shell > .mplayer-ctrls > .mplayer-btn:not(.is-skip):not(.is-play) { order: 8; }
.mplayer-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--gold-500);
  background: rgba(176, 144, 80, 0.14);
  color: var(--gold-300);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 160ms ease, transform 160ms ease, color 160ms ease;
}
.mplayer-btn:hover {
  background: rgba(176, 144, 80, 0.28);
  color: var(--gold-100);
}
.mplayer-btn:active { transform: scale(0.96); }
.mplayer-btn svg { width: 16px; height: 16px; }
.mplayer-btn.is-play svg { width: 18px; height: 18px; transform: translateX(1px); }

.mplayer-time {
  /* Clean system sans for numerics — Amiri (the display font) gives
     unreadable, ornate digits in a tiny timer. */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter',
               'Helvetica Neue', Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: rgba(236, 217, 165, 0.92);
  flex-shrink: 0;
  min-width: 92px;
  text-align: center;
  direction: ltr; /* time always LTR */
  white-space: nowrap;
}
.mplayer-track {
  position: relative;
  flex: 1 1 auto;
  height: 24px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
/* Invisible vertical tap-buffer: extends the track's hit area to fill
   the full height of the shell row. A finger tapping anywhere in the
   timeline's vertical band — not just on the 6px rail — gets caught. */
.mplayer-track::before {
  content: '';
  position: absolute;
  inset-inline: 0;
  top: -14px;
  bottom: -14px;
  z-index: 0;
}
.mplayer-track-rail, .mplayer-track-thumb { z-index: 1; }
.mplayer-track-rail {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.mplayer-track-buffer {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 0%;
  background: rgba(176, 144, 80, 0.22);
  border-radius: 999px;
  transition: width 220ms linear;
}
.mplayer-track-fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-500), var(--gold-300));
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(176, 144, 80, 0.4);
}
.mplayer-track-thumb {
  position: absolute;
  top: 50%;
  inset-inline-start: 0%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold-300);
  border: 2px solid #1a160e;
  box-shadow: 0 0 0 1px rgba(176, 144, 80, 0.6), 0 2px 6px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  transition: transform 160ms ease, box-shadow 160ms ease;
  pointer-events: none;
}
.mplayer-track:hover .mplayer-track-thumb,
.mplayer-track.is-scrubbing .mplayer-track-thumb {
  box-shadow: 0 0 0 4px rgba(176, 144, 80, 0.25), 0 0 0 1px rgba(176, 144, 80, 0.8), 0 2px 6px rgba(0, 0, 0, 0.5);
}

/* Precision-scrub hint: when the user slides their finger down off the
   rail while dragging, the seek speed drops. Show the current speed
   above the thumb so the gesture is discoverable. */
.mplayer-track.is-precision::after {
  content: attr(data-precision) ' speed';
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  background: rgba(12, 10, 7, 0.94);
  border: 1px solid rgba(176, 144, 80, 0.5);
  border-radius: 999px;
  color: var(--gold-100);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter',
               'Helvetica Neue', Arial, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.6);
  animation: precisionHintIn 120ms ease-out;
}
@keyframes precisionHintIn {
  from { opacity: 0; transform: translate(-50%, 4px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.mplayer-track.is-precision .mplayer-track-thumb {
  box-shadow: 0 0 0 6px rgba(176, 144, 80, 0.32), 0 0 0 1px rgba(176, 144, 80, 0.9), 0 2px 8px rgba(0, 0, 0, 0.6);
}
.mplayer-track.is-precision .mplayer-track-rail {
  /* Subtle glow when in precision mode — reinforces "you're locked in" */
  box-shadow: 0 0 0 1px rgba(176, 144, 80, 0.45);
}

.mplayer-vol {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.mplayer-vol-track {
  position: relative;
  width: 64px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  touch-action: none;
}
.mplayer-vol-fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 100%;
  background: rgba(176, 144, 80, 0.7);
  border-radius: 999px;
}

/* Skip buttons — slightly smaller than the play button */
.mplayer-btn.is-skip {
  width: 32px;
  height: 32px;
  border-color: rgba(176, 144, 80, 0.42);
  background: rgba(176, 144, 80, 0.08);
}
.mplayer-btn.is-skip svg { width: 16px; height: 16px; }

/* Playback-speed button + popup */
.mplayer-rate {
  position: relative;
  flex-shrink: 0;
}
.mplayer-btn.is-rate {
  width: auto;
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter',
               'Helvetica Neue', Arial, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}
.mplayer-rate-menu {
  /* Portaled to document.body. Use fixed positioning so the menu lives in
     viewport coordinates and is never clipped by an ancestor's overflow.
     `top` and `left` are set imperatively in JS from the speed button's
     getBoundingClientRect(), with viewport clamping in both axes. */
  position: fixed;
  top: 0;
  left: 0;
  min-width: 148px;
  padding: 6px;
  background: linear-gradient(180deg, rgba(28, 22, 16, 0.96), rgba(12, 10, 7, 0.98));
  border: 1px solid rgba(176, 144, 80, 0.42);
  border-radius: var(--r-md);
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Sit above the modal overlay (z-index 100ish) so the menu wins. */
  z-index: 10000;
  animation: rateMenuIn 140ms ease-out;
  /* No scrollbar — the menu has 7 fixed items and the portal positioner
     places it where it fits. Clip overflow rather than scroll. */
  overflow: hidden;
}
.mplayer-rate-menu.is-below { animation: rateMenuInDown 140ms ease-out; }
@keyframes rateMenuIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes rateMenuInDown {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.mplayer-rate-menu[hidden] { display: none; }
.mplayer-rate-opt {
  background: transparent;
  border: 0;
  color: rgba(236, 217, 165, 0.85);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter',
               'Helvetica Neue', Arial, sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  text-align: start;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
  font-variant-numeric: tabular-nums;
}
.mplayer-rate-opt:hover { background: rgba(176, 144, 80, 0.14); color: #f0c95e; }
.mplayer-rate-opt.is-active {
  background: rgba(176, 144, 80, 0.22);
  color: var(--gold-100);
}

.mplayer:focus-within .mplayer-shell {
  border-color: var(--gold-400);
  box-shadow: 0 0 0 3px rgba(176, 144, 80, 0.22),
              0 6px 20px -10px rgba(0, 0, 0, 0.45);
}

/* Video layout: shell is overlaid on the video and auto-hides while playing,
   so the picture is unobstructed during watching. */
.mplayer.is-video {
  position: relative;
  gap: 0;
  /* No rounded corners — sharp edges so no modal background peeks
     through the curve where the video meets the shell. */
  border-radius: 0;
  overflow: hidden;
}
.mplayer.is-video .mplayer-video-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.mplayer.is-video .mplayer-shell {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  /* Stronger gradient so text/buttons stay legible over any frame */
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.55) 35%, rgba(12, 10, 7, 0.92) 100%);
  padding-top: 28px;
  transition: opacity 200ms ease, transform 200ms ease;
}
/* Touch devices wider than 640px (tablets in landscape): bump up the
   button sizes and bottom-safe-area padding. The narrow-mobile layout
   above already handles phones; this block covers iPads, etc. */
@media (hover: none) and (min-width: 641px), (pointer: coarse) and (min-width: 641px) {
  .mplayer.is-video .mplayer-shell {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .mplayer-btn { width: 40px; height: 40px; }
  .mplayer-btn.is-skip { width: 36px; height: 36px; }
  .mplayer-btn.is-play { width: 44px; height: 44px; }
  .mplayer-track { height: 36px; }
  .mplayer-track-rail { height: 10px; }
  .mplayer-track-thumb { width: 22px; height: 22px; border-width: 3px; }
  .mplayer-track .mplayer-track-thumb {
    box-shadow: 0 0 0 4px rgba(176, 144, 80, 0.22), 0 0 0 1px rgba(176, 144, 80, 0.8), 0 2px 8px rgba(0, 0, 0, 0.55);
  }
  .mplayer-track.is-scrubbing .mplayer-track-thumb {
    transform: translate(-50%, -50%) scale(1.2);
  }
}
/* Auto-hide while playing. Revealed on hover, focus, pause, or any pointer
   activity over the player (see is-idle toggle in JS). */
.mplayer.is-video.is-idle .mplayer-shell {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.mplayer.is-video.is-idle .mplayer-video-wrap,
.mplayer.is-video.is-idle .mplayer-video-wrap video {
  cursor: none;
}
/* Keep shell visible when the rate menu is open, even if idle timer fires.
   .is-rate-open is toggled in JS because the menu is now portaled to body
   (so :has() against a descendant no longer works). */
.mplayer.is-video.is-rate-open .mplayer-shell {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Fullscreen: fullscreen the OUTER .mplayer so the overlaid shell comes
   with it. Video wrap and video stretch to fill. */
.mplayer:fullscreen,
.mplayer:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  background: #000;
}
.mplayer:fullscreen .mplayer-video-wrap,
.mplayer:-webkit-full-screen .mplayer-video-wrap {
  width: 100vw !important;
  height: 100vh !important;
  max-height: none !important;
  /* !important needed because JS sets an inline aspect-ratio on the wrap
     from the source video's natural dimensions; without this, the wrap
     stays at e.g. 480/360 inside the viewport and leaves dead space. */
  aspect-ratio: auto !important;
}
.mplayer:fullscreen .mplayer-video-wrap video,
.mplayer:-webkit-full-screen .mplayer-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Mobile: TWO-ROW shell layout — timeline on its own row (full width,
   generous tap area), buttons + time below. Matches the layout used
   by YouTube, Netflix, and Apple's mobile players. */
@media (max-width: 640px) {
  .mplayer-shell {
    flex-wrap: wrap;
    padding: 8px 10px 10px;
    gap: 6px 10px;
    border-radius: var(--r-md);
  }
  /* Row 1: timeline (full width). Mobile order overrides desktop. */
  .mplayer-shell > .mplayer-track {
    order: 0;
    flex: 1 0 100%;
    height: 40px;            /* full-width vertical tap area */
    margin-bottom: -4px;     /* tuck closer to row 2 */
  }
  .mplayer-shell > .mplayer-track::before {
    top: -6px;
    bottom: -6px;
  }
  .mplayer-track-rail { height: 8px; }
  .mplayer-track-thumb { width: 20px; height: 20px; border-width: 3px; }
  /* Thumb always visible on mobile (no hover state) */
  .mplayer-shell .mplayer-track .mplayer-track-thumb {
    box-shadow: 0 0 0 3px rgba(176, 144, 80, 0.22), 0 0 0 1px rgba(176, 144, 80, 0.8), 0 2px 8px rgba(0, 0, 0, 0.55);
  }
  /* Row 2: ctrls becomes a flex row (override desktop's display:contents)
     so all the buttons line up. Time pinned to the right. */
  .mplayer-shell > .mplayer-ctrls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    order: 1;
    min-width: 0;
  }
  /* Inside the ctrls flex, the children inherit the desktop `order`
     values via descendant selectors — reset them to their natural
     source order so back10/play/fwd10/.../fs lay out left-to-right. */
  .mplayer-shell > .mplayer-ctrls > * { order: 0; }
  .mplayer-shell > .mplayer-time {
    order: 2;
    min-width: 0;
    font-size: 12px;
    text-align: end;
    flex: 0 0 auto;
    margin-inline-start: auto;
  }
  .mplayer-vol-track { display: none; }
  .mplayer-btn { width: 36px; height: 36px; }
  .mplayer-btn.is-play { width: 42px; height: 42px; }
  .mplayer-btn.is-skip { width: 32px; height: 32px; }
  .mplayer-btn.is-rate { min-width: 42px; padding: 0 10px; font-size: 12px; height: 32px; }
  /* Let portrait/odd-ratio videos take the height they need on mobile
     instead of squeezing into 60vh and exposing black bars inside. */
  .mplayer-video-wrap { max-height: 80vh; }
  /* Bigger taps and a hard floor on the rate-menu height so it's always
     usable on a phone even if JS couldn't measure for some reason. */
  .mplayer-rate-menu {
    min-width: 148px;
    padding: 4px;
    /* Cap to viewport so the menu can never grow taller than the screen. */
    max-height: min(280px, 60vh);
  }
  .mplayer-rate-opt {
    padding: 12px 14px;
    font-size: 14px;
  }
}
@media (max-width: 420px) {
  /* Very narrow screens: drop the skip buttons (still available via
     keyboard ←/→) so the timeline keeps real estate. */
  .mplayer-btn.is-skip { display: none; }
}

/* Light-mode shell stays dark — it sits on the modal-stage which we
   keep dark for cinema feel — so no additional override needed. */

