* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #f5f5f5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  overflow-x: hidden;
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  position: relative;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(245, 245, 245, 0.95);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e0e0e0;
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-overlay p {
  font-size: 18px;
  font-weight: 500;
  color: #333;
}

.loading-percentage {
  font-size: 24px;
  font-weight: 700;
  color: #000;
  margin-top: 10px;
}

/* Search Controls */
.search-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 25px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-controls label {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.page-jump-input {
  width: 120px;
  padding: 8px 12px;
  font-size: 14px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s ease;
}

.page-jump-input:focus {
  border-color: #000;
}

.page-jump-input::-webkit-inner-spin-button,
.page-jump-input::-webkit-outer-spin-button {
  opacity: 1;
}

.btn-jump {
  min-width: 60px;
  background: #000;
  color: #fff;
}

.btn-jump:hover {
  background: #333;
  transform: translateY(-1px);
}

.btn-jump:active {
  transform: translateY(0);
}

.booklet-wrapper {
  perspective: 2500px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.book {
  position: relative;
  display: flex;
  /* PDF dimensions: 22cm width x 26cm height per page, 2 pages side by side */
  width: 1654px; /* 22cm * 2 pages * 37.5px/cm ≈ 1650px */
  height: 975px; /* 26cm * 37.5px/cm ≈ 975px */
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  border: 1px solid #e0e0e0;
  overflow: visible;
  transform-style: preserve-3d;
}

.page {
  width: 50%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fefefe;
  position: relative;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.page-left {
  border-right: 2px solid #e0e0e0;
  box-shadow: inset -5px 0 10px rgba(0, 0, 0, 0.05);
}

.page-right {
  border-left: 2px solid #e0e0e0;
  box-shadow: inset 5px 0 10px rgba(0, 0, 0, 0.05);
}

.page canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  object-fit: fill;
}

/* Page turning animation */
.book.turning-next .page-right {
  transform-origin: left center;
  animation: turnPageNext 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 10;
}

.book.turning-prev .page-left {
  transform-origin: right center;
  animation: turnPagePrev 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 10;
}

@keyframes turnPageNext {
  0% {
    transform: rotateY(0deg) translateZ(0);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
  25% {
    transform: rotateY(-45deg) translateZ(40px);
    box-shadow:
      -20px 0 40px rgba(0, 0, 0, 0.25),
      -5px 0 15px rgba(0, 0, 0, 0.1);
  }
  50% {
    transform: rotateY(-90deg) translateZ(50px);
    box-shadow:
      -30px 0 50px rgba(0, 0, 0, 0.3),
      -10px 0 20px rgba(0, 0, 0, 0.15);
  }
  75% {
    transform: rotateY(-135deg) translateZ(40px);
    box-shadow:
      -20px 0 40px rgba(0, 0, 0, 0.25),
      -5px 0 15px rgba(0, 0, 0, 0.1);
  }
  100% {
    transform: rotateY(-180deg) translateZ(0);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
}

@keyframes turnPagePrev {
  0% {
    transform: rotateY(0deg) translateZ(0);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
  25% {
    transform: rotateY(45deg) translateZ(40px);
    box-shadow:
      20px 0 40px rgba(0, 0, 0, 0.25),
      5px 0 15px rgba(0, 0, 0, 0.1);
  }
  50% {
    transform: rotateY(90deg) translateZ(50px);
    box-shadow:
      30px 0 50px rgba(0, 0, 0, 0.3),
      10px 0 20px rgba(0, 0, 0, 0.15);
  }
  75% {
    transform: rotateY(135deg) translateZ(40px);
    box-shadow:
      20px 0 40px rgba(0, 0, 0, 0.25),
      5px 0 15px rgba(0, 0, 0, 0.1);
  }
  100% {
    transform: rotateY(180deg) translateZ(0);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
}

.controls {
  display: flex;
  align-items: center;
  gap: 20px;
  background: white;
  padding: 20px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn {
  padding: 12px 24px;
  font-size: 16px;
  background: #000;
  color: white;
  border: 2px solid #000;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: white;
  color: #000;
}

.btn:active:not(:disabled) {
  background: #f0f0f0;
}

.btn:disabled {
  background: #e0e0e0;
  border-color: #e0e0e0;
  color: #999;
  cursor: not-allowed;
}

.page-info {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  min-width: 120px;
  text-align: center;
}

/* Responsive design - maintaining 22:26 aspect ratio per page */
@media (max-width: 1750px) {
  .book {
    width: 1320px; /* 22cm * 2 * 30px/cm */
    height: 780px; /* 26cm * 30px/cm */
  }
}

@media (max-width: 1400px) {
  .book {
    width: 1100px; /* 22cm * 2 * 25px/cm */
    height: 650px; /* 26cm * 25px/cm */
  }
}

@media (max-width: 1150px) {
  .book {
    width: 880px; /* 22cm * 2 * 20px/cm */
    height: 520px; /* 26cm * 20px/cm */
  }
}

@media (max-width: 950px) {
  .book {
    width: 660px; /* 22cm * 2 * 15px/cm */
    height: 390px; /* 26cm * 15px/cm */
  }
}

@media (max-width: 700px) {
  body {
    padding: 10px;
  }

  .container {
    gap: 15px;
    width: 100%;
  }

  .book {
    width: 95vw;
    max-width: 100%;
    height: calc(95vw * 0.59); /* Maintaining 22:26 ratio (26/44 ≈ 0.59) */
  }

  .controls {
    width: 95vw;
    max-width: 100%;
    padding: 15px;
    gap: 10px;
  }

  .btn {
    padding: 14px 20px;
    font-size: 15px;
    min-height: 48px;
    flex: 1;
  }

  .page-info {
    font-size: 14px;
    min-width: 100px;
    order: -1;
    margin-bottom: 5px;
  }

  .controls {
    flex-wrap: wrap;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  body {
    padding: 5px;
  }

  .container {
    gap: 10px;
  }

  .book {
    width: 98vw;
    height: calc(98vw * 0.59);
  }

  .controls {
    width: 98vw;
    padding: 12px;
  }

  .btn {
    padding: 12px 16px;
    font-size: 14px;
  }

  .page-info {
    font-size: 13px;
  }

  .loading-overlay p {
    font-size: 16px;
  }

  .loading-spinner {
    width: 40px;
    height: 40px;
  }
}

/* Landscape mobile orientation */
@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding: 5px;
  }

  .container {
    gap: 10px;
  }

  .book {
    width: 90vw;
    height: calc(90vh - 80px);
    max-height: calc(90vw * 0.59);
  }

  .controls {
    padding: 10px 15px;
  }

  .btn {
    padding: 10px 18px;
    font-size: 14px;
  }

  .page-info {
    font-size: 13px;
  }
}
