/* Book Structure and Page Turning Animations */

.book-wrapper {
  perspective: 2000px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.book {
  position: relative;
  width: 600px;
  height: 900px; /* 2:3 ratio (taller than wide) */
  transform-style: preserve-3d;
}

/* Book Cover */
.book-cover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    linear-gradient(135deg, #2d1b3d 0%, #1a0f2e 50%, #0f0819 100%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(138, 43, 226, 0.05) 2px, rgba(138, 43, 226, 0.05) 4px);
  border: 8px solid #4b0082;
  border-radius: 8px;
  box-shadow: 
    0 0 60px rgba(138, 43, 226, 0.4),
    inset 0 0 80px rgba(75, 0, 130, 0.2),
    0 20px 60px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transform-origin: left center;
  transition: transform 0.6s ease-in-out;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem;
  position: relative;
  overflow: hidden;
}

.book-cover::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: 
    radial-gradient(circle at 30% 30%, rgba(138, 43, 226, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(75, 0, 130, 0.15) 0%, transparent 50%);
  animation: cover-glow 8s ease-in-out infinite;
}

@keyframes cover-glow {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(180deg); }
}

.book-cover:hover {
  transform: rotateY(-5deg) scale(1.02);
}

.book-cover.opened {
  transform: rotateY(-180deg);
  pointer-events: none;
  z-index: 1;
}

/* Hide cover text when opened (instead of showing backwards) */
.book-cover.opened .book-cover-content {
  opacity: 0;
  visibility: hidden;
}

/* Hide cover decorations when opened */
.book-cover.opened .book-cover-decoration-top,
.book-cover.opened .book-cover-decoration-bottom {
  opacity: 0;
  visibility: hidden;
}

/* Ensure cover is always on top when closed */
.book-cover:not(.opened) {
  z-index: 100;
}

.book-cover-content {
  position: relative;
  z-index: 1;
  width: 100%;
}

.book-cover-title {
  font-family: 'UnifrakturMaguntia', cursive;
  font-size: 5rem;
  color: #da70d6;
  text-shadow: 
    0 0 20px rgba(218, 112, 214, 0.8),
    0 0 40px rgba(138, 43, 226, 0.6),
    2px 2px 4px rgba(0, 0, 0, 0.8);
  margin-bottom: 1rem;
  letter-spacing: 0.1em;
  line-height: 1.1;
}

.book-cover-subtitle {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.3rem;
  color: #9370db;
  font-style: italic;
  text-shadow: 0 0 10px rgba(147, 112, 219, 0.5);
  margin-bottom: 3rem;
  letter-spacing: 0.05em;
}

/* Remove purple glow for vintage theme - ensure complete override */
/* Note: This reset is handled in the specific vintage theme rules below */
/* body[data-theme="vintage"] .book-cover-title,
body[data-theme="vintage"] .book-cover-subtitle {
  text-shadow: none;
} */

.book-cover-decoration {
  margin: 2rem 0;
  font-size: 2rem;
  color: #9370db;
  opacity: 0.6;
  line-height: 1.5;
}

.book-cover-hint {
  font-family: 'MedievalSharp', cursive;
  font-size: 1rem;
  color: #d8bfd8;
  margin-top: 3rem;
  opacity: 0.7;
  animation: pulse-hint 2s ease-in-out infinite;
  position: relative;
  z-index: 1;
}

.book-cover-ornament {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 2px solid #9370db;
  opacity: 0.3;
}

.book-cover-ornament-tl {
  top: 20px;
  left: 20px;
  border-right: none;
  border-bottom: none;
}

.book-cover-ornament-tr {
  top: 20px;
  right: 20px;
  border-left: none;
  border-bottom: none;
}

.book-cover-ornament-bl {
  bottom: 20px;
  left: 20px;
  border-right: none;
  border-top: none;
}

.book-cover-ornament-br {
  bottom: 20px;
  right: 20px;
  border-left: none;
  border-top: none;
}

/* Decorative elements on book cover that reveal theme selector */
.book-cover-decoration-top,
.book-cover-decoration-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 60px;
  cursor: pointer;
  z-index: 10;
  opacity: 0.6;
  transition: opacity 0.3s ease;
  background-image: url('../images/deco-element.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.book-cover-decoration-top {
  top: 40px;
}

.book-cover-decoration-bottom {
  bottom: 40px;
  transform: translateX(-50%) rotate(180deg);
}

.book-cover-decoration-top:hover,
.book-cover-decoration-bottom:hover {
  opacity: 0.9;
}

/* Decorative element on TOC page */
.toc-decoration {
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: 350px;
  height: 60px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.3s ease;
  background-image: url('../images/deco-element.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.toc-decoration:hover {
  opacity: 0.8;
}

@keyframes pulse-hint {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Book Pages Container */
.book-pages {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  z-index: 0;
}

/* Hide pages initially until book is opened */
.book-cover:not(.opened) ~ .book-pages {
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  visibility: hidden;
}

/* When cover is opened, show pages */
.book-cover.opened ~ .book-pages {
  opacity: 1;
  visibility: visible;
}

/* When cover is opened, pages should be visible */
.book-cover.opened ~ .book-pages {
  z-index: 10;
}

/* Single page view - only show current page */
.book-pages.single-page-view .page {
  display: none !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.book-pages.single-page-view .page.active {
  display: block !important;
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}

/* Individual Page */
.page {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.6s ease-in-out;
  z-index: 10;
}

/* In single-page view, disable 3D transforms and show only front */
.book-pages.single-page-view .page {
  transform: none !important;
  transform-style: flat;
}

.book-pages.single-page-view .page-content {
  transform-style: flat;
}

.page.flipped {
  transform: rotateY(-180deg);
}

.page-content {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
}

.page-front {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 
    -5px 0 20px rgba(0, 0, 0, 0.3),
    inset -2px 0 10px rgba(0, 0, 0, 0.1);
  padding: 3rem 4rem;
  overflow-y: auto;
  backface-visibility: hidden;
  transform: rotateY(0deg);
}

/* In single-page view, make front page normal position */
.book-pages.single-page-view .page-front {
  transform: none;
}

.page-back {
  position: absolute;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 
    5px 0 20px rgba(0, 0, 0, 0.3),
    inset 2px 0 10px rgba(0, 0, 0, 0.1);
  padding: 3rem 4rem;
  overflow-y: auto;
  backface-visibility: hidden;
  transform: rotateY(180deg);
}

/* In single-page view, hide the back of pages */
.book-pages.single-page-view .page-back {
  display: none;
}

/* Page Navigation */
.page-nav {
  position: absolute;
  bottom: 20px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.book-cover.opened ~ .book-pages ~ .page-nav {
  opacity: 1;
}

.page-nav button {
  pointer-events: all;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.page-nav button:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.6);
  transform: scale(1.1);
}

.page-nav button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* Page Corner Flip Indicator */
.page-corner {
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: 60px;
  background: linear-gradient(225deg, transparent 50%, rgba(0, 0, 0, 0.1) 50%);
  cursor: pointer;
  z-index: 25;
  transition: all 0.3s ease;
  pointer-events: all;
}

.page-corner:hover {
  background: linear-gradient(225deg, transparent 50%, rgba(0, 0, 0, 0.2) 50%);
}

.page-corner::after {
  content: '→';
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 1.2rem;
  color: rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
}

.page-corner:hover::after {
  color: rgba(0, 0, 0, 0.7);
  transform: translateX(3px);
}

.page.flipped .page-corner {
  pointer-events: none;
  opacity: 0;
}

/* Table of Contents Page */
.toc-page {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: -1rem; /* Reduce space above TOC */
}

.toc-category {
  margin-bottom: 1rem;
}

.toc-category .section-title {
  margin-bottom: 0.5rem;
  font-size: 1.3rem;
  padding-bottom: 0.3rem;
}

.toc-item {
  padding: 0.6rem 0.8rem;
  border-left: 3px solid var(--accent-primary);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 0.4rem;
  display: block;
  text-decoration: none;
  color: inherit;
}

.toc-item:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateX(5px);
  border-left-width: 5px;
}

.toc-item-title {
  font-family: var(--font-title);
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
  font-weight: 600;
  line-height: 1.3;
}

.toc-item-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Page Number */
.page-number {
  position: absolute;
  bottom: 20px;
  right: 20px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  opacity: 0.6;
  font-family: var(--font-date);
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .book {
    width: 100%;
    max-width: 600px;
    height: auto;
    min-height: 900px;
    aspect-ratio: 2 / 3; /* Maintain 2:3 ratio */
  }
  
  .book-cover-title {
    font-size: 3rem;
  }
  
  .page-content {
    padding: 2rem;
  }
}

/* Theme-specific book cover adjustments */
body[data-theme="vintage"] .book-cover {
  /* Hardcover image background */
  background-image: url('../images/book-cover-hardcover.png');
  background: 
    url('../images/book-cover-hardcover.png'),
    linear-gradient(135deg, #8b6f47 0%, #5d4e37 100%);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* Thick border - can be removed or made thinner if desired */
  /* border: 8px solid #6b5d4f; */
  border: 2px solid #6b5d4f; /* Thinner border - comment out to remove completely */
  box-shadow: 
    0 0 40px rgba(139, 111, 71, 0.3),
    inset 0 0 60px rgba(101, 67, 33, 0.2),
    0 20px 60px rgba(0, 0, 0, 0.5);
}

body[data-theme="vintage"] .book-cover::before {
  background: 
    radial-gradient(circle at 30% 30%, rgba(139, 111, 71, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(101, 67, 33, 0.15) 0%, transparent 50%);
}

body[data-theme="vintage"] .book-cover-title {
  color: #d4c677;
  /* Engraved effect - halfway between subtle and intense */
  text-shadow: 
    /* Moderate shadow layers below for depth */
    0 1px 0 rgba(0, 0, 0, 0.9),
    0 2px 1px rgba(0, 0, 0, 0.85),
    0 3px 2px rgba(0, 0, 0, 0.75),
    0 4px 3px rgba(0, 0, 0, 0.65),
    0 5px 4px rgba(0, 0, 0, 0.55),
    0 6px 5px rgba(0, 0, 0, 0.45),
    0 7px 6px rgba(0, 0, 0, 0.4),
    /* Light highlight on top edge */
    0 -1px 0 rgba(255, 255, 255, 0.3),
    0 -2px 1px rgba(255, 255, 255, 0.25),
    0 -3px 2px rgba(255, 255, 255, 0.2),
    /* Side shadows for dimension */
    1px 2px 2px rgba(0, 0, 0, 0.5),
    -1px 2px 2px rgba(0, 0, 0, 0.5);
  /* Original: font-family: 'Playfair Display', serif; */
  /* Testing: New Rocker to replace Playfair Display and Cinzel */
  font-family: 'New Rocker', cursive;
  font-size: 5.2rem; /* ~15% bigger (4.5 * 1.15) */
  font-weight: 400; /* New Rocker doesn't have weight 700, using 400 */
}

body[data-theme="vintage"] .book-cover-subtitle {
  color: #d4c677;
  /* Engraved effect - matching title, halfway between subtle and intense */
  text-shadow: 
    /* Moderate shadow layers below for depth */
    0 1px 0 rgba(0, 0, 0, 0.9),
    0 2px 1px rgba(0, 0, 0, 0.85),
    0 3px 2px rgba(0, 0, 0, 0.75),
    0 4px 3px rgba(0, 0, 0, 0.65),
    0 5px 4px rgba(0, 0, 0, 0.55),
    0 6px 5px rgba(0, 0, 0, 0.45),
    0 7px 6px rgba(0, 0, 0, 0.4),
    /* Light highlight on top edge */
    0 -1px 0 rgba(255, 255, 255, 0.3),
    0 -2px 1px rgba(255, 255, 255, 0.25),
    0 -3px 2px rgba(255, 255, 255, 0.2),
    /* Side shadows for dimension */
    1px 2px 2px rgba(0, 0, 0, 0.5),
    -1px 2px 2px rgba(0, 0, 0, 0.5);
  /* Original: font-family: 'Playfair Display', serif; */
  /* Testing: Tinos to replace Playfair Display */
  font-family: 'Tinos', serif;
  font-size: 2.6rem; /* Twice as big (1.3 * 2) */
  opacity: 0.9;
  font-weight: 400; /* Tinos weight */
  font-style: normal; /* Remove italic for cleaner engraved look */
}

body[data-theme="vintage"] .book-cover-decoration {
  color: #6b5d4f;
}

body[data-theme="vintage"] .book-cover-hint {
  color: #5d4e37;
}

body[data-theme="vintage"] .book-cover-ornament {
  border-color: #6b5d4f;
}

body[data-theme="steampunk"] .book-cover {
  background: 
    linear-gradient(135deg, #1a0f08 0%, #2c1810 100%),
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(139, 111, 71, 0.05) 10px, rgba(139, 111, 71, 0.05) 20px);
  border-color: #8b6914;
  box-shadow: 
    0 0 40px rgba(184, 134, 11, 0.3),
    inset 0 0 60px rgba(0, 0, 0, 0.4),
    0 20px 60px rgba(0, 0, 0, 0.6);
}

body[data-theme="steampunk"] .book-cover::before {
  background: 
    radial-gradient(circle at 30% 30%, rgba(218, 165, 32, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(184, 134, 11, 0.1) 0%, transparent 50%);
}

body[data-theme="steampunk"] .book-cover-title {
  color: #daa520;
  text-shadow: 
    0 0 10px rgba(218, 165, 32, 0.5),
    2px 2px 4px rgba(0, 0, 0, 0.8);
  font-family: 'Orbitron', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 4rem;
}

body[data-theme="steampunk"] .book-cover-subtitle {
  color: #cd853f;
  text-shadow: none;
  font-family: 'Special Elite', cursive;
}

body[data-theme="steampunk"] .book-cover-decoration {
  color: #8b6914;
}

body[data-theme="steampunk"] .book-cover-hint {
  color: #cd853f;
}

body[data-theme="steampunk"] .book-cover-ornament {
  border-color: #8b6914;
}

body[data-theme="sketchbook"] .book-cover {
  background: 
    linear-gradient(135deg, #8b7355 0%, #6b5d4f 50%, #4a3e32 100%),
    repeating-linear-gradient(45deg, transparent, transparent 50px, rgba(139, 115, 85, 0.1) 50px, rgba(139, 115, 85, 0.1) 100px);
  border-color: #6b5d4f;
  box-shadow: 
    0 0 30px rgba(0, 0, 0, 0.3),
    inset 0 0 100px rgba(139, 115, 85, 0.05),
    0 20px 60px rgba(0, 0, 0, 0.4);
}

body[data-theme="sketchbook"] .book-cover::before {
  background: 
    radial-gradient(circle at 30% 30%, rgba(139, 115, 85, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(107, 93, 79, 0.1) 0%, transparent 50%);
}

body[data-theme="sketchbook"] .book-cover-title {
  color: #5d4e37;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
  font-family: 'Kalam', cursive;
  transform: rotate(-1deg);
  font-size: 4rem;
}

body[data-theme="sketchbook"] .book-cover-subtitle {
  color: #6b5d4f;
  text-shadow: none;
  font-family: 'Shadows Into Light', cursive;
  transform: rotate(0.5deg);
}

body[data-theme="sketchbook"] .book-cover-decoration {
  color: #6b5d4f;
  transform: rotate(1deg);
}

body[data-theme="sketchbook"] .book-cover-hint {
  color: #6b5d4f;
}

body[data-theme="sketchbook"] .book-cover-ornament {
  border-color: #6b5d4f;
  border-style: dashed;
}