/*
 * uFolien – Folien-Engine (Darstellung)
 *
 * Aufbau nach dem Start durch shared/folien.js:
 *   body.folien-aktiv.ansicht-folie | .ansicht-uebersicht | .ansicht-vorschau
 *     main.deck
 *       div.folie-huelle (.ist-aktuell)   <- Hülle, von der Engine eingefügt
 *         section.folie                   <- 1920 x 1080, per --skala eingepasst
 *         span.folie-beschriftung         <- nur in der Übersicht sichtbar
 *     nav.steuerleiste
 *     div.dreh-hinweis
 *
 * Die Box von .folie (width, height, position, transform, display,
 * visibility, overflow) gehört ausschließlich dieser Datei.
 * Beispiele färben die Bühne über --buehne an :root.
 */

/* ---------- Grundlagen ---------- */

.folie {
  box-sizing: border-box;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
}

html {
  height: 100%;
}

body.folien-aktiv {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--buehne, #14161a);
  -webkit-tap-highlight-color: transparent;
}

/* Nur für Bildschirmleser sichtbarer Text */
.ufolien-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Folienansicht ---------- */

.folien-aktiv .deck {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  outline: none;
}

.ansicht-folie .deck {
  /* Waagerechtes Wischen wertet die Engine aus, Zoomen bleibt erlaubt */
  touch-action: pan-y pinch-zoom;
}

.folien-aktiv .folie-huelle {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

.folien-aktiv .folie-huelle.ist-aktuell {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease, visibility 0s linear 0s;
}

/* Die aktuelle Hülle liegt oben – sonst blenden beim Schließen der Übersicht
   die später im DOM stehenden Hüllen sichtbar über ihr aus. */
.ansicht-folie .folie-huelle.ist-aktuell {
  z-index: 1;
}

/* Die Folie liegt mittig in der Hülle und wird um ihre Mitte skaliert.
   --skala setzt folien.js je Hülle (min(Breite/1920, Höhe/1080)). */
.folien-aktiv .folie {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  margin: 0;
  visibility: inherit;
  transform: translate(-50%, -50%) scale(var(--skala, 0.5));
  transform-origin: 50% 50%;
}

.folie-beschriftung {
  display: none;
}

/* ---------- Übersicht ---------- */

.ansicht-uebersicht .deck {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  align-content: start;
  gap: 28px;
  padding: 32px 32px 120px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ansicht-uebersicht .folie-huelle {
  position: relative;
  inset: auto;
  aspect-ratio: 16 / 9;
  opacity: 1;
  visibility: visible;
  cursor: pointer;
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 6px 20px rgba(0, 0, 0, 0.35);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.ansicht-uebersicht .folie-huelle:hover {
  transform: translateY(-2px);
}

.ansicht-uebersicht .folie-huelle:focus {
  outline: none;
}

.ansicht-uebersicht .folie-huelle:focus-visible {
  outline: 3px solid #8ab4ff;
  outline-offset: 4px;
}

.ansicht-uebersicht .folie-huelle.ist-aktuell {
  box-shadow: 0 0 0 4px #f2c14e, 0 6px 20px rgba(0, 0, 0, 0.35);
}

.ansicht-uebersicht .folie-beschriftung {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 12px;
  background: rgba(12, 14, 18, 0.86);
  color: #ffffff;
  font: 400 15px/1.3 "Source Sans 3", system-ui, sans-serif;
}

.folie-beschriftung .folie-nummer {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ansicht-uebersicht .folie-huelle.ist-aktuell .folie-beschriftung {
  background: #f2c14e;
  color: #1a1a1a;
}

/* ---------- Vorschau (Katalog-Kachel) ---------- */

.ansicht-vorschau .folie-huelle {
  opacity: 1;
  visibility: visible;
  transition: none;
}

.ansicht-vorschau .folie-huelle:not(.ist-aktuell) {
  display: none;
}

/* ---------- Steuerleiste ---------- */

.steuerleiste {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100% - 12px);
  padding: 5px;
  border-radius: 14px;
  background: rgba(18, 20, 24, 0.88);
  color: #f3f4f6;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font: 600 16px/1 "Source Sans 3", system-ui, sans-serif;
  transform: translateX(-50%);
  transition: opacity 0.3s ease, transform 0.3s ease;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

body.steuerung-ruht .steuerleiste {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
}

body.steuerung-ruht.ansicht-folie {
  cursor: none;
}

.steuer-knopf {
  box-sizing: border-box;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.steuer-knopf svg {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.steuer-knopf:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.steuer-knopf:focus {
  outline: none;
}

.steuer-knopf:focus-visible {
  outline: 2px solid #8ab4ff;
  outline-offset: 1px;
}

.steuer-knopf:disabled {
  opacity: 0.35;
  cursor: default;
}

.steuer-knopf[hidden] {
  display: none;
}

.steuer-knopf[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.18);
}

/* Vollbild-Symbol wechselt je nach Zustand */
.steuer-knopf .symbol-aus,
.steuer-knopf.ist-an .symbol-an {
  display: none;
}

.steuer-knopf.ist-an .symbol-aus {
  display: block;
}

.seitenzahl {
  flex: none;
  min-width: 4.6em;
  padding: 0 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.steuer-trenner {
  flex: none;
  width: 1px;
  height: 24px;
  margin: 0 4px;
  background: rgba(255, 255, 255, 0.22);
}

@media (max-width: 420px) {
  .steuerleiste .steuer-trenner,
  .steuerleiste .knopf-drucken {
    display: none;
  }

  .seitenzahl {
    min-width: 3.8em;
    padding: 0 2px;
  }
}

/* ---------- Hinweis „Gerät drehen" ---------- */

.dreh-hinweis {
  display: none;
}

@media (orientation: portrait) and (max-width: 600px) {
  body.ansicht-folie .dreh-hinweis:not(.ist-geschlossen) {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 12px;
    right: 12px;
    z-index: 21;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 6px 6px 14px;
    border-radius: 12px;
    background: rgba(18, 20, 24, 0.9);
    color: #f3f4f6;
    font: 400 16px/1.3 "Source Sans 3", system-ui, sans-serif;
  }
}

.dreh-hinweis > svg {
  flex: none;
  width: 26px;
  height: 26px;
}

.dreh-hinweis p {
  flex: 1;
  margin: 0;
}

/* ---------- Weniger Bewegung ---------- */

@media (prefers-reduced-motion: reduce) {
  .folien-aktiv .folie-huelle,
  .folien-aktiv .folie-huelle.ist-aktuell,
  .ansicht-uebersicht .folie-huelle,
  .steuerleiste {
    transition: none;
  }

  .ansicht-uebersicht .folie-huelle:hover {
    transform: none;
  }
}

/* ---------- Druck: jede Folie unskaliert auf eigener Seite ---------- */

/* Zwischen beforeprint und afterprint keine Übergänge */
body.druck-aktiv .folie-huelle {
  transition: none !important;
}

@media print {
  @page {
    size: 1920px 1080px;
    margin: 0;
  }

  html,
  body,
  body.folien-aktiv {
    height: auto !important;
    margin: 0 !important;
    overflow: visible !important;
    background: none !important;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .steuerleiste,
  .dreh-hinweis,
  .folie-beschriftung {
    display: none !important;
  }

  .deck {
    position: static !important;
    display: block !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .folie-huelle {
    position: relative !important;
    inset: auto !important;
    display: block !important;
    width: 1920px !important;
    height: 1080px !important;
    aspect-ratio: auto !important;
    overflow: hidden !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    transition: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    break-inside: avoid;
    break-after: page;
    page-break-after: always;
  }

  .folie-huelle:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .folie,
  .folien-aktiv .folie {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    visibility: visible !important;
    transform: none !important;
  }

  /* Ohne Engine (kein JS): Folien einfach untereinander */
  .deck > .folie {
    position: relative !important;
    break-after: page;
    page-break-after: always;
  }
}
