* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #111827;
  color: #f3f4f6;
  font-family: Arial, Helvetica, sans-serif;
}

body {
  min-height: 100vh;
}

.viewer-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(8px);
}

.viewer-heading h1 {
  margin: 0 0 6px;
  font-size: 28px;
  line-height: 1.1;
}

.viewer-heading p {
  margin: 0;
  color: rgba(243, 244, 246, 0.72);
  font-size: 14px;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.viewer-toolbar button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.viewer-toolbar button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #1d4ed8;
}

.viewer-toolbar button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#pageInfo {
  min-width: 90px;
  text-align: center;
  font-weight: 700;
  color: #e5e7eb;
}

.viewer-main {
  flex: 1;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: stretch;
  min-height: 0;
}

.book-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.book {
  width: min(1200px, 100%);
  height: min(78vh, 900px);
  position: relative;
  overflow: hidden;
}

.click-zone {
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s ease;
}

.click-zone:hover {
  background: rgba(255, 255, 255, 0.03);
}

.book-perspective {
  perspective: 2200px;
  perspective-origin: center center;
  width: 100%;
  height: 100%;
}

.spread {
  display: flex;
  width: 100%;
  height: 100%;
  gap: 0;
}

.page {
  position: relative;
  flex: 1 1 50%;
  height: 100%;
  overflow: hidden;
  background: transparent;
  padding: 6px;
}

.page.empty {
  visibility: hidden;
}

.page-sheet {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition:
    transform 1.8s cubic-bezier(0.22, 0.61, 0.36, 1),
    filter 1.8s ease,
    box-shadow 1.8s ease;
  will-change: transform;
}

.page.left .page-sheet {
  transform-origin: right center;
}

.page.right .page-sheet {
  transform-origin: left center;
}

.page-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.25),
    inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.page-face.front {
  z-index: 2;
}

.page-face.back {
  transform: rotateY(180deg);
  background:
    linear-gradient(
      to right,
      rgba(0, 0, 0, 0.10) 0%,
      rgba(255, 255, 255, 0.92) 12%,
      rgba(250, 250, 250, 1) 100%
    );
}

.zoom-surface {
  width: 100%;
  height: 100%;
  transform-origin: center center;
  transition: transform 0.25s ease;
  will-change: transform;
  cursor: zoom-in;
  touch-action: none;
}

.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.page-number {
  position: absolute;
  bottom: 12px;
  right: 16px;
  padding: 4px 8px;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.65);
  background: rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  z-index: 5;
}

.flip-anim-right {
  z-index: 30;
}

.flip-anim-right .page-sheet {
  animation: pageFlipRight 1.8s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.flip-anim-left {
  z-index: 30;
}

.flip-anim-left .page-sheet {
  animation: pageFlipLeft 1.8s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes pageFlipRight {
  0% {
    transform: rotateY(0deg);
    filter: brightness(1);
  }
  20% {
    transform: rotateY(-18deg);
    filter: brightness(0.98);
  }
  55% {
    transform: rotateY(-88deg);
    filter: brightness(0.92);
  }
  100% {
    transform: rotateY(-180deg);
    filter: brightness(0.96);
  }
}

@keyframes pageFlipLeft {
  0% {
    transform: rotateY(0deg);
    filter: brightness(1);
  }
  20% {
    transform: rotateY(18deg);
    filter: brightness(0.98);
  }
  55% {
    transform: rotateY(88deg);
    filter: brightness(0.92);
  }
  100% {
    transform: rotateY(180deg);
    filter: brightness(0.96);
  }
}

#book.zoomed .zoom-surface {
  cursor: grab;
}

#book.zoomed .zoom-surface:active {
  cursor: grabbing;
}

#book.zoomed .page-sheet {
  animation: none !important;
}

#book.zoomed .click-zone {
  pointer-events: none;
}

#book.single .page {
  flex-basis: 100%;
  max-width: 100%;
}

.empty-state {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.empty-state h2 {
  margin-top: 0;
}

.empty-state code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}

#downloadBtn {
  background: #059669;
}

#downloadBtn:hover:not(:disabled) {
  background: #047857;
}

.viewer-footer {
  text-align: center;
  padding: 12px 20px;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(17,24,39,0.9);
}

@media (max-width: 900px) {
  .viewer-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .viewer-main {
    grid-template-columns: 16px 1fr 16px;
  }

  .book-wrap {
    padding: 12px;
  }

  .book {
    height: min(72vh, 760px);
  }

  .page {
    padding: 0;
  }
}