/* ═══════════════════════════════════════════════════════════════
   Grundlage: Papier, Schrift, Bühne, Knöpfe.
   Die Farben kommen aus config.js und werden beim Start von
   main.js als Custom Properties auf :root gesetzt.
   ═══════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Gloria';
  src: url('../assets/fonts/gloria-hallelujah-latin.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122;
}
@font-face {
  font-family: 'Patrick';
  src: url('../assets/fonts/patrick-hand-latin.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122;
}

:root {
  /* Notfall-Werte, falls config.js nicht lädt */
  --papier:   #fbf6e9;
  --stift:    #3b2f27;
  --himmel:   #bfe3f2;
  --gras:     #8dc46a;
  --sonne:    #ffd24a;
  --geschenk: #e8607a;
  --schleife: #5fb8d6;
  --kuh-fleck:#4a3d34;
  --euter:    #f4a8b0;
  --schwein:  #f5c3c8;
  --steak:    #c2453f;
  --fett:     #f6e5cf;
  --wurst:    #c98a5e;
  --kiste:    #c9a06a;
  --akzent:   #f0932b;
  --haar:     #c39a5e;
  --bart:     #a87c42;
  --shirt:    #b8524a;
  --gitarre:  #332c38;

  /* Handschriften mit System-Rückfall, falls die Datei fehlt */
  --schrift-gross: 'Gloria', 'Bradley Hand', 'Chalkboard SE', 'Comic Sans MS', cursive;
  --schrift-text:  'Patrick', 'Bradley Hand', 'Chalkboard SE', 'Comic Sans MS', cursive;

  --sicher-oben:   env(safe-area-inset-top, 0px);
  --sicher-unten:  env(safe-area-inset-bottom, 0px);
}

/* ─── Reset ──────────────────────────────────────────────────── */

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--schrift-text);
  color: var(--stift);
  background: var(--papier);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  text-rendering: optimizeLegibility;
}

/* ─── Das Papier ──────────────────────────────────────────────────
   Grundton, eine feine Faserstruktur und ein ganz leichter
   Schatten zu den Rändern hin, damit es nach Blatt aussieht und
   nicht nach Bildschirm. Alles statisch, kostet nichts.          */

#papier {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 100% at 50% 0%, #fffdf6 0%, transparent 55%),
    radial-gradient(140% 120% at 50% 110%, rgba(120, 96, 60, .16) 0%, transparent 60%),
    var(--papier);
}

/* Faserkörnung als eigene Schicht — einmal gerastert, danach gratis. */
#papier::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: .5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23f)' opacity='.28'/%3E%3C/svg%3E");
}

/* ─── Bühne und Akte ─────────────────────────────────────────────
   Alle Akte liegen übereinander. Genau einer ist sichtbar.
   Kein Scrollen — jeder Akt füllt exakt den Bildschirm.          */

#buehne {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.akt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(.6rem, 2.5dvh, 1.6rem);
  padding:
    calc(var(--sicher-oben) + clamp(3rem, 8dvh, 5rem))
    clamp(1rem, 5vw, 2.5rem)
    calc(var(--sicher-unten) + clamp(1.2rem, 4dvh, 2.5rem));
  text-align: center;

  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s ease;
}

.akt.aktiv {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* Beim Verlassen soll der alte Akt schneller weg sein als der neue
   kommt, sonst überlagern sich zwei Bilder sichtbar. */
.akt.geht { transition: opacity .28s ease; }

/* ─── Schrift ────────────────────────────────────────────────── */

h1, h2 {
  font-family: var(--schrift-gross);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: .01em;
}

h1 {
  font-size: clamp(2rem, 11vw, 4.2rem);
  /* Sehr lange Namen sollen nicht aus dem Bild laufen */
  max-width: 100%;
  overflow-wrap: break-word;
}

h2 { font-size: clamp(1.4rem, 7vw, 2.6rem); }

p {
  font-size: clamp(1.05rem, 4.6vw, 1.5rem);
  line-height: 1.45;
  max-width: 22ch;
  text-wrap: balance;
}

p.klein {
  font-size: clamp(.85rem, 3.6vw, 1.1rem);
  opacity: .62;
  max-width: 26ch;
}

/* Einzelne Buchstaben im Titel — jeder minimal anders gesetzt.
   Die Werte --kipp/--hoch/--gross kommen aus kritzelText(). */
.buchstabe {
  display: inline-block;
  transform:
    translateY(var(--hoch, 0)) rotate(var(--kipp, 0deg)) scale(var(--gross, 1));
  transform-origin: center bottom;
}

/* ─── Knöpfe ─────────────────────────────────────────────────────
   Der klassische Trick für einen handgezeichneten Kasten:
   asymmetrische border-radius-Werte. Dazu ein zweiter, leicht
   verdrehter Rahmen als ::before — so sieht es aus, als hätte
   jemand zweimal nachgezogen und nicht getroffen.                */

.knopf {
  position: relative;
  display: inline-block;
  font-family: var(--schrift-gross);
  font-size: clamp(1.05rem, 4.6vw, 1.45rem);
  color: var(--stift);
  background: #fff8e6;
  border: 3px solid var(--stift);
  border-radius: 255px 18px 225px 15px / 15px 225px 18px 255px;
  padding: .7em 1.4em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .12s ease, background .2s ease;
  animation: knopf-wippt 3.4s ease-in-out infinite;
}

.knopf::before {
  content: '';
  position: absolute;
  inset: -6px;
  border: 2px solid var(--stift);
  border-radius: 15px 225px 18px 255px / 255px 18px 225px 15px;
  opacity: .35;
  pointer-events: none;
}

.knopf:active {
  transform: scale(.94) rotate(-1.5deg);
  background: var(--akzent);
  animation: none;
}

/* Auf Geräten mit Maus darf es beim Drüberfahren reagieren.
   Auf dem Handy würde :hover nach dem Tap kleben bleiben. */
@media (hover: hover) {
  .knopf:hover { background: #fff1cd; }
}

.knopf.leise { animation: none; }

/* ─── Ton-Schalter ───────────────────────────────────────────── */

#ton {
  position: fixed;
  z-index: 40;
  top: calc(var(--sicher-oben) + .7rem);
  right: .7rem;
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  background: #fff8e6;
  border: 2.5px solid var(--stift);
  border-radius: 62% 38% 55% 45% / 45% 55% 45% 55%;
  cursor: pointer;
  opacity: .85;
  transition: transform .15s ease, opacity .2s ease;
}

#ton:active { transform: scale(.9) rotate(6deg); }

/* Auf dem Startbildschirm macht der Schalter auf sich aufmerksam —
   sonst spielt die halbe Show stumm, weil ihn niemand findet. */
#ton.winkt { animation: knopf-wippt 1.3s ease-in-out infinite; opacity: 1; }
#ton svg { width: 1.5rem; height: 1.5rem; }
#ton .aus-strich { display: none; }
#ton[data-an="false"] { opacity: .55; }
#ton[data-an="false"] .aus-strich { display: block; }

/* ─── Partikel-Leinwand ──────────────────────────────────────── */

#fx {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

/* ─── Weißblitz beim Messerschnitt ───────────────────────────── */

#blitz {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

/* Muss stärker sein als display:grid/flex weiter oben — sonst
   bliebe eine versteckte Sprechblase sichtbar. Gilt auch für
   SVG-Gruppen, die per hidden ein- und ausgeblendet werden. */
[hidden] { display: none !important; }

/* ─── Zugänglichkeit ─────────────────────────────────────────── */

.nur-fuer-screenreader {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:focus-visible {
  outline: 3px dashed var(--akzent);
  outline-offset: 4px;
}
