/* Reader Layout */
.reader-container {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top Bar */
.reader-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.topbar-left a {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-left a:hover {
  color: var(--accent);
}

.topbar-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Main Reader Area */
.reader-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 0 48px;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* Flipbook Container */
.flipbook-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  height: 100%;
  padding: 12px 20px;
}

.nav-arrow {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 1.1rem;
  flex-shrink: 0;
  z-index: 10;
}

.nav-arrow:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.08);
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none !important;
}

/* StPageFlip container */
#flipbook {
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

/* Page base styles */
.flipbook-page {
  background: var(--bg-page);
  overflow: hidden;
  box-sizing: border-box;
}

.flipbook-page:nth-child(even) {
  background: var(--bg-page-alt);
}

/* ===================== */
/* Page Content Styles   */
/* ===================== */
.page-inner {
  padding: 36px 32px 44px;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  font-size: var(--page-font-size, 14px);
  line-height: 1.7;
}

.page-inner h3 {
  font-size: 1.15em;
  color: var(--accent);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent-bg);
  flex-shrink: 0;
}

.page-inner p {
  margin-bottom: 10px;
  font-size: 1em;
  line-height: 1.7;
  color: var(--text-primary);
}

.page-inner ul, .page-inner ol {
  margin-bottom: 10px;
  padding-left: 18px;
}

.page-inner li {
  margin-bottom: 5px;
  font-size: 0.95em;
  line-height: 1.6;
  color: var(--text-secondary);
}

.page-inner li strong {
  color: var(--text-primary);
}

.page-inner blockquote {
  margin: 14px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-heading);
  font-style: italic;
  font-size: 1em;
  color: var(--accent);
  flex-shrink: 0;
}

.page-inner .answer {
  background: var(--highlight);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-style: italic;
  margin-bottom: 10px;
  border-left: 3px solid var(--accent);
  font-size: 0.92em;
}

.page-inner .final-message {
  text-align: center;
  font-size: 1.05em;
  margin-top: 16px;
}

/* ===================== */
/* Chapter Title Page    */
/* ===================== */
.chapter-title-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 30px;
  height: 100%;
  width: 100%;
  background: var(--bg-page);
  box-sizing: border-box;
}

.chapter-title-page .chapter-heading {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 4px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.chapter-title-page .chapter-name {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  line-height: 1.2;
}

.chapter-title-page .chapter-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
}

.chapter-title-page .divider {
  width: 50px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin: 20px 0;
}

/* ===================== */
/* Cover Pages           */
/* ===================== */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 30px;
  height: 100%;
  width: 100%;
  background: linear-gradient(135deg, #8B1A1A 0%, #5D1212 60%, #3E0808 100%);
  color: white;
  box-sizing: border-box;
}

[data-theme="dark"] .cover-page {
  background: linear-gradient(135deg, #2D1B4E 0%, #1A1040 60%, #0F0A2A 100%);
}

.cover-page .cover-icon {
  font-size: 3rem;
  margin-bottom: 24px;
  opacity: 0.9;
}

.cover-page .cover-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.cover-page .cover-subtitle {
  font-size: 0.9rem;
  opacity: 0.85;
  max-width: 280px;
  line-height: 1.5;
  margin-bottom: 30px;
}

.cover-page .cover-divider {
  width: 50px;
  height: 2px;
  background: rgba(255,255,255,0.3);
  margin-bottom: 30px;
}

.cover-page .cover-author {
  font-size: 0.8rem;
  opacity: 0.7;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* Back Cover */
.back-cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 30px;
  height: 100%;
  width: 100%;
  background: linear-gradient(135deg, #3E0808 0%, #5D1212 50%, #8B1A1A 100%);
  color: white;
  box-sizing: border-box;
}

[data-theme="dark"] .back-cover-page {
  background: linear-gradient(135deg, #0F0A2A 0%, #1A1040 50%, #2D1B4E 100%);
}

.back-cover-page .back-message {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-style: italic;
  opacity: 0.9;
  max-width: 260px;
  line-height: 1.5;
}

.back-cover-page .back-year {
  margin-top: 30px;
  font-size: 0.8rem;
  opacity: 0.5;
  letter-spacing: 3px;
}

/* Page Number */
.page-number {
  position: absolute;
  bottom: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

.page-number.left {
  left: 32px;
}

.page-number.right {
  right: 32px;
}

/* ===================== */
/* Bottom Bar            */
/* ===================== */
.reader-bottombar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-light);
}

.progress-bar-track {
  width: 100%;
  height: 3px;
  background: var(--border);
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.5s ease;
  border-radius: 0 2px 2px 0;
}

.bottombar-content {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-indicator {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.page-indicator strong {
  color: var(--text-primary);
}

.chapter-indicator {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
  text-align: right;
}

/* ===================== */
/* Bookmark Panel        */
/* ===================== */
.bookmark-panel {
  position: fixed;
  top: 0;
  right: -360px;
  width: 360px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}

.bookmark-panel.open {
  right: 0;
}

.bookmark-panel-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

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

.bookmark-panel-header h3 {
  font-size: 1.05rem;
}

.bookmark-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 4px;
}

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

.bookmark-item-info {
  flex: 1;
  min-width: 0;
}

.bookmark-item-page {
  font-weight: 600;
  font-size: 0.9rem;
}

.bookmark-item-chapter {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-item-delete {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.bookmark-item-delete:hover {
  background: rgba(220,53,69,0.1);
  color: #DC3545;
}

.bookmark-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.bookmark-empty-icon {
  font-size: 2rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* ===================== */
/* TOC Panel             */
/* ===================== */
.toc-panel {
  position: fixed;
  top: 0;
  left: -360px;
  width: 360px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 200;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
}

.toc-panel.open {
  left: 0;
}

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

.toc-panel-header h3 {
  font-size: 1.05rem;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 3px;
}

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

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

.toc-item-number {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.toc-item-title {
  font-size: 0.9rem;
  font-weight: 500;
}

/* ===================== */
/* Font Size Controls    */
/* ===================== */
.font-size-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.font-size-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  transition: all var(--transition);
}

.font-size-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
}

.font-size-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 32px;
  text-align: center;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

/* Active state for bookmark button */
#bookmarkBtn.active {
  color: var(--accent) !important;
  background: var(--accent-bg) !important;
}

/* ===================== */
/* StPageFlip overrides  */
/* ===================== */

/* Fix rendering artifacts during page flip */
.stf__parent {
  overflow: visible !important;
}

.stf__wrapper {
  transition: none !important;
}

/* Ensure pages render cleanly */
.stf__item {
  background: var(--bg-page) !important;
}


/* ===================== */
/* RESPONSIVE            */
/* ===================== */

/* Large Desktop */
@media (min-width: 1200px) {
  .flipbook-wrapper {
    gap: 24px;
  }
}

/* Tablet landscape and small desktop */
@media (max-width: 1100px) {
  .flipbook-wrapper {
    gap: 12px;
    padding: 10px 12px;
  }

  .page-inner {
    padding: 28px 26px 36px;
    font-size: var(--page-font-size, 13px);
  }

  .page-inner h3 {
    font-size: 1.1em;
    margin-bottom: 8px;
  }

  .page-inner p {
    margin-bottom: 8px;
    line-height: 1.6;
  }

  .page-inner li {
    margin-bottom: 4px;
    line-height: 1.55;
  }
}

/* Tablet portrait */
@media (max-width: 780px) {
  .reader-topbar {
    padding: 0 12px;
    height: 50px;
  }

  .topbar-title {
    display: none;
  }

  .topbar-right {
    gap: 4px;
  }

  .reader-main {
    padding: 50px 0 44px;
  }

  .flipbook-wrapper {
    padding: 8px 10px;
  }

  .nav-arrow {
    display: none;
  }

  .page-inner {
    padding: 24px 20px 36px;
    font-size: var(--page-font-size, 12.5px);
  }

  .page-inner h3 {
    font-size: 1.05em;
    margin-bottom: 7px;
    padding-bottom: 5px;
  }

  .page-inner p {
    margin-bottom: 7px;
    line-height: 1.55;
  }

  .page-inner ul, .page-inner ol {
    margin-bottom: 7px;
    padding-left: 16px;
  }

  .page-inner li {
    margin-bottom: 3px;
    font-size: 0.92em;
    line-height: 1.5;
  }

  .page-inner blockquote {
    margin: 10px 0;
    padding: 8px 12px;
    font-size: 0.95em;
  }

  .page-inner .answer {
    padding: 6px 10px;
    margin-bottom: 7px;
    font-size: 0.9em;
  }

  .chapter-title-page .chapter-name {
    font-size: 1.5rem;
  }

  .chapter-title-page .chapter-subtitle {
    font-size: 0.85rem;
  }

  .cover-page .cover-title {
    font-size: 1.6rem;
  }

  .cover-page .cover-subtitle {
    font-size: 0.82rem;
    max-width: 220px;
    margin-bottom: 20px;
  }

  .cover-page .cover-icon {
    font-size: 2.4rem;
    margin-bottom: 16px;
  }

  .bookmark-panel, .toc-panel {
    width: 100%;
  }

  .bookmark-panel {
    right: -100%;
  }

  .toc-panel {
    left: -100%;
  }

  .bottombar-content {
    padding: 8px 14px;
  }

  .page-indicator, .chapter-indicator {
    font-size: 0.78rem;
  }

  .page-number {
    bottom: 12px;
    font-size: 0.7rem;
  }

  .page-number.left { left: 20px; }
  .page-number.right { right: 20px; }
}

/* Phone */
@media (max-width: 480px) {
  .reader-topbar {
    padding: 0 10px;
    height: 48px;
  }

  .topbar-left a span {
    display: none;
  }

  .font-size-controls {
    display: none;
  }

  .reader-main {
    padding: 48px 0 42px;
  }

  .flipbook-wrapper {
    padding: 4px 4px;
  }

  .page-inner {
    padding: 18px 16px 30px;
    font-size: var(--page-font-size, 12px);
  }

  .page-inner h3 {
    font-size: 1em;
    margin-bottom: 6px;
    padding-bottom: 4px;
  }

  .page-inner p {
    margin-bottom: 6px;
    line-height: 1.5;
  }

  .page-inner li {
    margin-bottom: 2px;
    font-size: 0.9em;
  }

  .chapter-title-page {
    padding: 30px 20px;
  }

  .chapter-title-page .chapter-name {
    font-size: 1.3rem;
  }

  .cover-page .cover-title {
    font-size: 1.4rem;
  }
}

/* Ensure all scrollable containers have momentum scrolling on iOS */
.bookmark-list,
.toc-list {
  -webkit-overflow-scrolling: touch;
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .reader-bottombar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .reader-topbar {
    padding-top: env(safe-area-inset-top);
  }
}

/* Extra small phone fix */
@media (max-width: 380px) {
  .topbar-right {
    gap: 2px;
  }

  .topbar-right .btn-icon {
    width: 36px;
    height: 36px;
  }

  .topbar-left a {
    font-size: 0.8rem;
    gap: 4px;
  }

  .topbar-left a svg {
    width: 16px;
    height: 16px;
  }

  .page-inner {
    padding: 14px 12px 26px;
  }

  .chapter-title-page .chapter-name {
    font-size: 1.1rem;
  }

  .chapter-title-page .chapter-heading {
    font-size: 0.75rem;
    letter-spacing: 2px;
  }
}

/* Prevent text selection during page flip on mobile */
.stf__parent * {
  -webkit-user-select: none;
  user-select: none;
}

/* Smooth touch for flipbook */
#flipbook {
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

/* ===================== */
/* In-book CTA pages     */
/* ===================== */
.cta-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 28px;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-page);
}

.cta-page-icon {
  margin-bottom: 20px;
  opacity: 0.9;
}

.cta-page-icons {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  opacity: 0.9;
}

.cta-page-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.cta-page-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
  max-width: 280px;
  margin-bottom: 24px;
}

.cta-page-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 220px;
}

.cta-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 24px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.25s ease;
  cursor: pointer;
  -webkit-user-select: auto;
  user-select: auto;
}

.cta-page-btn--wp {
  background: #25D366;
  color: white !important;
}

.cta-page-btn--wp:hover {
  background: #1DA851;
  box-shadow: 0 3px 12px rgba(37,211,102,0.3);
}

.cta-page-btn--donate {
  background: linear-gradient(135deg, #FF6B6B, #EE5A24);
  color: white !important;
}

.cta-page-btn--donate:hover {
  box-shadow: 0 3px 12px rgba(238,90,36,0.3);
}

/* ===================== */
/* Floating action btns  */
/* ===================== */
.reader-fab {
  position: fixed;
  right: 16px;
  bottom: 60px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 24px;
  border: none;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  text-decoration: none;
  white-space: nowrap;
}

.fab-btn:hover {
  transform: translateY(-2px);
}

.fab-btn svg { flex-shrink: 0; }

.fab-btn--wp {
  background: #25D366;
  color: white !important;
}

.fab-btn--wp:hover {
  box-shadow: 0 4px 18px rgba(37,211,102,0.4);
  color: white !important;
}

.fab-btn--donate {
  background: linear-gradient(135deg, #FF6B6B, #EE5A24);
  color: white !important;
}

.fab-btn--donate:hover {
  box-shadow: 0 4px 18px rgba(238,90,36,0.4);
  color: white !important;
}

@media (max-width: 780px) {
  .reader-fab {
    right: 8px;
    bottom: 52px;
    gap: 6px;
  }

  .fab-btn {
    padding: 7px 12px;
    font-size: 0.72rem;
    gap: 5px;
  }

  .fab-btn svg {
    width: 14px;
    height: 14px;
  }

  .cta-page {
    padding: 28px 20px;
  }

  .cta-page-title {
    font-size: 1.2rem;
  }

  .cta-page-desc {
    font-size: 0.82rem;
    max-width: 240px;
  }

  .cta-page-btn {
    font-size: 0.8rem;
    padding: 10px 20px;
  }
}

@media (max-width: 480px) {
  .fab-btn span {
    display: none;
  }

  .fab-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }
}
