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

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #1a1a2e;
  overflow: hidden;
}

/* ── Screen-reader only (visually hidden but accessible) ── */

.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;
}

/* ── Book area ── */

#book-area {
  flex: 9;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  position: relative;
  padding: 12px 0;
  overflow: visible;
}

#book-area.zoom-mode {
  cursor: grab;
  overflow: hidden;
  /* Stop the browser from intercepting touches as scroll/pinch — our
     pointermove handler does the panning. */
  touch-action: none;
}

#book-area.zoom-mode:active {
  cursor: grabbing;
}


#book {
  position: relative;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3))
          drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  transform-origin: center center;
  transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

/* Disable transition while panning so drags feel instant. */
#book.panning {
  transition: none;
}

.page {
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stf__item.--blank {
  --stf-blank-bg: #1a1a2e;
}



.page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stf__canvas {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  display: block;
}

.stf__wrapper {
  background: transparent !important;
}

.stf__block {
  background: transparent !important;
}

/* ── Navigation arrows (center of book sides) ── */

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 12px 4px;
  transition: color 0.2s;
  z-index: 20;
}

.nav-arrow .material-symbols-rounded {
  font-size: 2.5rem;
}

.nav-arrow:hover {
  color: rgba(255, 255, 255, 0.9);
}

.nav-left {
  left: 8px;
}

.nav-right {
  right: 8px;
}

/* ── First/Last page buttons (bottom of book sides) ── */

.nav-edge {
  position: absolute;
  bottom: 8px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
  z-index: 20;
}

.nav-edge .material-symbols-rounded {
  font-size: 1.2rem;
}

.nav-edge:hover {
  color: rgba(255, 255, 255, 0.9);
}

.nav-edge-left {
  left: 12px;
}

.nav-edge-right {
  right: 12px;
}

/* ── Zoom close button ── */

.zoom-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 30;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: #e0e0e0;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
  line-height: 1;
  transition: background 0.2s;
}

.zoom-close:hover {
  background: rgba(0, 0, 0, 0.7);
}

.zoom-close.hidden {
  display: none;
}

/* Page edges are now rendered natively by StPageFlip (showEdge option) */

/* ── Loading ── */

#loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  font-size: 1.2rem;
  z-index: 100;
}

/* Spinner = ::before; status text = ::after.
   Both pseudo-elements stack vertically via flex on #loading. */
#loading::before {
  content: '';
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  animation: loading-spin 0.9s linear infinite;
}

#loading::after { content: 'Loading…'; }
#loading[data-state="loading"]::after     { content: 'Loading PDF…'; }
#loading[data-state="cors-proxy"]::after  { content: 'Loading via CORS proxy…'; }
#loading[data-state="rendering"]::after   { content: 'Rendering…'; }
#loading[data-state="resizing"]::after    { content: 'Resizing…'; }
#loading[data-state="error"]::after       { content: 'Failed to load PDF. Please check the file and try again.'; }

/* Stop spinning on terminal error states. */
#loading[data-state="error"]::before { display: none; }

#loading.hidden {
  display: none;
}

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

/* ── Toolbar ── */

#toolbar {
  flex: 0 0 56px;
  height: 56px;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 4px 10px;
  padding: 0 12px;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.3s;
  position: relative;
  z-index: 10;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

#toolbar::-webkit-scrollbar {
  display: none;
}

#toolbar.visible {
  opacity: 1;
}

#toolbar button {
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 4px;
  transition: background 0.2s;
  flex-shrink: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  min-width: 36px;
}

#toolbar button .material-symbols-rounded {
  font-size: 24px;
  line-height: 1;
  vertical-align: middle;
}

#toolbar button:hover {
  background: rgba(255, 255, 255, 0.15);
}

#toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

#page-info,
#zoom-info {
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  min-width: 38px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

/* ── Page slider ── */

#page-slider {
  flex: 1;
  max-width: 300px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e0e0e0;
  cursor: pointer;
  transition: transform 0.15s;
}

#page-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

#page-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e0e0e0;
  border: none;
  cursor: pointer;
}

/* ── Thumbnail overlay ── */

#thumbnail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.95);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#thumbnail-overlay.hidden {
  display: none;
}

#thumbnail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  flex-shrink: 0;
}

#thumbnail-header button {
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}

#thumbnail-header button:hover {
  background: rgba(255, 255, 255, 0.15);
}

#thumbnail-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  padding: 0 20px 20px;
}

/* One page per thumb. aspect-ratio (set from JS via --page-aspect)
   locks each cell's height so active border doesn't shift layout and
   loading placeholders reserve the right space. */
.thumb-item {
  position: relative;
  aspect-ratio: var(--page-aspect, 0.707);
  background: rgba(0, 0, 0, 0.2);
  border: 2px solid transparent;
  box-sizing: border-box;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.thumb-item:hover {
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.03);
}

.thumb-item.active {
  border-color: #6c9bff;
}

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

.thumb-num {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 6px;
  font: 12px system-ui, sans-serif;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 3px;
  pointer-events: none;
}

/* ── Password dialog (encrypted PDF) ── */

#password-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.85);
  z-index: 300;
  display: flex;
  justify-content: center;
  align-items: center;
}

#password-overlay.hidden {
  display: none;
}

#password-dialog {
  background: #2a2a3e;
  border-radius: 12px;
  padding: 24px 32px;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  max-width: 360px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#password-dialog p {
  font-size: 1rem;
  margin: 0;
}

#password-dialog label {
  font-size: 0.85rem;
  color: #aaa;
}

#pdf-password {
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #e0e0e0;
  font-size: 1rem;
  outline: none;
}

#pdf-password:focus {
  border-color: #6c9bff;
  box-shadow: 0 0 0 2px rgba(108, 155, 255, 0.3);
}

#password-error {
  color: #ff6b6b;
  font-size: 0.85rem;
}

#password-error.hidden {
  display: none;
}

#password-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#password-actions button {
  padding: 6px 18px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

#btn-password-ok {
  background: #6c9bff;
  color: #fff;
}

#btn-password-ok:hover {
  background: #5a8ae6;
}

#btn-password-cancel {
  background: rgba(255, 255, 255, 0.15);
  color: #e0e0e0;
}

#btn-password-cancel:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ── Table of contents overlay ── */

#toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.95);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#toc-overlay.hidden {
  display: none;
}

#toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  flex-shrink: 0;
}

#toc-header button {
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}

#toc-header button:hover {
  background: rgba(255, 255, 255, 0.15);
}

#toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.toc-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: #ddd;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
}

.toc-item:hover,
.toc-item:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.toc-item:focus-visible {
  box-shadow: 0 0 0 2px #6c9bff;
}

.toc-item[aria-current="page"] {
  color: #6c9bff;
  background: rgba(108, 155, 255, 0.1);
}

.toc-item .toc-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 16px;
}

.toc-item .toc-page {
  color: #999;
  font-size: 0.85em;
  flex-shrink: 0;
}

.toc-item[aria-current="page"] .toc-page {
  color: #6c9bff;
}

/* ── Page link hotspots (overlay absolute rects above canvas) ── */

#page-links {
  position: absolute;
  pointer-events: none;
  inset: 0;
  z-index: 5;
}

#page-links.hidden {
  display: none;
}

.page-link {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  background: transparent;
  border: none;
  border-radius: 2px;
  transition: background 0.15s;
}

.page-link:hover,
.page-link:focus-visible {
  background: rgba(108, 155, 255, 0.25);
  outline: 2px solid rgba(108, 155, 255, 0.7);
}

/* ── Search overlay ── */

#search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.95);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#search-overlay.hidden {
  display: none;
}

#search-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  flex-shrink: 0;
}

#search-header button {
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
}

#search-header button:hover {
  background: rgba(255, 255, 255, 0.15);
}

#search-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 12px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #e0e0e0;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  outline: none;
}

#search-input:focus {
  border-color: #6c9bff;
  box-shadow: 0 0 0 2px rgba(108, 155, 255, 0.3);
}

#search-status {
  color: #aaa;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
  min-width: 80px;
  text-align: right;
}

#search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.search-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: #ddd;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.search-item:hover,
.search-item:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.search-item:focus-visible {
  box-shadow: 0 0 0 2px #6c9bff;
}

.search-item .search-page {
  color: #6c9bff;
  font-weight: 600;
  margin-right: 8px;
}

.search-item mark {
  background: rgba(108, 155, 255, 0.4);
  color: #fff;
  padding: 0 2px;
  border-radius: 2px;
}

/* ── Mobile RWD ── */

@media (max-width: 600px) {
  #toolbar {
    flex: 0 0 auto;
    height: auto;
    gap: 2px 4px;
    padding: 2px 6px;
    flex-wrap: wrap;
  }

  #page-slider {
    flex-basis: 100%;
    max-width: none;
    order: -1;
  }

  #toolbar button {
    padding: 0 4px;
    font-size: 0.9rem;
  }

  #toolbar-divider {
    display: none;
  }

  #zoom-info {
    display: none;
  }

  #thumbnail-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    padding: 0 12px 12px;
  }
}
