/* ============================================================
   FlipBook Pro — Viewer Styles
   Publuu-inspired cinematic viewer with floating pill toolbar
   ============================================================ */

/* ---------- Reset & Tokens ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Colors — deeper, warmer Publuu-style */
  --bg-deep:       #0a0a14;
  --bg-stage:      #12121f;
  --bg-surface:    #161a2e;
  --bg-overlay:    rgba(10, 10, 20, 0.88);
  --bg-glass:      rgba(22, 28, 50, 0.72);
  --bg-glass-dark: rgba(8, 8, 18, 0.92);

  --accent:        #4f7ef7;
  --accent-hover:  #6b96ff;
  --accent-glow:   rgba(79, 126, 247, 0.35);

  --text-primary:  #f0f4ff;
  --text-muted:    #8892b0;
  --text-dim:      #4a5568;

  --border:        rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);

  /* Shadows — dramatic */
  --shadow-book:   0 40px 100px rgba(0,0,0,0.9),
                   0 12px 32px rgba(0,0,0,0.6),
                   0 0 0 1px rgba(255,255,255,0.03);
  --shadow-panel:  0 -4px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-modal:  0 24px 80px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-btn:    0 2px 8px rgba(0,0,0,0.4);
  --shadow-thumb:  0 4px 16px rgba(0,0,0,0.5);

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Typography */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 15px;

  /* Transitions */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:    cubic-bezier(0, 0, 0.2, 1);

  /* Toolbar — compact Publuu pill */
  --toolbar-h: 48px;
  --toolbar-h-mobile: 46px;
  --thumb-panel-w: 200px;
  --thumb-panel-h: 160px;
  --thumb-panel-h-mobile: 140px;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: transparent;
  font-family: var(--font-ui);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

/* Screen-reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   Loading Screen — Book Flip Animation
   ============================================================ */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  gap: var(--sp-5);
  transition: opacity 0.5s var(--ease-smooth), visibility 0.5s;
}

#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Smooth fade-out + scale transition for loading → viewer */
#loading-screen.fade-out {
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 0.5s var(--ease-smooth), transform 0.5s var(--ease-smooth), visibility 0.5s;
}

.loading-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-5);
  margin-bottom: var(--sp-4);
}

/* Branded book-flip loading animation */
.loading-book-anim {
  perspective: 600px;
}

.loading-book {
  position: relative;
  width: 60px;
  height: 72px;
  transform-style: preserve-3d;
}

.loading-book-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: linear-gradient(180deg, rgba(255,255,255,0.3), rgba(255,255,255,0.1));
  border-radius: 1px;
  z-index: 10;
}

.loading-book-page {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  background: linear-gradient(135deg, var(--accent), #7c5bf5);
  border-radius: 0 3px 3px 0;
  transform-origin: left center;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
}

.loading-book-page-1 {
  background: linear-gradient(135deg, #5a8aff, #7c5bf5);
  animation: bookFlip1 1.8s ease-in-out infinite;
}

.loading-book-page-2 {
  background: linear-gradient(135deg, #4f7ef7, #6366f1);
  animation: bookFlip2 1.8s ease-in-out 0.3s infinite;
}

.loading-book-page-3 {
  background: linear-gradient(135deg, #4472e6, #8b5cf6);
  animation: bookFlip3 1.8s ease-in-out 0.6s infinite;
}

@keyframes bookFlip1 {
  0%, 100% { transform: rotateY(0deg); }
  30%, 70% { transform: rotateY(-160deg); }
}

@keyframes bookFlip2 {
  0%, 100% { transform: rotateY(0deg); }
  35%, 75% { transform: rotateY(-150deg); }
}

@keyframes bookFlip3 {
  0%, 100% { transform: rotateY(0deg); }
  40%, 80% { transform: rotateY(-140deg); }
}

.loading-logo-text {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.loading-logo-text span {
  color: var(--accent);
}

/* Loading meta: title + page count shown during load */
.loading-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: var(--sp-1);
  min-height: 44px;
}

.loading-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  text-align: center;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s var(--ease-smooth), transform 0.3s var(--ease-smooth);
}

.loading-title:not(:empty) {
  opacity: 1;
  transform: translateY(0);
}

.loading-page-count {
  font-size: var(--text-xs);
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s var(--ease-smooth);
}

.loading-page-count:not(:empty) {
  opacity: 1;
}

.loading-text {
  font-size: var(--text-sm);
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

/* Progress indicator: "Loading pages X/Y" */
.loading-progress-indicator {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  margin-top: var(--sp-2);
  min-height: 16px;
  opacity: 0;
  transition: opacity 0.3s var(--ease-smooth);
}

.loading-progress-indicator:not(:empty) {
  opacity: 1;
}

/* Encouraging message (appears after 3s) */
.loading-encourage {
  font-size: var(--text-xs);
  color: var(--accent);
  margin-top: var(--sp-3);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.5s var(--ease-smooth), transform 0.5s var(--ease-smooth);
  text-align: center;
  max-width: 280px;
}

.loading-encourage.visible {
  opacity: 1;
  transform: translateY(0);
}

.loading-progress-wrap {
  width: 200px;
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 99px;
  overflow: hidden;
  margin-top: var(--sp-1);
}

.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #7c5bf5);
  border-radius: 99px;
  transition: width 0.3s var(--ease-smooth);
}

/* ============================================================
   Main Viewer Stage
   ============================================================ */
#viewer-stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  overflow: hidden;
  --book-page-margin: 0px;
  --book-spread-gap: 26px;
  --book-spine-width: 10px;
  --book-spine-gradient: linear-gradient(180deg,
    rgba(250,245,236,0.92) 0%,
    rgba(196,171,138,0.78) 18%,
    rgba(83,58,38,0.48) 48%,
    rgba(193,168,138,0.76) 78%,
    rgba(249,244,234,0.92) 100%
  );
  --book-shadow-elevated: 0 40px 110px rgba(2, 8, 23, 0.48), 0 16px 36px rgba(2, 8, 23, 0.24);
}

/* When blurred page background is active, render it via ::before */
#viewer-stage.has-bg-image::before {
  content: '';
  position: absolute;
  inset: -120px;
  background-image: var(--bg-image-url);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(50px) brightness(0.3) saturate(1.4);
  pointer-events: none;
  z-index: 0;
}

/* When a custom background image is set by the flipbook owner */
#viewer-stage.has-custom-bg-image::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--custom-bg-image-url);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
}

/* Vignette overlay — always on top of blurred bg */
#viewer-stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      ellipse 85% 75% at 50% 50%,
      transparent 35%,
      rgba(6, 4, 12, 0.35) 70%,
      rgba(6, 4, 12, 0.55) 100%
    ),
    radial-gradient(
      ellipse 100% 100% at 50% 40%,
      rgba(60, 40, 20, 0.04) 0%,
      transparent 60%
    );
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 180ms ease;
}

#viewer-stage[data-bg-mode="blurred"]::after {
  opacity: 1;
}

/* ============================================================
   Viewer Title — Top-left
   ============================================================ */
.viewer-title {
  position: fixed;
  top: var(--sp-4);
  left: var(--sp-5);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 14px 6px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0.7;
  transition: opacity 0.3s var(--ease-smooth);
}

.viewer-title:hover {
  opacity: 1;
}

.viewer-title-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.viewer-title-text {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* ============================================================
   Viewer Badge — Top-right
   ============================================================ */
.viewer-badge {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-5);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px 12px;
  background: rgba(79, 126, 247, 0.08);
  border: 1px solid rgba(79, 126, 247, 0.15);
  border-radius: 8px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0.5;
  transition: opacity 0.3s var(--ease-smooth);
}

.viewer-badge:hover {
  opacity: 0.85;
}

.viewer-badge-text {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
}

/* ============================================================
   Flipbook Container
   ============================================================ */
#flipbook-container {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 24px 40px 68px;
  transition: padding 0.35s var(--ease-smooth);
}

/* When thumbnail side-panel is open, push content right */
#flipbook-container.thumbnails-open {
  padding-left: calc(var(--thumb-panel-w) + 20px);
}

.flipbook-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  flex: 0 0 auto;
}

/* Dramatic drop shadow under the book */
.flipbook-shadow {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  width: 85%;
  height: 36px;
  background: rgba(0,0,0,0.7);
  filter: blur(24px);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

/* Ambient light reflection on book surface */
.flipbook-ambient {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 18px;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.03) 0%, transparent 70%);
  pointer-events: none;
  z-index: 2;
}

/* Page flip book canvas / container */
#flipbook-inner {
  position: relative;
  z-index: 1;
  border-radius: 10px;
  overflow: visible;
  box-shadow: var(--book-shadow-elevated);
  transform-origin: center center;
  transition: transform 0.3s var(--ease-smooth);
  min-width: 200px;
  min-height: 100px;
}

#viewer-stage.spread-view #flipbook-inner {
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.18));
}

#viewer-stage.single-view #flipbook-inner::before {
  opacity: 0;
}

/* StPageFlip engine styles */
#flipbook-inner.stf__parent {
  display: block;
  position: relative;
  overflow: hidden;
}
#flipbook-inner .stf__wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#flipbook-inner.spread-view .stf__wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: var(--book-spine-width);
  margin-left: calc(var(--book-spine-width) * -0.5);
  background: var(--book-spine-gradient);
  box-shadow:
    -8px 0 20px rgba(0,0,0,0.16),
    8px 0 20px rgba(0,0,0,0.16),
    0 0 22px rgba(0,0,0,0.14);
  border-radius: 999px;
  pointer-events: none;
  z-index: 4;
}
#flipbook-inner .stf__block {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
#flipbook-inner .stf__item {
  position: absolute;
  top: 0;
  backface-visibility: hidden;
}

/* Pages inside the flipbook — HD rendering */
.flip-page {
  background: transparent;
  position: relative;
  overflow: hidden;
  will-change: transform;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 0;
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.16), 0 6px 14px rgba(15, 23, 42, 0.1);
}

.flip-page img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  margin: 0;
  image-rendering: auto;
  border-radius: 0;
}

.flip-page-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f8f8;
  color: #ccc;
  font-size: 24px;
  font-family: var(--font-ui);
}

/* Zoom modes — 5 levels */
#viewer-stage.zoom-100 #flipbook-inner {
  transform: scale(1);
}
#viewer-stage.zoom-150 #flipbook-inner {
  transform: scale(1.5);
}
#viewer-stage.zoom-200 #flipbook-inner {
  transform: scale(2);
}
#viewer-stage.zoom-300 #flipbook-inner {
  transform: scale(3);
}
#viewer-stage.zoom-500 #flipbook-inner {
  transform: scale(5);
}

/* When zoomed, allow overflow so panning works */
#viewer-stage[class*="zoom-1"] #flipbook-container,
#viewer-stage[class*="zoom-2"] #flipbook-container,
#viewer-stage[class*="zoom-3"] #flipbook-container,
#viewer-stage[class*="zoom-5"] #flipbook-container {
  overflow: hidden;
}

/* Zoom indicator badge */
.zoom-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  background: rgba(79, 126, 247, 0.1);
  border: 1px solid rgba(79, 126, 247, 0.2);
  padding: 2px 8px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: opacity 0.2s var(--ease-smooth);
  min-width: 42px;
  text-align: center;
  justify-content: center;
}

.zoom-indicator.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Zoom controls group in toolbar */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
}

.zoom-controls .tb-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  background: transparent;
}

.zoom-controls .tb-btn:hover {
  background: rgba(255,255,255,0.1);
  border: none;
}

.zoom-controls .zoom-indicator {
  border: none;
  background: transparent;
  padding: 2px 4px;
  min-width: 38px;
}

/* ============================================================
   CSS-based Page Flip (fallback)
   ============================================================ */
.flipbook-css-viewer {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 2000px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-spine {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: var(--book-spine-width);
  margin-left: calc(var(--book-spine-width) * -0.5);
  background: var(--book-spine-gradient);
  box-shadow:
    -8px 0 20px rgba(0,0,0,0.16),
    8px 0 20px rgba(0,0,0,0.16),
    0 0 22px rgba(0,0,0,0.14);
  z-index: 10;
  border-radius: 999px;
}

/* Spine inner highlight */
.book-spine::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(255,255,255,0.15) 0%,
    rgba(255,255,255,0.05) 30%,
    rgba(255,255,255,0.02) 50%,
    rgba(255,255,255,0.05) 70%,
    rgba(255,255,255,0.15) 100%
  );
  border-radius: inherit;
}

.book-page {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: var(--book-page-bg, transparent);
  transform-origin: right center;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1.000);
  will-change: transform;
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.18), 0 6px 14px rgba(15, 23, 42, 0.12);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 0;
}

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

.book-page.right {
  left: 50%;
  transform-origin: left center;
}

.book-page.flipping-right {
  transform: rotateY(-180deg);
}

.book-page-inner {
  position: absolute;
  inset: 0;
  margin: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
}

.book-page-inner img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  image-rendering: auto;
  border-radius: 0;
}

/* Page corners curl hint */
.page-corner-hint {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 28px 28px;
  border-color: transparent transparent rgba(0,0,0,0.12) transparent;
  transition: border-width 0.2s var(--ease-smooth);
  cursor: pointer;
  z-index: 5;
}

.book-page.right .page-corner-hint {
  right: 0;
}
.book-page.left .page-corner-hint {
  left: 0;
  right: auto;
  transform: scaleX(-1);
}

.book-page:hover .page-corner-hint {
  border-width: 0 0 40px 40px;
}

/* ============================================================
   Side Navigation — Tap Zones
   ============================================================ */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 120px;
  z-index: 5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s var(--ease-smooth);
  background: transparent;
  pointer-events: none;
}

.tap-zone:hover {
  opacity: 1;
}

.tap-zone-left {
  left: 0;
  padding-left: 20px;
  justify-content: flex-start;
  background: linear-gradient(90deg, rgba(0,0,0,0.2) 0%, transparent 100%);
}

.tap-zone-right {
  right: 0;
  padding-right: 20px;
  justify-content: flex-end;
  background: linear-gradient(-90deg, rgba(0,0,0,0.2) 0%, transparent 100%);
}

.tap-zone-arrow {
  width: 44px;
  height: 44px;
  background: rgba(12, 12, 24, 0.65);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  color: rgba(255,255,255,0.9);
  font-size: 18px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4),
              inset 0 1px 0 rgba(255,255,255,0.08);
  transition: transform 0.2s var(--ease-spring),
              background 0.2s,
              box-shadow 0.2s;
}

#viewer-edge-nav {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}

#viewer-edge-nav.hidden {
  display: none;
}

.edge-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  background: rgba(8, 15, 29, 0.46);
  color: rgba(255,255,255,0.78);
  box-shadow: 0 16px 32px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  pointer-events: auto;
  transition: transform 0.2s var(--ease-spring), opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
  opacity: 0.7;
}

.edge-nav-prev {
  left: max(8px, calc(50% - min(42vw, 620px) - 38px));
}

.edge-nav-next {
  right: max(8px, calc(50% - min(42vw, 620px) - 38px));
}

.edge-nav-btn:hover:not(:disabled) {
  transform: translateY(-50%) scale(1.06);
  background: rgba(12, 22, 42, 0.72);
  color: #fff;
  opacity: 1;
}

.edge-nav-btn:disabled {
  opacity: 0.22;
  cursor: default;
}

.edge-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.edge-nav-icon svg {
  width: 22px;
  height: 22px;
}

.tap-zone-arrow svg {
  width: 20px;
  height: 20px;
}

.tap-zone:hover .tap-zone-arrow {
  background: rgba(20, 20, 40, 0.8);
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,0.5),
              0 0 0 1px rgba(255,255,255,0.15),
              inset 0 1px 0 rgba(255,255,255,0.12);
}

.tap-zone:active .tap-zone-arrow {
  transform: scale(0.95);
}

/* ============================================================
   Top Toolbar — Floating Pill (Publuu-style)
   ============================================================ */
#viewer-toolbar {
  position: fixed;
  top: var(--sp-3);
  left: 50%;
  transform: translateX(-50%) translateY(0);
  z-index: 50;
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--sp-3);
  gap: var(--sp-1);
  max-width: fit-content;
  min-width: 380px;
  background: var(--bg-glass-dark);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5),
              0 0 0 1px rgba(255,255,255,0.04);
  transition: transform 0.35s var(--ease-smooth),
              opacity 0.35s var(--ease-smooth);
}

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

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Page counter badge */
.page-counter {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  background: rgba(255,255,255,0.05);
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.page-counter strong {
  color: var(--text-primary);
}

/* Toolbar buttons */
.tb-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.15s var(--ease-spring),
              box-shadow 0.15s;
  flex-shrink: 0;
  position: relative;
}

.tb-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
  transform: scale(1.08);
  box-shadow: 0 0 12px rgba(79, 126, 247, 0.15);
}

.tb-btn:active {
  transform: scale(0.92);
}

.tb-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 16px var(--accent-glow);
}

.tb-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tb-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.tb-btn-nav {
  width: 32px;
  height: 32px;
}

.tb-btn-nav:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* Page number input */
.page-input-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
}

.page-input {
  width: 28px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.page-input::-webkit-inner-spin-button,
.page-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.page-sep {
  color: var(--text-dim);
  font-size: 10px;
}

.page-total {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Divider between toolbar groups */
.tb-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

/* ============================================================
   Page Scrubber — Bottom Center
   ============================================================ */
.page-scrubber {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 48;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  width: min(500px, 70vw);
  opacity: 0;
  transition: opacity 0.3s var(--ease-smooth);
  pointer-events: none;
}

/* Show scrubber when toolbar is visible */
.scrubber-visible .page-scrubber {
  opacity: 0.5;
  pointer-events: auto;
}

.page-scrubber:hover {
  opacity: 1 !important;
}

.page-scrubber-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 99px;
  outline: none;
  cursor: pointer;
  transition: height 0.15s var(--ease-smooth);
}

.page-scrubber:hover .page-scrubber-input {
  height: 6px;
}

/* Track styling */
.page-scrubber-input::-webkit-slider-runnable-track {
  height: 100%;
  background: transparent;
  border-radius: 99px;
}

.page-scrubber-input::-moz-range-track {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 99px;
  border: none;
}

/* Thumb styling */
.page-scrubber-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
  margin-top: -5px;
  transition: transform 0.15s var(--ease-spring);
}

.page-scrubber-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
}

.page-scrubber-input:hover::-webkit-slider-thumb {
  transform: scale(1.2);
}

.page-scrubber-label {
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  min-height: 14px;
}

/* ============================================================
   Thumbnail Panel — Left Side (desktop)
   ============================================================ */
#thumbnail-panel {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 49;
  width: var(--thumb-panel-w);
  background: var(--bg-glass-dark);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 32px rgba(0,0,0,0.5),
              0 0 0 1px rgba(255,255,255,0.03);
  transform: translateX(-100%);
  transition: transform 0.35s var(--ease-spring);
  overflow: hidden;
}

#thumbnail-panel.open {
  transform: translateX(0);
}

.thumb-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-3) 0;
  position: sticky;
  top: 0;
  z-index: 1;
}

.thumb-panel-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.thumb-panel-close {
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.thumb-panel-close:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text-primary);
}

.thumb-panel-close svg {
  width: 12px;
  height: 12px;
}

.thumb-panel-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-4) var(--sp-3) var(--sp-6);
  gap: var(--sp-3);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
}

.thumb-panel-inner::-webkit-scrollbar {
  width: 3px;
}
.thumb-panel-inner::-webkit-scrollbar-track {
  background: transparent;
}
.thumb-panel-inner::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 99px;
}

.thumb-item {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  max-width: 160px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  transition: transform 0.2s var(--ease-spring);
  padding: var(--sp-1);
  border-radius: 8px;
}

.thumb-item:hover {
  transform: scale(1.03);
  background: rgba(255,255,255,0.04);
}

.thumb-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.thumb-item.active {
  background: rgba(79, 126, 247, 0.08);
}

.thumb-item.active .thumb-img-wrap {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow), var(--shadow-thumb);
}

.thumb-img-wrap {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  box-shadow: var(--shadow-thumb);
  background: rgba(255,255,255,0.05);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.thumb-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: var(--text-dim);
  font-size: var(--text-sm);
  font-weight: 600;
}

.thumb-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding: 2px 0;
}

.thumb-item.active .thumb-label {
  color: var(--accent);
  font-weight: 600;
}

/* ============================================================
   Share Modal — Enhanced with Tabs
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s var(--ease-smooth), visibility 0.25s;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  background: linear-gradient(180deg, #1c2233, #161a2e);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: var(--sp-6) var(--sp-6) var(--sp-5);
  width: 480px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  transform: scale(0.94) translateY(8px);
  transition: transform 0.3s var(--ease-spring);
  position: relative;
}

.modal-backdrop.open .modal-box {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.2s;
}

.modal-close:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text-primary);
  transform: rotate(90deg);
}

.modal-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal-close svg {
  width: 14px;
  height: 14px;
}

.modal-section {
  margin-bottom: var(--sp-5);
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  margin-bottom: var(--sp-3);
}

/* Tab system */
.share-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.04);
  padding: 3px;
  border-radius: 12px;
  margin-bottom: var(--sp-5);
}

.share-tab {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: center;
  white-space: nowrap;
}

.share-tab:hover {
  color: var(--text-primary);
}

.share-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.share-tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 6px rgba(79, 126, 247, 0.3);
}

.share-tab-content {
  display: none;
}

.share-tab-content.active {
  display: block;
  animation: shareTabFadeIn 0.2s var(--ease-smooth);
}

@keyframes shareTabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Copy link field */
.copy-field {
  display: flex;
  gap: var(--sp-2);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  padding: 3px 3px 3px var(--sp-3);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.copy-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 126, 247, 0.12);
}

.copy-field input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  min-width: 0;
}

.copy-btn {
  height: 34px;
  padding: 0 var(--sp-5);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.copy-btn:hover {
  background: var(--accent-hover);
}

.copy-btn:active {
  transform: scale(0.97);
}

.copy-btn.copied {
  background: #22c55e;
}

/* Social share buttons */
.social-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
}

.social-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: var(--sp-4) var(--sp-3);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s var(--ease-spring);
  text-decoration: none;
  color: var(--text-muted);
}

.social-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--border-strong);
  transform: translateY(-2px);
  color: var(--text-primary);
}

.social-btn:active {
  transform: translateY(0) scale(0.97);
}

.social-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.social-btn svg {
  width: 24px;
  height: 24px;
  transition: transform 0.2s var(--ease-spring);
}

.social-btn:hover svg {
  transform: scale(1.1);
}

.social-btn span {
  font-size: var(--text-xs);
  font-weight: 500;
}

/* Per-platform social hover colors */
.social-btn#share-fb:hover { border-color: rgba(24, 119, 242, 0.4); color: #5a9cf5; }
.social-btn#share-tw:hover { border-color: rgba(255, 255, 255, 0.2); color: #fff; }
.social-btn#share-li:hover { border-color: rgba(0, 119, 181, 0.4); color: #4d8fd4; }
.social-btn#share-wa:hover { border-color: rgba(37, 211, 102, 0.4); color: #5ede8f; }

/* Embed controls */
.embed-size-row {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.embed-size-btn {
  padding: 5px 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--font-ui);
  color: var(--text-muted);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.embed-size-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

.embed-size-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.embed-code {
  position: relative;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--sp-3);
  padding-right: 60px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
  word-break: break-all;
  max-height: 80px;
  overflow-y: auto;
}

.embed-copy-btn {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  height: 26px;
  padding: 0 var(--sp-3);
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.embed-copy-btn:hover {
  background: rgba(255,255,255,0.16);
  color: var(--text-primary);
}

.embed-copy-btn.copied {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.3);
}

/* QR code */
.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) 0 var(--sp-2);
}

#qr-canvas {
  border-radius: 10px;
  background: white;
  padding: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.qr-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.qr-download-btn:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text-primary);
}

.qr-download-btn svg {
  width: 13px;
  height: 13px;
}

/* ============================================================
   Error State
   ============================================================ */
#error-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  gap: var(--sp-4);
  text-align: center;
  padding: var(--sp-8);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

#error-screen.visible {
  opacity: 1;
  visibility: visible;
}

.error-icon {
  width: 64px;
  height: 64px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-2);
}

.error-icon svg {
  width: 32px;
  height: 32px;
  color: #ef4444;
}

.error-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.error-message {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.6;
}

/* ============================================================
   Toast Notifications
   ============================================================ */
#toast-container {
  position: fixed;
  top: calc(var(--toolbar-h) + var(--sp-8));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  background: rgba(20, 24, 40, 0.95);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 18px;
  font-size: var(--text-sm);
  color: var(--text-primary);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: toastIn 0.25s var(--ease-spring) forwards;
  pointer-events: auto;
  white-space: nowrap;
}

.toast.out {
  animation: toastOut 0.25s var(--ease-smooth) forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(4px) scale(0.96); }
}

/* ============================================================
   Keyboard Shortcuts Overlay
   ============================================================ */
#shortcuts-overlay {
  position: fixed;
  inset: 0;
  z-index: 180;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

#shortcuts-overlay.open {
  opacity: 1;
  visibility: visible;
}

.shortcuts-box {
  background: linear-gradient(180deg, #1c2233, #161a2e);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: var(--sp-6);
  width: 360px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-modal);
}

.shortcuts-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: var(--sp-5);
  color: var(--text-primary);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}

.shortcut-row:last-child {
  border-bottom: none;
}

.shortcut-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.shortcut-keys {
  display: flex;
  gap: var(--sp-1);
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--font-ui);
}

/* ============================================================
   Page Flip Animation
   ============================================================ */
@keyframes pageTurnForward {
  0%   { transform: perspective(1200px) rotateY(0deg); }
  100% { transform: perspective(1200px) rotateY(-180deg); }
}

@keyframes pageTurnBackward {
  0%   { transform: perspective(1200px) rotateY(0deg); }
  100% { transform: perspective(1200px) rotateY(180deg); }
}

.page-turning-forward {
  animation: pageTurnForward 0.7s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

.page-turning-backward {
  animation: pageTurnBackward 0.7s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

/* ============================================================
   Fullscreen Mode
   ============================================================ */
:fullscreen::backdrop,
:-webkit-full-screen::backdrop {
  background: transparent !important;
}

:fullscreen,
:-webkit-full-screen {
  background: transparent !important;
}

:fullscreen body,
:-webkit-full-screen body,
:fullscreen #viewer-root,
:-webkit-full-screen #viewer-root,
:fullscreen #viewer-stage,
:-webkit-full-screen #viewer-stage {
  background-color: transparent !important;
}

:fullscreen #viewer-toolbar,
:-webkit-full-screen #viewer-toolbar {
  top: auto !important;
  left: auto !important;
  right: 18px !important;
  bottom: 18px !important;
  transform: none !important;
}

:fullscreen #flipbook-container,
:-webkit-full-screen #flipbook-container {
  padding: 28px 54px;
}

/* ============================================================
   Loading shimmer for images
   ============================================================ */
.img-loading {
  background: linear-gradient(90deg,
    rgba(255,255,255,0.03) 25%,
    rgba(255,255,255,0.07) 50%,
    rgba(255,255,255,0.03) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }

}

/* ============================================================
   Page Skeleton / Shimmer for Unloaded Pages
   ============================================================ */
.page-skeleton {
  background: linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.02) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-shimmer {
  width: 70%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.shimmer-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.03) 25%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.03) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.shimmer-line.wide {
  width: 100%;
  height: 16px;
}

.shimmer-line.narrow {
  width: 55%;
}

/* Thumbnail-first progressive loading: blur-up effect */
.page-img-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: blur(2px);
  transition: filter 0.3s var(--ease-smooth);
}

/* ============================================================
   Page Error State with Retry
   ============================================================ */
.img-error {
  background: rgba(255,255,255,0.02);
}

.page-error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 10px;
  padding: 20px;
}

.page-error-icon {
  color: #ef4444;
  opacity: 0.6;
}

.page-error-icon svg {
  width: 32px;
  height: 32px;
}

.page-error-text {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
}

.page-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background: rgba(79, 126, 247, 0.12);
  border: 1px solid rgba(79, 126, 247, 0.25);
  border-radius: 8px;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s var(--ease-spring);
}

.page-retry-btn:hover {
  background: rgba(79, 126, 247, 0.2);
  transform: scale(1.04);
}

.page-retry-btn:active {
  transform: scale(0.96);
}

.page-retry-btn svg {
  flex-shrink: 0;
}

/* ============================================================
   Error Screen Enhancements
   ============================================================ */
.error-link {
  margin-top: var(--sp-3);
}

.error-retry-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 500;
  transition: background 0.15s, transform 0.15s;
}

.error-retry-btn:hover {
  background: var(--accent-hover);
}

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

/* ============================================================
   Content Visibility for Performance
   ============================================================ */
.book-page[style*="content-visibility"] {
  contain-intrinsic-size: auto 50% auto 100%;
}

/* ============================================================
   Screen Reader Announcements
   ============================================================ */
#aria-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}


/* ============================================================
   Mobile Responsive
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --toolbar-h: var(--toolbar-h-mobile);
    --thumb-panel-h: var(--thumb-panel-h-mobile);
  }

  /* Toolbar goes to BOTTOM on mobile — slides up */
  #viewer-toolbar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    max-width: 100%;
    min-width: 0;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border);
    padding: 0 var(--sp-3);
    gap: var(--sp-1);
    justify-content: space-between;
    transition: transform 0.35s var(--ease-smooth),
                opacity 0.35s var(--ease-smooth);
  }

  #viewer-toolbar.hidden {
    transform: translateY(100%);
    opacity: 0;
  }

  /* Flipbook container adjusts for bottom toolbar on mobile */
  #flipbook-container {
    padding: 12px 10px calc(var(--toolbar-h) + 8px);
  }

  #flipbook-container.thumbnails-open {
    padding-left: 12px;
    padding-bottom: calc(var(--toolbar-h) + var(--thumb-panel-h) + 12px);
  }

  /* Thumbnails slide from BOTTOM on mobile */
  #thumbnail-panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: var(--toolbar-h);
    width: auto;
    height: var(--thumb-panel-h);
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-panel);
    transform: translateY(100%);
    border-radius: 0;
  }

  #thumbnail-panel.open {
    transform: translateY(0);
  }

  .thumb-panel-inner {
    flex-direction: row;
    align-items: center;
    padding: var(--sp-3) var(--sp-4);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .thumb-panel-inner::-webkit-scrollbar {
    height: 3px;
    width: auto;
  }

  .thumb-item {
    width: 60px;
    max-width: 60px;
  }

  .thumb-img-wrap {
    width: 60px;
  }

  /* Hide viewer title & badge on mobile */
  .viewer-title,
  .viewer-badge {
    display: none;
  }

  /* Page scrubber above bottom toolbar on mobile */
  .page-scrubber {
    bottom: calc(var(--toolbar-h) + var(--sp-3));
  }

  .page-counter {
    display: none;
  }

  .tb-divider {
    display: none;
  }

  /* hide less important buttons on mobile */
  .tb-btn[data-hide-mobile] {
    display: none;
  }

  .tb-btn {
    width: 32px;
    height: 32px;
  }

  .tb-btn svg {
    width: 15px;
    height: 15px;
  }

  .tb-btn-nav {
    width: 34px;
    height: 34px;
  }

  .page-input-wrap {
    padding: 3px 6px;
  }

  .page-input {
    width: 24px;
    font-size: 11px;
  }

  .social-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Tap zones — slimmer on mobile */
  .tap-zone {
    width: 60px;
    opacity: 0;
  }

  .tap-zone .tap-zone-arrow {
    width: 40px;
    height: 40px;
    opacity: 0.6;
  }

  /* Toast moved for bottom toolbar */
  #toast-container {
    top: auto;
    bottom: calc(var(--toolbar-h) + 16px);
  }

  .edge-nav-btn {
    width: 42px;
    height: 42px;
    opacity: 0.58;
  }

  .edge-nav-prev {
    left: 8px;
  }

  .edge-nav-next {
    right: 8px;
  }
}

@media (max-width: 480px) {
  .tb-btn[data-hide-small] {
    display: none;
  }

  .page-scrubber {
    width: 85vw;
  }

  .share-tabs {
    flex-wrap: wrap;
  }

  .share-tab {
    flex: 1 1 calc(50% - 4px);
  }
}

/* ============================================================
   Orientation: Landscape on Mobile
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --toolbar-h: 44px;
  }

  #flipbook-container {
    padding: 8px 8px calc(var(--toolbar-h) + 4px);
  }

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

  .page-scrubber {
    bottom: calc(var(--toolbar-h) + var(--sp-2));
  }
}

/* ============================================================
   Embed / iframe mode
   ============================================================ */
/* In embed mode, hide the vignette but keep blurred bg if active */
.embed-mode #viewer-stage::after {
  display: none;
}

.embed-mode .viewer-title,
.embed-mode .viewer-badge {
  display: none;
}

/* ============================================================
   Reduced Motion Support
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .page-scrubber,
  #viewer-toolbar,
  #thumbnail-panel,
  .modal-backdrop .modal-box,
  .toast {
    transition: none !important;
    animation: none !important;
  }
}

/* ============================================================
   HD Rendering Enhancements (Agent 2)
   ============================================================ */

/* GPU-accelerated page rendering */
#flipbook-inner .stf__item {
  will-change: transform;
  transform-style: preserve-3d;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

#flipbook-inner .stf__item img {
  image-rendering: auto;
  object-fit: fill;
}

/* Page-edge effects are applied in the final viewer overrides only. */

.book-page.right .book-page-inner::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 20px;
  background: linear-gradient(to right,
    rgba(0,0,0,0.06) 0%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 3;
}

/* ============================================================
   Enhanced Shimmer Loading Placeholder
   ============================================================ */
.page-shimmer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 245, 245, 0.95);
  pointer-events: none;
  z-index: 1;
}

.page-shimmer::before {
  content: '';
  width: 36px;
  height: 36px;
  border: 3px solid rgba(0,0,0,0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pageSpinner 0.8s linear infinite;
}

.page-shimmer::after {
  content: 'Loading\2026';
  position: absolute;
  bottom: 40%;
  font-size: 11px;
  color: rgba(0,0,0,0.35);
  font-family: var(--font-ui);
  letter-spacing: 0.5px;
  margin-top: 12px;
}

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

/* ============================================================
   Enhanced Flip Animation Quality (60fps)
   ============================================================ */

/* Ensure smooth 60fps flips via compositor */
.stf__parent {
  transform-style: preserve-3d;
  perspective: 2000px;
}

.stf__wrapper {
  transform-style: preserve-3d;
}

/* Page turn shadow overlay — applied dynamically during flip */
.flip-shadow-overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.15s ease;
}

.flip-shadow-overlay.left {
  right: 0;
  background: linear-gradient(to left,
    rgba(0,0,0,0.18) 0%,
    rgba(0,0,0,0.08) 30%,
    rgba(0,0,0,0.02) 60%,
    transparent 100%
  );
}

.flip-shadow-overlay.right {
  left: 0;
  background: linear-gradient(to right,
    rgba(0,0,0,0.18) 0%,
    rgba(0,0,0,0.08) 30%,
    rgba(0,0,0,0.02) 60%,
    transparent 100%
  );
}

/* ============================================================
   Pinch-to-zoom Touch States
   ============================================================ */
#viewer-stage.is-pinching {
  touch-action: none;
}

#viewer-stage.is-pinching #flipbook-inner {
  transition: none !important;
}

/* Cursor states for zoom drag */
#viewer-stage.is-zoomed {
  cursor: grab;
}

#viewer-stage.is-zoomed.is-dragging {
  cursor: grabbing;
}

#viewer-stage.is-zoomed #flipbook-inner {
  cursor: grab;
}

#viewer-stage.is-zoomed.is-dragging #flipbook-inner {
  cursor: grabbing;
}

/* ============================================================
   Zoom reset button
   ============================================================ */
.tb-btn.zoom-reset {
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-ui);
  color: var(--text-muted);
  width: auto;
  padding: 0 6px;
  letter-spacing: -0.2px;
}

.tb-btn.zoom-reset:hover {
  color: var(--accent);
}

/* Hide zoom controls on very small screens */
@media (max-width: 480px) {
  .zoom-controls {
    display: none;
  }
}

/* ============================================================
   Light Theme Variables (Improvement 3)
   ============================================================ */
[data-theme="light"] {
  --bg-deep:       #f5f5f0;
  --bg-stage:      #e8e8e2;
  --bg-surface:    #ffffff;
  --bg-overlay:    rgba(245, 245, 240, 0.88);
  --bg-glass:      rgba(255, 255, 255, 0.72);
  --bg-glass-dark: rgba(255, 255, 255, 0.92);
  --text-primary:  #1a1a2e;
  --text-muted:    #666680;
  --text-dim:      #999;
  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);
  --shadow-book:   0 40px 100px rgba(0,0,0,0.15), 0 12px 32px rgba(0,0,0,0.1);
  --shadow-panel:  0 -4px 32px rgba(0,0,0,0.1);
  --shadow-modal:  0 24px 80px rgba(0,0,0,0.15);
  --shadow-btn:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-thumb:  0 4px 16px rgba(0,0,0,0.08);
}

[data-theme="light"] html,
[data-theme="light"] body {
  background: transparent;
  color: var(--text-primary);
}

[data-theme="light"] #viewer-stage {
  background: transparent;
}

/* Blurred Background Image — now applied via ::before on #viewer-stage.has-bg-image */
/* (see #viewer-stage::before rule above) */

/* ============================================================
   Bottom Bar (Improvement 4D)
   ============================================================ */
#viewer-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 48;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(8, 14, 27, 0.72);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: 1px solid var(--border);
  box-shadow: 0 -12px 30px rgba(0,0,0,0.18);
  transition: opacity 0.3s var(--ease-smooth), transform 0.3s var(--ease-smooth);
}

.bottom-bar-page-info {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 72px;
  text-align: center;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
}

.bottom-bar-scrubber {
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
}

.bottom-bar-scrubber .page-scrubber-input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
  accent-color: var(--accent);
}

.bottom-bar-scrubber .page-scrubber-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  transition: transform 0.15s var(--ease-spring);
}

.bottom-bar-scrubber .page-scrubber-input:hover::-webkit-slider-thumb {
  transform: scale(1.3);
}

.bottom-bar-scrubber .page-scrubber-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.bottom-bar-fs {
  width: 30px !important;
  height: 30px !important;
  flex-shrink: 0;
}

/* ============================================================
   Page Thickness Effect — Book Edge Lines (Improvement 4B)
   ============================================================ */
#flipbook-inner::after {
  content: '';
  position: absolute;
  top: 2px;
  right: -8px;
  bottom: 2px;
  width: 10px;
  background: repeating-linear-gradient(
    to right,
    rgba(220,215,205,0.25) 0px,
    rgba(0,0,0,0.10) 1px,
    rgba(240,235,225,0.20) 2px,
    rgba(0,0,0,0.08) 3px,
    rgba(230,225,215,0.18) 4px
  );
  border-radius: 0 3px 3px 0;
  pointer-events: none;
  z-index: 2;
  box-shadow: 2px 0 8px rgba(0,0,0,0.35), 1px 0 2px rgba(0,0,0,0.2);
}

/* Left-side page thickness for two-page spread */
#flipbook-inner::before {
  content: '';
  position: absolute;
  top: 2px;
  left: -8px;
  bottom: 2px;
  width: 10px;
  background: repeating-linear-gradient(
    to left,
    rgba(220,215,205,0.25) 0px,
    rgba(0,0,0,0.10) 1px,
    rgba(240,235,225,0.20) 2px,
    rgba(0,0,0,0.08) 3px,
    rgba(230,225,215,0.18) 4px
  );
  border-radius: 3px 0 0 3px;
  pointer-events: none;
  z-index: 2;
  box-shadow: -2px 0 8px rgba(0,0,0,0.35), -1px 0 2px rgba(0,0,0,0.2);
}

/* ============================================================
   Background Settings Popover (Improvement 2)
   ============================================================ */
.bg-picker-popover {
  position: fixed;
  z-index: 200;
  background: var(--bg-glass-dark);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 14px;
  width: 250px;
  box-shadow: var(--shadow-modal);
  animation: popover-in 0.18s var(--ease-spring);
}

@keyframes popover-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bg-picker-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  letter-spacing: -0.2px;
}

.bg-picker-section {
  margin-bottom: 10px;
}

.bg-picker-label {
  font-size: var(--text-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  margin-bottom: 6px;
}

.bg-picker-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bg-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.bg-opt:hover {
  background: var(--bg-glass);
  border-color: var(--border);
}

.bg-opt.active {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.bg-opt-preview {
  display: block;
  width: 36px;
  height: 28px;
  border-radius: 5px;
  border: 1px solid var(--border);
}

.bg-opt-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* ============================================================
   Page scrubber visibility — ensure old scrubber stays hidden
   when bottom bar is active
   ============================================================ */
.page-scrubber {
  display: none;
}

/* ============================================================
   Enhanced Navigation Arrows (Improvement 4E)
   ============================================================ */
.tap-zone-arrow {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tap-zone-arrow svg {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.6));
  stroke-width: 2;
}

/* Remove circle background from arrows for cleaner Publuu look */
.tap-zone {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.tap-zone:hover .tap-zone-arrow svg {
  stroke: var(--accent);
  filter: drop-shadow(0 2px 12px var(--accent-glow));
}

@media print {
  #viewer-toolbar,
  #viewer-bottom-bar,
  #viewer-edge-nav,
  #thumbnail-panel,
  .viewer-title,
  .viewer-badge,
  .tap-zone,
  #toast-container {
    display: none !important;
  }

  #viewer-stage,
  #flipbook-container,
  #flipbook-inner,
  .book-page,
  .book-page-inner,
  .flip-page {
    background: #fff !important;
    box-shadow: none !important;
    filter: none !important;
  }

  #flipbook-container {
    padding: 0 !important;
  }
}

/* ============================================================
   Editorial Viewer Override
   ============================================================ */
#viewer-stage {
  --editorial-header-h: 48px;
  --editorial-bottom-h: 0px;
  --editorial-panel-w: 318px;
  --editorial-page-pad: 14px;
  background: transparent;
}

#viewer-stage::after {
  display: none;
}

.viewer-title,
.viewer-badge,
.page-scrubber,
.tap-zone,
.book-spine,
#flipbook-inner::before,
#flipbook-inner::after,
#flipbook-inner.spread-view .stf__wrapper::before,
.flipbook-ambient,
.page-corner-hint,
.flip-shadow-overlay,
.bg-picker-popover {
  display: none !important;
}

#flipbook-container {
  padding: 28px 54px;
}

#flipbook-container.thumbnails-open,
#flipbook-container.panel-open {
  padding-left: calc(var(--editorial-panel-w) + 38px);
}

#flipbook-inner {
  border-radius: 2px !important;
  box-shadow: 0 18px 42px rgba(0,0,0,0.18), 0 4px 14px rgba(0,0,0,0.12) !important;
  filter: none !important;
}

.flip-page,
.book-page {
  background: transparent !important;
  border-radius: 0 !important;
  border: 1px solid rgba(91, 96, 105, 0.22);
  box-shadow: 0 10px 24px rgba(0,0,0,0.08) !important;
}

.flip-page::after,
.book-page::after {
  display: none;
}

.flip-page img,
.book-page-inner img {
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  border-radius: 0 !important;
  object-fit: fill;
  background: transparent;
}

.book-page-inner {
  inset: 0;
  margin: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.book-page.left .book-page-inner::after,
.book-page.right .book-page-inner::before {
  width: 10px;
  background: linear-gradient(to right, rgba(0,0,0,0.08), transparent);
}

.book-page.right .book-page-inner::before {
  background: linear-gradient(to left, rgba(0,0,0,0.08), transparent);
}

#viewer-toolbar {
  top: 0;
  left: 0;
  right: 0;
  bottom: auto;
  transform: none;
  width: auto;
  height: 52px;
  min-width: 0;
  max-width: none;
  padding: 0 20px;
  border: 0;
  border-bottom: 1px solid rgba(16, 24, 32, 0.1);
  border-radius: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,255,255,0.58));
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  box-shadow: 0 2px 18px rgba(18, 22, 30, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  z-index: 40;
}

#viewer-toolbar.hidden {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

#viewer-toolbar.hidden-by-setting {
  display: none !important;
}

.toolbar-title-block {
  display: flex !important;
  align-items: center;
  flex: 1 1 280px;
  min-width: 0;
}

.toolbar-title-text {
  color: rgba(34, 39, 45, 0.9);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 0 1 auto;
  min-width: 0;
  margin-left: auto;
}

.toolbar-brand {
  display: flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 180px;
  min-width: 0;
  color: rgba(37, 41, 48, 0.72);
}

.toolbar-brand.is-empty {
  visibility: hidden;
  pointer-events: none;
}

.toolbar-brand-shell {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.toolbar-brand-logo {
  display: block;
  max-width: 108px;
  width: auto;
  height: 22px;
  object-fit: contain;
}

.toolbar-brand-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgba(31, 35, 41, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent !important;
  color: rgba(46, 52, 58, 0.7);
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

.tb-btn:hover:not(:disabled),
.tb-btn.active {
  background: rgba(15, 23, 42, 0.08) !important;
  color: rgba(17, 20, 24, 0.96);
}

.tb-btn svg {
  width: 16px;
  height: 16px;
}

.tb-divider,
.page-input-wrap,
.page-counter,
.toolbar-page-count,
.page-scrubber,
.zoom-indicator {
  display: none !important;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0;
  background: transparent;
  border: 0;
}

.zoom-controls .tb-btn {
  width: 32px;
  height: 32px;
}

#viewer-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 39;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 24px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.44) 42%, rgba(255,255,255,0.66) 100%);
  border-top: 1px solid rgba(16, 24, 32, 0.08);
  backdrop-filter: blur(10px) saturate(1.08);
  -webkit-backdrop-filter: blur(10px) saturate(1.08);
  box-shadow: 0 -10px 22px rgba(15, 23, 42, 0.04);
}

#viewer-bottom-bar.hidden-by-setting {
  display: none !important;
}

.bottom-bar-side {
  display: flex;
  align-items: center;
  min-width: 92px;
  flex: 0 0 92px;
}

.bottom-bar-side-right {
  justify-content: flex-end;
}

.bottom-bar-center {
  display: flex;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
}

.bottom-bar-page-info {
  font-size: 13px;
  font-weight: 500;
  color: rgba(35, 39, 46, 0.78);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.bottom-bar-page-info.is-hidden {
  visibility: hidden;
}

.bottom-bar-scrubber {
  width: min(100%, 560px);
  display: flex;
  align-items: center;
}

.bottom-bar-scrubber .page-scrubber-input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 2px;
  border-radius: 999px;
  background: rgba(55, 65, 81, 0.18);
  outline: none;
  cursor: pointer;
}

.bottom-bar-scrubber .page-scrubber-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: rgba(51, 65, 85, 0.8);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.78);
  transition: transform 0.15s var(--ease-spring), background 0.15s ease;
}

.bottom-bar-scrubber .page-scrubber-input:hover::-webkit-slider-thumb {
  transform: scale(1.12);
  background: rgba(17, 24, 39, 0.92);
}

.bottom-bar-scrubber .page-scrubber-input::-moz-range-track {
  height: 2px;
  border-radius: 999px;
  background: rgba(55, 65, 81, 0.18);
}

.bottom-bar-scrubber .page-scrubber-input::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: rgba(51, 65, 85, 0.8);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.78);
  cursor: pointer;
}

.bottom-bar-fs {
  width: 32px !important;
  height: 32px !important;
}

.bottom-bar-spacer {
  width: 32px;
  height: 32px;
  display: block;
}

#viewer-edge-nav {
  inset: 56px 0 56px;
}

.edge-nav-btn {
  width: 36px;
  height: 72px;
  border: 0;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none !important;
  color: rgba(38,40,44,0.5);
  opacity: 0.92;
}

.edge-nav-prev {
  left: 8px !important;
}

.edge-nav-next {
  right: 8px !important;
}

.edge-nav-btn:hover:not(:disabled) {
  background: transparent !important;
  color: rgba(28,30,34,0.92);
  transform: translateY(-50%) scale(1.04);
}

.edge-nav-btn:disabled {
  opacity: 0.2;
}

.edge-nav-icon svg {
  width: 26px;
  height: 26px;
  stroke-width: 1.85;
}

#flipbook-container {
  padding: 76px var(--viewer-side-gutter, 72px) 72px;
}

#flipbook-container.thumbnails-open,
#flipbook-container.panel-open {
  padding-left: calc(var(--editorial-panel-w) + var(--viewer-side-gutter, 72px));
  padding-right: var(--viewer-side-gutter, 72px);
}

#thumbnail-panel {
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--editorial-panel-w);
  height: auto;
  border: 0;
  border-right: 1px solid rgba(255,255,255,0.08);
  border-radius: 0;
  background: rgba(21, 22, 26, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: none;
  transform: translateX(-100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#thumbnail-panel.open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.viewer-panel-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.viewer-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.viewer-panel-tabs {
  display: flex;
  gap: 6px;
}

.viewer-panel-tab,
.viewer-panel-close,
.contents-item {
  font: inherit;
}

.viewer-panel-tab {
  border: 0;
  background: transparent;
  color: rgba(255,255,255,0.62);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.viewer-panel-tab.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.viewer-panel-close {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255,255,255,0.74);
  cursor: pointer;
}

.viewer-panel-close:hover {
  background: rgba(255,255,255,0.08);
}

.viewer-panel-close svg {
  width: 16px;
  height: 16px;
}

.viewer-panel-body {
  flex: 1;
  overflow: hidden;
}

.viewer-panel-view {
  display: none;
  height: 100%;
}

.viewer-panel-view.active {
  display: block;
}

.thumb-panel-inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 14px;
  overflow-y: auto;
  overflow-x: hidden;
}

.thumb-item {
  width: 100%;
  max-width: none;
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
}

.thumb-item.active {
  background: rgba(255,255,255,0.08);
}

.thumb-img-wrap {
  width: 100%;
  border-radius: 6px;
}

.contents-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  overflow-y: auto;
  height: 100%;
}

.contents-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255,255,255,0.84);
  cursor: pointer;
  text-align: left;
}

.contents-item:hover,
.contents-item.active {
  background: rgba(255,255,255,0.08);
}

.contents-item-title {
  font-size: 13px;
  line-height: 1.35;
}

.contents-item-page {
  font-size: 12px;
  color: rgba(255,255,255,0.58);
  flex-shrink: 0;
}

.search-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  padding: 12px;
}

.search-panel-field input {
  width: 100%;
  height: 40px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  color: #fff;
  font: inherit;
  padding: 0 14px;
  outline: none;
}

.search-panel-field input::placeholder {
  color: rgba(255,255,255,0.44);
}

.search-panel-field input:focus {
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.08);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.search-result-item,
.search-empty-state {
  border-radius: 12px;
  padding: 12px;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 0;
  width: 100%;
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.9);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.search-result-item:hover,
.search-result-item.active {
  background: rgba(255,255,255,0.1);
}

.search-result-page {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.62);
}

.search-result-snippet {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255,255,255,0.88);
}

.search-result-snippet mark {
  background: rgba(250, 204, 21, 0.3);
  color: #fff;
  border-radius: 4px;
  padding: 0 2px;
}

.search-empty-state {
  background: rgba(255,255,255,0.03);
  color: rgba(255,255,255,0.56);
  font-size: 13px;
}

@media (max-width: 900px) {
  #viewer-toolbar {
    height: 48px;
    padding: 0 12px;
    gap: 10px;
  }

  .toolbar-title-block {
    flex-basis: 36vw;
  }

  .toolbar-title-text {
    font-size: 13px;
  }

  .toolbar-brand {
    display: none !important;
  }

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

  #viewer-toolbar .tb-btn[aria-label="Download flipbook"],
  #viewer-toolbar .tb-btn[aria-label="Print flipbook"] {
    display: none;
  }

  #viewer-bottom-bar {
    padding: 10px 14px 12px;
    gap: 12px;
  }

  .bottom-bar-side {
    min-width: 76px;
    flex-basis: 76px;
  }

  #flipbook-container {
    --viewer-side-gutter: 56px;
    padding: 68px var(--viewer-side-gutter) 64px;
  }

  #flipbook-container.thumbnails-open,
  #flipbook-container.panel-open {
    padding-left: var(--viewer-side-gutter);
    padding-right: var(--viewer-side-gutter);
  }

  #thumbnail-panel {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(48vh, 420px);
    border-right: 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    transform: translateY(100%);
  }

  #thumbnail-panel.open {
    transform: translateY(0);
  }

  .thumb-panel-inner {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .edge-nav-prev {
    left: 4px !important;
  }

  .edge-nav-next {
    right: 4px !important;
  }
}

@media (max-width: 640px) {
  #viewer-toolbar {
    height: 44px;
    padding: 0 10px;
    gap: 8px;
  }

  .toolbar-title-block {
    flex-basis: 44vw;
  }

  .toolbar-title-text {
    font-size: 12px;
  }

  .toolbar-actions {
    gap: 2px;
  }

  .tb-btn {
    width: 28px;
    height: 28px;
  }

  .zoom-controls,
  #viewer-toolbar .tb-btn[aria-label="Share flipbook"],
  #viewer-toolbar .tb-btn[aria-label="Download flipbook"],
  #viewer-toolbar .tb-btn[aria-label="Print flipbook"] {
    display: none !important;
  }

  #viewer-bottom-bar {
    padding: 8px 10px 10px;
    gap: 10px;
  }

  .bottom-bar-side {
    min-width: 58px;
    flex-basis: 58px;
  }

  .bottom-bar-page-info {
    font-size: 12px;
  }

  #flipbook-container {
    --viewer-side-gutter: 44px;
    padding: 60px var(--viewer-side-gutter) 56px;
  }

  #flipbook-container.thumbnails-open,
  #flipbook-container.panel-open {
    padding-left: var(--viewer-side-gutter);
    padding-right: var(--viewer-side-gutter);
  }

  .thumb-panel-inner {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

:fullscreen #viewer-toolbar,
:-webkit-full-screen #viewer-toolbar {
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: auto !important;
}

:fullscreen #viewer-bottom-bar,
:-webkit-full-screen #viewer-bottom-bar {
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
}

:fullscreen #flipbook-container,
:-webkit-full-screen #flipbook-container {
  padding: 76px var(--viewer-side-gutter, 72px) 72px !important;
}

@media (max-width: 900px) {
  :fullscreen #flipbook-container,
  :-webkit-full-screen #flipbook-container {
    padding: 68px var(--viewer-side-gutter, 56px) 64px !important;
  }
}

@media (max-width: 640px) {
  :fullscreen #flipbook-container,
  :-webkit-full-screen #flipbook-container {
    padding: 60px var(--viewer-side-gutter, 44px) 56px !important;
  }
}

/* ============================================================
   Clean Stage and Book Surface Effects
   Keep the stage flat; render crease and fore-edge on the pages only.
   ============================================================ */
#flipbook-container {
  --viewer-side-gutter: 72px;
}

#viewer-stage[data-bg-mode="default"] {
  background-image: none !important;
  background-color: transparent !important;
}

#viewer-stage::after,
.embed-mode #viewer-stage::after,
.flipbook-ambient,
.flipbook-shadow,
.flip-shadow-overlay,
.book-spine,
#flipbook-inner::before,
#flipbook-inner::after,
#flipbook-inner.spread-view .stf__wrapper::before {
  display: none !important;
  content: none !important;
  background: none !important;
  box-shadow: none !important;
  filter: none !important;
}

#flipbook-inner,
#viewer-stage.spread-view #flipbook-inner,
.flip-page,
.book-page {
  box-shadow: none !important;
  filter: none !important;
}

#flipbook-inner,
#viewer-stage.spread-view #flipbook-inner {
  overflow: hidden !important;
}

.flip-page,
.book-page {
  border: 0 !important;
  border-radius: 0 !important;
  overflow: hidden !important;
  background: transparent !important;
}

.flip-page-inner,
.book-page-inner {
  position: absolute;
  inset: 0;
  margin: 0 !important;
  overflow: hidden;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.flip-page img,
.flip-page-inner img,
.book-page-inner img {
  width: 100% !important;
  height: 100% !important;
  object-fit: fill !important;
  margin: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  image-rendering: auto !important;
}

.page-text-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
}

.page-text-layer.active {
  opacity: 1;
}

.page-text-span {
  position: absolute;
  display: inline-block;
  white-space: pre;
  overflow: visible;
  color: rgba(20, 23, 31, 0.92);
  line-height: 1;
  letter-spacing: 0;
  mix-blend-mode: multiply;
  transform-origin: top left;
}

.page-text-span.search-hit {
  background: rgba(250, 204, 21, 0.32);
  box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.18);
}

.flip-page::before,
.flip-page::after,
.book-page::before,
.book-page::after,
.flip-page-inner::before,
.flip-page-inner::after,
.book-page-inner::before,
.book-page-inner::after {
  display: none;
  content: none;
}

.flip-page::after,
.book-page::after,
.flip-page:hover::after,
.book-page:hover::after {
  opacity: 0 !important;
}

#viewer-edge-nav {
  position: fixed !important;
  inset: 56px 0 56px !important;
  z-index: 30;
  pointer-events: none;
}

.edge-nav-btn {
  position: absolute !important;
  top: 0;
  bottom: 0;
  width: var(--viewer-side-gutter, 72px);
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0 !important;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  color: rgba(52, 57, 64, 0.5);
  opacity: 0.92;
  pointer-events: auto;
  transform: none !important;
}

.edge-nav-prev {
  left: 0 !important;
}

.edge-nav-next {
  right: 0 !important;
}

.edge-nav-btn:hover:not(:disabled) {
  transform: none !important;
  background: transparent !important;
  box-shadow: none !important;
  color: rgba(18, 20, 24, 0.9);
}

.edge-nav-btn:disabled {
  opacity: 0.18;
}

.edge-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.edge-nav-icon svg {
  width: 26px;
  height: 26px;
  stroke-width: 1.85;
}

.book-page.page-spread-active.page-left .book-page-inner::after,
.flip-page.page-spread-active.page-left .flip-page-inner::after {
  display: block;
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(to left,
    rgba(0,0,0,0.08) 0%,
    rgba(0,0,0,0.04) 22%,
    rgba(0,0,0,0.018) 44%,
    rgba(0,0,0,0.006) 66%,
    transparent 100%);
  pointer-events: none;
  z-index: 4;
}

.book-page.page-spread-active.page-right .book-page-inner::before,
.flip-page.page-spread-active.page-right .flip-page-inner::before {
  display: block;
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(to right,
    rgba(0,0,0,0.08) 0%,
    rgba(0,0,0,0.04) 22%,
    rgba(0,0,0,0.018) 44%,
    rgba(0,0,0,0.006) 66%,
    transparent 100%);
  pointer-events: none;
  z-index: 4;
}

.book-page.page-spread-active.page-right::after,
.flip-page.page-spread-active.page-right::after {
  display: none !important;
  content: none !important;
}

@media (max-width: 900px) {
  .edge-nav-btn {
    width: var(--viewer-side-gutter, 56px);
  }
}

@media (max-width: 640px) {
  #viewer-edge-nav {
    inset: 44px 0 48px !important;
  }
}
