/* 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: 'Bookerly', 'Literata', 'ProportionalTamil', 'Noto Serif Tamil', Georgia, 'Times New Roman', serif !important;
  font-size: 16px !important;
  color: var(--text-color);
  font-weight: normal !important;
}

.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;
}

.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;
}

.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;
}

.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;
}

.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;
}

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

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

.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);
}

.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);
}

.page-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  scrollbar-width: thin;
  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 {
  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);
}

.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;
}

.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;
}

.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 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 para:first-of-type > text:first-of-type::first-letter {
  font-size: inherit !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.38 !important;
}

@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly'), local('Bookerly Regular'), local('Bookerly-Regular');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly Bold'), local('Bookerly-Bold');
  font-weight: bold;
  font-style: normal;
}
@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly Italic'), local('Bookerly-Italic'), local('Bookerly Regular Italic');
  font-weight: normal;
  font-style: italic;
}
@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly Bold Italic'), local('Bookerly-BoldItalic');
  font-weight: bold;
  font-style: italic;
}
@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: 88%;
}

.page-content,
.page-content para > text,
.page-content text,
.page-content footnote > text,
.page-content li,
.page-content table,
.page-content .caption,
.page-content figcaption,
.page-content em,
.page-content i,
.cover-title,
.cover-author,
.toc-heading,
.toc-link {
  font-family: 'Bookerly', 'Literata', 'ProportionalTamil', 'Noto Serif Tamil', Georgia, 'Times New Roman', serif !important;
}

.page-content verse[language="ta"],
.page-content verse[language="ta"] > line {
  font-family: 'ProportionalTamil', 'Noto Serif Tamil', 'Noto Sans Tamil', serif !important;
  font-style: normal !important;
}

.page-content verse[language="en"],
.page-content verse[language="en"] > line {
  font-family: 'Bookerly', 'Literata', Georgia, 'Times New Roman', serif !important;
  font-style: italic !important;
  color: #3a2b22;
}

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

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

.page-content ol.bibliography {
  margin: 0.16em 0 !important;
  padding-left: 1.9em !important;
  font-size: 0.92rem !important;
  line-height: 1.46 !important;
  list-style: decimal outside !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: 8px auto !important;
  text-align: center;
  page-break-before: avoid !important;
}

.page-content .caption, .page-content figcaption {
  font-size: 0.88rem !important;
  font-weight: bold !important;
  line-height: 1.4 !important;
  color: #4a3d33;
  margin-top: 6px;
}

.page-content img {
  max-width: 82% !important;
  max-height: 30vh !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;
}

.page-content img.full,
.page-content img.pfull {
  max-width: 88% !important;
  max-height: 58vh !important;
}

.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);
}

.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, .page-content .floatnone {
  float: none !important;
  width: auto !important;
  max-width: 100% !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);
}

.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;
}

: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;
  }
}

.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;
}

@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;
  }
}
