/*
   GLOBAL AND BASE STYLES
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
}

html,
body {
  overflow: hidden;
}

/* Main container */
.container {
  width: 100vw;
  height: 100vh;
  position: relative;
  background: #000;
  color: white;
}

/* ============================================
   FLIPBOOK AND BOOK DISPLAY AREA
   ============================================ */

/* Main section containing the book and navigation */
.top-part {
  width: 100%;
  height: 80%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  top: 56px;
}

/* Left navigation arrow area */
.left-arrow-navigation {
  width: 10%;
  height: 75%;
  display: flex;
  justify-content: start;
  align-items: center;
  pointer-events: none;
}

.left-arrow-navigation img {
  pointer-events: auto;
  cursor: pointer;
}

/* Book area */
.book-area {
  width: 1000px;
  height: 680px;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
  position: relative;
  transition: transform 0.3s ease;
}

/* Book spine */
.book-spine {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  transform: translateX(-50%);
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.1),
    rgba(0, 0, 0, 0.35),
    rgba(0, 0, 0, 0.1)
  );
  box-shadow:
    -3px 0 8px rgba(0, 0, 0, 0.5),
    3px 0 8px rgba(0, 0, 0, 0.5);
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* Book depth */
.book-depth {
  position: absolute;
  top: 0;
  left: 50%;
  width: 40px;
  height: 100%;
  transform: translateX(-50%);
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0.35) 0%,
    rgba(0, 0, 0, 0.15) 35%,
    rgba(0, 0, 0, 0.05) 60%,
    rgba(0, 0, 0, 0) 75%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 99;
}

/* Stage */
.stage {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 1;
}

#flipbook.single {
  margin: 0 auto;
}

.stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.right-arrow-navigation {
  width: 10%;
  height: 75%;
  display: flex;
  justify-content: end;
  align-items: center;
  pointer-events: none;
}

.right-arrow-navigation img {
  pointer-events: auto;
  cursor: pointer;
}

.middle-part {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-block: 16px;
  padding-inline: 12px;
  position: absolute;
  left: 0px;
  bottom: 48px;
}

/* ============================================
   BOTTOM CONTROL BAR
   ============================================ */

/* Bottom control */
.bottom-part {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
  padding-block: 12px;
  padding-inline: 36px;
  position: absolute;
  left: 8px;
  bottom: 12px;
}

/* Slider */
.slider {
  width: 75%;
  position: relative;
}

.slider-line {
  width: 100%;
  height: 2px;
  background-color: white;
}

.slider-progress-indicator {
  position: absolute;
  top: -8px;
  width: 16px;
  height: 16px;
  background-color: whitesmoke;
  border-radius: 50%;
}

/* ============================================
   PAGE STYLING
   ============================================ */

#flipbook .page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
}

#flipbook .page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
}

#flipbook .page {
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}

.turn-page-wrapper {
  perspective: 2000px;
}

.zoom-button {
  color: white;
  cursor: pointer;
  transition: color 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
}

.zoom-button:hover {
  color: grey;
}

.pageflip-sound {
  cursor: pointer;
  transition: color 0.3s ease;
  color: whitesmoke;
  display: flex;
}

.pageflip-sound:hover {
  color: grey;
}

.pageflip-sound.hidden-button {
  display: none;
}

/* Volume off button */
.pageflip-sound-off {
  cursor: pointer;
  transition: color 0.3s ease;
  color: whitesmoke;
  display: none;
}

.pageflip-sound-off:hover {
  color: grey;
}

.pageflip-sound-off.visible {
  display: flex;
}

/* Search panel */
.search-panel {
  position: fixed;
  top: 30px;
  left: -300px;
  width: 300px;
  height: calc(100% - 100px);
  background: #2f4f7f;
  z-index: 999;
  transition: left 0.3s ease;
  padding: 10px;
  pointer-events: auto;
}

.search-panel.open {
  left: 0;
}

/* Shift book area when search panel opens */
.search-panel.open ~ .top-part .book-area {
  transform: translateX(150px);
}

/* Search header */
.search-header {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Search input field with webkit fixes for number input visibility */
.search-header input {
  flex: 1;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #ccc;
  pointer-events: auto;
  cursor: text;
  outline: none;
  box-shadow: none;
  background: white;
  color: #000 !important;
  -webkit-text-fill-color: #000 !important;
  font-size: 14px !important;
  font-family: Arial, sans-serif;
  line-height: 1.5;
  letter-spacing: normal;
  -webkit-autofill: none;
}

.search-header input:focus {
  border-color: #3fa9f5;
  box-shadow: 0 0 4px rgba(63, 169, 245, 0.5);
}

.search-header input::placeholder {
  color: #999 !important;
  -webkit-text-fill-color: #999 !important;
  opacity: 0.7;
}

/* Remove spinner arrows from number input */
.search-header input::-webkit-outer-spin-button,
.search-header input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.search-header button {
  padding: 6px 10px;
  background: #3fa9f5;
  color: white;
  border: none;
  cursor: pointer;
}

.search-close {
  cursor: pointer;
  font-size: 18px;
}

/* Search Results */
.search-results {
  margin-top: 10px;
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding-top: 10px;
}

.search-result-item {
  padding: 8px 10px;
  margin: 4px 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 13px;
  color: white;
}

.search-result-item:hover {
  background: rgba(0, 255, 153, 0.3);
}

.search-no-results {
  padding: 8px 10px;
  text-align: center;
  color: #999;
  font-size: 13px;
}

.search-results::-webkit-scrollbar {
  width: 6px;
}

.search-results::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.search-results::-webkit-scrollbar-thumb {
  background: #00ff99;
  border-radius: 3px;
}

.search-results::-webkit-scrollbar-thumb:hover {
  background: #fff;
}
/* ============================================
   CONTROL BUTTONS
   ============================================ */

/* Page range */
.pages-range {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: white;
  font-size: 12px;
}

/* Search button */
.search-button {
  color: white;
  cursor: pointer;
  transition: color 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
}

.search-button:hover {
  color: grey;
}

/* Autoplay button */
.autoplay-button {
  color: whitesmoke;
  cursor: pointer;
  transition: color 0.3s ease;
  display: flex;
}

.autoplay-button:hover {
  color: grey;
}

.autoplay-button.hidden-button {
  display: none;
}

/* Pause button */
.pause-button {
  color: whitesmoke;
  cursor: pointer;
  transition: color 0.3s ease;
  display: none;
}

.pause-button:hover {
  color: grey;
}

.pause-button.visible {
  display: flex;
}

/* ============================================
   THUMBNAIL GRID
   ============================================ */

/* Thumbnail bar */
.thumbnail-bar {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  max-width: 90%;
  width: 90%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  opacity: 0;
  z-index: 999;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
  pointer-events: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.thumbnail-bar::-webkit-scrollbar {
  display: none;
}

.thumbnail-bar.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.thumbnail {
  height: 100%;
  width: 120px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border 0.2s;
  flex-shrink: 0;
}

.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail.active {
  border-color: #00ff99;
}

.thumbnail-button {
  color: whitesmoke;
}

.thumbnail-button:hover {
  color: grey;
  cursor: pointer;
}

/* ============================================
   NAVIGATION ARROWS
   ============================================ */

#left-arrow {
  &:hover {
    cursor: pointer;
  }
}

#right-arrow {
  &:hover {
    cursor: pointer;
  }
}

.extreme-left-arrow-navigation {
  &:hover {
    cursor: pointer;
  }
}

.extreme-right-arrow-navigation {
  &:hover {
    cursor: pointer;
  }
}

/* ============================================
   LOADING OVERLAY
   ============================================ */

/* Loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.5s ease-in-out;
  pointer-events: auto;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Spinner */
.loader {
  border: 5px solid rgba(255, 255, 255, 0.2);
  border-top: 5px solid #00ff99;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-overlay p {
  color: #00ff99;
  font-size: 16px;
  margin-top: 10px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Table of Contents Panel */
.toc-panel {
  position: fixed;
  top: 30px;
  right: -350px;
  width: 350px;
  height: calc(100% - 100px);
  background: #2f4f7f;
  z-index: 998;
  transition: right 0.3s ease;
  padding: 10px;
  color: white;
  border-radius: 4px;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
}

.toc-panel.open {
  right: 0;
}

.toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 2px solid #00ff99;
  margin-bottom: 10px;
}

.toc-header h3 {
  margin: 0;
  font-size: 16px;
}

.toc-close {
  cursor: pointer;
  font-size: 20px;
  color: #00ff99;
}

.toc-close:hover {
  color: #fff;
}

.toc-list {
  height: calc(100% - 60px);
  overflow-y: auto;
  padding-right: 8px;
}

.toc-item {
  padding: 8px 10px;
  margin: 4px 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toc-item:hover {
  background: rgba(0, 255, 153, 0.3);
}

.toc-page-num {
  display: block;
  font-size: 14px;
}

.toc-list::-webkit-scrollbar {
  width: 6px;
}

.toc-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.toc-list::-webkit-scrollbar-thumb {
  background: #00ff99;
  border-radius: 3px;
}

.toc-list::-webkit-scrollbar-thumb:hover {
  background: #fff;
}

.table-of-content {
  color: white;
  cursor: pointer;
  transition: color 0.3s ease;
}

.table-of-content:hover {
  color: grey;
}

.turn-page-wrapper {
  perspective: 2000px;
}

/* Mobile Responsiveness */

@media (max-width: 768px) {
  .container {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }
  /* Full-width layout for mobile */
  .top-part {
    top: 0;
    width: 100%;
    height: 80%;
    justify-content: center;
  }

  /* Overlay arrows on the book instead of taking side space */
  .left-arrow-navigation {
    position: absolute;
    left: 0;
    width: 12%;
    height: 100%;
    z-index: 20;
    justify-content: center;
    min-width: 50px;
    pointer-events: none;
  }

  .left-arrow-navigation img {
    width: 48px;
    height: 48px;
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
  }

  .right-arrow-navigation {
    position: absolute;
    right: 0;
    width: 12%;
    height: 100%;
    z-index: 20;
    justify-content: center;
    min-width: 50px;
    pointer-events: none;
  }

  .right-arrow-navigation img {
    width: 48px;
    height: 48px;
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
  }

  /* Expand book to fill most of the screen */
  .book-area {
    width: 100%;
    height: 70vh;
    max-width: 100%;
    aspect-ratio: auto;
    transform: none;
    padding: 6px;
    margin: 4px;
    border-radius: 4px;
  }

  /* Better control bar spacing */
  .bottom-part {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
    bottom: 36px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
  }

  /* Responsive slider width */
  .slider {
    width: 100%;
    order: 10;
    margin-top: 4px;
  }

  /* Increase touch targets on mobile */
  .bottom-part > div {
    min-height: 32px;
    display: flex;
    align-items: center;
  }

  /* Better thumbnail bar positioning */
  .thumbnail-bar {
    bottom: 130px;
    width: calc(100% - 20px);
  }

  .thumbnail {
    width: 70px;
    height: 80px;
  }

  /* Page range */
  .pages-range {
    font-size: 12px;
    flex-shrink: 0;
  }

  /* Panels on mobile */
  .search-panel {
    width: 100vw;
    height: 80vh;
    left: -100vw;
    top: 0;
    z-index: 999;
  }

  .search-panel.open {
    left: 0;
  }

  .toc-panel {
    width: 100vw;
    height: 90vh;
    right: -100vw;
    top: 0;
    z-index: 999;
  }

  .toc-panel.open {
    right: 0;
  }

  /* Extreme navigation */
  .middle-part {
    display: flex;
    position: fixed;
    bottom: 65px;
    left: 0;
    right: 0;
    width: 100vw;
    height: auto;
    padding: 0;
    gap: 0;
    z-index: 50;
    justify-content: space-between;
    transform: none;
  }

  .extreme-left-arrow-navigation {
    position: relative;
    left: 8px;
    top: -24px;
    transform: none;
    width: auto;
    height: auto;
    z-index: 50;
  }

  .extreme-right-arrow-navigation {
    position: relative;
    right: 8px;
    top: -24px;
    transform: none;
    width: auto;
    height: auto;
    z-index: 50;
  }

  .extreme-left-arrow-navigation img,
  .extreme-right-arrow-navigation img {
    width: 32px;
    height: 32px;
    opacity: 0.7;
  }

  .extreme-left-arrow-navigation:hover,
  .extreme-right-arrow-navigation:hover {
    opacity: 1;
  }

  /* Hide buttons on mobile */
  .more-button,
  .table-of-content,
  .slider {
    display: none !important;
  }

  /* Autoplay and sound buttons show by default but can be hidden by class */
  .autoplay-button {
    display: flex;
  }

  .autoplay-button.hidden-button {
    display: none !important;
    flex: 0 !important;
  }

  .pageflip-sound {
    display: flex;
  }

  .pageflip-sound.hidden-button {
    display: none !important;
    flex: 0 !important;
  }

  /* Pause button state */
  .pause-button {
    display: none !important;
  }

  .pause-button.visible {
    display: flex !important;
    flex: 1;
    justify-content: center;
  }

  /* Sound off button state */
  .pageflip-sound-off {
    display: none !important;
  }

  .pageflip-sound-off.visible {
    display: flex !important;
    flex: 1;
    justify-content: center;
  }

  /* Button spacing */
  .thumbnail-button,
  .zoom-button,
  .search-button,
  .pages-range,
  .menu-button {
    flex: 1;
    justify-content: center;
  }

  /* Autoplay flex */
  .autoplay-button {
    flex: 1;
    justify-content: center;
  }

  .autoplay-button.hidden-button {
    flex: 0;
  }

  /* Pause button flex */
  .pause-button.visible {
    flex: 1;
    justify-content: center;
  }

  /* Sound button flex */
  .pageflip-sound {
    flex: 1;
    justify-content: center;
  }

  .pageflip-sound.hidden-button {
    flex: 0;
  }

  /* Sound off flex */
  .pageflip-sound-off.visible {
    flex: 1;
    justify-content: center;
  }

  /* Menu button on mobile */
  .menu-button {
    display: block;
    color: whitesmoke;
    font-size: 18px;
    cursor: pointer;
    transition: color 0.3s ease;
  }

  .menu-button:hover {
    color: grey;
  }

  .bottom-part svg {
    transform: translateZ(0);
    backface-visibility: hidden;
  }

  .bottom-part svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    display: block;
  }
}

/* Mobile menu */
.mobile-menu {
  position: absolute;
  bottom: 50px;
  right: 12px;
  width: 180px;
  background: #2f4f7f;
  border-radius: 8px;
  padding: 8px 0;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.mobile-menu.open {
  display: flex;
}

.mobile-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  color: white;
  transition: background 0.2s ease;
  font-size: 13px;
  white-space: nowrap;
}

.mobile-menu-item:hover {
  background: rgba(0, 255, 153, 0.3);
}

.mobile-menu-item i {
  font-size: 16px;
  min-width: 16px;
}

/* Show buttons on desktop */
@media (min-width: 769px) {
  /* Show all buttons on desktop by default */
  .zoom-button,
  .search-button,
  .thumbnail-button,
  .pages-range,
  .slider,
  .table-of-content,
  .more-button {
    display: flex !important;
  }

  /* Autoplay and sound buttons show by default but can be hidden by class */
  .autoplay-button {
    display: flex;
  }

  .pageflip-sound {
    display: flex;
  }

  /* Show pause and sound-off buttons only when visible class is added */
  .pause-button {
    display: none;
  }

  .pageflip-sound-off {
    display: none;
  }

  .pause-button.visible {
    display: flex;
  }

  .pageflip-sound-off.visible {
    display: flex;
  }

  /* Hide when hidden-button class is added */
  .autoplay-button.hidden-button {
    display: none;
  }

  .pageflip-sound.hidden-button {
    display: none;
  }

  /* Hide hamburger menu on desktop */
  .menu-button {
    display: none !important;
  }

  /* Hide mobile menu dropdown on desktop */
  .mobile-menu {
    display: none !important;
  }
}
