/* 
 * Bookshelf Specific CSS Styles
 * Comic Gallery Website
 */

/* ===== Bookshelf Container ===== */
.bookshelf-container {
  position: relative;
  height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2rem;
}

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

/* ===== Book Animation Keyframes ===== */
@keyframes floatAnimation {
  0% { transform: translateY(0) rotate(var(--book-rotation, 0deg)); }
  50% { transform: translateY(-5px) rotate(var(--book-rotation, 0deg)); }
  100% { transform: translateY(0) rotate(var(--book-rotation, 0deg)); }
}

@keyframes pulseAnimation {
  0% { transform: translateY(-50px) scale(1.1) rotate(0deg); }
  50% { transform: translateY(-55px) scale(1.15) rotate(0deg); }
  100% { transform: translateY(-50px) scale(1.1) rotate(0deg); }
}

@keyframes bookHoverPulse {
  0% { transform: translateY(-15px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1.05)); }
  50% { transform: translateY(-18px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1.08)); }
  100% { transform: translateY(-15px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1.05)); }
}

@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;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  bottom: 20px; /* Rest on shelf */
  animation: none;
  padding: 0 !important;
  box-sizing: border-box;
}

.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;
  animation: bookHoverPulse 1.5s ease-in-out infinite;
}

.book.active {
  z-index: 50 !important;
  animation: pulseAnimation 3s 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;
}

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

/* ===== 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%);
  transition: transform 0.3s ease;
  z-index: 5;
  max-height: 100%;
  overflow: hidden;
}

.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;
  transition: var(--transition-normal);
}

.nav-button:hover {
  background-color: rgba(0, 0, 0, 0.5);
}

.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;
  transition: var(--transition-normal);
}

.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;
  transition: var(--transition-normal);
}

.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%;
  transition: font-size 0.3s ease;
  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;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

.error-content {
  padding: 2rem;
  text-align: center;
  color: #666;
}

.error-content h2 {
  color: #e53e3e;
  margin-bottom: 1rem;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 768px) {
  .book {
    width: 100px;
    height: 150px;
  }
  
  .book-title {
    font-size: 0.8rem;
  }
  
  .book-subtitle, .book-volume {
    font-size: 0.6rem;
  }
  
  .nav-button {
    width: 2.5rem;
    height: 2.5rem;
  }
}

@media (max-width: 480px) {
  .book {
    width: 80px;
    height: 120px;
  }
  
  .book-title {
    font-size: 0.7rem;
  }
  
  .book-icon {
    width: 16px;
    height: 16px;
  }
  
  .nav-button {
    width: 2rem;
    height: 2rem;
  }
}

.bookshelf-container {
  scroll-behavior: smooth; /* Keep smooth scrolling for bookshelf */
  contain: layout paint style; /* Contain scroll effects to this container */
}

/* Isolate any bookshelf-specific scroll animations */
.bookshelf-container * {
  animation-play-state: running !important; /* Keep animations running in bookshelf */
}

/* Make sure the book viewer isn't affected by bookshelf styles */
body:has(.book-viewer-container.active) .bookshelf-container {
  pointer-events: none; /* Disable pointer events when book viewer is active */
}

/* 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; /* Lower than book viewer */
}

/* 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-Friendly Bookshelf CSS Styles
 * Optimizations for better mobile viewing
 */

/* ===== Improved Book Animation Keyframes ===== */
@keyframes floatAnimation {
  0% { transform: translateY(0) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1)); }
  50% { transform: translateY(-5px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1)); }
  100% { transform: translateY(0) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1)); }
}

@keyframes pulseAnimation {
  0% { transform: translateY(var(--pulse-y, -50px)) scale(var(--book-scale, 1.1)) rotate(0deg); }
  50% { transform: translateY(calc(var(--pulse-y, -50px) - 5px)) scale(var(--book-scale, 1.15)) rotate(0deg); }
  100% { transform: translateY(var(--pulse-y, -50px)) scale(var(--book-scale, 1.1)) rotate(0deg); }
}

@keyframes bookHoverPulse {
  0% { transform: translateY(var(--hover-y, -15px)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale, 1.05)); }
  50% { transform: translateY(calc(var(--hover-y, -15px) - 3px)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale, 1.08)); }
  100% { transform: translateY(var(--hover-y, -15px)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale, 1.05)); }
}

/* ===== Responsive Bookshelf Container ===== */
.bookshelf-container {
  position: relative;
  height: 60vh;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2rem;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  touch-action: pan-y; /* Better touch handling */
}

/* ===== Book Styles Optimized for Mobile ===== */
.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;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  bottom: 20px; /* Rest on shelf */
  animation: none;
  padding: 0 !important;
  box-sizing: border-box;
  touch-action: none; /* Prevent default touch actions */
  will-change: transform, opacity; /* Performance hint */
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

/* Enhanced hover states for touch devices */
.book:hover {
  --hover-y: -15px;
  --hover-scale: 1.05;
  transform: translateY(var(--hover-y)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale)) !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;
  animation: bookHoverPulse 1.5s ease-in-out infinite;
}

.book.active {
  --pulse-y: -50px;
  z-index: 50 !important;
  animation: pulseAnimation 3s 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);
}

/* Improved Book Info Hover for touch */
.book-info-hover {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.8); /* Darker for better readability */
  color: white !important;
  padding: 12px; /* Larger padding for touch */
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 5;
  max-height: 100%;
  overflow: hidden;
}

/* Improve touch targets for navigation buttons */
.nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(0, 0, 0, 0.4); /* Darker for better visibility */
  color: white;
  border: none;
  border-radius: 50%;
  width: 3.5rem; /* Larger for touch */
  height: 3.5rem; /* Larger for touch */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: var(--transition-normal);
  /* Add touch-friendly properties */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.nav-button:hover {
  background-color: rgba(0, 0, 0, 0.6);
}

.prev-button {
  left: 1rem;
}

.next-button {
  right: 1rem;
}

/* Add a larger hit area for improved touch target on mobile */
.nav-button::after {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  z-index: -1;
}

/* ===== Enhanced Responsive Adjustments ===== */
@media (max-width: 768px) {
  .bookshelf-container {
    height: 70vh; /* Taller to accommodate larger books */
    min-height: 450px;
  }
  
  .book {
    width: 256px; /* Full-sized books on mobile as requested */
    height: 384px; /* Maintain proportion */
    border-width: 4px; /* Standard border */
  }
  
  .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); /* Darker background for better contrast */
    transform: translateY(0); /* Show full info panel by default */
    max-height: 35%; /* Reduced height since we're only showing the title */
  }
  
  .book-info-hover .book-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0; /* No margin needed since subtitle is hidden */
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
    display: block; /* Change from -webkit-box to normal block display */
    -webkit-line-clamp: unset; /* Remove line clamping */
    -webkit-box-orient: unset;
    max-height: none; /* Let it take the space it needs */
  }
  
  .book-info-hover .book-subtitle {
    display: none; /* Hide subtitle on mobile */
  }
  
  .book-spine {
    top: 10px;
    left: -30px;
    font-size: 0.8rem;
    max-width: 180px;
    font-weight: bold;
  }
  
  .nav-button {
    width: 4rem;
    height: 4rem;
  }
  
  .prev-button {
    left: 0.5rem;
  }
  
  .next-button {
    right: 0.5rem;
  }
  
  /* Active book animations */
  .book.active {
    --pulse-y: -50px; /* Full pulse on mobile */
  }
  
  .book:hover {
    --hover-y: -20px; /* More visible hover on mobile */
    --hover-scale: 1.08;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .bookshelf-container {
    height: 65vh;
    min-height: 420px;
  }
  
  .book {
    width: 220px; /* Still large on smallest screens but allowing for spacing */
    height: 330px;
    border-width: 4px;
  }
  
  .book-info-hover {
    max-height: 60%; /* Allow info panel to be taller on small screens */
  }
  
  .nav-button {
    width: 3.5rem;
    height: 3.5rem;
  }
}

/* Fix for book layout jumping on orientation change */
@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 */
@media (prefers-reduced-motion: reduce) {
  .book {
    animation: none !important;
    transition: transform 0.2s ease-out !important;
  }
  
  .book:hover, .book.active {
    animation: none !important;
  }
}

/* Fix for touch devices to make the books reliably tappable */
@media (hover: none) {
  .book-info-hover {
    /* Make info always visible on touch devices */
    transform: translateY(60%);
  }
  
  .book:active .book-info-hover {
    transform: translateY(0);
  }
  
  /* Ensure proper tapping behavior */
  .book {
    transition: transform 0.2s ease-out;
  }
}

/* 
 * Mobile-Friendly Bookshelf CSS Styles
 * Optimizations for better mobile viewing
 */

/* ===== Improved Book Animation Keyframes ===== */
@keyframes floatAnimation {
  0% { transform: translateY(0) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1)); }
  50% { transform: translateY(-5px) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1)); }
  100% { transform: translateY(0) rotate(var(--book-rotation, 0deg)) scale(var(--book-scale, 1)); }
}

@keyframes pulseAnimation {
  0% { transform: translateY(var(--pulse-y, -50px)) scale(var(--book-scale, 1.1)) rotate(0deg); }
  50% { transform: translateY(calc(var(--pulse-y, -50px) - 5px)) scale(var(--book-scale, 1.15)) rotate(0deg); }
  100% { transform: translateY(var(--pulse-y, -50px)) scale(var(--book-scale, 1.1)) rotate(0deg); }
}

@keyframes bookHoverPulse {
  0% { transform: translateY(var(--hover-y, -15px)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale, 1.05)); }
  50% { transform: translateY(calc(var(--hover-y, -15px) - 3px)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale, 1.08)); }
  100% { transform: translateY(var(--hover-y, -15px)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale, 1.05)); }
}

/* ===== Responsive Bookshelf Container ===== */
.bookshelf-container {
  position: relative;
  height: 60vh;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2rem;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  touch-action: pan-y; /* Better touch handling */
}

/* ===== Book Styles Optimized for Mobile ===== */
.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;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  bottom: 20px; /* Rest on shelf */
  animation: none;
  padding: 0 !important;
  box-sizing: border-box;
  touch-action: none; /* Prevent default touch actions */
  will-change: transform, opacity; /* Performance hint */
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

/* Enhanced hover states for touch devices */
.book:hover {
  --hover-y: -15px;
  --hover-scale: 1.05;
  transform: translateY(var(--hover-y)) rotate(var(--book-rotation, 0deg)) scale(var(--hover-scale)) !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;
  animation: bookHoverPulse 1.5s ease-in-out infinite;
}

.book.active {
  --pulse-y: -50px;
  z-index: 50 !important;
  animation: pulseAnimation 3s 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);
}

/* Improved Book Info Hover for touch */
.book-info-hover {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.8); /* Darker for better readability */
  color: white !important;
  padding: 12px; /* Larger padding for touch */
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 5;
  max-height: 100%;
  overflow: hidden;
}

/* Improve touch targets for navigation buttons */
.nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(0, 0, 0, 0.4); /* Darker for better visibility */
  color: white;
  border: none;
  border-radius: 50%;
  width: 3.5rem; /* Larger for touch */
  height: 3.5rem; /* Larger for touch */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: var(--transition-normal);
  /* Add touch-friendly properties */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.nav-button:hover {
  background-color: rgba(0, 0, 0, 0.6);
}

.prev-button {
  left: 1rem;
}

.next-button {
  right: 1rem;
}

/* Add a larger hit area for improved touch target on mobile */
.nav-button::after {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  z-index: -1;
}

/* ===== Enhanced Responsive Adjustments ===== */
@media (max-width: 768px) {
  .bookshelf-container {
    height: 70vh; /* Taller to accommodate larger books */
    min-height: 450px;
  }
  
  .book {
    width: 256px; /* Full-sized books on mobile as requested */
    height: 384px; /* Maintain proportion */
    border-width: 4px; /* Standard border */
  }
  
  .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); /* Darker background for better contrast */
    transform: translateY(0); /* Show full info panel by default */
    max-height: 35%; /* Reduced height since we're only showing the title */
  }
  
  .book-info-hover .book-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0; /* No margin needed since subtitle is hidden */
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
    text-overflow: initial;
    display: block; /* Change from -webkit-box to normal block display */
    -webkit-line-clamp: unset; /* Remove line clamping */
    -webkit-box-orient: unset;
    max-height: none; /* Let it take the space it needs */
  }
  
  .book-info-hover .book-subtitle {
    display: none; /* Hide subtitle on mobile */
  }
  
  .book-spine {
    top: 10px;
    left: -30px;
    font-size: 0.8rem;
    max-width: 180px;
    font-weight: bold;
  }
  
  .nav-button {
    width: 4rem;
    height: 4rem;
  }
  
  .prev-button {
    left: 0.5rem;
  }
  
  .next-button {
    right: 0.5rem;
  }
  
  /* Active book animations */
  .book.active {
    --pulse-y: -50px; /* Full pulse on mobile */
  }
  
  .book:hover {
    --hover-y: -20px; /* More visible hover on mobile */
    --hover-scale: 1.08;
  }
}

/* Extra small devices */
@media (max-width: 480px) {
  .bookshelf-container {
    height: 65vh;
    min-height: 420px;
  }
  
  .book {
    width: 220px; /* Still large on smallest screens but allowing for spacing */
    height: 330px;
    border-width: 4px;
  }
  
  .book-info-hover {
    max-height: 60%; /* Allow info panel to be taller on small screens */
  }
  
  .nav-button {
    width: 3.5rem;
    height: 3.5rem;
  }
}

/* Fix for book layout jumping on orientation change */
@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 */
@media (prefers-reduced-motion: reduce) {
  .book {
    animation: none !important;
    transition: transform 0.2s ease-out !important;
  }
  
  .book:hover, .book.active {
    animation: none !important;
  }
}

/* Fix for touch devices to make the books reliably tappable */
@media (hover: none) {
  .book-info-hover {
    /* Make info always visible on touch devices */
    transform: translateY(60%);
  }
  
  .book:active .book-info-hover {
    transform: translateY(0);
  }
  
  /* Ensure proper tapping behavior */
  .book {
    transition: transform 0.2s ease-out;
  }
}