/* Hardware-Accelerated 3D Flipbook */
@import url('common.css');

:root {
  --bg-dark: #1e1b18;
  --paper-bg: #fdfaf3;
  --paper-border: #d8ceb8;
  --spine-shadow: rgba(0, 0, 0, 0.26);
  --accent: #7a2021;
  --accent-gold: #c9a24d;
  --text-color: #1f1a17;
  --flip-duration: 520ms;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0 !important;
  padding: 0 !important;
  width: 100%;
  height: 100%;
  overflow: hidden !important;
  background: radial-gradient(circle at center, #332922 0%, #15110e 100%) !important;
  font-family: 'Times New Roman', 'Noto Sans', 'Noto Sans Tamil', 'Noto Sans Devanagari', serif !important;
  font-size: 16px !important;
  color: var(--text-color);
  font-weight: normal !important;
}

/* Top Toolbar */
.flipbook-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: rgba(24, 19, 16, 0.95);
  border-bottom: 1px solid rgba(201, 162, 77, 0.35);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 9999;
  color: #f5ebd6;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: bold;
  font-size: 1rem;
  color: #f5ebd6;
}

.toolbar-brand span.sub {
  font-size: 0.84rem;
  color: var(--accent-gold);
  font-weight: normal;
}

.spread-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-nav {
  background: #2e241e;
  color: #f5ebd6;
  border: 1px solid rgba(201, 162, 77, 0.45);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  user-select: none;
}

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

.btn-nav.disabled {
  opacity: 0.38;
  pointer-events: none;
}

.page-indicator {
  font-size: 0.86rem;
  color: var(--accent-gold);
  min-width: 150px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.page-jump-form {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}

.page-jump-input {
  width: 58px;
  background: #1a1411;
  color: #f5ebd6;
  border: 1px solid rgba(201, 162, 77, 0.45);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 0.82rem;
  text-align: center;
}

.toolbar-links a {
  color: var(--accent-gold);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 5px 10px;
  border: 1px solid rgba(201, 162, 77, 0.35);
  border-radius: 6px;
}

.toolbar-links a:hover {
  background: rgba(201, 162, 77, 0.15);
  color: #fff;
}

/* Stage & 3D Book Container */
.flipbook-stage {
  position: fixed;
  top: 52px;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 48px;
  overflow: hidden;
}

.book {
  position: relative;
  width: min(92vw, 1340px);
  height: min(88vh, 860px);
  perspective: 2600px;
  user-select: text;
}

/* Center spine visual */
.book::before {
  content: "";
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: 50%;
  width: 24px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #3c1212, #641e1e 50%, #3c1212);
  border-radius: 4px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.75);
  z-index: 1;
}

/* Hardcover backing behind pages */
.book::after {
  content: "";
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: -6px;
  right: -6px;
  background: #4e1515;
  border: 2px solid var(--accent-gold);
  border-radius: 8px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 0;
}

/* Individual Turning Sheet (Leaf)
   Pre-staged sheets use GPU-accelerated transform-only transitions with zero mid-flip z-index changes */
.sheet {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--flip-duration) cubic-bezier(0.33, 0.0, 0.2, 1);
  display: none;
  pointer-events: none;
  z-index: 1;
  -webkit-font-smoothing: antialiased;
}

.sheet.staged {
  display: block;
}

.sheet.no-anim {
  transition: none !important;
}

.sheet.pos-left-under {
  transform: rotateY(-180deg);
  z-index: 10;
  pointer-events: none;
}

.sheet.pos-right-under {
  transform: rotateY(0deg);
  z-index: 10;
  pointer-events: none;
}

.sheet.pos-left-top {
  transform: rotateY(-180deg);
  z-index: 20;
  pointer-events: auto;
}

.sheet.pos-left-top .page-back {
  pointer-events: auto;
}

.sheet.pos-left-top .page-front {
  pointer-events: none;
}

.sheet.pos-right-top {
  transform: rotateY(0deg);
  z-index: 20;
  pointer-events: auto;
}

.sheet.pos-right-top .page-front {
  pointer-events: auto;
}

.sheet.pos-right-top .page-back {
  pointer-events: none;
}

/* Turning leaf stays at z-index 45 for the entire flip so z-index never changes mid-animation! */
.sheet.turning-left {
  transform: rotateY(-180deg);
  z-index: 45;
  pointer-events: none;
}

.sheet.turning-right {
  transform: rotateY(0deg);
  z-index: 45;
  pointer-events: none;
}

/* Front & Back Page Faces */
.page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-color: var(--paper-bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden !important;
  border: 1px solid var(--paper-border);
}

.page-front {
  transform: rotateY(0deg);
  border-radius: 0 6px 6px 0;
  background: linear-gradient(to right, #ede4d1 0%, var(--paper-bg) 7%, var(--paper-bg) 100%);
  box-shadow: inset 14px 0 24px -12px var(--spine-shadow);
  z-index: 2;
}

.page-back {
  transform: rotateY(180deg);
  border-radius: 6px 0 0 6px;
  background: linear-gradient(to left, #ede4d1 0%, var(--paper-bg) 7%, var(--paper-bg) 100%);
  box-shadow: inset -14px 0 24px -12px var(--spine-shadow);
  z-index: 1;
}

.footer-turn-btn {
  cursor: pointer;
  user-select: none;
  padding: 2px 6px;
  border-radius: 4px;
}

.footer-turn-btn:hover {
  background: rgba(122, 32, 33, 0.12);
}

/* Clickable Page-Turn Overlay Zones on outer edges of each page */
.page-turn-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14%;
  z-index: 20;
  cursor: pointer;
}

.zone-right {
  right: 0;
}

.zone-right:hover {
  background: linear-gradient(to left, rgba(201, 162, 77, 0.14), transparent);
}

.zone-left {
  left: 0;
}

.zone-left:hover {
  background: linear-gradient(to right, rgba(201, 162, 77, 0.14), transparent);
}

/* Non-scrolling Page Interior (NO z-index here so interactive links inside .page-content
   with z-index: 45 sit above .page-turn-zone!) */
.page-content {
  flex: 1;
  overflow: hidden !important;
  padding: 20px 28px 10px 28px;
  font-size: 0.95rem;
  line-height: 1.54;
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
}

/* Page Footer */
.page-footer {
  height: 34px;
  padding: 0 28px;
  border-top: 1px solid #e6dcc8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #6d5e4c;
  background: rgba(244, 237, 222, 0.65);
  flex-shrink: 0;
}

.page-header-book {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 78%;
}

.page-number {
  font-weight: bold;
  color: var(--accent);
}

/* Cover Page Styling */
.page-cover-face {
  background: linear-gradient(135deg, #5e1414 0%, #380909 100%) !important;
  color: #f8eed9;
  border: 2px solid var(--accent-gold);
}

.page-cover-face .page-content {
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden !important;
  padding: 16px;
}

.cover-page {
  width: 100%;
  height: 100%;
  border: 2px double var(--accent-gold);
  border-radius: 6px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.cover-frame {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cover-img {
  max-height: 46vh !important;
  max-width: 78% !important;
  width: auto !important;
  height: auto !important;
  border: 3px solid var(--accent-gold);
  border-radius: 4px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.6);
  margin: 0 auto 12px auto !important;
  object-fit: contain;
  flex-shrink: 1;
}

.cover-title {
  color: #ffdf8e !important;
  font-size: 1.45rem !important;
  margin: 6px 0 4px 0 !important;
  border-bottom: none !important;
  padding-bottom: 0 !important;
  page-break-before: avoid !important;
  flex-shrink: 0;
}

.cover-author {
  font-size: 1.1rem;
  color: #f7ebd2;
  font-weight: bold;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.cover-meta {
  font-size: 0.9rem;
  color: #d6c39b;
  flex-shrink: 0;
}

/* Table of Contents Styling */
.toc-heading {
  font-size: 1.22rem !important;
  color: var(--accent) !important;
  border-bottom: 2px solid var(--accent-gold);
  padding-bottom: 6px;
  margin-top: 0 !important;
  margin-bottom: 10px !important;
  page-break-before: avoid !important;
  text-align: center;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  z-index: 40;
}

.toc-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 8px;
  border-bottom: 1px dotted #d7cbb4;
  color: #2b211b !important;
  text-decoration: none;
  font-size: 0.89rem;
  line-height: 1.42;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.toc-link:hover {
  background: #efe5cf;
  color: var(--accent) !important;
}

.toc-page-num {
  font-weight: bold;
  color: var(--accent);
  margin-left: 10px;
  flex-shrink: 0;
}

/* Typography inside flipbook pages */
.page-content h1, .page-content atitle {
  font-size: 1.18rem !important;
  color: var(--accent);
  text-align: center;
  margin-top: 0 !important;
  margin-bottom: 0.45em !important;
  padding-bottom: 4px;
  page-break-before: avoid !important;
}

.page-content h1 {
  border-bottom: 1px solid #e2d6be;
}

.page-content h1 atitle, .page-content h1 atitle > line {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  font-size: inherit !important;
  line-height: 1.3 !important;
}

.page-content h2, .page-content h3, .page-content h4, .page-content p-title, .page-content s-title {
  color: #5b1919;
  font-size: 1.01rem !important;
  margin-top: 0.45em !important;
  margin-bottom: 0.25em !important;
  font-weight: bold;
  page-break-before: avoid !important;
}

.page-content h2 p-title, .page-content h3 p-title, .page-content h4 p-title {
  margin: 0 !important;
}

.page-content para {
  display: block;
  margin-top: 0.35em !important;
  margin-bottom: 0.35em !important;
  text-align: justify;
}

.page-content para > text, .page-content text {
  display: block;
  text-indent: 1.4em;
  line-height: 1.54;
  font-size: 0.94rem;
}

.page-content text.continued-text {
  text-indent: 0 !important;
}

.page-content footnote {
  display: block;
  margin-top: 0.25em;
  margin-bottom: 0.25em;
}

.page-content footnote > text, .page-content footnote para > text {
  text-indent: 0 !important;
  font-size: 0.87rem !important;
  line-height: 1.44 !important;
  margin-top: 0.25em !important;
  margin-bottom: 0.25em !important;
}

.fn-jump-label {
  color: var(--accent);
  cursor: pointer;
  font-weight: bold;
  position: relative;
  z-index: 50;
  display: inline-block;
  text-indent: 0 !important;
  padding: 1px 4px;
  border-radius: 4px;
  text-decoration: none;
  transition: background 0.2s, box-shadow 0.2s;
}

.fn-ref-link {
  display: inline !important;
  text-indent: 0 !important;
  padding: 0 1px !important;
  margin-left: 0 !important;
  margin-right: 0.05em !important;
}

.fn-ref-link sup {
  margin-left: 0 !important;
  margin-right: 0 !important;
  text-indent: 0 !important;
}

.fn-back-link {
  background: rgba(122, 32, 33, 0.09);
  border: 1px solid rgba(122, 32, 33, 0.28);
  padding: 1px 6px;
  margin-right: 4px;
  text-indent: 0 !important;
}

.fn-jump-label:hover {
  background: var(--accent);
  color: #fff !important;
  text-decoration: none;
}

.fn-jump-label:hover sup {
  color: #fff !important;
}

@keyframes fnPulse {
  0% { background-color: rgba(201, 162, 77, 0.85); box-shadow: 0 0 0 6px rgba(201, 162, 77, 0.45); }
  100% { background-color: transparent; box-shadow: 0 0 0 0 rgba(201, 162, 77, 0); }
}

.fn-target-highlight {
  animation: fnPulse 2.2s ease-out;
  border-radius: 4px;
}

.page-content preamble > line {
  font-size: 1.05rem !important;
  line-height: 1.42 !important;
}

.page-content preamble1 > line {
  font-size: 0.98rem !important;
  font-weight: bold;
  color: #5b1919;
  line-height: 1.38 !important;
}

.page-content verse, .page-content verse2, .page-content verse3,
.page-content sverse, .page-content gverse, .page-content inscription {
  display: block;
  margin: 0.35em 0.8em !important;
  font-size: 0.88rem !important;
  line-height: 1.38 !important;
}

.page-content line,
.page-content verse > line, .page-content verse2 > line, .page-content verse3 > line,
.page-content sverse > line, .page-content gverse > line, .page-content inscription > line {
  display: block !important;
  line-height: 1.35 !important;
}

/* English, Tamil, Sanskrit, and Grantha proportional font scaling */
@font-face {
  font-family: 'ProportionalTamil';
  src: local('Noto Serif Tamil'), local('Noto Sans Tamil'), local('Latha'), local('Nirmala UI'), local('Vijaya'), local('Tamil MN');
  unicode-range: U+0B80-0BFF;
  size-adjust: 86%;
}

@font-face {
  font-family: 'ProportionalSanskrit';
  src: local('Sanskrit 2003'), local('Noto Serif Devanagari'), local('Noto Sans Devanagari'), local('Mangal'), local('Nirmala UI'), local('Devanagari MT');
  unicode-range: U+0900-097F, U+1CD0-1CFF, U+A8E0-A8FF;
  size-adjust: 92%;
}

.page-content,
.page-content para > text,
.page-content text,
.page-content footnote > text,
.page-content li {
  font-family: 'Times New Roman', 'ProportionalTamil', 'ProportionalSanskrit', 'Noto Sans', serif !important;
}

.page-content verse[language="en"], .page-content verse2[language="en"], .page-content verse3[language="en"],
.page-content verse[language="en"] > line, .page-content verse2[language="en"] > line, .page-content verse3[language="en"] > line {
  font-family: 'Bookerly', 'Literata', Georgia, 'Times New Roman', serif !important;
  font-size: calc(0.86rem * 1.15 * var(--reader-font-scale, 1)) !important;
  line-height: 1.4 !important;
}

.page-content verse[language="ta"], .page-content verse2[language="ta"], .page-content verse3[language="ta"],
.page-content verse[language="ta"] > line, .page-content verse2[language="ta"] > line, .page-content verse3[language="ta"] > line {
  font-family: 'ProportionalTamil', 'Noto Serif Tamil', 'Noto Sans Tamil', serif !important;
  font-size: calc(0.88rem * var(--reader-font-scale, 1)) !important;
  line-height: 1.42 !important;
}

.page-content verse[language="sa"], .page-content verse2[language="sa"], .page-content verse3[language="sa"], .page-content sverse,
.page-content verse[language="sa"] > line, .page-content verse2[language="sa"] > line, .page-content verse3[language="sa"] > line, .page-content sverse > line {
  font-family: 'ProportionalSanskrit', 'Sanskrit 2003', 'Noto Serif Devanagari', 'Noto Sans Devanagari', serif !important;
  font-size: calc(0.90rem * var(--reader-font-scale, 1)) !important;
  line-height: 1.42 !important;
}

.page-content verse[language="gr"], .page-content gverse,
.page-content verse[language="gr"] > line, .page-content gverse > line {
  font-family: 'Noto Serif Grantha', 'Noto Sans Grantha', serif !important;
  font-size: calc(0.84rem * var(--reader-font-scale, 1)) !important;
  line-height: 1.42 !important;
}

.page-content em, .page-content i {
  font-family: 'Bookerly', 'Literata', Georgia, 'Times New Roman', 'ProportionalTamil', 'ProportionalSanskrit', serif !important;
  font-style: italic !important;
  font-size: 0.92em !important;
}

.page-content ul, .page-content ol {
  margin: 0.22em 0 !important;
  padding-left: 1.6em !important;
  text-indent: 0 !important;
  list-style-position: outside !important;
  text-align: left;
}

.page-content ul > li, .page-content ol > li {
  margin: 0.12em 0 !important;
  padding-left: 0.15em !important;
  text-indent: 0 !important;
  line-height: 1.42 !important;
}

.page-content li > ul, .page-content li > ol,
.page-content ul > ul, .page-content ol > ul {
  margin: 0.12em 0 0.18em 0 !important;
  padding-left: 1.4em !important;
  text-indent: 0 !important;
}

.page-content .two-columns {
  display: flex !important;
  flex-wrap: wrap !important;
  column-gap: 1.5em !important;
  padding-left: 1.6em !important;
}

.page-content .two-columns > li {
  width: calc(50% - 0.8em) !important;
  box-sizing: border-box !important;
}

.page-content ol.bibliography {
  margin: 0.14em 0 !important;
  padding-left: 1.8em !important;
  font-size: 0.9rem !important;
  line-height: 1.44 !important;
  list-style: decimal outside !important;
}

.page-content ol.bibliography > li {
  text-indent: 0 !important;
  line-height: 1.44 !important;
}

.page-content .table-wrap {
  margin: 6px 0;
  width: 100%;
}

.page-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem !important;
  line-height: 1.3 !important;
}

.page-content th, .page-content td {
  padding: 3px 6px !important;
  border: 1px solid #cbbba0 !important;
}

.page-content thead td, .page-content thead th {
  background: #ece1ca;
  font-weight: bold;
  color: var(--accent);
}

.page-content figure, .page-content figure2 {
  display: block;
  margin: 6px auto !important;
  text-align: center;
  page-break-before: avoid !important;
}

.page-content .caption, .page-content figcaption {
  font-size: 0.84rem !important;
  line-height: 1.38 !important;
  color: #4a3d33;
  margin-top: 4px;
}

.page-content img {
  max-width: 80% !important;
  max-height: 26vh !important;
  width: auto !important;
  height: auto !important;
  display: block;
  margin: 6px auto !important;
  border-radius: 4px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.zoom-label {
  display: block;
  position: relative;
  z-index: 45;
  cursor: zoom-in;
  text-align: center;
}

.zoom-label:hover img {
  transform: scale(1.03);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

/* Single Shared Fullscreen Photo Lightbox Modal */
.zoom-modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 9, 8, 0.94);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  cursor: zoom-out;
  padding: 28px;
}

.zoom-modal.open {
  display: flex;
}

.zoom-modal-img {
  max-width: 92vw !important;
  max-height: 86vh !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
  border: 3px solid var(--accent-gold);
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.85);
  background: #1a1412;
}

.zoom-close-btn {
  position: fixed;
  top: 18px;
  right: 24px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent-gold);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.92rem;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  cursor: pointer;
}

.page-content .floatleft, .page-content .floatright {
  float: none !important;
  width: auto !important;
  padding: 0 !important;
  margin: 6px auto !important;
}

.end-page {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--accent);
}

/* Side Floating Prev / Next Click Arrows */
.edge-Zone {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 80px;
  background: rgba(28, 22, 18, 0.78);
  border: 1px solid rgba(201, 162, 77, 0.45);
  color: #f5ebd6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  cursor: pointer;
  z-index: 9000;
  transition: background 0.15s;
  user-select: none;
}

.edge-Zone:hover:not(.disabled) {
  background: var(--accent);
  color: #fff;
}

.edge-Zone.disabled {
  opacity: 0;
  pointer-events: none;
}

.edge-prev {
  left: 6px;
  border-radius: 0 8px 8px 0;
}

.edge-next {
  right: 6px;
  border-radius: 8px 0 0 8px;
}

/* Responsive Device Compatibility (Tablet & Mobile) */
.page-content figure {
  margin: 0.6em auto;
  text-align: center;
}

.page-content figure img {
  max-width: 82% !important;
  height: auto !important;
}

.page-content figcaption {
  font-size: 0.82rem;
  margin-top: 0.25em;
  color: #4a3525;
}

@media (max-width: 900px) {
  .book {
    width: 96vw;
    height: min(76vh, 720px);
  }
  .page-content {
    padding: 18px 18px 26px 18px;
  }
}

@media (max-width: 600px) {
  .page-content {
    padding: 10px 10px 20px 10px;
    line-height: 1.45;
  }
  .page-content figure img {
    max-width: 92% !important;
  }
  .btn-nav {
    font-size: 0.78rem;
    padding: 4px 8px;
  }
}

/* Adjustable Reader Font Scale (smaller default on phones) */
:root {
  --reader-font-scale: 1;
}

.page-content {
  font-size: calc(0.95rem * var(--reader-font-scale)) !important;
}

.page-content para > text,
.page-content text {
  font-size: calc(0.95rem * var(--reader-font-scale)) !important;
}

.page-content verse, .page-content verse2, .page-content verse3,
.page-content sverse, .page-content gverse, .page-content inscription {
  font-size: calc(0.88rem * var(--reader-font-scale)) !important;
}

@media (max-width: 768px) {
  :root {
    --reader-font-scale: 0.82;
  }
  .page-content h1 {
    font-size: calc(1.15rem * var(--reader-font-scale)) !important;
  }
  .page-content h2, .page-content h3, .page-content p-title {
    font-size: calc(0.98rem * var(--reader-font-scale)) !important;
  }
}

/* Left Slide-In Controls Drawer */
.toolbar-toggle {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10002;
  background: rgba(24, 17, 13, 0.9);
  color: #f5ebd6;
  border: 1px solid rgba(201, 162, 77, 0.65);
  border-radius: 6px;
  width: 38px;
  height: 36px;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  transition: background 0.15s;
}

.toolbar-toggle:hover {
  background: var(--accent);
}

.flipbook-toolbar {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  bottom: 0 !important;
  right: auto !important;
  width: min(300px, 84vw) !important;
  height: 100vh !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  gap: 14px !important;
  padding: 56px 16px 20px 16px !important;
  z-index: 10001 !important;
  overflow-y: auto !important;
  transform: translateX(-105%);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.55);
}

.flipbook-toolbar.open {
  transform: translateX(0);
}

.flipbook-toolbar .toolbar-brand {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border-bottom: 1px solid rgba(201, 162, 77, 0.3);
  padding-bottom: 10px;
}

.flipbook-toolbar .toolbar-controls,
.flipbook-toolbar .spread-bar,
.flipbook-toolbar .toolbar-links {
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 8px !important;
}

.flipbook-toolbar .page-jump-form {
  display: flex;
  gap: 6px;
}

.flipbook-toolbar .page-jump-input {
  flex: 1;
}

.flipbook-stage {
  top: 0 !important;
  bottom: 0 !important;
  height: 100dvh !important;
  padding: 10px 48px 18px 48px !important;
}

/* Single-Page Mode on Phones & Small Devices */
@media (max-width: 768px) {
  .flipbook-stage {
    padding: 8px 6px !important;
  }
  .book {
    width: min(94vw, 480px) !important;
    height: min(88vh, 720px) !important;
    perspective: none !important;
  }
  .book::before,
  .book::after {
    display: none !important;
  }
  .sheet {
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    transition: none !important;
    display: none !important;
  }
  .sheet.mobile-active-sheet {
    display: block !important;
    z-index: 5 !important;
    pointer-events: auto !important;
  }
  .page {
    display: none !important;
    transform: none !important;
    backface-visibility: visible !important;
    width: 100% !important;
    height: 100% !important;
  }
  .page.mobile-active-page {
    display: flex !important;
    pointer-events: auto !important;
  }
  .page-content {
    padding: 16px 16px 24px 16px !important;
    line-height: 1.5 !important;
  }
  .edge-Zone {
    width: 28px !important;
    height: 54px !important;
    font-size: 1.25rem !important;
    touch-action: manipulation;
  }
  .btn-nav, .toolbar-toggle, .footer-turn-btn, .toc-link, .page-turn-zone {
    touch-action: manipulation;
  }
}
