/* ===== Book Viewer Container and Structure ===== */
.book-viewer-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.book-viewer-container.active {
  display: flex;
}

.book-viewer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(2px);
}

.book-viewer {
  position: relative;
  width: 90%;
  max-width: 1200px;
  height: 85vh;
  background-color: #f5f5f5;
  border-radius: min(8px, 1vw);
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  z-index: 1001;
  display: flex;
  flex-direction: column;
}

/* ===== Book Viewer Header ===== */
.book-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(0.5rem, 1vw, 1rem);
  background-color: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

.book-title {
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: bold;
  color: #1f2937;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 80px);
}

.book-close-btn, 
.settings-toggle, 
.toc-toggle,
.view-mode-toggle {
  background: transparent;
  border: none;
  color: #6b7280;
  cursor: pointer;
  padding: clamp(0.25rem, 0.5vw, 0.5rem);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-close-btn:hover, 
.settings-toggle:hover, 
.toc-toggle:hover,
.view-mode-toggle:hover {
  background-color: #f3f4f6;
  color: #1f2937;
}

.book-close-btn svg, 
.settings-toggle svg, 
.toc-toggle svg,
.view-mode-toggle svg {
  width: clamp(16px, 2vw, 24px);
  height: clamp(16px, 2vw, 24px);
}

.view-mode-toggle {
  margin-right: 8px;
}

/* ===== Book Content Container ===== */
.book-content {
  flex: 1;
  overflow: hidden;
  background-color: #f5f5f5;
  position: relative;
  height: 100%;
}

.book-viewer.scroll-mode .book-content {
  overflow: auto !important;
}

/* ===== Two-Page Spread ===== */
.book-spread {
  display: flex;
  height: 100%;
  background-color: #f5f5f5;
  border-radius: 4px;
}

/* Book Pages */
.book-page {
  flex: 1;
  padding: clamp(1rem, 2vw, 1.5rem);
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  color: #4b5563;
  position: relative;
  height: var(--book-page-height, 100%);
  width: var(--book-page-width, 50%);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.book-page-inner {
  height: 100%;
  overflow: hidden;
  padding: 1.5rem;
}

.book-page-content {
  height: 100%;
  overflow: hidden;
}

.book-page-left {
  border-radius: 4px 0 0 4px;
  margin-right: min(2px, 0.25vw);
}

.book-page-right {
  border-radius: 0 4px 4px 0;
  margin-left: min(2px, 0.25vw);
}

.book-page-divider {
  width: min(4px, 0.5vw);
  background: linear-gradient(to right, rgba(0,0,0,0.1), rgba(0,0,0,0.2), rgba(0,0,0,0.1));
  position: relative;
  box-shadow: inset -1px 0 3px rgba(0,0,0,0.1), inset 1px 0 3px rgba(0,0,0,0.1);
}

/* ===== Special Page Styles ===== */
.book-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: clamp(1rem, 3vw, 2rem);
}

.book-cover h1 {
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  margin-bottom: clamp(0.5rem, 1vw, 1rem);
  color: #1f2937;
}

.book-author {
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  margin-bottom: clamp(1rem, 2vw, 2rem);
  color: #4b5563;
}

.book-cover-image {
  margin-top: clamp(1rem, 2vw, 2rem);
  width: min(200px, 30vw);
  height: min(300px, 40vh);
}

.book-cover-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.book-intro {
  padding: clamp(1rem, 3vw, 2rem);
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.book-intro h2 {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  margin-bottom: clamp(0.5rem, 1vw, 1rem);
  color: #1f2937;
}

.book-blank-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #9ca3af;
  font-style: italic;
}

/* ===== Navigation Controls ===== */
.book-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(0.5rem, 1vw, 1rem);
  background-color: #f9fafb;
  border-top: 1px solid #e5e7eb;
}

.book-viewer .book-nav-btn {
  background-color: #e5e7eb;
  border: none;
  color: #4b5563;
  border-radius: min(4px, 0.5vw);
  padding: clamp(0.25rem, 0.75vw, 0.5rem) clamp(0.5rem, 1vw, 1rem);
  display: flex;
  align-items: center;
  gap: clamp(0.25rem, 0.5vw, 0.5rem);
  cursor: pointer;
  font-weight: 500;
  font-size: clamp(0.8rem, 1.5vw, 0.95rem);
  transition: all 0.2s ease;
}

.book-viewer .book-nav-btn:hover:not(:disabled) {
  background-color: #d1d5db;
  color: #1f2937;
}

.book-viewer .book-nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.book-nav-btn svg {
  width: clamp(16px, 1.5vw, 20px);
  height: clamp(16px, 1.5vw, 20px);
}

.book-page-indicator {
  font-size: clamp(0.75rem, 1.25vw, 0.875rem);
  color: #6b7280;
}

/* ===== Scrollable Book Content ===== */
.book-scrollable-content {
  padding: clamp(1rem, 5vw, 2rem);
  max-width: 1100px;
  margin: 0 auto;
  background-color: var(--bg-color);
  color: var(--text-color);
  box-shadow: 0 2px 10px var(--shadow-color);
  border-radius: 4px;
  font-size: var(--font-size);
  font-family: var(--font-family);
  line-height: var(--line-height);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.book-viewer.scroll-mode .book-scrollable-content.normal-scroll {
  overflow-y: auto !important;
  height: 100% !important;
  scroll-behavior: auto !important;
  -webkit-overflow-scrolling: touch;
  transform: none !important;
  will-change: auto !important;
  transition: none !important;
}





/* ===== Loading and Error States ===== */
.book-loading,
.book-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  padding: clamp(1rem, 2vw, 2rem);
  text-align: center;
}

.book-viewer .spinner {
  width: clamp(30px, 5vw, 40px);
  height: clamp(30px, 5vw, 40px);
  border: min(4px, 0.5vw) solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-left-color: #3b82f6;
  animation: spin 1s linear infinite;
  margin-bottom: clamp(0.5rem, 1vw, 1rem);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Content Typography for Scrollable Mode ===== */
.book-scrollable-content h1,
.book-scrollable-content h2,
.book-scrollable-content h3,
.book-scrollable-content h4,
.book-scrollable-content h5,
.book-scrollable-content h6 {
  color: var(--heading-color);
}

.book-scrollable-content p,
.book-scrollable-content li,
.book-scrollable-content span,
.book-scrollable-content div {
  color: var(--text-color);
}

.book-scrollable-content h1 {
  font-size: calc(var(--font-size) * 1.8);
  margin-bottom: 1rem;
}

.book-scrollable-content h2 {
  font-size: calc(var(--font-size) * 1.5);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.book-scrollable-content h3 {
  font-size: calc(var(--font-size) * 1.3);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.book-scrollable-content p {
  font-size: var(--font-size);
  line-height: var(--line-height);
  margin-bottom: 1rem;
  text-align: justify;
}

/* ===== Content Typography for Book Pages ===== */
.book-viewer .book-page h1 {
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  margin-bottom: clamp(0.5rem, 1vw, 1rem);
  color: #1f2937;
}

.book-viewer .book-page h2 {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  margin-top: clamp(1rem, 1.5vw, 1.5rem);
  margin-bottom: clamp(0.4rem, 0.75vw, 0.75rem);
  color: #1f2937;
}

.book-viewer .book-page h3 {
  font-size: clamp(1rem, 2vw, 1.25rem);
  margin-top: clamp(0.75rem, 1.25vw, 1.25rem);
  margin-bottom: clamp(0.3rem, 0.5vw, 0.5rem);
  color: #1f2937;
}

.book-viewer .book-page p {
  margin-bottom: clamp(0.5rem, 1vw, 1rem);
  line-height: 1.6;
  color: #4b5563;
  text-align: justify;
}

.book-viewer .book-page ul, 
.book-viewer .book-page ol {
  margin-bottom: clamp(0.5rem, 1vw, 1rem);
  padding-left: clamp(1rem, 1.5vw, 1.5rem);
}

.book-viewer .book-page li {
  margin-bottom: clamp(0.25rem, 0.5vw, 0.5rem);
  line-height: 1.5;
  color: #4b5563;
  font-size: clamp(0.875rem, 1.5vw, 1rem);
}

.book-viewer .book-page img {
  max-width: 100%;
  height: auto;
  margin: clamp(0.5rem, 1vw, 1rem) 0;
}

/* ===== Font Size Controls ===== */
.book-viewer.font-size-small .book-scrollable-content {
  --font-size: 0.9rem;
}

.book-viewer.font-size-medium .book-scrollable-content {
  --font-size: 1rem;
}

.book-viewer.font-size-large .book-scrollable-content {
  --font-size: 1.1rem;
}

.book-viewer.font-size-xl .book-scrollable-content {
  --font-size: 1.6rem;
}

.book-viewer.font-size-xxl .book-scrollable-content {
  --font-size: 2rem;
}

/* ===== Font Family Controls ===== */
.book-viewer.font-serif .book-scrollable-content {
  --font-family: 'Georgia', serif;
}

.book-viewer.font-sans .book-scrollable-content {
  --font-family: 'Arial', 'Helvetica', sans-serif;
}

.book-viewer.font-mono .book-scrollable-content {
  --font-family: 'Courier New', monospace;
}

.book-viewer.font-dyslexic .book-scrollable-content {
  --font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif;
}

/* ===== Theme-specific Styles ===== */
.book-viewer.theme-dark .book-scrollable-content,
.book-viewer.theme-sepia .book-scrollable-content {
  background-color: var(--bg-color);
  color: var(--text-color);
}

.book-viewer.theme-dark .book-scrollable-content h1,
.book-viewer.theme-dark .book-scrollable-content h2,
.book-viewer.theme-dark .book-scrollable-content h3,
.book-viewer.theme-dark .book-scrollable-content h4,
.book-viewer.theme-dark .book-scrollable-content h5,
.book-viewer.theme-dark .book-scrollable-content h6,
.book-viewer.theme-sepia .book-scrollable-content h1,
.book-viewer.theme-sepia .book-scrollable-content h2,
.book-viewer.theme-sepia .book-scrollable-content h3,
.book-viewer.theme-sepia .book-scrollable-content h4,
.book-viewer.theme-sepia .book-scrollable-content h5,
.book-viewer.theme-sepia .book-scrollable-content h6 {
  color: var(--heading-color);
}

/* ===== Special Elements Styling ===== */
.book-scrollable-content blockquote {
  border-left: 3px solid var(--border-color);
  padding-left: 1rem;
  margin-left: 0;
  color: var(--text-color);
  opacity: 0.9;
}

.book-scrollable-content a {
  color: var(--heading-color);
  text-decoration: underline;
}

.book-scrollable-content code, 
.book-scrollable-content pre {
  font-family: var(--font-family, monospace);
  background-color: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.2em 0.4em;
  
}

.book-viewer.theme-dark .book-scrollable-content code,
.book-viewer.theme-dark .book-scrollable-content pre {
  background-color: rgba(255, 255, 255, 0.1);
}

/* ===== Cover Section in Scrollable Mode ===== */
.book-scrollable-content .book-cover-section {
  text-align: center;
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 2rem;
}

.book-scrollable-content .book-cover-section h1 {
  color: var(--heading-color);
}

.book-scrollable-content .book-author {
  color: var(--text-color);
  opacity: 0.8;
}

/* ===== Word Count & Reading Time Styles ===== */
.book-metadata {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin: 1rem 0;
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.85;
}

.book-metadata-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 20px;
  white-space: nowrap;
}

.theme-dark .book-metadata-item {
  background-color: rgba(255, 255, 255, 0.1);
}

.theme-sepia .book-metadata-item {
  background-color: rgba(139, 115, 85, 0.1);
}

.book-metadata-icon {
  width: 16px;
  height: 16px;
  opacity: 0.8;
}

.book-viewer .book-page .book-cover .book-metadata,
.book-viewer .book-scrollable-content .book-cover-section .book-metadata {
  margin-top: 1rem;
}

/* ===== Reading Progress Display ===== */
.reading-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-color);
  opacity: 0.8;
  margin-right: 1rem;
  min-width: 120px;
}

.progress-bar-container {
  width: 80px;
  height: 4px;
  background-color: var(--border-color);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background-color: var(--heading-color);
  width: 0;
  transition: width 0.3s ease;
}

.progress-percentage {
  min-width: 36px;
  text-align: left;
}

/* ===== Responsive Layout ===== */
@media (max-width: 768px) {
  .book-spread {
    flex-direction: column;
  }
  
  .book-page-left {
    border-radius: 4px 4px 0 0;
    margin-right: 0;
    margin-bottom: min(2px, 0.25vw);
  }
  
  .book-page-right {
    border-radius: 0 0 4px 4px;
    margin-left: 0;
    margin-top: min(2px, 0.25vw);
  }
  
  .book-page-divider {
    width: 100%;
    height: min(4px, 0.5vw);
  }
  
  .book-nav-btn {
    font-size: clamp(0.75rem, 1.25vw, 0.9rem);
  }
  
  .book-scrollable-content {
    padding: 1rem;
    border-radius: 0;
  }
  
  .book-metadata {
    font-size: 0.8rem;
  }
  
  .book-metadata-item {
    padding: 0.25rem 0.5rem;
  }
}

@media (max-width: 480px) {
  .book-viewer {
    width: 95%;
    height: 90vh;
  }
  
  .book-page-indicator {
    font-size: 0.7rem;
  }
  
  .book-title {
    font-size: 0.9rem;
    max-width: calc(100% - 70px);
  }
}

@media (max-width: 360px) {
  .book-nav-btn span {
    display: none;
  }
  
  .book-nav-btn {
    padding: 0.4rem;
  }
}



.book-viewer.scroll-mode .book-scrollable-content {
  animation: none !important;
  transition: none !important;
  transform: none !important;
  will-change: auto !important;
  
  /* Force pure native scrolling with no fancy behavior */
  scroll-behavior: auto !important;
  scroll-snap-type: none !important;
  scroll-margin: 0 !important;
  scroll-padding: 0 !important;
  overscroll-behavior: auto !important;
  
  /* Make sure height is correct */
  height: 100% !important;
  max-height: 100% !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  
  /* Remove any custom styling that might interfere */
  position: relative !important;
}

/* Prevent any scrolling in the parent container */
.book-viewer.scroll-mode .book-content {
  overflow: hidden !important;
}

/* Ensure scroll content doesn't bounce back */
.book-viewer.scroll-mode {
  /* Prevent propagation of scroll events to parent */
  isolation: isolate;
  contain: strict;
}

/* Style the scrollbar for better visibility */
.book-viewer.scroll-mode .book-scrollable-content::-webkit-scrollbar {
  width: 8px;
  background-color: rgba(0, 0, 0, 0.05);
}

.book-viewer.scroll-mode .book-scrollable-content::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.book-cover-side-by-side {
  display: flex;
  align-items: center;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

/* Left column with cover image - ensure image is centered */
.book-cover-left {
  flex: 0 0 30%; /* or whatever percentage you want */
  display: flex;
  justify-content: center;
  align-items: stretch; /* Stretch the image vertically */
}

/* Image container - centered within left column */
.book-cover-image {
  display: flex;
  align-items: stretch;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* The actual cover image */
.book-cover-image img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* Or use 'contain' if you want full visibility */
  border-radius: 6px;
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}

/* Right column with all text content */
.book-cover-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;  /* This is good */
  text-align: center;
  width: 100%;
}

/* Container for header content */
.book-header-content {
  width: 100%;
  max-width: 800px;  /* Optional: to limit line length */
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Container for metadata */
.book-metadata-container {
  margin-bottom: 1.5rem;
  width: 100%;
  display: flex;
  justify-content: center;
}

/* Metadata styling */
.book-metadata {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.book-metadata-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: rgba(0, 0, 0, 0.05);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.9rem;
}

.book-metadata-icon {
  width: 16px;
  height: 16px;
}

/* Title and subtitle container to ensure alignment */
.book-title, .book-subtitle {
  width: 100%;
  text-align: center;
}

/* Title styling */
.book-title {
  font-size: clamp(1rem, 3vw, 2.5rem);
  margin-bottom: 0.5rem;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  word-wrap: break-word;
}

/* Subtitle styling - aligned with title */
.book-subtitle {
  font-size: clamp(1rem, 2vw, 1.3rem);
  margin-bottom: 1.5rem;
  opacity: 0.8;
  font-style: italic;
  text-align: center;
  display: block;
  width: 100%;
  white-space: normal;
}

/* Intro text styling */
.book-intro {
  padding-top: 1rem;
  font-style: italic;
  color: var(--text-color, #4b5563);
  line-height: 1.6;
  width: 100%;
  text-align: center;
}

/* Quotation marks for intro */


/* Responsive adjustments */
@media (max-width: 768px) {
  .book-cover-side-by-side {
    flex-direction: column;
    padding: 1.5rem 1rem;
  }
  
  .book-cover-left {
    flex: none;
    width: 70%;
    margin-right: 0;
    margin-bottom: 2rem;
  }
  
  .book-cover-image img {
    max-height: 450px;
  }
  
  .book-metadata {
    flex-wrap: wrap;
  }
}

/* Theme-specific adjustments */
.theme-dark .book-metadata-item {
  background-color: rgba(255, 255, 255, 0.1);
}

.theme-sepia .book-metadata-item {
  background-color: rgba(139, 69, 19, 0.1);
}