/* 
 * Optimized Bookshelf CSS Styles
 * Comic Gallery Website - Performance Optimized
 */

/* ===== Bookshelf Container ===== */
.bookshelf-container {
  position: relative;
  height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2rem;
  /* Performance optimizations */
  will-change: auto;
  contain: layout style paint;
}

.bookshelf {
  position: relative;
  width: 100%;
  max-width: 1000px;
  height: 350px;
  margin: 0 auto;
}

.shelf-background {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 20px;
  background-image: linear-gradient(to bottom, var(--shelf-color), var(--shelf-shadow));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  z-index: 1;
}

.books-container {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ===== Optimized Book Animation Keyframes ===== */
@keyframes floatAnimation {
  0%, 100% { transform: translateY(0) rotate(var(--book-rotation, 0deg)); }
  50% { transform: translateY(-5px) rotate(var(--book-rotation, 0deg)); }
}

@keyframes pulseAnimation {
  0%, 100% { transform: translateY(-50px) scale(1.1) rotate(0deg); }
  50% { transform: translateY(-53px) scale(1.13) rotate(0deg); }
}

@keyframes bookHoverPulse {
  0%, 100% { transform: translateY(-15px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1.05)); }
  50% { transform: translateY(-17px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1.07)); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Individual Book Styles ===== */
.book {
  position: absolute;
  width: 256px;
  height: 384px;
  border-radius: 6px;
  border: 4px solid #1a202c;
  overflow: hidden;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transform-origin: bottom center;
  /* Optimized transition - faster and smoother */
  transition: transform 0.2s ease-out, box-shadow 0.2s ease-out, z-index 0s;
  bottom: 20px;
  animation: none;
  padding: 0 !important;
  box-sizing: border-box;
  /* Performance optimizations */
  will-change: transform;
  backface-visibility: hidden;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.book:hover {
  transform: translateY(-15px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1.05)) !important;
  box-shadow: 0 15px 20px -3px rgba(0, 0, 0, 0.5), 0 8px 10px -2px rgba(0, 0, 0, 0.2);
  z-index: 60 !important;
  /* Faster pulse animation */
  animation: bookHoverPulse 1s ease-in-out infinite;
}

.book.active {
  z-index: 50 !important;
  /* Faster pulse animation */
  animation: pulseAnimation 2s ease-in-out infinite;
  box-shadow: 0 20px 30px -3px rgba(0, 0, 0, 0.4), 0 8px 10px -2px rgba(0, 0, 0, 0.2);
}

.book-content {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0 !important;
  margin: 0 !important;
}

.book-cover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 1;
  mix-blend-mode: normal;
  padding: 0 !important;
  margin: 0 !important;
  /* Performance optimization */
  will-change: auto;
}

.book-spine {
  position: absolute;
  top: 10px;
  left: -30px;
  background-color: white;
  color: #1a202c;
  font-weight: bold;
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  transform: rotate(90deg);
  transform-origin: left bottom;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  z-index: 10;
  border-radius: 2px 2px 0 0;
  /* Performance optimization */
  will-change: auto;
}

/* ===== Book Info Hover ===== */
.book-info-hover {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.75);
  color: white !important;
  padding: 8px;
  transform: translateY(100%);
  /* Faster transition */
  transition: transform 0.2s ease-out;
  z-index: 5;
  max-height: 100%;
  overflow: hidden;
  /* Performance optimization */
  will-change: transform;
}

.book:hover .book-info-hover {
  transform: translateY(0);
}

.book-info-hover .book-title {
  font-size: 0.9rem;
  font-weight: bold;
  margin-bottom: 4px;
  color: white !important;
  white-space: normal;
  overflow: visible;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
}

.book-info-hover .book-subtitle {
  font-size: 0.75rem;
  opacity: 0.9;
  margin-bottom: 0.25rem;
  color: rgba(255, 255, 255, 0.9) !important;
  white-space: normal;
  overflow: visible;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.book-info-hover .book-metadata {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.9;
  justify-content: flex-start;
}

.book-info-hover .book-metadata-item {
  padding: 0.2rem 0.5rem;
  background-color: rgba(255, 255, 255, 0.15);
}

/* ===== Book Colors ===== */
.book-blue { background-color: #3b82f6; }
.book-red { background-color: #ef4444; }
.book-green { background-color: #10b981; }
.book-purple { background-color: #8b5cf6; }
.book-yellow { background-color: #f59e0b; }
.book-pink { background-color: #ec4899; }
.book-indigo { background-color: #6366f1; }
.book-cyan { background-color: #06b6d4; }
.book-orange { background-color: #f97316; }
.book-teal { background-color: #14b8a6; }

/* ===== Book Elements ===== */
.book-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 0.5rem;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"/><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"/></svg>');
  background-repeat: no-repeat;
  background-position: center;
}

.book-title {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.book-subtitle {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-bottom: 0.5rem;
}

.book-volume {
  font-size: 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
}

.book-counter {
  position: absolute;
  bottom: 2rem;
  left: 0;
  right: 0;
  text-align: center;
}

.book-counter span {
  display: inline-block;
  padding: 0.5rem 1rem;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 1rem;
  font-size: 0.875rem;
}

/* ===== Navigation Controls ===== */
.nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(0, 0, 0, 0.3);
  color: white;
  border: none;
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  /* Faster transition */
  transition: background-color 0.15s ease-out, transform 0.15s ease-out;
  /* Performance optimization */
  will-change: background-color;
}

.nav-button:hover {
  background-color: rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) scale(1.05);
}

.nav-button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.prev-button {
  left: 1rem;
}

.next-button {
  right: 1rem;
}

/* ===== Dot Navigation ===== */
.dot-navigation {
  position: absolute;
  bottom: 1rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.nav-dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  /* Faster transition */
  transition: background-color 0.15s ease-out, transform 0.15s ease-out;
  /* Performance optimization */
  will-change: background-color, transform;
}

.nav-dot.active {
  background-color: white;
  transform: scale(1.25);
}

.nav-dot:hover {
  background-color: rgba(255, 255, 255, 0.7);
}

/* ===== Reader Controls ===== */
.reader-controls {
  padding: 0.5rem 1rem;
  background-color: #f0f0f0;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: flex-end;
  position: sticky;
  top: 0;
  z-index: 10;
}

.font-size-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.font-size-btn {
  padding: 0.25rem 0.75rem;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  /* Faster transition */
  transition: background-color 0.15s ease-out;
}

.font-size-btn:hover {
  background-color: #eee;
}

.font-size-btn.decrease {
  font-size: 0.9rem;
}

.font-size-btn.increase {
  font-size: 1.1rem;
}

/* ===== Content Styling ===== */
.content-wrapper {
  font-size: 100%;
  /* Faster transition */
  transition: font-size 0.2s ease-out;
  padding: 1rem 2rem 3rem;
}

.content-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: #666;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-left-color: #4f46e5;
  /* Faster spin */
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

.error-content {
  padding: 2rem;
  text-align: center;
  color: #666;
}

.error-content h2 {
  color: #e53e3e;
  margin-bottom: 1rem;
}

/* ===== Performance Optimizations ===== */
.bookshelf-container {
  scroll-behavior: auto; /* Disable smooth scroll for better performance */
  contain: layout paint style;
  isolation: isolate;
}

/* Optimize animations for better performance */
.bookshelf-container * {
  animation-play-state: running !important;
}

/* Make sure the book viewer isn't affected by bookshelf styles */
body:has(.book-viewer-container.active) .bookshelf-container {
  pointer-events: none;
}

/* Override any inherited scroll behavior from global styles */
:not(.bookshelf-container) {
  scroll-behavior: auto;
}

/* Ensure book viewer components don't inherit bookshelf animations */
.book-viewer-container .book,
.book-viewer-container .book-content,
.book-viewer-container .book-page {
  animation: none !important;
  transform: none !important;
  transition: none !important;
}

.bookshelf-container {
  isolation: isolate;
  contain: layout style;
}

/* Make sure bookshelf scroll effects don't leak */
.bookshelf-container * {
  scroll-snap-type: var(--bookshelf-scroll-snap-type, none);
  scroll-snap-align: var(--bookshelf-scroll-align, none);
}

/* Disable bookshelf scroll effects when book viewer is active */
body:has(.book-viewer-container.active) .bookshelf-container {
  pointer-events: none;
  z-index: 1;
}

/* Reset any book behavior that might interfere with book viewer */
.book-viewer-container .book,
.book-viewer-container .book-content {
  animation: none !important;
  transform: none !important;
  transition: none !important;
}

/* Alternative for browsers that don't support :has() */
.book-viewer-container.active ~ .bookshelf-container {
  pointer-events: none;
  z-index: 1;
}

/* Fix for wheel event handling in the bookshelf */
.bookshelf-container {
  --bookshelf-wheel-handled: true;
}

/* Prevent scroll animations from affecting outside content */
@media (prefers-reduced-motion: no-preference) {
  .bookshelf-container .book:not(:hover) {
    animation-play-state: running !important;
  }
  
  body:has(.book-viewer-container.active) .bookshelf-container .book {
    animation-play-state: paused !important;
  }
}

/* ===== Mobile Optimizations ===== */
@media (max-width: 768px) {
  .bookshelf-container {
    height: 70vh;
    min-height: 450px;
  }
  
  .book {
    width: 256px;
    height: 384px;
    border-width: 4px;
    /* Faster transitions on mobile */
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
  }
  
  .book-title {
    font-size: 1rem;
  }
  
  .book-subtitle, .book-volume {
    font-size: 0.8rem;
  }
  
  .book-info-hover {
    padding: 16px;
    background-color: rgba(0, 0, 0, 0.85);
    transform: translateY(0);
    max-height: 35%;
    /* Faster transition on mobile */
    transition: transform 0.15s ease-out;
  }
  
  .book-info-hover .book-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0;
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
    max-height: none;
  }
  
  .book-info-hover .book-subtitle {
    display: none;
  }
  
  .book-spine {
    top: 10px;
    left: -30px;
    font-size: 0.8rem;
    max-width: 180px;
    font-weight: bold;
  }
  
  .nav-button {
    width: 4rem;
    height: 4rem;
    /* Faster transitions on mobile */
    transition: background-color 0.1s ease-out, transform 0.1s ease-out;
  }
  
  .prev-button {
    left: 0.5rem;
  }
  
  .next-button {
    right: 0.5rem;
  }
  
  /* Faster animations on mobile */
  .book.active {
    animation: pulseAnimation 1.5s ease-in-out infinite;
  }
  
  .book:hover {
    animation: bookHoverPulse 0.8s ease-in-out infinite;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .bookshelf-container {
    height: 65vh;
    min-height: 420px;
  }
  
  .book {
    width: 220px;
    height: 330px;
    border-width: 4px;
  }
  
  .book-info-hover {
    max-height: 60%;
  }
  
  .nav-button {
    width: 3.5rem;
    height: 3.5rem;
  }
}
@media (max-width: 768px) {
  .bookshelf-container {
    height: 70vh;
    min-height: 450px;
  }
  
  .book {
    width: 256px;
    height: 384px;
    border-width: 4px;
    /* Faster transitions on mobile */
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
  }
  
  .book-title {
    font-size: 1rem;
  }
  
  .book-subtitle, .book-volume {
    font-size: 0.8rem;
  }
  
  .book-info-hover {
    padding: 16px;
    background-color: rgba(0, 0, 0, 0.85);
    transform: translateY(0);
    max-height: 35%;
    /* Faster transition on mobile */
    transition: transform 0.15s ease-out;
  }
  
  .book-info-hover .book-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0;
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
    max-height: none;
  }
  
  .book-info-hover .book-subtitle {
    display: none;
  }
  
  .book-spine {
    top: 10px;
    left: -30px;
    font-size: 0.8rem;
    max-width: 180px;
    font-weight: bold;
  }
  
  .nav-button {
    width: 4rem;
    height: 4rem;
    /* Faster transitions on mobile */
    transition: background-color 0.1s ease-out, transform 0.1s ease-out;
  }
  
  .prev-button {
    left: 0.5rem;
  }
  
  .next-button {
    right: 0.5rem;
  }
  
  /* Faster animations on mobile */
  .book.active {
    animation: pulseAnimation 1.5s ease-in-out infinite;
  }
  
  .book:hover {
    animation: bookHoverPulse 0.8s ease-in-out infinite;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .bookshelf-container {
    height: 65vh;
    min-height: 420px;
  }
  
  .book {
    width: 220px;
    height: 330px;
    border-width: 4px;
  }
  
  .book-info-hover {
    max-height: 60%;
  }
  
  .nav-button {
    width: 3.5rem;
    height: 3.5rem;
  }
}

/* Fix for orientation changes */
@media screen and (orientation: portrait) {
  .bookshelf-container {
    height: 50vh;
  }
}

@media screen and (orientation: landscape) and (max-width: 768px) {
  .bookshelf-container {
    height: 70vh;
  }
}

/* Reduced motion preferences - disable animations entirely */
@media (prefers-reduced-motion: reduce) {
  .book {
    animation: none !important;
    transition: transform 0.1s ease-out !important;
  }
  
  .book:hover, .book.active {
    animation: none !important;
  }
  
  .nav-button, .nav-dot {
    transition: background-color 0.1s ease-out !important;
  }
}

/* Touch device optimizations */
@media (hover: none) {
  .book-info-hover {
    transform: translateY(60%);
  }
  
  .book:active .book-info-hover {
    transform: translateY(0);
  }
  
  .book {
    /* Even faster transitions on touch devices */
    transition: transform 0.1s ease-out;
  }
}