/* ============================================================
   Buchjournal2Flipbook - Stylesheet
   Modernes, helles Erscheinungsbild mit warmem Off-White
   und Petrol als Akzentton.
   ============================================================ */

:root {
  --bg-color: #faf7f2;
  --bg-panel: #ffffff;
  --accent: #2a6f7a;
  --accent-hover: #1f5560;
  --accent-light: #e8f0f1;
  --text-color: #2d2d2d;
  --text-muted: #6b6b6b;
  --shadow-page: 0 4px 20px rgba(0, 0, 0, 0.15);
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.08);
  --border-radius: 10px;
  --border-radius-sm: 6px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background-color: var(--bg-panel);
  box-shadow: var(--shadow-soft);
  z-index: 100;
  flex-shrink: 0;
}

/* Linker Toolbar-Block: Thumbnails-Button + Titel */
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

/* Mittlerer Toolbar-Block: Navigation (zentriert) */
.toolbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* Rechter Toolbar-Block: Link zurueck zur Archiv-Uebersicht (rechtsbuendig,
   balanciert das Layout symmetrisch zum linken Toolbar-Block) */
.toolbar-right {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

/* Basis-Button-Stil fuer alle Buttons in Toolbar und Sidebar-Header
   (der Zurueck-Link nutzt bewusst denselben Stil wie die anderen
   Toolbar-Buttons - z. B. Blaettern/Miniaturansichten - fuer ein
   einheitliches Erscheinungsbild). */
.toolbar button,
.thumbnails-header button,
.toolbar-back-link {
  background-color: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--border-radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  font-family: var(--font-ui);
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}

.toolbar button:hover,
.thumbnails-header button:hover,
.toolbar-back-link:hover {
  background-color: var(--accent-hover);
}

.toolbar-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toolbar-back-link svg {
  flex-shrink: 0;
}

.toolbar button:disabled,
.thumbnails-header button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Icon-Button (quadratisch, fuer Toolbar- und Sidebar-Header-Icons) */
.toolbar .icon-btn,
.thumbnails-header .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  flex-shrink: 0;
}

.toolbar .page-info {
  font-size: 14px;
  color: var(--text-muted);
  min-width: 80px;
  text-align: center;
}

.toolbar .title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  padding-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Haupt-Layout: Sidebar + Flipbook ---------- */

#viewer-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ---------- Thumbnails-Sidebar ---------- */

#thumbnails-panel {
  width: 240px;
  flex-shrink: 0;
  background-color: var(--bg-panel);
  border-right: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, transform 0.25s ease;
}

#thumbnails-panel.collapsed {
  width: 0;
  border-right: none;
}

.thumbnails-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.thumbnails-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.thumbnails-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* touch-action: pan-y erlaubt vertikales Scrollen, unterstuetzt aber
     browserseitigen Pinch-Zoom (nicht none, siehe SPECS 4.4) */
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.thumbnail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  background-color: transparent;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.thumbnail-item:hover {
  background-color: var(--accent-light);
}

.thumbnail-item.active {
  border-color: var(--accent);
  background-color: var(--accent-light);
}

.thumbnail-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  box-shadow: var(--shadow-soft);
  background: #fff;
}

.thumbnail-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--accent-light);
  color: var(--text-muted);
  font-size: 12px;
  border-radius: 3px;
}

.thumbnail-page-num {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Flipbook Container ---------- */

#flipbook-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 16px;
  min-width: 0;
  /* touch-action: none erlaubt uns, Pinch-to-Zoom selbst zu behandeln,
     statt den Browser-Pinch-Zoom zu verwenden (siehe SPECS 4.4 / ToDo P7). */
  touch-action: none;
}

#flipbook {
  position: relative;
  box-shadow: var(--shadow-page);
  border-radius: 4px;
  overflow: hidden;
}

/* Einzelne Seite im Flipbook */
.stf__item {
  background: #fff;
  overflow: hidden;
}

.page-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Platzhalter waehrend des Ladens */
.page-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: var(--accent-light);
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Hotspot-Overlays ---------- */

.hotspot-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Hoher z-index (siehe Kommentar bei den Blaetteranimations-Schatten
     unten), damit die Hotspot-Ebene innerhalb ihrer eigenen Seite
     (.stf__item/.page-wrapper) niemals von Kind-Elementen mit
     zufaellig hoeherem Stacking ueberdeckt wird. */
  z-index: 500;
}

/* Grundzustand (fest, immer sichtbar, fuer alle Geraete) */
.hotspot {
  position: absolute;
  border-radius: 4px;
  background-color: rgba(200, 120, 60, 0.12);
  cursor: pointer;
  pointer-events: auto;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

/* Bugfix: ISBN-Hotspot vs. Blaetteranimation
   ------------------------------------------
   cubicFUSION JS PageFlip (St.PageFlip) fuegt pro Flipbook-Instanz vier
   rein dekorative Schatten-Divs in den Seiten-Container ein
   (.stf__outerShadow/.stf__innerShadow/.stf__hardShadow/
   .stf__hardInnerShadow), die waehrend des Blaetterns per Inline-Style
   positioniert und mit einem POSITIVEN z-index (bis zu startZIndex+5)
   versehen werden. Da diese Divs kein eigenes pointer-events setzen,
   sind sie standardmaessig interaktiv (pointer-events: auto) UND
   gewinnen dank des positiven z-index das Stacking gegenueber
   .stf__item-Seiten ohne explizites z-index (z-index: auto verliert
   IMMER gegen jedes Element mit positivem z-index, unabhaengig von der
   DOM-Reihenfolge). Ergebnis (gemeldeter Bug): Ein Klick auf einen
   ISBN-Hotspot landet stattdessen auf einem unsichtbaren/halbtransparenten
   Schatten-Div, der als "swipe"-Ziel interpretiert wird - die Seite
   blaettert um, statt den Shop-Link zu oeffnen. Ausserdem kann der
   Hotspot/Tooltip dadurch optisch von der Animation ueberdeckt werden.
   Fix: Die vier Schatten-Divs sind rein visuell (Gradient-Overlay) und
   muessen niemals klickbar sein - pointer-events wird daher fest auf
   none gesetzt. Klicks "fallen durch" bis zum eigentlichen Hotspot
   (<a>) bzw. zur Seite darunter, PageFlip's eigene Klick-Weiterleitung
   (clickEventForward, schliesst a/button-Tags von der Swipe-Erkennung
   aus) greift dann zuverlaessig. */
.stf__outerShadow,
.stf__innerShadow,
.stf__hardShadow,
.stf__hardInnerShadow {
  pointer-events: none !important;
}

/* Option 1: differenziert Desktop/Touch (Standard)
   Die Auswahl-Klasse wird einmalig auf <body> gesetzt (siehe viewer.js).
   Nutzt den Grundzustand (.hotspot) unveraendert; nur der Hover-Zustand
   auf Desktop bzw. der Puls-Kringel auf Touch werden unten ergaenzt. */

@media (hover: hover) and (pointer: fine) {
  .hotspot-style-differentiated .hotspot:hover {
    background-color: rgba(200, 120, 60, 0.30);
    transform: scale(1.03);
  }
}

@media (hover: none), (pointer: coarse) {
  .hotspot-style-differentiated .hotspot::after {
    content: "";
    position: absolute;
    /* Negativer Offset: Der Kringel ragt etwas ueber den eigentlichen
       Hotspot-Rand hinaus, damit er insgesamt groesser und praesenter
       wirkt statt exakt auf der Hotspot-Groesse zu sitzen. */
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(200, 120, 60, 0.6);
    animation: hotspot-pulse 2.5s ease-out infinite;
    pointer-events: none;
  }
}

/* Option 2: Puls-Kringel auf allen Geraeten gleich */
.hotspot-style-pulse-always .hotspot::after {
  content: "";
  position: absolute;
  /* Negativer Offset: siehe Kommentar oben (differentiated-Variante). */
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(200, 120, 60, 0.6);
  animation: hotspot-pulse 2.5s ease-out infinite;
  pointer-events: none;
}

@keyframes hotspot-pulse {
  0%   { transform: scale(0.9);   opacity: 0.9; }
  70%  { transform: scale(1.5); opacity: 0; }
  100% { opacity: 0; }
}

/* ---------- Tooltip ---------- */

.hotspot-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  background-color: var(--accent);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 200;
  box-shadow: var(--shadow-soft);
}

.hotspot-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--accent);
}

.hotspot:hover .hotspot-tooltip {
  opacity: 1;
}

/* Kollisionspruefung: Tooltips am linken/rechten Seitenrand
   entsprechend ausrichten, damit sie nicht abgeschnitten werden. */
.hotspot-tooltip.tooltip-align-left {
  left: 0;
  transform: none;
}

.hotspot-tooltip.tooltip-align-left::after {
  left: 16px;
  transform: none;
}

.hotspot-tooltip.tooltip-align-right {
  left: auto;
  right: 0;
  transform: none;
}

.hotspot-tooltip.tooltip-align-right::after {
  left: auto;
  right: 16px;
  transform: none;
}

/* ---------- Loading-Overlay ---------- */

#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 16px;
}

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

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--accent-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#loading-text {
  font-size: 15px;
  color: var(--text-muted);
}

/* ---------- Footer ---------- */

.footer {
  padding: 8px 16px;
  background-color: var(--bg-panel);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

.footer p {
  margin: 0;
  line-height: 1.5;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ---------- Lizenzhinweis-Details (Klick-Einblendung) ---------- */

/* WICHTIG: [hidden] muss explizit erzwungen werden, da die unten
   folgende .license-details { display: inline }-Regel das native
   UA-Defaultverhalten von [hidden] schlagen wuerde. */
.license-details[hidden] {
  display: none !important;
}

.footer-copyright {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  justify-content: center;
  font-size: 11px;
  color: var(--text-color);
  font-weight: 500;
}

.license-details-btn {
  display: inline-block;
  margin-left: 4px;
  color: var(--accent);
  background: none;
  border: 1px solid rgba(42, 107, 122, 0.25);
  border-radius: var(--border-radius-sm);
  padding: 1px 6px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 10px;
  line-height: 1.4;
}

.license-details-btn:hover {
  background-color: var(--accent-light);
  text-decoration: underline;
}

.license-details {
  display: inline;
  margin-left: 4px;
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  flex-basis: 100%;
}

.license-details code {
  font-size: 10px;
  background-color: var(--accent-light);
  padding: 1px 3px;
  border-radius: var(--border-radius-sm);
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
  }

  .toolbar .title {
    font-size: 14px;
    /* Auf kleinen Displays: Titel als eigene Zeile unterhalb der
       Toolbar-Buttons erzwingen, damit er nicht zwischen den
       Icon-Buttons verschwindet. */
    flex-basis: 100%;
    order: 10;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    text-align: center;
  }

  .toolbar .icon-btn,
  .thumbnails-header .icon-btn {
    width: 32px;
    height: 32px;
  }

  .toolbar button,
  .thumbnails-header button {
    padding: 6px 12px;
    font-size: 13px;
  }

  .toolbar-back-link {
    font-size: 13px;
  }

  /* Der Zurueck-Link darf nicht unter seine Inhaltsbreite schrumpfen
     (sonst ueberlappt der nicht umbrechende Linktext die Blaettertasten
     in .toolbar-center statt selbst in eine neue Zeile umzubrechen). */
  .toolbar-right {
    min-width: auto;
  }

  #flipbook-container {
    padding: 8px;
  }

  /* Auf kleinen Displays: Sidebar als Overlay ueber dem Viewer,
     damit die einzelne Buchseite nicht zu klein gerendert wird. */
  #viewer-layout {
    position: relative;
  }

  #thumbnails-panel {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 200;
    box-shadow: var(--shadow-page);
  }

  #thumbnails-panel.collapsed {
    transform: translateX(-100%);
    width: 240px;
    border-right: none;
  }
}

/* Sehr kleine Displays (z. B. Smartphones im Hochformat):
   Titel komplett ausblenden, da er im Browser-Tab (<title>)
   weiterhin sichtbar ist und der Platz fuer Navigation gebraucht wird. */
@media (max-width: 480px) {
  .toolbar .title {
    display: none;
  }

  /* Blaettertasten (Vor/Zurueck) haben Vorrang vor dem Uebersicht-Link -
     dessen Text wird auf das Noetigste gekuerzt, damit auf schmalen
     Smartphone-Displays (z. B. 412px CSS-Breite) nichts ueberlappt. */
  .back-link-text-full {
    display: none;
  }

  .toolbar-back-link {
    padding: 6px 10px;
  }
}
