/*
 * Mobile Image Sidebar Extension for Flipbook
 * 
 * This CSS file adds mobile image sidebars to the flipbook with:
 * - Large images on left and right sides
 * - Drop shadows and hover animations
 * - Responsive design
 * - Non-intrusive positioning
 * 
 * To integrate: Add this line to your HTML head:
 * <link rel="stylesheet" href="mobile-sidebar-extension/mobile-sidebar.css" />
 */

/* Ensure body background is preserved on mobile */
body {
  background-image: url("./files/mobile-ext/backGroundImgURL.jpg") !important;
  background-size: cover !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
  background-attachment: fixed !important;
}

/* Force background visibility on all devices */
html,
body {
  background-color: transparent !important;
}

/* Ensure background shows through book containers */
.bookContainer,
.bookStage {
  background: transparent !important;
}

/* tmpContainer background applied via inline JS styling */

/* Mobile image sidebar styles */
.mobile-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 280px; /* Initial width, will be overridden by dynamic sizing */
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  padding: 0 20px;
  pointer-events: none; /* Allow clicks to pass through the sidebar */
  opacity: 0; /* Hidden initially, will fade in when .book is ready */
  visibility: hidden;
  transition: all 0.5s ease; /* Smooth transitions for width, opacity, and visibility */
}

/* Show sidebars when ready */
.mobile-sidebar.ready {
  opacity: 1;
  visibility: visible;
}

/* Bottom grid layout (used when sidebar images would be too small) */
.mobile-bottom-grid {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: none; /* hidden by default, shown in bottom layout */
  flex-direction: column;
  gap: 16px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  /* Ensure it never overlaps book content */
  max-height: 25vh; /* Limit height to 25% of viewport */
  overflow: auto;
}

.mobile-bottom-grid.show {
  display: flex;
}

.mobile-images-grid {
  display: grid;
  gap: 16px;
  justify-items: center;
  align-items: center;
}

.mobile-bottom-grid .mobile-image-container {
  pointer-events: auto;
}

.mobile-bottom-grid .mobile-image {
  width: auto;
  height: 110px; /* uniform height for all bottom images */
  object-fit: contain;
}

/* Desktop: single row (6 columns) */
@media (min-width: 1025px) {
  .mobile-images-grid {
    grid-template-columns: repeat(6, minmax(80px, 1fr));
    align-items: center;
  }
}

/* Tablet: 2 rows x 3 columns */
@media (min-width: 769px) and (max-width: 1280px) {
  .mobile-images-grid {
    grid-template-columns: repeat(3, minmax(100px, 1fr));
  }
}

/* Mobile: 2 columns; very small: 1 column */
@media (max-width: 768px) {
  .mobile-images-grid {
    grid-template-columns: repeat(2, minmax(100px, 1fr));
  }
  .mobile-bottom-grid .mobile-image {
    height: 90px;
  }
}
@media (max-width: 420px) {
  .mobile-images-grid {
    grid-template-columns: 1fr;
  }
  .mobile-bottom-grid .mobile-image {
    height: 80px;
  }
}

/* Adjust book positioning when bottom layout is active */
body.bottom-layout .bookStage,
body.bottom-layout .bookContainer,
body.bottom-layout .book {
  transform: scale(0.9);
  transform-origin: top center;
  transition: transform 0.3s ease;
  /* Ensure adequate space for bottom grid */
  position: relative;
  z-index: 1;
}

/* Enhanced mobile spacing for bottom layout */
@media (max-width: 768px) {
  body.bottom-layout .bookStage,
  body.bottom-layout .bookContainer,
  body.bottom-layout .book {
    transform: scale(0.85);
    margin-bottom: 20px;
  }

  .mobile-bottom-grid {
    padding: 8px 12px;
    gap: 12px;
  }

  .mobile-bottom-grid .mobile-image {
    height: 120px;
  }
}

@media (max-width: 480px) {
  body.bottom-layout .bookStage,
  body.bottom-layout .bookContainer,
  body.bottom-layout .book {
    transform: scale(0.8);
    margin-bottom: 15px;
  }

  .mobile-bottom-grid {
    padding: 6px 8px;
    gap: 8px;
  }

  .mobile-bottom-grid .mobile-image {
    height: 70px;
  }
}

/* When bottom layout is active, hide sidebars robustly */
body.bottom-layout .mobile-sidebar {
  display: none !important;
}

/* Ensure symmetric side paddings on both sidebars */
.mobile-sidebar.left-sidebar,
.mobile-sidebar.right-sidebar {
  padding-left: 20px;
  padding-right: 20px;
}

/* Align images to inner edge so distance to viewport border equals padding (20px) */
.mobile-sidebar.left-sidebar {
  align-items: flex-start;
}
.mobile-sidebar.right-sidebar {
  align-items: flex-end;
}

.left-sidebar {
  left: 0;
}

.right-sidebar {
  right: 0;
}

.mobile-image-container {
  position: relative;
  pointer-events: auto; /* Re-enable clicks for the image containers */
  cursor: pointer;
  transition: all 0.3s ease;
}

.mobile-image {
  width: 230px; /* Initial width, will be overridden by dynamic sizing */
  height: auto;
  border-radius: 0; /* No border radius */
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  display: block;
  object-fit: cover; /* Ensure images maintain aspect ratio */
}

/* Hover animations - upwards movement and scale */
.mobile-image-container:hover {
  transform: translateY(-8px);
}

.mobile-image-container:hover .mobile-image {
  transform: scale(1.1);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4), 0 8px 16px rgba(0, 0, 0, 0.3);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .mobile-sidebar {
    display: none !important; /* Hide sidebars on mobile devices */
  }
}

/* Dynamic sizing takes precedence over static responsive rules */
@media (min-width: 769px) {
  .mobile-sidebar {
    display: flex !important; /* Ensure sidebars are visible on larger screens */
  }
}

/* Ensure sidebars don't interfere with flipbook controls */
.mobile-sidebar {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Additional shadow variations for better depth perception */
.mobile-image-container:hover .mobile-image {
  filter: brightness(1.05);
}

/* Smooth animation timing */
.mobile-image-container,
.mobile-image {
  transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
