/* ==========================================================================
   FOKALiS Flipbook – Gestaltung
   Alle Farben stehen als --fb-Variablen auf :root. Pro Website in der eigenen
   CSS-Datei überschreiben (auf :root, damit auch die Großansicht sie erbt):
     :root { --fb-akzent: #c00; --fb-hintergrund: #fff; --fb-text: #222; ... }
   ========================================================================== */
:root {
  --fb-akzent: #d7aa4e;                          /* Buttons, Pfeile, Linien */
  --fb-akzent-kontrast: #1f1302;                 /* Schrift/Icon auf Akzentfläche (Hover) */
  --fb-text: #e8e8e8;                            /* Seitenzähler, Hinweise */
  --fb-hintergrund: #1f1302;                     /* Vollbild, mitlaufende Handy-Leiste */
  --fb-linie: rgba(215, 170, 78, .35);           /* Trennlinien, Rahmen */
  --fb-zoom-hintergrund: rgba(15, 9, 1, .96);    /* Großansicht */
  --fb-kante-hell: #4a3a22;                      /* Seitenkanten (Papierstapel) */
  --fb-kante-dunkel: #0e0801;
  --fb-sticky-top: var(--header-h, 0px);         /* Abstand der Handy-Leiste unter fixer Kopfleiste */
}
.flipbook {
  --fb-ratio: .7071;            /* wird aus dem PDF gesetzt */
  --fb-reserve: 220px;          /* Platz über/unter dem Buch (Kopfleiste, Leiste) */

  position: relative;
  display: grid;
  gap: 20px;
}

/* ---------- Bühne mit Buch und Pfeilen ---------- */
.flipbook__stage {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 12px;
  min-height: 300px;
}
.flipbook__frame {
  justify-self: center;
  width: 100%;
  /* Doppelseite passt immer in die Bildschirmhöhe */
  max-width: max(300px, calc((100vh - var(--fb-reserve)) * var(--fb-ratio) * 2));
  max-width: max(300px, calc((100svh - var(--fb-reserve)) * var(--fb-ratio) * 2));
  opacity: 0;
  transition: opacity .6s ease;
}
.flipbook.is-ready .flipbook__frame { opacity: 1; }
.flipbook__book { width: 100%; }

.flipbook__page {
  background: #111;
  overflow: hidden;
}
.flipbook__page img {
  width: 100%; height: 100%;
  object-fit: cover;
  user-select: none; -webkit-user-drag: none;
  opacity: 0; transition: opacity .4s ease;
}
.flipbook__page.is-rendered img { opacity: 1; }
.flipbook .stf__parent { cursor: grab; }

/* ---------- Papier-Optik: Falz, Wölbung, Seitenkanten ---------- */
.flipbook__page::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
/* linke Seite: Schatten zum Falz rechts, leichte Wölbung */
.flipbook__page.--left::after {
  background:
    linear-gradient(to left, rgba(0,0,0,.55) 0, rgba(0,0,0,.2) 1.5%, rgba(255,255,255,.05) 3.5%, rgba(255,255,255,0) 8%),
    linear-gradient(to right, rgba(255,255,255,.05) 0, rgba(255,255,255,0) 35%);
}
/* rechte Seite: Schatten zum Falz links */
.flipbook__page.--right::after {
  background:
    linear-gradient(to right, rgba(0,0,0,.55) 0, rgba(0,0,0,.2) 1.5%, rgba(255,255,255,.05) 3.5%, rgba(255,255,255,0) 8%),
    linear-gradient(to left, rgba(255,255,255,.05) 0, rgba(255,255,255,0) 35%);
}
/* Seitenkanten wie bei einem Papierstapel + Schatten auf dem Tisch */
.flipbook__page.--left {
  box-shadow:
    -1px 0 0 var(--fb-kante-hell), -2px 1px 0 var(--fb-kante-dunkel),
    -3px 1px 0 var(--fb-kante-hell), -4px 2px 0 var(--fb-kante-dunkel),
    -5px 2px 0 var(--fb-kante-hell),
    -8px 18px 40px rgba(0,0,0,.6);
}
.flipbook__page.--right {
  box-shadow:
    1px 0 0 var(--fb-kante-hell), 2px 1px 0 var(--fb-kante-dunkel),
    3px 1px 0 var(--fb-kante-hell), 4px 2px 0 var(--fb-kante-dunkel),
    5px 2px 0 var(--fb-kante-hell),
    8px 18px 40px rgba(0,0,0,.6);
}
/* Die Bibliothek zeichnet die Wölbung der umschlagenden Seite mit einem
   schwarzen Verlauf – auf dunklen Seiten unsichtbar. Umgekehrt wird er
   zur Lichtkante, die über die gebogene Seite wandert. */
.flipbook .stf__innerShadow { filter: invert(1); opacity: .45; }
.flipbook .stf__outerShadow { opacity: 1; }

.flipbook__nav {
  width: 48px; height: 48px; padding: 0;
  display: grid; place-items: center;
  background: transparent; color: var(--fb-akzent);
  border: 1px solid var(--fb-akzent); border-radius: 50%;
  cursor: pointer; transition: background .25s, color .25s, opacity .25s;
}
.flipbook__nav:hover:not([disabled]) { background: var(--fb-akzent); color: var(--fb-akzent-kontrast); }
.flipbook__nav[disabled] { opacity: .25; cursor: default; }
.flipbook__nav svg, .flipbook__tool svg, .flipbook-zoom__btn svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Ladeanzeige ---------- */
.flipbook__loader {
  position: absolute; inset: 0;
  display: none; place-items: center; align-content: center; gap: 14px;
  color: var(--fb-text);
}
.flipbook.is-loading .flipbook__loader { display: grid; }
.flipbook__spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .15); border-top-color: var(--fb-akzent);
  animation: fb-dreh 1s linear infinite;
}
@keyframes fb-dreh { to { transform: rotate(360deg); } }

/* ---------- Leiste unter dem Buch ---------- */
.flipbook {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "stage stage" "status tools";
  column-gap: 0;
  align-items: center;
}
.flipbook__stage { grid-area: stage; }
.flipbook__status { grid-area: status; display: flex; align-items: center; gap: 12px; padding-right: 20px; }
.flipbook__bar { grid-area: tools; }
.flipbook__status, .flipbook__bar { padding-top: 16px; border-top: 1px solid var(--fb-linie); align-self: stretch; }
.flipbook__nav--bar { display: none; width: 40px; height: 40px; flex-shrink: 0; }
.flipbook__counter { margin: 0; font-variant-numeric: tabular-nums; color: var(--fb-text); }
.flipbook__hint { display: block; font-size: 13px; opacity: .65; }
@media (hover: none) { .flipbook__hint { display: none; } }
.flipbook__tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.flipbook__tool {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: transparent; color: var(--fb-akzent);
  border: 1px solid var(--fb-akzent); border-radius: 5px;
  font: inherit; font-size: 15px; cursor: pointer; text-decoration: none;
  transition: background .25s, color .25s;
}
.flipbook__tool:hover { background: var(--fb-akzent); color: var(--fb-akzent-kontrast); }
.flipbook:not(.is-ready):not(.is-error) :is(.flipbook__bar, .flipbook__status) { visibility: hidden; }

.flipbook__error { margin: 0; padding: 14px 18px; border: 1px solid var(--fb-akzent); border-radius: 8px; }
.flipbook.is-error { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
.flipbook.is-error :is(.flipbook__stage, .flipbook__status) { display: none; }
.flipbook.is-error .flipbook__bar { grid-area: auto; border: 0; padding: 0; }
.flipbook.is-error .flipbook__tools { justify-content: flex-start; }

/* ---------- Vollbild ---------- */
.flipbook.is-fullscreen {
  --fb-reserve: 120px;
  background: var(--fb-hintergrund);
  padding: 20px;
  align-content: center;
}

/* ---------- Passend zur Höhe (Opt-in: data-flipbook-fit) ----------
   Das Buch richtet sich nach dem Platz, den der Container tatsächlich hat
   (statt nach Bildschirmhöhe minus --fb-reserve). Der Container braucht dafür
   eine feste Höhe, die die eigene Seite vorgibt. Nur Desktop/Tablet; ohne
   Container-Queries bleibt die Reserve-Berechnung von oben aktiv. */
@supports (container-type: size) {
  @media (min-width: 701px) {
    .flipbook[data-flipbook-fit] { grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
    .flipbook[data-flipbook-fit] .flipbook__stage {
      container-type: size;
      align-self: stretch;
      min-height: 200px;
    }
    .flipbook[data-flipbook-fit] .flipbook__frame {
      max-width: calc(100cqh * var(--fb-ratio) * 2);
    }
  }
}

/* ---------- Großansicht (Lupe) ---------- */
.flipbook-zoom {
  position: fixed; inset: 0; z-index: 1000;
  display: none; grid-template-rows: auto 1fr;
  background: var(--fb-zoom-hintergrund);
  color: var(--fb-text);
}
.flipbook-zoom.is-open { display: grid; }
html.flipbook-zoom-offen { overflow: hidden; }
.flipbook-zoom__bar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--fb-linie);
}
.flipbook-zoom__count { margin: 0; min-width: 130px; text-align: center; font-variant-numeric: tabular-nums; }
.flipbook-zoom__btn {
  width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
  background: transparent; color: var(--fb-akzent);
  border: 1px solid currentColor; border-radius: 50%; cursor: pointer;
}
.flipbook-zoom__btn[disabled] { opacity: .25; cursor: default; }
.flipbook-zoom__close { position: absolute; right: 16px; top: 10px; }
.flipbook-zoom__scroll { overflow: auto; overscroll-behavior: contain; padding: 16px; touch-action: pan-y pinch-zoom; }
.flipbook-zoom__img { display: block; width: min(100%, 1000px); height: auto; margin: 0 auto; box-shadow: 0 10px 40px rgba(0, 0, 0, .6); }

@media (max-width: 700px) {
  /* Einzelseite in voller Breite – gut lesbar, vertikal scrollbar */
  .flipbook__frame { max-width: 100%; }
  .flipbook { gap: 12px; column-gap: 0; grid-template-columns: minmax(0, 1fr); grid-template-areas: "status" "stage" "tools"; }
  .flipbook__stage { grid-template-columns: minmax(0, 1fr); }
  .flipbook__nav--prev, .flipbook__nav--next { display: none; }
  /* schlanke Statuszeile, läuft beim Scrollen unter der Kopfleiste mit */
  .flipbook__status {
    position: sticky; top: calc(var(--fb-sticky-top) + 6px); z-index: 20;
    justify-content: space-between; padding: 6px;
    background: var(--fb-hintergrund); border: 1px solid var(--fb-linie); border-radius: 30px;
  }
  .flipbook__nav--bar { display: grid; }
  .flipbook__hint { display: none; }
  .flipbook__bar { border: 0; padding: 0; }
  .flipbook__tools { justify-content: center; }
  .flipbook-zoom__close { position: static; margin-left: auto; }
  .flipbook-zoom__bar { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .flipbook__spinner { animation-duration: 3s; }
}
