:root {
  --deck-viewport-bg: var(--paper, #ffffff);
  --deck-viewport-accent: var(--blue, #2a6fdb);
  --deck-viewport-accent-opacity: 1;
}

/* Nur die Gestaltung läuft bis zum Fensterrand. Die Folienbühne bleibt 16:9.
   Die Bühnenfarbe wechselt nicht hart, sondern blendet über die Dauer des
   Smooth-Scrolls: viewport-bleed.js setzt sie in dem Moment, in dem die neue
   Folie .active wird – der Folienwechsel selbst dauert aber noch 300–500 ms.
   Ohne Überblendung zeigen Letterbox-Balken und Akzentkante schon die Farbe
   der nächsten Folie, während die alte noch im Bild ist. */
body {
  background: var(--deck-viewport-bg) !important;
  transition: background-color 360ms ease;
}

.deck-viewport-accent-edge {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: max(4px, calc(10px * var(--deck-scale, 1)));
  background: var(--deck-viewport-accent);
  opacity: var(--deck-viewport-accent-opacity);
  pointer-events: none;
  transition: background-color 360ms ease, opacity 360ms ease;
}

@media screen {
  /* Die bisherige Kante in der 16:9-Fläche wird am Fensterrand weitergeführt. */
  .deck > section.slide::before { display: none !important; }
}

/* Mobile Präsentationsansicht. Der Editor wird durch presentation-view bewusst ausgeschlossen. */
@media screen and (max-width: 900px), screen and (pointer: coarse) {
  html.presentation-view {
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
  }

  html.presentation-view::-webkit-scrollbar { display: none; }

  html.presentation-view body:not(.editor-mode) {
    min-height: 100dvh;
    overflow-x: hidden;
    overscroll-behavior-y: none;
  }

  html.presentation-view body:not(.editor-mode) .deck {
    touch-action: pan-y pinch-zoom;
  }

  html.presentation-view body:not(.editor-mode) .deck > section.slide {
    scroll-snap-align: center;
    scroll-snap-stop: always;
  }

  html.presentation-view body:not(.editor-mode) .progress {
    top: env(safe-area-inset-top, 0px);
  }

  html.presentation-view body:not(.editor-mode) .deck-chrome {
    right: auto;
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    opacity: .94;
    background: color-mix(in srgb, var(--rule-strong) 92%, transparent);
    backdrop-filter: blur(10px) saturate(140%);
    -webkit-backdrop-filter: blur(10px) saturate(140%);
    transform: translateX(-50%) !important;
  }

  html.presentation-view body:not(.editor-mode) .deck-chrome button,
  html.presentation-view body:not(.editor-mode) .deck-counter {
    min-height: 46px;
    padding: 9px 12px;
    font-size: 12px;
  }

  html.presentation-view body:not(.editor-mode) #navPrev,
  html.presentation-view body:not(.editor-mode) #navNext {
    width: 48px;
    min-width: 48px;
    padding: 0;
    font-size: 0;
  }

  html.presentation-view body:not(.editor-mode) #navPrev::before,
  html.presentation-view body:not(.editor-mode) #navNext::before {
    font-size: 20px;
    line-height: 1;
  }

  html.presentation-view body:not(.editor-mode) #navPrev::before { content: "←"; }
  html.presentation-view body:not(.editor-mode) #navNext::before { content: "→"; }

  html.presentation-view body:not(.editor-mode) .overlay {
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }

  html.presentation-view body:not(.editor-mode) .overlay-panel {
    max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 22px;
  }
}

@media screen and (max-width: 480px) {
  html.presentation-view body:not(.editor-mode) .overlay-panel header {
    gap: 12px;
    margin-bottom: 18px;
  }

  html.presentation-view body:not(.editor-mode) .overlay-panel h2 { font-size: 30px; }
  html.presentation-view body:not(.editor-mode) .help-panel dl div { grid-template-columns: 1fr; gap: 5px; }
}

/* Lesemodus (Mobile). Unterhalb von ~720px Breite verlässt die Präsentation
   die starre 1440×810-Bühne, die editor.css unter @media screen zentral für
   Editor UND Präsentationsansicht setzt (fixe Grösse + zoom: var(--deck-scale)
   — die "einheitliche Folienbühne"). Auf einem Handy-Bildschirm bedeutet das
   sonst: jede Folie bleibt ein 16:9-Brett, wird auf Handy-Breite herunter-
   gezoomt und der ganze Inhalt schrumpft proportional mit — Schrift wird
   unlesbar klein oder läuft über den (dann winzigen) Folienrand hinaus.

   Der Lesemodus hebt die feste Bühne NUR hier auf: Folien bekommen echte
   Blockhöhe (min-height: 100dvh statt der gezoomten 810px), Container-Type
   "size" fällt weg (cqw/cqh in core.css und deck.css fallen dadurch auf die
   echte Viewport-Grösse zurück statt auf die eingefrorene 1440er-Bühne —
   damit greifen bestehende @media(max-width:900px)-Regeln in core.css und in
   deck.css zum ersten Mal wirklich), und Titel/Fliesstext bekommen eigene,
   handygerechte clamp()-Werte statt der für 1440px kalibrierten Minimalwerte.

   Bewusst ausgenommen: der Editor (body.editor-mode — eigener Arbeitsbereich,
   nicht Teil dieses Auftrags), Presenter-Frames (html.presenter-frame — die
   Bühne im Vortragsfenster bleibt exakt wie am Beamer) und Druck/PDF-Export
   (eigenes @media print, läuft ausserdem immer mit 1440px Bühnenbreite, siehe
   runtime/print.css und server/pdf-export.mjs — unterhalb dieser Query nie
   erreicht). Querformat auf dem Handy (z.B. 844×390) wurde geprüft: die
   16:9-Bühne bleibt dort genauso winzig wie im Hochformat-Fehlerbild, darum
   greift der Lesemodus zusätzlich über eine Höhen-Schwelle (kurze, breite
   Viewports). Ein normal grosses Präsentationsfenster oder ein breiter
   Browser ist nie so flach — die Höhen-Schwelle trifft praktisch nur echte
   Handy-Querformate. */
@media screen and (max-width: 720px), screen and (max-width: 900px) and (max-height: 480px) {
  html.presentation-view:not(.presenter-frame) {
    scroll-snap-type: y proximity;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .deck {
    align-items: stretch;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .deck > section.slide {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    margin: 0 !important;
    overflow: visible !important;
    container-type: normal !important;
    zoom: 1 !important;
    scroll-snap-align: start !important;
    scroll-snap-stop: normal !important;
    font-size: clamp(16px, 4.1vw, 17px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .deck > section.slide > .slide__content {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    /* Unten Platz für die fixe Chrome-Pille reservieren (siehe .deck-chrome
       weiter oben) — sonst endet Inhalt sichtbar hinter ihr statt davor. */
    padding: 28px 20px calc(88px + env(safe-area-inset-bottom, 0px)) 20px !important;
    gap: 16px;
  }

  /* Freigesetzte Elemente (siehe app.js applyFreePositioningReflow) landen als
     direkte Kinder von .slide ausserhalb von .slide__content und tragen aus
     editor.css "margin: 0 !important" / "max-width: none !important" — ohne
     eigene Regel sassen sie darum bündig am Folienrand statt im selben
     seitlichen Innenabstand wie .slide__content oben (20px). Hier bekommen
     sie denselben Abstand zurück plus einen Vertikalabstand zueinander. */
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .is-reflowed {
    margin-inline: 20px !important;
    max-width: calc(100% - 40px) !important;
    box-sizing: border-box !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .is-reflowed ~ .is-reflowed {
    margin-top: 14px !important;
  }

  /* Zwei-Spalten-Abschlussfolie (Text + Signet, siehe core.css) rutscht durch
     die bestehende @media(max-width:900px)-Regel in core.css bereits auf eine
     Spalte; hier nur noch die Ausrichtung von "end" auf "start" korrigiert,
     damit das Signet nicht seltsam unten klebt. */
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide--closing .slide__content {
    align-items: start !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide h1 {
    max-width: 100%;
    font-size: clamp(28px, 7.4vw, 34px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide h2 {
    max-width: 100%;
    font-size: clamp(24px, 6.4vw, 30px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide h3 {
    font-size: clamp(19px, 5vw, 22px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .lead {
    max-width: 100%;
    font-size: clamp(17px, 4.6vw, 19px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .eyebrow,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .section-number,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .col-label,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .card-index,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .title-meta,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .slide-footnote,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .quote-source,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .notes-kicker {
    font-size: clamp(11px, 2.9vw, 12px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .statement-wrap h2 {
    font-size: clamp(30px, 8vw, 38px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .quote-block {
    font-size: clamp(28px, 7.6vw, 34px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .metric strong {
    font-size: clamp(48px, 14vw, 64px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .metric span {
    font-size: clamp(15px, 4vw, 16px) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .slide-header {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 12px;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .title-mark img,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .closing-mark img {
    width: clamp(120px, 40vw, 180px);
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .deck-viewport-accent-edge {
    width: 4px !important;
  }

  /* Kennzahlen (.metric-row), Prozess-Schritte (.steps) und Kartenraster
     (.cards) sind für die 3-spaltige Desktop-Bühne kalibriert: grosses
     Padding und feste min-height füllen dort sichtbar leere Fläche, sobald
     die bestehende @media(max-width:900px)-Regel in core.css sie auf eine
     Spalte stapelt (jetzt zum ersten Mal wirksam, siehe oben). Hier auf
     kompakte, einzeln umrandete Karten mit echtem Abstand umgestellt statt
     der aneinanderstossenden Tabellen-Optik der Desktop-Bühne. */
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .metric-row,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .steps,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .cards,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .two-col {
    gap: 12px !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .metric,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .steps li,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .card,
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .two-col article {
    min-height: auto !important;
    padding: 20px !important;
  }

  /* .metric trägt auf der Desktop-Bühne nur Trennlinien (border-right/
     border-bottom), .steps li nur eine linke Kante am ersten Kind — beides
     ergibt als Einzelkarte eine unvollständige Box. Auf Mobile bekommt jede
     Karte ihren eigenen vollständigen Rahmen. */
  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .metric {
    border: 1px solid var(--rule-strong) !important;
    border-top: 4px solid var(--accent) !important;
  }

  html.presentation-view:not(.presenter-frame) body:not(.editor-mode) .slide .steps li {
    border: 1px solid var(--rule-strong) !important;
    border-top: 6px solid var(--accent) !important;
  }
}

@media print {
  body { background: var(--paper, #ffffff) !important; }
  .deck-viewport-accent-edge { display: none !important; }
  .deck > section.slide::before { display: block !important; }
  .deck > section.slide[data-tone="saturated"]::before { display: none !important; }
}
