/* 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;
  --reader-font-scale: 1;
}

* { 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: 'Noto Serif Tamil', 'Noto Sans Tamil', '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; bottom: 0;
  width: min(300px, 84vw);
  height: 100vh;
  background: rgba(24, 19, 16, 0.96);
  border-right: 1px solid rgba(201, 162, 77, 0.35);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 14px;
  padding: 56px 16px 20px 16px;
  z-index: 10001;
  overflow-y: auto;
  color: #f5ebd6;
  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); }

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

.toolbar-brand {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  font-weight: bold; font-size: 1rem; color: #f5ebd6;
  border-bottom: 1px solid rgba(201, 162, 77, 0.3);
  padding-bottom: 10px;
}
.toolbar-brand span.sub { font-size: 0.84rem; color: var(--accent-gold); font-weight: normal; }

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

.btn-nav {
  background: #2e241e; color: #f5ebd6;
  border: 1px solid rgba(201, 162, 77, 0.45);
  border-radius: 6px; padding: 6px 11px;
  font-size: 0.86rem; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  display: inline-flex; align-items: center; justify-content: 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);
  text-align: center; font-variant-numeric: tabular-nums;
}
.page-jump-form { display: flex; align-items: center; gap: 6px; }
.page-jump-input {
  flex: 1; background: #1a1411; color: #f5ebd6;
  border: 1px solid rgba(201, 162, 77, 0.45);
  border-radius: 5px; padding: 5px 6px; font-size: 0.82rem; text-align: center;
}
.toolbar-links a {
  color: var(--accent-gold); text-decoration: none; font-size: 0.85rem;
  padding: 6px 10px; border: 1px solid rgba(201, 162, 77, 0.35);
  border-radius: 6px; text-align: center;
}
.toolbar-links a:hover { background: rgba(201, 162, 77, 0.15); color: #fff; }

.flipbook-stage {
  position: fixed;
  top: 0; bottom: 0; left: 0; right: 0;
  height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 10px 48px 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: 12%; 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; overflow-y: auto !important;
  padding: 20px 28px 10px 28px;
  font-size: calc(0.94rem * var(--reader-font-scale));
  line-height: 1.56; 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; }
.cover-author { font-size: 1.1rem; color: #f7ebd2; font-weight: bold; margin-bottom: 4px; }
.cover-meta { font-size: 0.9rem; color: #d6c39b; }

.credits-page { height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 6px 4px; }
.credits-heading { font-size: 1.18rem !important; color: var(--accent) !important; border-bottom: 2px solid var(--accent-gold); padding-bottom: 6px; margin: 0 0 14px 0 !important; text-align: center; }
.credits-card { border: 1px solid rgba(201, 162, 77, 0.55); background: rgba(201, 162, 77, 0.07); border-radius: 8px; padding: 14px 16px; }
.credits-subtitle { text-align: center; font-size: 0.85rem; font-style: italic; color: #5c4a3d; }
.credits-speaker { text-align: center; font-size: 1.05rem; font-weight: bold; color: var(--accent); margin-top: 2px; }
.credits-divider { text-align: center; color: var(--accent-gold); margin: 8px 0 10px 0; font-size: 1rem; }
.credits-list { margin: 0; padding: 0; }
.credits-row { padding: 6px 0; border-bottom: 1px dotted rgba(201, 162, 77, 0.45); }
.credits-row:last-child { border-bottom: none; }
.credits-row dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: #6b584b; margin-bottom: 2px; }
.credits-row dd { margin: 0; font-size: 0.9rem; color: var(--text-color); line-height: 1.42; }

.toc-heading { font-size: 1.18rem !important; color: var(--accent) !important; border-bottom: 2px solid var(--accent-gold); padding-bottom: 6px; margin: 0 0 10px 0 !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.88rem; 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.16rem !important; color: var(--accent); text-align: center;
  margin-top: 0 !important; margin-bottom: 0.45em !important; padding-bottom: 4px;
}
.page-content h1 { border-bottom: 1px solid #e2d6be; }
.page-content h2, .page-content h3, .page-content p-title {
  color: #5b1919; font-size: 1.0rem !important; margin-top: 0.45em !important; margin-bottom: 0.25em !important; font-weight: bold;
}
.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;
  font-family: 'Noto Serif Tamil', 'ProportionalTamil', 'Times New Roman', serif !important;
  font-size: calc(0.93rem * var(--reader-font-scale)) !important;
  line-height: 1.56;
}
.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 {
  text-indent: 0 !important; font-size: calc(0.85rem * var(--reader-font-scale)) !important;
  line-height: 1.45 !important; color: #4a3d33;
}
.page-content verse, .page-content inscription {
  display: block; margin: 0.35em 0.9em !important;
  font-size: calc(0.88rem * var(--reader-font-scale)) !important; line-height: 1.42 !important;
}
.page-content line { display: block !important; line-height: 1.4 !important; }

.page-content figure { display: block; margin: 0.6em auto !important; text-align: center; }
.page-content figure img {
  max-width: 88% !important; max-height: 52vh !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 figcaption { font-size: 0.84rem !important; line-height: 1.4 !important; color: #4a3525; margin-top: 6px; }
.zoom-label { display: block; position: relative; z-index: 45; cursor: zoom-in; text-align: center; }
.zoom-label:hover img { transform: scale(1.02); 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;
}

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

@media (max-width: 768px) {
  :root { --reader-font-scale: 0.85; }
  .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; }
}
