/* ============================================
   Smart PDF Flipbook Viewer - Stylesheet
   Premium + Minimal + Professional + Realistic
   ============================================ */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: linear-gradient(135deg, #e8e8ed 0%, #d8d8e0 50%, #d0d0d8 100%);
  color: #333;
}

/* ============================================
   App Container
   ============================================ */

#flipbook-app {
  width: 100vw;
  height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#flipbook-app::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255,255,255,0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 30% 70%, rgba(200,210,230,0.2) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ============================================
   Loading Screen
   ============================================ */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e8e8ed 0%, #d8d8e0 50%, #d0d0d8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-book-icon {
  width: 70px;
  height: 90px;
  margin: 0 auto 24px;
  position: relative;
  perspective: 300px;
}

.loading-book-cover {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #4a6fa5, #3a5a8a);
  border-radius: 2px 6px 6px 2px;
  transform-origin: left center;
  animation: bookOpenClose 2.5s ease-in-out infinite;
  box-shadow:
    2px 2px 15px rgba(0,0,0,0.25),
    inset -3px 0 0 rgba(0,0,0,0.15);
}

.loading-book-spine {
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 100%;
  background: linear-gradient(to right, rgba(0,0,0,0.3), transparent);
  border-radius: 2px 0 0 2px;
}

@keyframes bookOpenClose {
  0%, 100% { transform: rotateY(0deg); }
  50% { transform: rotateY(-50deg); }
}

.loading-text {
  color: #333;
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 18px;
  letter-spacing: 0.3px;
}

.loading-bar-container {
  width: 260px;
  height: 6px;
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
  overflow: hidden;
  margin: 0 auto;
}

.loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, #4a6fa5, #6a9fd8);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.loading-percent {
  color: #777;
  font-size: 12px;
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}

/* ============================================
   Error Screen
   ============================================ */

#error-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e8e8ed 0%, #d8d8e0 50%, #d0d0d8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.error-content {
  text-align: center;
}

.error-icon {
  color: #999;
  margin-bottom: 16px;
}

.error-title {
  font-size: 20px;
  color: #333;
  font-weight: 600;
  margin-bottom: 8px;
}

.error-message {
  color: #777;
  font-size: 14px;
  margin-bottom: 24px;
}

.retry-button {
  padding: 10px 32px;
  background: #4a6fa5;
  color: white;
  border: none;
  border-radius: 25px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.retry-button:hover {
  background: #3a5a8a;
}

.retry-button:active {
  transform: scale(0.97);
}

/* ============================================
   Book Viewport & Wrapper
   ============================================ */

.book-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  z-index: 1;
  padding: 20px;
}

.book-wrapper {
  position: relative;
  width: 100%;
  max-width: 1100px;
  height: 100%;
  max-height: calc(100vh - 140px);
  transform-origin: center center;
  transition: transform 0.3s ease;
  cursor: grab;
}

.book-wrapper.zoomed {
  cursor: grab;
}

.book-wrapper.zoomed:active {
  cursor: grabbing;
}

.book {
  width: 100%;
  height: 100%;
}

/* Spine overlay - center shadow for book realism */
.book-spine-overlay {
  position: absolute;
  top: 0;
  left: 50%;
  width: 20px;
  height: 100%;
  transform: translateX(-50%);
  background: linear-gradient(
    to right,
    transparent 0%,
    rgba(0,0,0,0.06) 30%,
    rgba(0,0,0,0.18) 50%,
    rgba(0,0,0,0.06) 70%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.book-wrapper.spread-active .book-spine-overlay {
  opacity: 1;
}

/* ============================================
   PageFlip Internal Elements
   ============================================ */

.stf__parent,
.stf__wrapper,
.stf__block {
  width: 100%;
  height: 100%;
}

.stf__item {
  background: #fff;
  overflow: hidden;
}

/* ============================================
   Page Content
   ============================================ */

.page {
  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden;
  position: relative;
}

.page-content {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.page-image {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.page-loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(0,0,0,0.08);
  border-top-color: rgba(74,111,165,0.7);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Toolbar
   ============================================ */

.toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 50px;
  box-shadow:
    0 4px 24px rgba(0,0,0,0.12),
    0 1px 3px rgba(0,0,0,0.08);
  z-index: 200;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toolbar.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);
}

.toolbar-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: #444;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: rgba(0,0,0,0.07);
  color: #222;
}

.toolbar-btn:active {
  background: rgba(0,0,0,0.14);
  transform: scale(0.93);
}

.toolbar-btn.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.toolbar-btn:focus-visible {
  outline: 2px solid #4a90d9;
  outline-offset: 2px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(0,0,0,0.1);
  margin: 0 6px;
  flex-shrink: 0;
}

.page-indicator {
  font-size: 13px;
  color: #555;
  padding: 0 8px;
  min-width: 90px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 900px) {
  .book-wrapper {
    max-width: 700px;
    max-height: calc(100vh - 120px);
  }

  .toolbar {
    gap: 1px;
    padding: 6px 8px;
    bottom: 16px;
  }

  .toolbar-btn {
    width: 38px;
    height: 38px;
  }

  .page-indicator {
    font-size: 12px;
    min-width: 70px;
    padding: 0 4px;
  }

  .toolbar-divider {
    margin: 0 3px;
  }
}

@media (max-width: 600px) {
  .book-viewport {
    padding: 10px;
  }

  .book-wrapper {
    max-width: 100%;
    max-height: calc(100vh - 110px);
  }

  .toolbar {
    gap: 0;
    padding: 5px 6px;
    bottom: 12px;
  }

  .toolbar-btn {
    width: 34px;
    height: 34px;
  }

  .toolbar-btn svg {
    width: 18px;
    height: 18px;
  }

  .page-indicator {
    font-size: 11px;
    min-width: 56px;
    padding: 0 2px;
  }

  .toolbar-divider {
    margin: 0 2px;
    height: 20px;
  }

  .loading-bar-container {
    width: 200px;
  }
}

@media (max-width: 380px) {
  .toolbar {
    padding: 4px 4px;
  }

  .toolbar-btn {
    width: 30px;
    height: 30px;
  }
}

/* ============================================
   Landscape orientation adjustments for mobile
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
  .book-wrapper {
    max-height: calc(100vh - 80px);
  }

  .toolbar {
    bottom: 8px;
  }
}

/* ============================================
   Utility
   ============================================ */

.hidden {
  display: none !important;
}

/* Prevent text selection during interactions */
.book-wrapper,
.toolbar {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Prevent iOS callout on long press */
.book,
.page,
.page-image {
  -webkit-touch-callout: none;
}
