/* PDF Flipbook viewer – (C) 2026 Stefan Kirchhoff, webkiste.net – GPL-2.0-or-later
   Colours can be overridden via URL: ?accent=2a6fdb&bar=1f2328&barfg=f2f2f2&stage=e9ecef */
:root {
  --bk-accent: #2a6fdb;
  --bk-accent-dark: #2259b4;
  --bk-accent-soft: rgba(42, 111, 219, 0.1);   /* hover background of search results */
  --bk-accent-mark: rgba(42, 111, 219, 0.28);  /* highlighted search term */
  --bk-accent-ring: rgba(42, 111, 219, 0.2);   /* focus ring */
  --bk-bar-bg: #1f2328;
  --bk-bar-fg: #f2f2f2;
  --bk-stage-bg: #e9ecef;
  --bk-panel-bg: #ffffff;
  --bk-flip-ms: 800ms;          /* flip duration, override with ?flip=900 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: #222;
  background: var(--bk-stage-bg);
}

.bk {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.bk-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Leiste ---------- */
.bk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--bk-bar-bg);
  color: var(--bk-bar-fg);
  border-bottom: 3px solid var(--bk-accent);
  flex: 0 0 auto;
  z-index: 20;
}
.bk-title {
  flex: 1 1 0;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bk-nav, .bk-tools { display: flex; align-items: center; gap: 2px; }
.bk-lang option { color: #222; background: #fff; }
.bk-tools { flex: 1 1 0; justify-content: flex-end; }

.bk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}
.bk-btn svg, .bk-arrow svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.bk-btn:hover, .bk-btn:focus-visible { background: rgba(127,127,127,0.2); outline: none; }
.bk-btn:focus-visible { box-shadow: 0 0 0 2px var(--bk-accent); }
.bk-btn[disabled] { opacity: 0.35; cursor: default; background: transparent; }
.bk-btn.is-active { color: var(--bk-accent); }

.bk-pageinfo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 6px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.bk-pageinfo input {
  width: 64px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid rgba(127,127,127,0.55);
  border-radius: 4px;
  background: rgba(127,127,127,0.16);
  color: inherit;
  text-align: center;
  font: inherit;
}
.bk-pageinfo input:focus { outline: none; border-color: var(--bk-accent); }

.bk-lang {
  height: 30px;
  margin-left: 6px;
  border: 1px solid rgba(127,127,127,0.55);
  border-radius: 4px;
  background: rgba(127,127,127,0.16);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
}

/* ---------- Bühne & Buch ---------- */
.bk-stage {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}

.bk-book {
  position: relative;
  perspective: 2600px;
  transition: transform var(--bk-flip-ms) ease;
}
.bk-book.is-cover  { transform: translateX(-25%); }   /* Titelseite allein mittig */
.bk-book.is-back   { transform: translateX(25%); }    /* Rückseite allein mittig */

.bk-side {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  background: #fff;
  overflow: hidden;
}
.bk-left  { left: 0; box-shadow: -4px 4px 14px rgba(0,0,0,0.18); }
.bk-right { left: 50%; box-shadow: 4px 4px 14px rgba(0,0,0,0.18); }
.bk-side.is-empty { background: transparent; box-shadow: none; }

/* Falz-Schatten in der Buchmitte */
.bk-left::after, .bk-right::after {
  content: "";
  position: absolute; top: 0; bottom: 0; width: 6%;
  pointer-events: none;
  z-index: 2;
}
.bk-left::after  { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.16), rgba(0,0,0,0)); }
.bk-right::after { left: 0;  background: linear-gradient(to right, rgba(0,0,0,0.16), rgba(0,0,0,0)); }
.bk-side.is-empty::after,
.bk-book.is-cover .bk-right::after,
.bk-book.is-back .bk-left::after { display: none; }

/* Einzelseiten-Modus (schmale Bildschirme) */
.bk-book.is-single .bk-left { display: none; }
.bk-book.is-single .bk-right { left: 0; width: 100%; }
.bk-book.is-single .bk-right::after { display: none; }

.bk-pageimg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
.bk-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #aaa; font-size: 0.9rem;
  background: repeating-linear-gradient(45deg, #fafafa, #fafafa 10px, #f3f3f3 10px, #f3f3f3 20px);
}

/* Links aus dem PDF */
.bk-links { position: absolute; inset: 0; z-index: 3; }
.bk-link {
  position: absolute;
  display: block;
  border-radius: 2px;
  transition: background 0.15s;
}
.bk-link:hover, .bk-link:focus-visible {
  background: rgba(240, 142, 0, 0.18);
  outline: 1px solid rgba(240, 142, 0, 0.6);
}

/* Umblättern: Blatt mit Vorder- und Rückseite */
.bk-leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  z-index: 10;
  transition: transform var(--bk-flip-ms) cubic-bezier(0.45, 0.05, 0.35, 1);
}
.bk-leaf.fwd { left: 50%; transform-origin: left center; }
.bk-leaf.bwd { left: 0;   transform-origin: right center; }
.bk-leaf .bk-face {
  position: absolute; inset: 0;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.bk-leaf .bk-face.back { transform: rotateY(180deg); }
.bk-leaf .bk-face::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to right, rgba(0,0,0,0) 60%, rgba(0,0,0,0.12));
  opacity: 0; transition: opacity var(--bk-flip-ms);
}
.bk-leaf.is-turning .bk-face::after { opacity: 1; }
.bk-leaf .bk-face.empty { background: transparent; }

/* Einzelseite: seitliches Schieben statt Blättern */
.bk-slide {
  position: absolute; inset: 0;
  background: #fff;
  z-index: 10;
  transition: transform 350ms ease, opacity 350ms ease;
}

/* Seitenpfeile */
.bk-arrow {
  position: absolute;
  top: 50%;
  z-index: 15;
  width: 46px; height: 46px;
  margin-top: -23px;
  border: 0;
  border-radius: 50%;
  background: rgba(31, 35, 40, 0.75);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
.bk-arrow:hover { background: var(--bk-accent); }
.bk-arrow[disabled] { opacity: 0; pointer-events: none; }
.bk-arrow-prev { left: 12px; }
.bk-arrow-next { right: 12px; }

/* Laden */
.bk-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 20px;
  background: var(--bk-stage-bg);
  z-index: 30;
  font-size: 0.95rem;
  color: #444;
  transition: opacity 0.3s ease;
}
.bk-loading[hidden] { display: none; }
.bk-loading.is-fading { opacity: 0; pointer-events: none; }
.bk-loading.is-error .bk-spinner,
.bk-loading.is-error .bk-progress,
.bk-loading.is-error .bk-loading-cover,
.bk-loading.is-error #bk-progress-pct { display: none; }

/* Titelbild aus dem Modul, sofort sichtbar während das PDF lädt */
.bk-loading-cover {
  display: block;
  /* Größe setzt das Skript passend zur Bühne (ungefähr so groß wie die echte Seite danach) */
  object-fit: contain;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0,0,0,0.22);
}
.bk-loading.has-cover .bk-spinner { display: none; }

.bk-spinner {
  width: 40px; height: 40px;
  border: 4px solid #d5d8dc;
  border-top-color: var(--bk-accent);
  border-radius: 50%;
  animation: bk-spin 0.9s linear infinite;
}
@keyframes bk-spin { to { transform: rotate(360deg); } }

.bk-loading-info { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.bk-loading-text { font-size: 0.9rem; color: #444; }
#bk-progress-pct { font-variant-numeric: tabular-nums; color: #666; }

/* Ladebalken: gefüllter Anteil + durchlaufender Lichtstreifen, damit immer Bewegung sichtbar ist */
.bk-progress {
  position: relative;
  width: min(320px, 80vw);
  height: 8px;
  background: #d5d8dc;
  border-radius: 4px;
  overflow: hidden;
}
#bk-progress-bar {
  height: 100%;
  width: 8%;
  background: var(--bk-accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.bk-progress::after {
  content: "";
  position: absolute; top: 0; bottom: 0; left: -40%;
  width: 40%;
  background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,0.65), rgba(255,255,255,0));
  animation: bk-sheen 1.3s ease-in-out infinite;
}
@keyframes bk-sheen { to { left: 100%; } }

/* ---------- Seitenpanels (Übersicht, Suche) ---------- */
.bk-panel {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: min(420px, 100%);
  display: flex; flex-direction: column;
  background: var(--bk-panel-bg);
  box-shadow: -6px 0 24px rgba(0,0,0,0.2);
  z-index: 40;
}
.bk-panel[hidden] { display: none; }
.bk-overview { width: min(560px, 100%); }
.bk-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 10px 18px;
  border-bottom: 1px solid #e5e5e5;
}
.bk-panel-head h2 { margin: 0; font-size: 1.05rem; }
.bk-panel .bk-btn { color: #333; }
.bk-panel .bk-btn:hover { background: #f0f0f0; }

.bk-thumbs {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 16px 12px;
  align-content: start;
}
.bk-thumb {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 0.8rem; color: #555;
}
.bk-thumb-img {
  width: 100%;
  background: #f4f4f4;
  border: 2px solid transparent;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  display: block;
}
.bk-thumb:hover .bk-thumb-img, .bk-thumb:focus-visible .bk-thumb-img { border-color: #bbb; }
.bk-thumb.is-current .bk-thumb-img { border-color: var(--bk-accent); }
.bk-thumb.is-current { color: var(--bk-accent-dark); font-weight: 600; }

.bk-searchform { display: flex; gap: 6px; padding: 14px 16px 6px; }
.bk-searchform input {
  flex: 1 1 auto;
  height: 38px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font: inherit;
}
.bk-searchform input:focus { outline: none; border-color: var(--bk-accent); box-shadow: 0 0 0 2px var(--bk-accent-ring); }
.bk-searchform .bk-btn { background: var(--bk-accent); color: #fff; }
.bk-searchform .bk-btn:hover { background: var(--bk-accent-dark); }
.bk-searchstatus { padding: 4px 18px 8px; font-size: 0.85rem; color: #666; min-height: 1.6em; }
.bk-results { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1 1 auto; }
.bk-results button {
  display: block; width: 100%; text-align: left;
  padding: 10px; border: 0; border-radius: 6px; background: none; cursor: pointer;
  font: inherit; font-size: 0.88rem; color: #333; line-height: 1.4;
}
.bk-results button:hover, .bk-results button:focus-visible { background: var(--bk-accent-soft); outline: none; }
.bk-results .bk-res-page { display: block; font-weight: 600; font-size: 0.8rem; color: var(--bk-accent-dark); margin-bottom: 2px; }
.bk-results mark { background: var(--bk-accent-mark); color: inherit; padding: 0 1px; border-radius: 2px; }

/* ---------- Zoom ---------- */
.bk-zoom {
  position: absolute; inset: 0;
  z-index: 50;
  background: rgba(20, 22, 25, 0.96);
  display: flex; flex-direction: column;
}
.bk-zoom[hidden] { display: none; }
.bk-zoom-bar {
  display: flex; justify-content: flex-end; gap: 4px;
  padding: 6px 12px; color: #fff;
}
.bk-zoom-scroll { flex: 1 1 auto; overflow: auto; cursor: grab; }
.bk-zoom-scroll.is-dragging { cursor: grabbing; }
.bk-zoom-pages { display: flex; gap: 0; margin: 0 auto; padding: 0 20px 20px; width: max-content; }
.bk-zoom-page { position: relative; background: #fff; }
.bk-zoom-page img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  .bk-title { display: none; }
  .bk-bar { gap: 4px; padding: 4px 6px; flex-wrap: wrap; justify-content: center; }
  .bk-tools { flex: 0 0 auto; }
  #bk-first, #bk-last { display: none; }
  .bk-btn { width: 36px; height: 36px; }
  .bk-pageinfo { margin: 0 2px; }
  .bk-pageinfo input { width: 52px; }
  .bk-arrow { width: 38px; height: 38px; margin-top: -19px; }
  .bk-arrow-prev { left: 4px; }
  .bk-arrow-next { right: 4px; }
}

/* Bei „Animationen reduzieren“ im Betriebssystem kürzer, aber weiterhin sichtbar blättern */
@media (prefers-reduced-motion: reduce) {
  :root { --bk-flip-ms: 450ms; }
}
