/**
 * Jinx Epaper: viewer page, structure only
 *
 * Colors, fonts and the look of buttons are in viewer-colors.css. Without it (setting "Farben im Viewer")
 * the styles of the theme apply, so all rules are scoped and set the properties the layout depends on.
 */

.jinx-epaper-viewer {
  --thumb-h: 84px;
}

html:has(> body.jinx-epaper-viewer),
body.jinx-epaper-viewer {
  margin: 0 !important;
  height: 100%;
}

body.jinx-epaper-viewer {
  display: flex; flex-direction: column;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
}

.jinx-epaper-viewer * { box-sizing: border-box; }

.jinx-epaper-viewer button,
.jinx-epaper-viewer .close {
  min-width: 40px; height: 36px; margin: 0; padding: 0 10px;
  font-size: 18px; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.jinx-epaper-viewer button:disabled { opacity: .3; cursor: default; }

/* Top bar */
.jinx-epaper-viewer__bar {
  flex: none; height: 52px; margin: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
}
.jinx-epaper-viewer__bar .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.jinx-epaper-viewer__bar .close { width: 40px; height: 40px; padding: 0; font-size: 26px; text-decoration: none; }
.jinx-epaper-viewer__bar .download {
  width: 40px; height: 40px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}

/* Search */
.jinx-epaper-viewer__bar .search-toggle { width: 40px; height: 40px; padding: 0; }
.jinx-epaper-viewer .search {
  position: absolute; top: 52px; right: 0; z-index: 20;
  width: min(380px, 100%); max-height: calc(100dvh - 52px - 120px);
  display: flex; flex-direction: column;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.jinx-epaper-viewer .search[hidden] { display: none; }
.jinx-epaper-viewer .search input {
  width: 100%; height: 38px; margin: 0; padding: 0 10px;
  font: inherit; font-size: 16px;
}
.jinx-epaper-viewer .search-status { font-size: 12px; padding: 8px 2px 4px; }
.jinx-epaper-viewer .search-status:empty { display: none; }
.jinx-epaper-viewer .search-results { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.jinx-epaper-viewer .search-results button {
  width: 100%; height: auto; min-width: 0; margin: 0; padding: 8px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left; font-size: 13px; line-height: 1.4;
}
.jinx-epaper-viewer .search-results strong { font-size: 12px; }

/* Table of contents */
.jinx-epaper-viewer__bar .toc-toggle { width: 40px; height: 40px; padding: 0; }
.jinx-epaper-viewer .toc {
  position: absolute; top: 52px; right: 0; z-index: 20;
  width: min(380px, 100%); max-height: calc(100dvh - 52px - 120px);
  overflow-y: auto;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  background: inherit;
}
.jinx-epaper-viewer .toc[hidden] { display: none; }
.jinx-epaper-viewer .toc-list { list-style: none; margin: 0; padding: 0; }
.jinx-epaper-viewer .toc-list button {
  width: 100%; height: auto; min-width: 0; margin: 0; padding: 8px 10px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  text-align: left; font-size: 14px; line-height: 1.35;
}
.jinx-epaper-viewer .toc-page { flex: none; font-size: 12px; font-variant-numeric: tabular-nums; opacity: .7; }
.jinx-epaper-viewer .toc-list button.active { font-weight: 600; }

/* Page overview */
.jinx-epaper-viewer__bar .overview-toggle { width: 40px; height: 40px; padding: 0; }
.jinx-epaper-viewer .overview {
  position: fixed; top: 52px; left: 0; right: 0; bottom: 0; z-index: 30;
  overflow-y: auto;
  padding: 24px;
  /* the background of the page, the book must not shine through */
  background: inherit;
}
.jinx-epaper-viewer .overview[hidden] { display: none; }
.jinx-epaper-viewer .overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 28px 24px;
  max-width: 1600px; margin: 0 auto;
}
.jinx-epaper-viewer .overview-page {
  width: auto; height: auto; min-width: 0; margin: 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 0; background: none; color: inherit; font-size: 13px;
}
.jinx-epaper-viewer .overview-page .ph {
  width: 100%; display: block; overflow: hidden;
  background: #fff;
  outline: 3px solid transparent; outline-offset: 2px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  transition: transform .15s, outline-color .15s;
}
.jinx-epaper-viewer .overview-page:hover .ph { transform: translateY(-3px); }
.jinx-epaper-viewer .overview-page .ph img,
.jinx-epaper-viewer .overview-page .ph canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.jinx-epaper-viewer .overview-page.active .ph { outline-color: currentColor; }

@media (max-width: 720px) {
  .jinx-epaper-viewer .overview { padding: 16px; }
  .jinx-epaper-viewer .overview-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 14px; }
}

/* Book area */
#viewport {
  flex: 1; min-height: 0; margin: 0;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 20px 64px;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
  /* touch-action none so pinch/pan are handled by the viewer */
  touch-action: none;
}
#book { flex: none; }
/* the PDF page itself is always white, the neutral shadow separates it from light backgrounds */
.jinx-epaper-viewer .page {
  background: #fff;
  overflow: hidden;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .18);
}
.jinx-epaper-viewer .page canvas {
  display: block; width: 100%; height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Zoom layer around the book */
#zoom { flex: none; transform-origin: 50% 50%; will-change: transform; }
#zoom.smooth { transition: transform .25s ease; }
#viewport.zoomed { cursor: grab; }
#viewport.zoomed.panning { cursor: grabbing; }
.jinx-epaper-viewer .zoom-ctl { display: flex; align-items: center; gap: 4px; }
.jinx-epaper-viewer .zoom-ctl button { height: 30px; min-width: 32px; font-size: 16px; padding: 0 6px; }
#zoomLevel { font-size: 12px; min-width: 52px; font-variant-numeric: tabular-nums; }

/* StPageFlip base styles (not bundled with the JS) */
.stf__parent { position: relative; display: block; box-sizing: border-box; transform: translateZ(0); touch-action: pan-y; }
.stf__wrapper { position: relative; width: 100%; box-sizing: border-box; }
.stf__parent canvas { position: absolute; width: 100%; height: 100%; left: 0; top: 0; }
.stf__block { position: absolute; width: 100%; height: 100%; box-sizing: border-box; perspective: 2000px; }
.stf__item { display: none; position: absolute; transform-style: preserve-3d; }
.stf__outerShadow, .stf__innerShadow, .stf__hardShadow, .stf__hardInnerShadow { position: absolute; left: 0; top: 0; }

.jinx-epaper-viewer .side-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; padding: 0;
  font-size: 24px;
  z-index: 5;
}
.jinx-epaper-viewer .side-btn.prev { left: 10px; }
.jinx-epaper-viewer .side-btn.next { right: 10px; }
#status {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 10;
}
#status:empty { display: none; }

/* Bottom navigation */
.jinx-epaper-viewer__nav {
  flex: none; margin: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.jinx-epaper-viewer .scrub {
  display: flex; align-items: center; gap: 10px;
  padding: 0 4px 8px;
}
.jinx-epaper-viewer .scrub input[type=range] { flex: 1; min-width: 0; margin: 0; }
.jinx-epaper-viewer .counter { white-space: nowrap; font-variant-numeric: tabular-nums; }
.jinx-epaper-viewer .counter input {
  width: 3.5em; height: 30px; margin: 0; padding: 0 4px; text-align: center;
  font: inherit;
  /* no spin buttons, the arrow keys still work */
  -moz-appearance: textfield;
  appearance: textfield;
}
.jinx-epaper-viewer .counter input::-webkit-inner-spin-button,
.jinx-epaper-viewer .counter input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.jinx-epaper-viewer .carousel { display: flex; align-items: center; gap: 6px; }
.jinx-epaper-viewer .carousel > button { height: calc(var(--thumb-h) + 20px); min-width: 32px; padding: 0; }
#thumbs {
  position: relative;
  flex: 1; min-width: 0;
  display: flex; gap: 10px;
  overflow-x: auto; overflow-y: hidden;
  padding: 2px 4px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  cursor: grab;
}
#thumbs::-webkit-scrollbar { display: none; }
#thumbs.dragging { cursor: grabbing; scroll-snap-type: none; }
/* All thumbnails fit: spread them evenly across the full width, no scrolling */
.jinx-epaper-viewer .carousel.fits > button { display: none; }
.jinx-epaper-viewer .carousel.fits #thumbs { justify-content: space-evenly; cursor: default; overflow-x: hidden; }
.jinx-epaper-viewer .thumb {
  flex: none; height: auto; min-width: 0;
  padding: 0; border: 0; border-radius: 4px; background: none; color: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px;
  scroll-snap-align: center;
}
.jinx-epaper-viewer .thumb:hover { background: none; }
.jinx-epaper-viewer .thumb .ph {
  height: var(--thumb-h);
  border-radius: 3px;
  outline: 2px solid transparent; outline-offset: 1px;
  overflow: hidden; display: block;
  transition: outline-color .15s, transform .15s;
}
.jinx-epaper-viewer .thumb:hover .ph { transform: translateY(-2px); }
.jinx-epaper-viewer .thumb canvas,
.jinx-epaper-viewer .thumb img { height: 100%; width: 100%; display: block; object-fit: contain; }
.jinx-epaper-viewer .thumb:not(.active) { opacity: .7; }
.jinx-epaper-viewer .thumb.active .ph { outline-color: currentColor; }

@media (max-width: 720px) {
  .jinx-epaper-viewer { --thumb-h: 60px; }
  .jinx-epaper-viewer .search,
  .jinx-epaper-viewer .toc { width: 100%; }
  #viewport { padding: 12px; }
  .jinx-epaper-viewer .side-btn,
  .jinx-epaper-viewer .carousel > button,
  #zoomOut, #zoomIn { display: none; }
}
