/* ===== LOCAL FONTS (fonts/) ===== */

/* Vazirmatn (UI Font) */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-400.woff2") format("woff2");
  font-weight: 300 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-700.woff2") format("woff2");
  font-weight: 700 800;
  font-style: normal;
  font-display: swap;
}

/* Lotus / Yaqoot (Book Font) */
@font-face {
  font-family: "Lotus";
  src: url("fonts/Lotus-Light.woff2") format("woff2"),
    url("fonts/lotus.ttf") format("truetype");
  font-weight: 300 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Lotus";
  src: url("fonts/Lotus-Bold.woff2") format("woff2");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Lotus Linotype";
  src: url("fonts/Lotus-Light.woff2") format("woff2"),
    url("fonts/lotus.ttf") format("truetype");
  font-weight: 300 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Lotus Linotype";
  src: url("fonts/Lotus-Bold.woff2") format("woff2");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Yaqoot";
  src: url("fonts/Lotus-Light.woff2") format("woff2"),
    url("fonts/lotus.ttf") format("truetype");
  font-weight: 300 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Yaqoot";
  src: url("fonts/Lotus-Bold.woff2") format("woff2");
  font-weight: 700 900;
  font-style: normal;
  font-display: swap;
}

/* Amiri */
@font-face {
  font-family: "Amiri";
  src: url("fonts/amiri-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Amiri";
  src: url("fonts/amiri-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* Noto Naskh Arabic */
@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("fonts/noto-naskh-arabic-400.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("fonts/noto-naskh-arabic-700.woff2") format("woff2");
  font-weight: 600 700;
  font-style: normal;
  font-display: swap;
}

/* Digital Khatt — Uthmanic Hafs (KFGQPC V2, 1421H), OFL-1.1
   https://fonts.quran.ws/fonts/digital-khatt-v2/ */
@font-face {
  font-family: "DigitalKhatt";
  src: url("fonts/digital-khatt-v2.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ===== CSS RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --book-font: "Yaqoot", "Lotus", "Lotus Linotype", serif;
  --bg: #eef3f8;
  --bg: #f3f6fb;
  --page-bg: #ffffff;
  --page-bg-sepia: #f4ecd8;
  --page-bg-dark: #2d2d2d;
  --header-bg: #ffffff;
  --sidebar-bg: #ffffff;
  --toolbar-bg: #ffffff;
  --text: #1a2332;
  --text-muted: #5a6a7a;
  --text-light: #8a9aab;
  --border: #d4deea;
  --border: #bccde6;
  --accent: #143686;
  --accent-hover: #0e265e;
  --accent-light: #e4ebf7;
  --accent-hover: #102d6f;
  --accent-light: #e2edf8;
  --accent-glow: rgba(20, 54, 134, .18);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .12);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, .18);
  --shadow-book: -8px 0 24px rgba(0, 0, 0, .18), 8px 0 24px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .1);
  --radius: 8px;
  --font-size: 17px;
  --line-height: 2.2;
  --page-max-width: 990px;
  --transition: .2s ease;

  /* lib.iq blue palette tokens */
  --ink: #143686;
  --ink-deep: #0b1f4d;
  --paper: #f4f7fb;
  --paper-soft: #e8eef6;
  --paper-soft: #e2edf8;
  --sand: #d9e3ef;
  --sand-deep: #c5d2e3;
  --sand-deep: #bccde6;
  --teal: #007bc0;
  --teal-soft: #d6ecf8;
  --gold: #64b1fc;
  --muted: #5a6a7a;
  --rule: #d4deea;
  --rule: #bccde6;

  /* Search highlight & selection colors (Default: Blue) */
  --search-hl-bg: #cfe4fc;
  --search-hl-color: #0b2a63;
  --search-hl-active-bg: #143686;
  --search-hl-active-color: #ffffff;
  --search-hl-active-outline: #007bc0;
  --search-hl-active-glow: rgba(20, 54, 134, 0.35);
  --selection-bg: #cfe4fc;
  --selection-color: #0b2a63;
}

body.theme-blue {
  --bg: #eef3f8;
  --bg: #f3f6fb;
  --page-bg: #ffffff;
  --header-bg: #ffffff;
  --sidebar-bg: #ffffff;
  --toolbar-bg: #ffffff;
  --text: #1a2332;
  --text-muted: #5a6a7a;
  --text-light: #8a9aab;
  --border: #d4deea;
  --border: #bccde6;
  --accent: #143686;
  --accent-hover: #0e265e;
  --accent-light: #e4ebf7;
  --accent-hover: #102d6f;
  --accent-light: #e2edf8;
  --accent-glow: rgba(20, 54, 134, .18);
  --ink: #143686;
  --ink-deep: #0b1f4d;
  --paper: #f4f7fb;
  --paper-soft: #e8eef6;
  --paper-soft: #e2edf8;
  --sand: #d9e3ef;
  --sand-deep: #c5d2e3;
  --sand-deep: #bccde6;
  --teal: #007bc0;
  --teal-soft: #d6ecf8;
  --gold: #64b1fc;
  --muted: #5a6a7a;
  --rule: #d4deea;
  --rule: #bccde6;

  /* Search highlight & selection colors (Default: Blue) */
  --search-hl-bg: #cfe4fc;
  --search-hl-color: #0b2a63;
  --search-hl-active-bg: #143686;
  --search-hl-active-color: #ffffff;
  --search-hl-active-outline: #007bc0;
  --search-hl-active-glow: rgba(20, 54, 134, 0.35);
  --selection-bg: #cfe4fc;
  --selection-color: #0b2a63;
}

body.theme-light {
  --bg: #f5f0eb;
  --page-bg: #fffef8;
  --header-bg: #ffffff;
  --sidebar-bg: #ffffff;
  --toolbar-bg: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --text-light: #999;
  --border: #e0dbd4;
  --accent: #1a73e8;
  --accent-hover: #1557b0;
  --accent-light: #e8f0fe;
  --accent-glow: rgba(26, 115, 232, .15);
  --ink: #1c2d2a;
  --ink-deep: #12201e;
  --paper: #f7f1e6;
  --paper-soft: #efe6d6;
  --sand: #e4d7c3;
  --sand-deep: #d8c7ad;
  --teal: #2f6f68;
  --teal-soft: #d7ebe6;
  --gold: #c4a35a;
  --muted: #5c6b67;
  --rule: #d2c4ae;

  /* Search highlight & selection colors */
  --search-hl-bg: #fef08a;
  --search-hl-color: #1a1a1a;
  --search-hl-active-bg: #f59e0b;
  --search-hl-active-color: #111111;
  --search-hl-active-outline: #b45309;
  --search-hl-active-glow: rgba(245, 158, 11, 0.45);
  --selection-bg: #fef08a;
  --selection-color: #1a1a1a;
}

body.theme-dark {
  --bg: #1a1a1a;
  --page-bg: #2a2a2a;
  --header-bg: #222;
  --sidebar-bg: #222;
  --toolbar-bg: #222;
  --text: #e8e8e8;
  --text-muted: #aaa;
  --text-light: #777;
  --border: #3a3a3a;
  --accent-glow: rgba(26, 115, 232, .25);
  --shadow-book: -8px 0 24px rgba(0, 0, 0, .5), 8px 0 24px rgba(0, 0, 0, .4);

  /* dl.lib.iq reader palette tokens - Night */
  --ink: #e7e1d6;
  --ink-deep: #f4efe4;
  --paper: #1a211e;
  --paper-soft: #26302c;
  --sand: #2c3833;
  --sand-deep: #38443e;
  --teal: #8fcec0;
  --teal-soft: #243833;
  --gold: #d4b56a;
  --muted: #b7c2bc;
  --rule: #3c4843;

  /* Search highlight & selection colors */
  --search-hl-bg: #1e3a5f;
  --search-hl-color: #bfdbfe;
  --search-hl-active-bg: #2563eb;
  --search-hl-active-color: #ffffff;
  --search-hl-active-outline: #93c5fd;
  --search-hl-active-glow: rgba(37, 99, 235, 0.5);
  --selection-bg: #1e3a5f;
  --selection-color: #ffffff;
}

body.theme-sepia {
  --bg: #e8dcc8;
  --page-bg: #f4ecd8;
  --header-bg: #f0e6d0;
  --sidebar-bg: #f0e6d0;
  --toolbar-bg: #f0e6d0;
  --text: #3b2f1e;
  --text-muted: #7a6045;
  --border: #d4c4a0;
  --accent-glow: rgba(42, 99, 86, .18);

  /* dl.lib.iq reader palette tokens - Sepia */
  --ink: #3b2f1e;
  --ink-deep: #281e10;
  --paper: #f4ecd8;
  --paper-soft: #ede1c7;
  --sand: #e5d6b8;
  --sand-deep: #d8c4a0;
  --teal: #2a6356;
  --teal-soft: #dbeae4;
  --gold: #b38b36;
  --muted: #7a6045;
  --rule: #d4c4a0;

  /* Search highlight & selection colors */
  --search-hl-bg: #e6c875;
  --search-hl-color: #2b1f0d;
  --search-hl-active-bg: #d97706;
  --search-hl-active-color: #ffffff;
  --search-hl-active-outline: #92400e;
  --search-hl-active-glow: rgba(217, 119, 6, 0.45);
  --selection-bg: #e6c875;
  --selection-color: #2b1f0d;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Vazirmatn', 'Tahoma', 'Arial', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ===== HEADER ===== */
#header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: 64px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}

body.theme-blue #header {
  background: radial-gradient(circle at 50% 101%, #64b1fc, #007bc0 86%);
  border-bottom: none;
  box-shadow: 0 2px 10px rgba(0, 123, 192, 0.28);
  color: #ffffff;
}

body.theme-blue #header .header-btn {
  color: #ffffff;
}

body.theme-blue #header .header-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

body.theme-blue #book-title {
  color: #ffffff;
}

body.theme-blue #book-subtitle {
  color: rgba(255, 255, 255, 0.88);
}

body.theme-blue .subtitle-sep {
  color: rgba(255, 255, 255, 0.5);
}

body.theme-blue .subtitle-page-text {
  color: rgba(255, 255, 255, 0.88);
}

body.theme-blue .subtitle-badge-wrap {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

body.theme-blue .subtitle-badge-wrap:hover {
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.6);
  color: #ffffff;
}

body.theme-blue .subtitle-picker-btn {
  color: #ffffff;
}

body.theme-blue .book-info-btn {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

body.theme-blue .book-info-btn:hover {
  background: #ffffff;
  border-color: #ffffff;
  color: #007bc0;
}

body.theme-blue #book-thumb {
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}

body.theme-blue #search-input {
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #1a2332;
  caret-color: #007bc0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

body.theme-blue #search-input::placeholder {
  color: #7b8c9d;
}

body.theme-blue #search-input:focus {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45), 0 2px 8px rgba(0, 0, 0, 0.15);
  background: #ffffff;
}

body.theme-blue .search-icon {
  color: #007bc0;
}

body.theme-blue .search-header-count {
  background: #e2edf8;
  color: #143686;
}

body.theme-blue .search-mini-btn {
  color: #143686;
}

body.theme-blue .search-mini-btn:hover:not(:disabled) {
  background: #e2edf8;
  color: #0b1f4d;
}

body.theme-blue .subtitle-dropdown-menu,
body.theme-blue .lang-dropdown-menu {
  background: #ffffff;
  border: 1px solid #bccde6;
  box-shadow: 0 6px 18px rgba(11, 31, 77, 0.16);
}

body.theme-blue .subtitle-dropdown-item,
body.theme-blue .lang-dropdown-item {
  color: #1a2332;
}

body.theme-blue .subtitle-dropdown-item:hover,
body.theme-blue .lang-dropdown-item:hover {
  background: #f3f6fb;
  color: #143686;
}

body.theme-blue .subtitle-dropdown-item.active,
body.theme-blue .lang-dropdown-item.active {
  background: #e2edf8;
  color: #143686;
  font-weight: 700;
}

body.theme-blue #sidebar-header,
body.theme-blue .panel-header {
  background-color: #e2edf8;
  border-bottom: 1px solid #bccde6;
}

body.theme-blue #sidebar-title,
body.theme-blue .panel-title {
  color: #143686;
}

body.theme-blue #sidebar {
  border-inline-end-color: #bccde6;
}

body.theme-blue #toc-search-input {
  background: #ffffff;
  border-color: #bccde6;
  caret-color: #007bc0;
}

body.theme-blue #toc-search-input:focus {
  border-color: #007bc0;
  box-shadow: 0 0 0 3px rgba(0, 123, 192, 0.18);
}

body.theme-blue #toolbar {
  background: #ffffff;
  border-top: 1px solid #bccde6;
  box-shadow: 0 -2px 10px rgba(20, 54, 134, 0.05);
}

body.theme-blue .tool-btn:hover {
  background: #e2edf8;
  color: #143686;
}

body.theme-blue .tool-btn.active {
  background: #143686;
  color: #ffffff;
}

body.theme-blue .page-num-pill {
  border-color: #bccde6;
  background: #f3f6fb;
  color: #143686;
}

body.theme-blue .page-num-pill:hover,
body.theme-blue .page-num-pill:focus-within {
  border-color: #007bc0;
  box-shadow: 0 0 0 2px rgba(0, 123, 192, 0.18);
}

.header-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.header-btn:hover {
  background: rgba(0, 0, 0, .07);
  color: var(--text);
}

.header-btn svg,
.header-btn img {
  width: 22px;
  height: 22px;
  fill: currentColor;
  display: block;
}

/* آیکون‌های عملیاتی انتهای هدر: فاصلهٔ کمتر از هم */
#header>#btn-search-mobile,
#header>#btn-bookmarks-list,
#header>#btn-toc,
#header>.lang-dropdown-wrap,
#header>#btn-settings,
#header>#btn-more {
  margin-inline-start: -6px;
}

#header>#btn-search-mobile,
#header>#btn-bookmarks-list,
#header>#btn-toc,
#header>.lang-dropdown-wrap>.header-btn,
#header>#btn-settings,
#header>#btn-more {
  width: 34px;
  height: 34px;
}

/* ===== HEADER LANGUAGE DROPDOWN ===== */
.lang-dropdown-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.lang-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  inset-inline-start: auto;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  min-width: 130px;
  padding: 6px 0;
  z-index: 300;
  display: none;
  flex-direction: column;
}

.lang-dropdown-menu.show {
  display: flex;
}

.lang-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: start;
  transition: background var(--transition), color var(--transition);
  width: 100%;
  white-space: nowrap;
}

.lang-dropdown-item:hover {
  background: rgba(0, 0, 0, .06);
}

body.theme-dark .lang-dropdown-item:hover {
  background: rgba(255, 255, 255, .08);
}

.lang-dropdown-item.active {
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-light);
}

body.theme-dark .lang-dropdown-item.active {
  background: var(--accent-glow);
  color: #60a5fa;
}

#book-thumb {
  width: 34px;
  height: 48px;
  border-radius: 4px;
  object-fit: cover;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  flex-shrink: 0;
  background: #f0ebe4;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  display: block;
}

#book-thumb:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
}

#book-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.book-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

#book-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.book-info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  outline: none;
}

.book-info-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: scale(1.12);
}

.book-info-btn:active {
  transform: scale(0.94);
}

.book-info-btn svg {
  display: block;
}

#book-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  white-space: nowrap;
}

.subtitle-badge-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, .04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1px 6px 1px 8px;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  transition: all var(--transition);
}

.subtitle-badge-wrap:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

body.theme-dark .subtitle-badge-wrap {
  background: rgba(255, 255, 255, .06);
  border-color: rgba(255, 255, 255, .15);
}

body.theme-dark .subtitle-badge-wrap:hover {
  background: var(--accent-glow);
  border-color: #60a5fa;
  color: #93c5fd;
}

body.theme-sepia .subtitle-badge-wrap {
  background: rgba(100, 70, 30, .06);
  border-color: rgba(100, 70, 30, .18);
}

body.theme-sepia .subtitle-badge-wrap:hover {
  background: rgba(139, 105, 20, .12);
  border-color: var(--accent);
  color: var(--accent);
}

.subtitle-badge-label {
  pointer-events: none;
}

.subtitle-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  background: transparent;
  color: currentColor;
  cursor: pointer;
  border-radius: 50%;
  transition: transform var(--transition);
}

.subtitle-badge-wrap.open .subtitle-picker-btn {
  transform: rotate(180deg);
}

.subtitle-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
  min-width: 140px;
  max-width: 260px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  z-index: 1050;
  display: none;
  flex-direction: column;
  gap: 2px;
  animation: subtitleMenuFadeIn 0.15s ease-out;
}

.subtitle-dropdown-menu.show {
  display: flex;
}

@keyframes subtitleMenuFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.subtitle-menu-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
  user-select: none;
}

.subtitle-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: start;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.subtitle-menu-item:hover {
  background: rgba(0, 0, 0, .06);
  color: var(--accent);
}

body.theme-dark .subtitle-menu-item:hover {
  background: rgba(255, 255, 255, .08);
  color: #60a5fa;
}

.subtitle-menu-item.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.subtitle-menu-item.active:hover {
  background: var(--accent-hover, var(--accent));
  color: #fff;
}

.subtitle-menu-item .menu-check {
  font-size: 12px;
  display: inline-block;
  margin-inline-start: 4px;
}

.subtitle-sep {
  color: var(--text-muted);
  opacity: 0.5;
  font-size: 11px;
}

.subtitle-page-text {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#search-wrap {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.search-input-box {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  background: #f5f5f5;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 7px 16px;
  padding-inline-start: 36px;
  padding-inline-end: 16px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  width: 200px;
  outline: none;
  transition: width var(--transition), border-color var(--transition), box-shadow var(--transition), background var(--transition);
  direction: inherit;
  text-align: start;
}

#search-wrap.has-results #search-input {
  width: 290px;
  padding-inline-end: 105px;
}

body.theme-dark #search-input {
  background: #333;
  border-color: #444;
  color: #ddd;
}

body.theme-sepia #search-input {
  background: #ebe0c8;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#search-input::placeholder {
  color: var(--text-light);
}

.search-icon {
  position: absolute;
  inset-inline-start: 11px;
  inset-inline-end: auto;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
  z-index: 2;
}

.search-icon:hover {
  color: var(--accent);
}

.search-icon svg,
.search-icon img {
  width: 16px;
  height: 16px;
  fill: currentColor;
  display: block;
}

.search-header-ctrls {
  position: absolute;
  inset-inline-end: 5px;
  inset-inline-start: auto;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 2;
}

.search-header-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
  user-select: none;
}

.search-mini-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  padding: 0;
}

.search-mini-btn svg,
.search-mini-btn img {
  width: 14px;
  height: 14px;
  fill: currentColor;
  display: block;
}

.search-mini-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, .08);
  color: var(--text);
}

body.theme-dark .search-mini-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, .1);
  color: #fff;
}

.search-mini-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

#btn-search-mobile {
  display: none;
}

/* ===== LAYOUT ===== */
#main-layout {
  margin-top: 64px;
  margin-bottom: 56px;
  flex: 1;
  display: flex;
  overflow: hidden;
  height: calc(100vh - 64px - 56px);
  position: relative;
}

/* ===== SIDEBAR ===== */
#sidebar {
  width: 300px;
  background: var(--sidebar-bg);
  border-inline-end: 1px solid var(--border);
  border-left: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition), transform var(--transition), background var(--transition), border-color var(--transition);
}

#sidebar.closed {
  width: 0;
  border-inline-end-width: 0;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#sidebar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

#toc-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#toc-search-input {
  width: 100%;
  background: #f5f5f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  direction: inherit;
  text-align: start;
}

body.theme-dark #toc-search-input {
  background: #333;
  border-color: #444;
  color: #ddd;
}

body.theme-sepia #toc-search-input {
  background: #ebe0c8;
}

#toc-search-input:focus {
  border-color: var(--accent);
}

#toc-list {
  /* flex: 1; */
  overflow-y: auto;
  padding: 0px;
  height: calc(100vh - 238px);
}

#toc-list::-webkit-scrollbar {
  width: 5px;
}

#toc-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .15);
  border-radius: 4px;
}

.toc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 8px;
  transition: background var(--transition), color var(--transition);
  font-size: 14px;
}

.toc-item:hover {
  background: var(--accent-light);
}

.toc-item.active {
  background: var(--accent);
  color: #fff;
}

.toc-item.active .toc-name {
  font-weight: 700;
}

.toc-item.active .toc-page {
  color: rgba(255, 255, 255, .9);
}

.toc-name {
  /* flex: 1; */
  font-weight: 500;
}

.toc-dots {
  flex: 1;
  border-bottom: 1px dotted var(--border);
  margin: 0 8px;
}

.toc-item.active .toc-dots {
  border-color: rgba(255, 255, 255, .4);
}

.toc-page {
  font-size: 13px;
  color: var(--text-muted);
  direction: ltr;
}

body.theme-dark .toc-item:hover {
  background: rgba(255, 255, 255, .08);
}

body.theme-dark .toc-item.active {
  background: #2563eb;
  color: #ffffff;
}

body.theme-dark .toc-item.active .toc-dots {
  border-color: rgba(255, 255, 255, .35);
}

body.theme-dark .toc-item.active .toc-page {
  color: rgba(255, 255, 255, .85);
}

body.theme-sepia .toc-item:hover {
  background: rgba(139, 105, 20, .12);
}

body.theme-sepia .toc-item.active {
  background: #8b6914;
  color: #ffffff;
}

body.theme-sepia .toc-item.active .toc-dots {
  border-color: rgba(255, 255, 255, .35);
}

body.theme-sepia .toc-item.active .toc-page {
  color: rgba(255, 255, 255, .85);
}

/* ===== READER AREA ===== */
#reader-area {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 72px;
  position: relative;
  height: 100%;
}

/* Navigation Arrows */
.nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 80px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  z-index: 35;
  box-shadow: var(--shadow-md);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition), opacity var(--transition), color var(--transition), right var(--transition), left var(--transition);
  backdrop-filter: blur(4px);
}

body.theme-dark .nav-arrow {
  background: rgba(45, 45, 45, .88);
  color: var(--text-muted);
  border-color: var(--border);
}

body.theme-sepia .nav-arrow {
  background: rgba(244, 236, 216, .92);
  color: var(--text-muted);
  border-color: var(--border);
}

.nav-arrow:hover:not(:disabled) {
  background: rgba(255, 255, 255, .98);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

body.theme-dark .nav-arrow:hover:not(:disabled) {
  background: rgba(60, 60, 60, .98);
  color: var(--text);
}

body.theme-sepia .nav-arrow:hover:not(:disabled) {
  background: rgba(240, 230, 208, .98);
  color: var(--text);
}

.nav-arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

.nav-arrow svg,
.nav-arrow img {
  width: 28px;
  height: 28px;
  fill: currentColor;
  display: block;
}

[dir="rtl"] #nav-prev {
  right: 14px;
  left: auto;
}

[dir="rtl"] #nav-next {
  left: 14px;
  right: auto;
}

[dir="ltr"] #nav-prev {
  left: 14px;
  right: auto;
}

[dir="ltr"] #nav-next {
  right: 14px;
  left: auto;
}

[dir="rtl"] #nav-prev:hover:not(:disabled) {
  transform: translateY(-50%) translateX(-2px);
}

[dir="rtl"] #nav-next:hover:not(:disabled) {
  transform: translateY(-50%) translateX(2px);
}

[dir="ltr"] #nav-prev:hover:not(:disabled) {
  transform: translateY(-50%) translateX(-2px);
}

[dir="ltr"] #nav-next:hover:not(:disabled) {
  transform: translateY(-50%) translateX(2px);
}

@media (min-width: 769px) {
  [dir="rtl"] #sidebar:not(.closed)~#reader-area #nav-prev {
    right: calc(300px + 14px);
    left: auto;
  }

  [dir="ltr"] #sidebar:not(.closed)~#reader-area #nav-prev {
    left: calc(300px + 14px);
    right: auto;
  }
}

/* Book Container - Always keeps RTL layout for Eastern/Arabic book reading */
#book-container {
  direction: rtl;
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 100%;
  max-height: 100%;
  position: relative;
  margin: auto;
  zoom: var(--book-zoom, 1);
  transition: zoom var(--transition), transform var(--transition);
}

@supports not (zoom: 1) {
  #book-container {
    transform: scale(var(--book-zoom, 1));
    transform-origin: center center;
  }
}

/* Page Turn Animation removed to keep book container completely fixed */
#book-container.page-turning-forward,
#book-container.page-turning-backward {
  animation: none;
}

.page-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
  transition: background var(--transition);
}

/* Double page mode */
#book-container.double-mode {
  box-shadow: 0 10px 32px rgba(0, 0, 0, .14), 0 2px 8px rgba(0, 0, 0, .06);
  border-radius: 5px;
  min-height: max(620px, calc(100vh - 150px));
}

#book-container.double-mode .page-wrapper {
  width: calc((min(var(--page-max-width, 990px), 92vw)) / 2);
  min-width: min(352px, calc(var(--page-max-width, 990px) / 2));
  min-height: max(620px, calc(100vh - 150px));
  position: relative;
}

#book-container.double-mode #page-right {
  border-radius: 5px 0 0 5px;
  border: 1px solid rgba(0, 0, 0, .08);
  border-left: none;
}

#book-container.double-mode #page-left {
  border-radius: 0 5px 5px 0;
  border: 1px solid rgba(0, 0, 0, .08);
  border-right: none;
}

/* Center Crease / Spine (Seam) */
#book-spine {
  width: 1px;
  background: rgba(0, 0, 0, .12);
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  display: none;
}

#book-container.double-mode #book-spine {
  display: block;
}

/* ===== BOOK SHADING GRADIENTS (ترام وسط و کناره‌های کتاب) ===== */

/* ترام عطف وسط کتاب - سمت راست */
#book-container.double-mode #page-right::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 48px;
  background: linear-gradient(to right, rgba(0, 0, 0, .15) 0%, rgba(0, 0, 0, .08) 22%, rgba(0, 0, 0, .03) 55%, rgba(0, 0, 0, .008) 80%, transparent 100%);
  pointer-events: none;
  z-index: 4;
}

/* ترام عطف وسط کتاب - سمت چپ */
#book-container.double-mode #page-left::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 48px;
  background: linear-gradient(to left, rgba(0, 0, 0, .15) 0%, rgba(0, 0, 0, .08) 22%, rgba(0, 0, 0, .03) 55%, rgba(0, 0, 0, .008) 80%, transparent 100%);
  pointer-events: none;
  z-index: 4;
}

/* ترام لبه بیرونی صفحه راست (کنار کتاب) */
#book-container.double-mode #page-right::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 28px;
  background: linear-gradient(to left, rgba(0, 0, 0, .05) 0%, rgba(0, 0, 0, .02) 45%, rgba(0, 0, 0, .005) 75%, transparent 100%);
  pointer-events: none;
  z-index: 4;
}

/* ترام لبه بیرونی صفحه چپ (کنار کتاب) */
#book-container.double-mode #page-left::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 28px;
  background: linear-gradient(to right, rgba(0, 0, 0, .05) 0%, rgba(0, 0, 0, .02) 45%, rgba(0, 0, 0, .005) 75%, transparent 100%);
  pointer-events: none;
  z-index: 4;
}

/* انطباق ترام‌ها در پوسته تاریک (Dark Theme) */
body.theme-dark #book-container.double-mode #page-right {
  border-color: rgba(255, 255, 255, .08);
  box-shadow:
    1px 0 0 0 rgba(0, 0, 0, .3),
    2px 0 0 0 var(--page-bg),
    3px 0 0 0 rgba(0, 0, 0, .25),
    4px 0 0 0 var(--page-bg),
    5px 0 0 0 rgba(0, 0, 0, .2),
    6px 0 0 0 var(--page-bg),
    8px 2px 18px rgba(0, 0, 0, .5);
}

body.theme-dark #book-container.double-mode #page-left {
  border-color: rgba(255, 255, 255, .08);
  box-shadow:
    -1px 0 0 0 rgba(0, 0, 0, .3),
    -2px 0 0 0 var(--page-bg),
    -3px 0 0 0 rgba(0, 0, 0, .25),
    -4px 0 0 0 var(--page-bg),
    -5px 0 0 0 rgba(0, 0, 0, .2),
    -6px 0 0 0 var(--page-bg),
    -8px 2px 18px rgba(0, 0, 0, .5);
}

body.theme-dark #book-spine {
  background: rgba(0, 0, 0, .6);
}

body.theme-dark #book-container.double-mode #page-right::after {
  background: linear-gradient(to right, rgba(0, 0, 0, .5) 0%, rgba(0, 0, 0, .3) 25%, rgba(0, 0, 0, .1) 60%, transparent 100%);
}

body.theme-dark #book-container.double-mode #page-left::after {
  background: linear-gradient(to left, rgba(0, 0, 0, .5) 0%, rgba(0, 0, 0, .3) 25%, rgba(0, 0, 0, .1) 60%, transparent 100%);
}

body.theme-dark #book-container.double-mode #page-right::before {
  background: linear-gradient(to left, rgba(0, 0, 0, .22) 0%, rgba(0, 0, 0, .08) 50%, transparent 100%);
}

body.theme-dark #book-container.double-mode #page-left::before {
  background: linear-gradient(to right, rgba(0, 0, 0, .22) 0%, rgba(0, 0, 0, .08) 50%, transparent 100%);
}

/* انطباق ترام‌ها در پوسته کاغذی (Sepia Theme) */
body.theme-sepia #book-container.double-mode #page-right {
  border-color: rgba(80, 50, 20, .12);
  box-shadow:
    1px 0 0 0 rgba(90, 60, 20, .09),
    2px 0 0 0 var(--page-bg),
    3px 0 0 0 rgba(90, 60, 20, .07),
    4px 0 0 0 var(--page-bg),
    5px 0 0 0 rgba(90, 60, 20, .05),
    6px 0 0 0 var(--page-bg),
    7px 1px 14px rgba(70, 45, 15, .1);
}

body.theme-sepia #book-container.double-mode #page-left {
  border-color: rgba(80, 50, 20, .12);
  box-shadow:
    -1px 0 0 0 rgba(90, 60, 20, .09),
    -2px 0 0 0 var(--page-bg),
    -3px 0 0 0 rgba(90, 60, 20, .07),
    -4px 0 0 0 var(--page-bg),
    -5px 0 0 0 rgba(90, 60, 20, .05),
    -6px 0 0 0 var(--page-bg),
    -7px 1px 14px rgba(70, 45, 15, .1);
}

body.theme-sepia #book-spine {
  background: rgba(80, 50, 20, .16);
}

body.theme-sepia #book-container.double-mode #page-right::after {
  background: linear-gradient(to right, rgba(80, 50, 20, .18) 0%, rgba(80, 50, 20, .09) 22%, rgba(80, 50, 20, .03) 55%, transparent 100%);
}

body.theme-sepia #book-container.double-mode #page-left::after {
  background: linear-gradient(to left, rgba(80, 50, 20, .18) 0%, rgba(80, 50, 20, .09) 22%, rgba(80, 50, 20, .03) 55%, transparent 100%);
}

body.theme-sepia #book-container.double-mode #page-right::before {
  background: linear-gradient(to left, rgba(80, 50, 20, .06) 0%, rgba(80, 50, 20, .02) 50%, transparent 100%);
}

body.theme-sepia #book-container.double-mode #page-left::before {
  background: linear-gradient(to right, rgba(80, 50, 20, .06) 0%, rgba(80, 50, 20, .02) 50%, transparent 100%);
}

/* Single page mode */
#book-container.single-mode {
  box-shadow: -4px 0 16px rgba(0, 0, 0, .15), 4px 0 16px rgba(0, 0, 0, .1), 0 2px 8px rgba(0, 0, 0, .1);
}

#book-container.single-mode .page-wrapper {
  width: min(calc(var(--page-max-width, 990px) * 0.58), 92vw);
  border-radius: 4px;
}

#book-container.single-mode #page-left {
  display: none;
}

#book-container.single-mode #book-spine {
  display: none;
}

/* ===== VERTICAL SCROLL MODE (Single page continuous) ===== */
#reader-area.vertical-mode {
  padding: 0;
  overflow: hidden;
  align-items: stretch;
  justify-content: stretch;
}

#vertical-scroll-container {
  width: 100%;
  height: 100vh;
  height: calc(100vh / var(--book-zoom, 1));
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 64px 90px;
  overscroll-behavior-y: contain;
  position: relative;
  zoom: var(--book-zoom, 1);
}

@supports not (zoom: 1) {
  .vertical-page {
    transform: scale(var(--book-zoom, 1));
    transform-origin: top center;
  }
}

.vertical-page {
  width: min(calc(var(--page-max-width, 990px) * 0.66), 94vw);
  min-height: 820px;
  background: var(--page-bg);
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .08), 0 1px 4px rgba(0, 0, 0, .04);
  margin-bottom: 32px;
  position: relative;
  display: flex;
  flex-direction: column;
  transition: background var(--transition);
  flex-shrink: 0;
}

body.theme-dark .vertical-page {
  box-shadow: 0 4px 20px rgba(0, 0, 0, .45);
}

.vertical-page .page-inner {
  padding: 26px 36px;
  overflow: visible;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.vertical-page .page-content {
  overflow: visible;
  flex: 1;
}

/* Page internals */
.page-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 50px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 16px;
  flex-shrink: 0;
}




.page-bookmark-btn {
  position: absolute;
  top: -2;
  z-index: 8;
  width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

html[dir="rtl"] .page-bookmark-btn {
  left: 0px;
  right: auto;
}

html[dir="ltr"] .page-bookmark-btn {
  right: 0px;
  left: auto;
}

/* حالت دو صفحه‌ای: نشانک صفحه فرد سمت چپ، صفحه زوج سمت راست */
#book-container.double-mode .page-bookmark-btn.is-odd {
  left: 10px;
  right: auto;
}

#book-container.double-mode .page-bookmark-btn.is-even {
  right: 10px;
  left: auto;
}

.page-bookmark-btn svg {
  width: 27px;
  height: 27px;
  fill: currentColor;
  display: block;
}

.page-bookmark-btn:hover {
  color: var(--accent);
  background: transparent;
  transform: translateY(1px);
}

.page-bookmark-btn.is-active {
  color: var(--accent);
  background: transparent;
}

.page-bookmark-btn.is-hidden {
  display: none;
}

.page-header-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .03em;
}

.page-number-corner {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Chapter heading in left page header */
#chapter-heading-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: calc(100% - 40px);
}

#chapter-heading-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ornament {
  color: #c9a96e;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}

/* Page text content */
.page-content {
  flex: 1;
  overflow: hidden;
  font-family: var(--book-font, "Yaqoot", "Lotus", "Lotus Linotype", serif);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--text);
  text-align: justify;
  direction: rtl;
  position: relative;
}

.page-content p,
.page-content div,
.page-content span {
  font-family: inherit;
}

/* Bismillah / decorative */
.bismillah {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: #8b6914;
  margin-bottom: 20px;
  letter-spacing: .05em;
}

/* Page footer - not needed as in original design */
.page-footer {
  display: none;
}

.page-footer-num {
  display: none;
}

/* Loading overlay */
.page-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  z-index: 20;
  border-radius: inherit;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Error state */
.page-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  text-align: center;
}

.page-error svg,
.page-error img {
  width: 48px;
  height: 48px;
  color: var(--text-light);
  fill: currentColor;
  display: block;
}

.page-error p {
  color: var(--text-muted);
  font-size: 14px;
}

.retry-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: background var(--transition);
}

.retry-btn:hover {
  background: var(--accent-hover);
}

/* ===== BOTTOM TOOLBAR ===== */
#toolbar {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  height: 56px;
  background: var(--toolbar-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 -1px 6px rgba(0, 0, 0, .06);
  transition: background var(--transition), border-color var(--transition);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

#toolbar-group-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.tool-btn:hover {
  background: rgba(0, 0, 0, .06);
  color: var(--text);
}

.tool-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tool-btn svg,
.tool-btn img {
  width: 18px;
  height: 18px;
  fill: currentColor;
  display: block;
}

#zoom-display {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 48px;
  text-align: center;
  padding: 0 4px;
}

/* ===== PAGE NAV WIDGET (Toolbar) ===== */
.page-nav-widget {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  direction: rtl;
  user-select: none;
}

.page-nav-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
  padding: 0;
}

.page-nav-chevron:hover:not(:disabled) {
  background: rgba(0, 0, 0, .06);
  color: var(--text);
}

body.theme-dark .page-nav-chevron:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

body.theme-sepia .page-nav-chevron:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
}

.page-nav-chevron:disabled {
  opacity: 0.35;
  color: var(--text-light);
  border-color: var(--border);
  cursor: not-allowed;
  pointer-events: none;
}

.page-nav-chevron svg,
.page-nav-chevron img {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.page-nav-total {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: .02em;
}

.page-num-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  min-width: 52px;
  height: 36px;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.page-num-pill:hover,
.page-num-pill:focus-within {
  background: rgba(0, 0, 0, 0.03);
  border-color: var(--accent);
}

body.theme-dark .page-num-pill:hover,
body.theme-dark .page-num-pill:focus-within {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--accent);
}

body.theme-sepia .page-num-pill:hover,
body.theme-sepia .page-num-pill:focus-within {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--border);
}

#page-current-input {
  width: 48px;
  border: none;
  background: transparent;
  text-align: center;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  padding: 0;
  cursor: text;
  direction: ltr;
}

.nav-page-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.nav-page-btn:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.nav-page-btn:disabled {
  color: var(--text-light);
  border-color: var(--border);
  cursor: not-allowed;
  opacity: 0.4;
  background: transparent;
}

/* ===== MODAL PANELS ===== */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.panel-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.panel {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  width: min(480px, 92vw);
  max-height: calc(100vh - 140px);
  background: var(--sidebar-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 201;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  border: 1px solid var(--border);
}

.panel.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  transition: background var(--transition);
}

.close-btn:hover {
  background: rgba(0, 0, 0, .08);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.panel-body::-webkit-scrollbar {
  width: 5px;
}

.panel-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .15);
  border-radius: 4px;
}

/* ===== BOOK COVER MODAL ===== */
#panel-book-cover {
  width: min(460px, 94vw);
}

.book-cover-modal-wrap {
  display: flex;
  flex-direction: column;
}

.book-cover-modal-head {
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.book-cover-modal-head .book-modal-title {
  margin: 0 0 4px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
}

.book-cover-image-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-height: 220px;
  max-height: 58vh;
  overflow: hidden;
  position: relative;
}

.book-cover-full-img {
  max-width: 100%;
  max-height: calc(58vh - 28px);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
  transition: transform .25s ease, box-shadow .25s ease;
  background: var(--page-bg);
  cursor: zoom-in;
}

.book-cover-full-img:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
}

/* ===== BOOK INFO MODAL ===== */
#panel-book-info {
  width: min(520px, 94vw);
}

.book-modal-header {
  display: flex;
  gap: 14px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 14px;
  align-items: center;
}

.book-modal-cover-wrap {
  width: 64px;
  height: 90px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  background: var(--page-bg);
}

.book-modal-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-modal-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  margin: 0;
  word-break: break-word;
}

.book-modal-author {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.book-modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.book-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  line-height: 1.5;
}

.book-badge-vol {
  background: var(--accent-light);
  color: var(--accent);
}

.book-badge-type {
  background: rgba(0, 0, 0, .05);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

[data-theme="dark"] .book-badge-type {
  background: rgba(255, 255, 255, .08);
}

.book-modal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 480px) {
  .book-modal-grid {
    grid-template-columns: 1fr;
  }
}

.book-meta-item {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.book-meta-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.book-meta-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.book-modal-desc-box {
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.book-meta-desc-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.book-meta-desc-text {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.8;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.book-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.book-modal-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.book-modal-action-btn:hover {
  background: var(--accent-hover);
}

.book-modal-close-action {
  padding: 8px 14px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.book-modal-close-action:hover {
  background: rgba(0, 0, 0, .05);
}

[data-theme="dark"] .book-modal-close-action:hover {
  background: rgba(255, 255, 255, .08);
}

/* Search Side Panel */
#panel-search {
  top: 64px;
  bottom: 56px;
  height: calc(100vh - 64px - 56px);
  max-height: none;
  width: min(390px, 92vw);
  border-radius: 0;
  border: none;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  z-index: 99;
}

[dir="rtl"] #panel-search {
  right: 0;
  left: auto;
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
}

[dir="ltr"] #panel-search {
  left: 0;
  right: auto;
  border-right: 1px solid var(--border);
  box-shadow: 6px 0 24px rgba(0, 0, 0, 0.12);
  transform: translateX(-100%);
}

#panel-search.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 768px) {
  #panel-search {
    top: 60px;
    bottom: 0;
    height: calc(100vh - 60px);
    width: min(360px, 92vw);
    z-index: 201;
  }
}

/* Search panel elements */
.search-panel-input-box {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
}

.search-panel-field {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-panel-icon {
  position: absolute;
  inset-inline-start: 12px;
  inset-inline-end: auto;
  width: 16px;
  height: 16px;
  color: var(--text-light);
  fill: currentColor;
  pointer-events: none;
}

#panel-search-input {
  width: 100%;
  padding: 8px 16px;
  padding-inline-start: 36px;
  padding-inline-end: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f5f5f5;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  direction: inherit;
  text-align: start;
  transition: border-color var(--transition);
}

body.theme-dark #panel-search-input {
  background: #333;
  border-color: #444;
  color: #ddd;
}

body.theme-sepia #panel-search-input {
  background: #ebe0c8;
}

#panel-search-input:focus {
  border-color: var(--accent);
}

.panel-clear-btn {
  position: absolute;
  inset-inline-end: 8px;
  inset-inline-start: auto;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  border-radius: 50%;
  line-height: 1;
}

.panel-search-btn {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity var(--transition);
  white-space: nowrap;
}

.panel-search-btn:hover {
  opacity: .9;
}

.search-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.search-panel-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.search-badge-total {
  font-weight: 700;
  color: var(--accent);
}

.search-badge-pos {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, .06);
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

body.theme-dark .search-badge-pos {
  background: rgba(255, 255, 255, .1);
  color: #ccc;
}

.search-panel-nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-nav-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.search-nav-action-btn svg,
.search-nav-action-btn img {
  width: 14px;
  height: 14px;
  fill: currentColor;
  display: block;
}

.search-nav-action-btn:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.search-nav-action-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.search-result-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
  background: var(--sidebar-bg);
}

.search-result-item:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.search-result-item.is-current {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.search-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.search-result-page {
  font-size: 13px;
  color: var(--accent);
  font-weight: 700;
}

.search-result-idx {
  font-size: 11px;
  color: var(--text-muted);
}

.search-result-excerpt {
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--text);
  word-break: break-word;
}

/* Selection color per theme */
::selection {
  background: var(--selection-bg, #cfe4fc);
  color: var(--selection-color, #0b2a63);
}

.search-result-excerpt b,
.search-result-excerpt mark,
.search-highlight,
.search-hl {
  background: var(--search-hl-bg, #cfe4fc);
  color: var(--search-hl-color, #0b2a63);
  border-radius: 3px;
  padding: 1px 4px;
  font-weight: 700;
  transition: background .2s ease, box-shadow .2s ease;
}

.search-hl.search-hl-active,
.search-highlight.search-hl-active {
  background: var(--search-hl-active-bg, #143686) !important;
  color: var(--search-hl-active-color, #ffffff) !important;
  outline: 2px solid var(--search-hl-active-outline, #007bc0);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px var(--search-hl-active-glow, rgba(20, 54, 134, 0.35));
}

/* Theme Blue: Harmonious soft blue highlight & deep accent blue active */
body.theme-blue .search-result-excerpt b,
body.theme-blue .search-result-excerpt mark,
body.theme-blue .search-highlight,
body.theme-blue .search-hl {
  background: #cfe4fc;
  color: #0b2a63;
}

body.theme-blue .search-hl.search-hl-active,
body.theme-blue .search-highlight.search-hl-active {
  background: #143686 !important;
  color: #ffffff !important;
  outline: 2px solid #007bc0;
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(20, 54, 134, 0.35);
}

/* Theme Light: Warm amber/yellow highlighter */
body.theme-light .search-result-excerpt b,
body.theme-light .search-result-excerpt mark,
body.theme-light .search-highlight,
body.theme-light .search-hl {
  background: #fef08a;
  color: #1a1a1a;
}

body.theme-light .search-hl.search-hl-active,
body.theme-light .search-highlight.search-hl-active {
  background: #f59e0b !important;
  color: #111111 !important;
  outline: 2px solid #b45309;
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.45);
}

/* Theme Dark: Night navy highlight & bright blue active */
body.theme-dark .search-result-excerpt b,
body.theme-dark .search-result-excerpt mark,
body.theme-dark .search-highlight,
body.theme-dark .search-hl {
  background: #1e3a5f;
  color: #bfdbfe;
}

body.theme-dark .search-hl.search-hl-active,
body.theme-dark .search-highlight.search-hl-active {
  background: #2563eb !important;
  color: #ffffff !important;
  outline: 2px solid #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.5);
}

/* Theme Sepia: Warm golden parchment highlight & amber active */
body.theme-sepia .search-result-excerpt b,
body.theme-sepia .search-result-excerpt mark,
body.theme-sepia .search-highlight,
body.theme-sepia .search-hl {
  background: #e6c875;
  color: #2b1f0d;
}

body.theme-sepia .search-hl.search-hl-active,
body.theme-sepia .search-highlight.search-hl-active {
  background: #d97706 !important;
  color: #ffffff !important;
  outline: 2px solid #92400e;
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.45);
}

.search-initial-hint,
.search-empty-state,
.search-loading-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.8;
}

/* Bookmark panel */
.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--transition);
}

.bookmark-item:hover {
  background: var(--accent-light);
}

.bookmark-item.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.bookmark-info {
  flex: 1;
}

.bookmark-section {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.bookmark-page {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.bookmark-menu-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background var(--transition);
}

.bookmark-menu-btn:hover {
  background: rgba(0, 0, 0, .08);
}

.no-items {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 0;
  font-size: 14px;
}

#btn-bookmarks-list {
  position: relative;
}

#btn-bookmarks-list .badge {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  inset-inline-start: auto;
  width: 16px;
  height: 16px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Settings panel */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.setting-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

#page-width-label {
  cursor: pointer;
  user-select: none;
}

input[type=range] {
  -webkit-appearance: none;
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
}

.theme-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.theme-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  background: transparent;
  color: var(--text);
}

.theme-btn:hover {
  border-color: var(--accent);
}

.theme-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.font-btns {
  display: flex;
  gap: 6px;
}

.font-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  background: transparent;
  color: var(--text);
}

.font-btn:hover {
  border-color: var(--accent);
}

.font-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.font-btn[data-font="yaqoot"] {
  font-family: "Yaqoot", "Lotus", "Lotus Linotype", serif;
  font-size: 14px;
}

.font-btn[data-font="amiri"] {
  font-family: "Amiri", serif;
  font-size: 14px;
}

.font-btn[data-font="naskh"] {
  font-family: "Noto Naskh Arabic", serif;
  font-size: 13px;
}

.lang-btns {
  display: flex;
  gap: 6px;
}

.lang-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  background: transparent;
  color: var(--text);
}

.lang-btn:hover {
  border-color: var(--accent);
}

.lang-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

/* ===== CONTEXT MENU ===== */
#context-menu {
  position: fixed;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  display: none;
  min-width: 140px;
  overflow: hidden;
}

.ctx-item {
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition);
}

.ctx-item:hover {
  background: rgba(0, 0, 0, .06);
}

.ctx-item.danger {
  color: #dc2626;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #search-wrap {
    display: none;
  }

  #btn-search-mobile {
    display: flex;
  }

  #btn-view-toggle {
    display: none !important;
  }

  /* Center pager is absolutely positioned on desktop and overlaps the
     side buttons once the bar gets narrow. Equal side columns keep it
     centered without covering the tools. */
  #toolbar {
    display: grid;
    grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
    align-items: center;
    padding: 0 10px;
    column-gap: 6px;
  }

  #toolbar-group-zoom {
    grid-column: 1;
    justify-self: start;
  }

  #toolbar-group-view {
    grid-column: 3;
    justify-self: end;
  }

  #toolbar-group-center {
    grid-column: 2;
    position: static;
    left: auto;
    transform: none;
    min-width: 0;
    justify-content: center;
  }

  #zoom-display {
    min-width: 40px;
  }

  .page-nav-widget {
    gap: 6px;
    max-width: 100%;
  }

  .page-nav-total {
    display: none;
  }

  #book-info #book-subtitle {
    display: flex;
    font-size: 11px;
    gap: 4px;
  }

  @media (max-width: 480px) {

    #book-info #book-subtitle .subtitle-page-text,
    #book-info #book-subtitle .subtitle-sep:last-of-type {
      display: none;
    }
  }

  [dir="rtl"] #sidebar {
    position: absolute;
    right: 0;
    left: auto;
    top: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    border-left: 1px solid var(--border);
  }

  [dir="rtl"] #sidebar.closed {
    transform: translateX(100%);
    width: 300px;
  }

  [dir="rtl"] #sidebar:not(.closed) {
    transform: translateX(0);
  }

  [dir="ltr"] #sidebar {
    position: absolute;
    left: 0;
    right: auto;
    top: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    border-right: 1px solid var(--border);
  }

  [dir="ltr"] #sidebar.closed {
    transform: translateX(-100%);
    width: 300px;
  }

  [dir="ltr"] #sidebar:not(.closed) {
    transform: translateX(0);
  }

  #reader-area {
    padding: 12px 56px;
  }

  .vertical-page .page-inner {
    padding: 26px 6px;
  }

  html[dir="rtl"] .page-header {
    padding-left: 46px;
  }

  html[dir="ltr"] .page-header {
    padding-right: 46px;
  }

  .nav-arrow {
    width: 38px;
    height: 64px;
    z-index: 35;
    display: none !important;
  }

  [dir="rtl"] #nav-prev {
    right: 8px;
    left: auto;
  }

  [dir="rtl"] #nav-next {
    left: 8px;
    right: auto;
  }

  [dir="ltr"] #nav-prev {
    left: 8px;
    right: auto;
  }

  [dir="ltr"] #nav-next {
    right: 8px;
    left: auto;
  }

  #book-container.double-mode .page-wrapper {
    min-width: unset;
  }
}

@media (max-width: 480px) {
  #toolbar-group-zoom {
    display: none;
  }

  #toolbar {
    padding: 0 8px;
    gap: 4px;
  }

  #toolbar .tool-btn,
  .page-nav-chevron {
    width: 34px;
    height: 34px;
  }

  .page-nav-widget {
    gap: 4px;
  }

  .page-num-pill {
    min-width: 44px;
    height: 34px;
    padding: 2px 4px;
  }

  #page-current-input {
    width: 40px;
    font-size: 14px;
  }

  .page-nav-total {
    font-size: 13px;
  }

  #reader-area {
    padding: 8px 48px;
  }
}

@media (max-width: 340px) {
  #toolbar {
    padding: 0 4px;
    column-gap: 2px;
  }

  #toolbar .tool-btn,
  .page-nav-chevron {
    width: 32px;
    height: 32px;
  }

  .page-nav-widget {
    gap: 2px;
  }

  .page-num-pill {
    min-width: 40px;
    height: 32px;
  }

  #page-current-input {
    width: 36px;
  }
}

@media (max-height: 640px) {

  #book-container.double-mode,
  #book-container.double-mode .page-wrapper {
    min-height: calc(100vh - 130px);
  }
}

/* ===== FULLSCREEN ===== */
#main-layout:fullscreen,
#main-layout:-webkit-full-screen {
  background: var(--bg);
}

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 400;
  opacity: 0;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* page-number input modal */
#page-jump-wrap {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* Scrollbar global */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .15);
  border-radius: 4px;
}

/* ===== IMAGE VIEW MODE ===== */
.page-html-content.page-image-mode {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.book-page-image,
.page-html-content.page-image-mode img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: auto;
  border-radius: 3px;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 0.25s ease, transform 0.2s ease;
}

.page-content.is-image-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

body.content-mode-image .page-inner {
  padding: 8px 12px;
}

body.content-mode-image .page-header {
  display: none !important;
}

/* Vertical page in image mode */
.vertical-page .page-content.is-image-page {
  min-height: 700px;
}

.vertical-page .page-html-content.page-image-mode {
  height: auto;
  min-height: 680px;
}

.vertical-page .book-page-image,
.vertical-page .page-html-content.page-image-mode img {
  max-width: 100%;
  height: auto;
  max-height: 88vh;
}

/* Dark and sepia adjustments for scanned page images */
body.theme-dark .book-page-image,
body.theme-dark .page-html-content.page-image-mode img {
  opacity: 0.92;
  box-shadow: 0 3px 16px rgba(0, 0, 0, .5);
}

body.theme-sepia .book-page-image,
body.theme-sepia .page-html-content.page-image-mode img {
  filter: sepia(0.06);
}

/* Content mode toolbar button & settings */
#btn-content-mode {
  display: none;
  position: relative;
}

#btn-content-mode.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.mode-btns {
  display: flex;
  gap: 8px;
}

.content-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.content-mode-btn:hover {
  background: rgba(0, 0, 0, .05);
  border-color: var(--accent);
}

body.theme-dark .content-mode-btn:hover {
  background: rgba(255, 255, 255, .08);
}

.content-mode-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

/* ===== LTR / RTL ARROWS & ICONS ===== */
[dir="rtl"] #btn-back svg {
  transform: scaleX(-1);
}

[dir="ltr"] .nav-arrow svg,
[dir="ltr"] .page-nav-chevron svg,
[dir="ltr"] .search-mini-btn svg,
[dir="ltr"] .search-nav-action-btn svg {
  transform: scaleX(-1);
}

/* Book reading orientation remains strictly RTL regardless of UI language */
#book-container {
  direction: rtl;
}

.vertical-page {
  direction: rtl;
}

.page-content {
  direction: rtl;
  text-align: justify;
  min-height: calc(100vh - 150px);
}

/* ===== PAGE 1 COVER BANNER (TEXT MODE) ===== */
.page-cover-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 14px auto 26px;
  width: 100%;
  text-align: center;
  user-select: none;
}

.page-cover-card {
  display: inline-flex;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .1);
  transition: transform var(--transition), box-shadow var(--transition);
}

.page-cover-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.page-cover-image {
  width: auto;
  max-width: min(240px, 70vw);
  max-height: min(340px, 48vh);
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .16);
  cursor: pointer;
  display: block;
  background: var(--page-bg);
}

body.theme-dark .page-cover-card {
  box-shadow: 0 4px 20px rgba(0, 0, 0, .4);
}

/* ========================================================
   BOOK CONTENT TYPOGRAPHY & CLASSES (dl.lib.iq Reader Styles)
   ======================================================== */

.page-container {
  padding: 12px 0px;
  line-height: var(--line-height, 2.2);
  unicode-bidi: isolate;
  direction: rtl;
}

/* Standard text blocks */
.page-container .text-block:not(.heading):not(.remark):not(.pome):not(.quran-ayah):not(.quote-line):not(.footnote-entry),
.page-content .text-block:not(.heading):not(.remark):not(.pome):not(.quran-ayah):not(.quote-line):not(.footnote-entry) {
  margin: 0;
  padding: 0.35rem 0.15rem;
  text-indent: 2rem;
  text-align: justify;
  color: var(--text);
  font-weight: 400;
  line-height: inherit;
}

/* Headings */
.page-container .heading,
.page-content .heading,
.page-container .text-block.heading,
.page-content .text-block.heading {
  display: block;
  margin: 1.25rem 0 0.75rem;
  text-align: center;
  text-indent: 0;
  font-weight: 700;
  color: var(--ink-deep, #12201e);
  line-height: 1.5;
}

.page-container .heading.level-1,
.page-content .heading.level-1 {
  font-size: 1.65rem;
}

.page-container .heading.level-2,
.page-content .heading.level-2 {
  font-size: 1.4rem;
}

.page-container .heading.level-3,
.page-content .heading.level-3,
.page-container .heading.level-4,
.page-content .heading.level-4 {
  font-size: 1.2rem;
}

/* Honorifics / Du'a / Salawat */
.page-container .honorific,
.page-content .honorific {
  color: var(--teal, #2f6f68);
  font-size: 0.9em;
  font-weight: 600;
}

.page-container .honorific-as,
.page-content .honorific-as,
.page-container .honorific-salawat,
.page-content .honorific-salawat {
  color: var(--teal, #2f6f68);
}

.page-container .honorific-aj,
.page-content .honorific-aj,
.page-container .honorific-qs,
.page-content .honorific-qs,
.page-container .honorific-ra,
.page-content .honorific-ra,
.page-container .honorific-rh,
.page-content .honorific-rh {
  color: var(--muted, #5c6b67);
  font-weight: 500;
}

.page-container .honorific-abbrev,
.page-content .honorific-abbrev {
  white-space: nowrap;
  font-size: 0.85em;
  font-weight: 700;
}

/* Quranic verses & references */
.page-container .quran-ayah,
.page-content .quran-ayah,
.page-container span.quran-ayah,
.page-content span.quran-ayah,
.page-container p.quran-ayah,
.page-content p.quran-ayah,
.page-container .ayah,
.page-content .ayah {
  direction: rtl;
  unicode-bidi: isolate;
  font-family: "DigitalKhatt", "Noto Naskh Arabic", "Amiri", serif;
  font-weight: 400;
  font-synthesis: none;
  font-size: 1em;
  /* line-height: max(2.35, var(--line-height)); */
  color: var(--teal, #2f6f68);
  text-align: justify;
  text-indent: 0;
  margin: 0.35rem 0;
  padding: 0.35rem 0.15rem;
}

.page-container .quran-ayah-link,
.page-content .quran-ayah-link,
.page-container .quran-ref,
.page-content .quran-ref {
  color: var(--teal, #2f6f68);
  text-decoration: none;
}

.page-container .quran-ayah-link:hover,
.page-content .quran-ayah-link:hover,
.page-container .quran-ref:hover,
.page-content .quran-ref:hover {
  text-decoration: underline;
}

/* Poetry (Pome) */
.page-container .pome,
.page-content .pome,
.page-container p.pome,
.page-content p.pome {
  text-indent: 0;
  color: var(--ink-deep, #12201e);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.35rem 1.5rem;
  margin: 0.75rem 0;
  padding: 0.35rem 0.5rem;
  font-size: 1.05em;
  line-height: 2.1;
}

.page-container .rightpome,
.page-content .rightpome,
.page-container .leftpome,
.page-content .leftpome {
  text-align: center;
  min-inline-size: min(100%, 14rem);
  display: inline-block;
}

.page-container .poetry,
.page-content .poetry {
  border-inline-start: 3px solid var(--teal, #2f6f68);
  background: rgba(47, 111, 104, 0.04);
  margin: 0.85rem 0;
  padding: 0.5rem 0.75rem;
}

.page-container .poetry .verse,
.page-content .poetry .verse,
.page-container .poetry p,
.page-content .poetry p {
  text-indent: 0;
  text-align: center;
  margin: 0.15rem 0;
  line-height: 2;
}

/* Remarks & Editorial Notes */
.page-container .remark,
.page-content .remark,
.page-container p.remark,
.page-content p.remark {
  text-indent: 0;
  color: #3d524c;
  border-inline-start: 3px solid var(--gold, #c4a35a);
  background: rgba(196, 163, 90, 0.1);
  margin: 0.75rem 0;
  padding: 0.45rem 0.85rem;
  font-size: 0.95rem;
  line-height: 1.95;
  border-radius: 0 4px 4px 0;
}

/* Quotes */
.page-container .quote,
.page-content .quote {
  color: var(--text);
  font-style: italic;
}

.page-container p.quote-line,
.page-content p.quote-line {
  text-indent: 0;
  border-inline-start: 3px solid #a66b2b;
  margin: 0.75rem 0;
  padding: 0.35rem 0.75rem;
  font-style: italic;
  line-height: 1.95;
}

/* Footnotes */
.page-container hr.footnote-sep,
.page-content hr.footnote-sep,
.page-container .footnote-sep,
.page-content .footnote-sep {
  border: 0;
  border-top: 1px solid var(--rule, #d2c4ae);
  width: 30%;
  margin: 1.5rem 0 0.85rem;
}

.page-container .footnote-entry,
.page-content .footnote-entry {
  text-indent: 0;
  text-align: start;
  color: #4a5f5a;
  font-size: 0.9rem;
  font-weight: 400;
  line-height: 1.85;
  margin: 0.35rem 0;
  padding: 0.15rem;
}

.page-container .fn-ref,
.page-content .fn-ref,
.page-container .fn-marker,
.page-content .fn-marker {
  vertical-align: super;
  font-size: 0.75em;
  font-weight: 700;
  line-height: 0;
  position: relative;
  top: -0.15em;
}

.page-container .fn-ref a,
.page-content .fn-ref a,
.page-container .fn-marker,
.page-content .fn-marker {
  color: var(--teal, #2f6f68) !important;
  text-decoration: none !important;
}

/* Theme overrides for Dark Theme */
body.theme-dark .page-container .heading,
body.theme-dark .page-content .heading {
  color: var(--ink-deep, #f4efe4);
}

body.theme-dark .page-container .footnote-entry,
body.theme-dark .page-content .footnote-entry {
  color: #c9b89a;
}

body.theme-dark .page-container .remark,
body.theme-dark .page-content .remark {
  color: #d8c7ad;
  background: rgba(212, 181, 106, 0.15);
}

body.theme-dark .page-container .poetry,
body.theme-dark .page-content .poetry {
  background: rgba(143, 206, 192, 0.06);
}

/* Theme overrides for Sepia Theme */
body.theme-sepia .page-container .footnote-entry,
body.theme-sepia .page-content .footnote-entry {
  color: #5c4832;
}

body.theme-sepia .page-container .remark,
body.theme-sepia .page-content .remark {
  color: #4a3a24;
  background: rgba(179, 139, 54, 0.12);
}

.hidden {
  display: none;
}