/* ================================================================================================================================ */
/* Irish Pub, Etappe 3 Witz (themeAnim/irishpub/finnHost.js, finnDirector.js, react.js): W1 Barkeeper Finn hinter dem Tresen,         */
/* W2 Sprechblase, W3 die Stammgäste reagieren. Nur transform/opacity. Dauerschleifen (polieren, wippen, Noten, schnarchen) stehen     */
/* über loops.js in der Phase der Serverzeit. Reduzierte Bewegung: Finn steht still (die Ebene schaltet alle Animationen ab).         */
/* ================================================================================================================================ */

/* Drehpunkte wie in finn.js: `translate(px py)` außen, Klasse innen, Ursprung 0 0. */
.ipf :is(.ipf-lean, .ipf-finn__body, .ipf-finn__head, .ipf-finn__arm, .ipf-finn__brow, .ipf-finn__towel, .ipf-finn__glass, .ipf-finn__bow, .ipf-finn__swing, .ipf-finn__notes, .ipf-finn__note) {
  transform-box: view-box;
  transform-origin: 0 0;
}
.ipf :is(.ipf-finn__pop, .ipf-finn__z) {
  transform-box: fill-box;
  transform-origin: 0% 100%;
}

/* Er lehnt sich für Gesten und Sprüche über den Tresen (wächst von der Tresenkante aus). */
.ipf-lean { transition: transform 420ms cubic-bezier(0.2, 1.3, 0.4, 1); }
.ipf.is-on .ipf-lean { transform: scale(1.08); }

/* idle: poliert langsam ein Glas (Tuch-Hand kreist, das Glas dreht sich ein wenig). */
.ipf[data-gesture="idle"] .ipf-finn__arm--r { animation: ipf-polish 2.4s ease-in-out infinite; }
.ipf[data-gesture="idle"] .ipf-finn__glass { animation: ipf-glass 4.8s ease-in-out infinite; }
@keyframes ipf-polish {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(6deg); }
}
@keyframes ipf-glass {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}
/* Er spricht: der Kopf nickt im Satz. */
.ipf.is-talking .ipf-finn__head { animation: ipf-talk 0.46s ease-in-out infinite alternate; }
@keyframes ipf-talk {
  from { transform: rotate(-3deg); }
  to { transform: rotate(3deg) translateY(1px); }
}

/* wonder: deutlich (auch bei 1280×720): lehnt sich weiter vor, zuckt zurück, die rechte Braue schnellt zweimal hoch, der Kopf legt sich
   schief, die Staunstriche blitzen dreimal auf. */
.ipf[data-gesture="wonder"].is-on .ipf-lean { transform: scale(1.14); }
.ipf[data-gesture="wonder"] .ipf-finn__body { animation: ipf-jolt 900ms cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.ipf[data-gesture="wonder"] .ipf-finn__brow--r { animation: ipf-brow 1100ms ease-in-out 200ms 2 both; }
.ipf[data-gesture="wonder"] .ipf-finn__brow--l { animation: ipf-brow-l 1100ms ease-in-out 200ms 2 both; }
.ipf[data-gesture="wonder"] .ipf-finn__head { animation: ipf-tilt 2600ms ease-in-out both; }
.ipf[data-gesture="wonder"] .ipf-finn__pop { animation: ipf-pop 760ms ease-out 3 both; }
/* Fragezeichen in Messing über dem Kopf: ploppt auf, wackelt, bleibt bis zum Ende der Geste. */
.ipf .ipf-mark { transform-box: fill-box; transform-origin: 50% 100%; }
.ipf[data-gesture="wonder"] .ipf-mark { animation: ipf-mark 2800ms cubic-bezier(0.2, 1.5, 0.4, 1) both; }
@keyframes ipf-mark {
  0% { opacity: 0; transform: scale(0.3); }
  12% { opacity: 1; transform: scale(1.15); }
  20% { transform: scale(1) rotate(0deg); }
  35% { transform: rotate(-10deg); }
  50% { transform: rotate(8deg); }
  65% { transform: rotate(-4deg); }
  80%, 92% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: scale(0.9); }
}
@keyframes ipf-jolt {
  0% { transform: none; }
  30% { transform: translateY(-10px) scale(0.97, 1.05); }
  60% { transform: translateY(0) scale(1.03, 0.97); }
  100% { transform: none; }
}
@keyframes ipf-brow {
  0%, 100% { transform: none; }
  30%, 70% { transform: translateY(-6px) rotate(-10deg) scale(1.15); }
}
@keyframes ipf-brow-l {
  0%, 100% { transform: none; }
  30%, 70% { transform: translateY(2px) rotate(6deg); }
}
@keyframes ipf-tilt {
  0% { transform: none; }
  20%, 80% { transform: rotate(9deg) translateX(3px); }
  100% { transform: none; }
}
@keyframes ipf-pop {
  0% { opacity: 0; transform: scale(0.6); }
  35% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.45); }
}

/* facepalm: sackt zusammen, schüttelt langsam den Kopf. */
.ipf[data-gesture="facepalm"] .ipf-finn__body { animation: ipf-sag 3000ms ease-in-out both; }
.ipf[data-gesture="facepalm"] .ipf-finn__head { animation: ipf-shake 0.7s ease-in-out 300ms 3 alternate both; }
.ipf[data-gesture="facepalm"] .ipf-finn__pop { animation: ipf-drip 1400ms ease-in 400ms 2 both; }
@keyframes ipf-sag {
  0%, 100% { transform: none; }
  20%, 80% { transform: scale(1.02, 0.95); }
}
@keyframes ipf-shake {
  from { transform: rotate(-6deg); }
  to { transform: rotate(6deg); }
}
@keyframes ipf-drip {
  0% { opacity: 0; transform: translateY(-4px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(14px); }
}

/* thumbs: hüpft, die Daumen pumpen dreimal. */
.ipf[data-gesture="thumbs"] .ipf-finn__body { animation: ipf-hop 0.52s ease-out 3 both; }
.ipf[data-gesture="thumbs"] .ipf-finn__arm--l { animation: ipf-pump-l 0.52s ease-in-out 3 both; }
.ipf[data-gesture="thumbs"] .ipf-finn__arm--r { animation: ipf-pump-r 0.52s ease-in-out 3 both; }
@keyframes ipf-hop {
  0%, 100% { transform: none; }
  45% { transform: translateY(-8px); }
}
@keyframes ipf-pump-l {
  0%, 100% { transform: none; }
  50% { transform: rotate(-12deg); }
}
@keyframes ipf-pump-r {
  0%, 100% { transform: none; }
  50% { transform: rotate(12deg); }
}

/* sway: wippt im Takt (Dauerschleife), Noten steigen auf. */
.ipf[data-gesture="sway"] .ipf-finn__swing { animation: ipf-sway 1.2s ease-in-out infinite; }
.ipf[data-gesture="sway"] .ipf-finn__note { animation: ipf-note 2.4s ease-out infinite; animation-delay: calc(var(--i, 0) * -1.2s); }
@keyframes ipf-sway {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}
@keyframes ipf-note {
  0% { opacity: 0; transform: translateY(10px); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-34px); }
}

/* sleep: döst auf dem Tresen, Zzz steigen nacheinander. */
.ipf[data-gesture="sleep"] .ipf-finn__z { animation: ipf-zzz 2.7s ease-in-out infinite; animation-delay: calc(var(--i, 0) * -0.9s); }
@keyframes ipf-zzz {
  0% { opacity: 0; transform: translateY(6px) scale(0.8); }
  30%, 70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px) scale(1.1); }
}

/* wave: die Hand winkt viermal. */
.ipf[data-gesture="wave"] .ipf-finn__arm--r { animation: ipf-wave 0.5s ease-in-out 6 alternate both; }
@keyframes ipf-wave {
  from { transform: rotate(-10deg); }
  to { transform: rotate(12deg); }
}

/* bow: verbeugt sich tiefer und richtet sich wieder auf. */
.ipf[data-gesture="bow"] .ipf-finn__bow { animation: ipf-bow 3200ms ease-in-out both; }
@keyframes ipf-bow {
  0%, 100% { transform: none; }
  30%, 70% { transform: translateY(var(--bow, 8px)) scale(1, 0.96); }
}

/* Antwortzeit: Finn steht still (keine Bewegung, während gelesen wird). */
.pq-themeanim[data-pq-themeanim="irishpub"][data-phase="question"] .ipf * { animation: none !important; transition: none !important; }

/* ---------------------------------------------------------------- Sprechblase (W2) */
.pq-themeanim .ipf-talk {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ipf-bubble {
  position: absolute;
  z-index: 1;
  box-sizing: border-box;
  width: max-content;
  max-width: 19vw;
  padding: 1.2vh 1.7vh;
  border: 0.42vh solid #c9a24a;
  border-radius: 2.2vh;
  background: #f4f1e8;
  box-shadow: 0 0.6vh 0 #1f5a3c, 0 1.4vh 3vh rgba(12, 8, 4, 0.5);
  color: #1d1a24;
  font: 800 3vh/1.18 Inter, system-ui, sans-serif;
  text-align: left;
  transform-origin: 80% 100%;
}
.ipf-bubble[data-size="sm"] { font-size: 2.5vh; max-width: 14vw; padding: 0.9vh 1.2vh; }
/* Schwänzchen zu Finn. */
.ipf-bubble::after {
  content: "";
  position: absolute;
  width: 2vh;
  height: 2vh;
  background: #f4f1e8;
  border: solid #c9a24a;
  border-width: 0 0.42vh 0.42vh 0;
}
.ipf-bubble[data-at="up"] { transform-origin: 25% 100%; }
.ipf-bubble[data-at="up"]::after { left: 22%; bottom: -1.24vh; transform: rotate(45deg); }
.ipf-bubble[data-at="upr"]::after { right: 12%; bottom: -1.24vh; transform: rotate(45deg); }
.ipf-bubble[data-at="upright"] { transform-origin: 0% 100%; }
.ipf-bubble[data-at="upright"]::after { left: 1.6vh; bottom: -1.24vh; transform: rotate(45deg); }
.ipf-bubble[data-at="upleft"] { transform-origin: 100% 100%; }
.ipf-bubble[data-at="upleft"]::after { right: 12%; bottom: -1.24vh; transform: rotate(45deg); }
.ipf-bubble[data-at="left"] { transform-origin: 100% 30%; }
.ipf-bubble[data-at="left"]::after { right: -1.24vh; top: 1.6vh; transform: rotate(-45deg); }
.ipf-bubble[data-state="in"] { animation: ipf-bubble-in 300ms cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.ipf-bubble[data-state="out"] { animation: ipf-bubble-out 240ms ease-in both; }
@keyframes ipf-bubble-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: none; }
}
@keyframes ipf-bubble-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: scale(0.85); }
}

/* ---------------------------------------------------------------- Die Stammgäste reagieren (W3) */
.ipa-scene :is(.ipa-guest__fig, .ipa-guest__head, .ipa-guest__arm) {
  transform-box: view-box;
  transform-origin: 0 0;
}
/* Jubeln: beide Arme hoch, zwei kleine Hüpfer. */
.ipa-guest.is-react-cheer .ipa-guest__fig { animation: ipr-hop 0.55s ease-out var(--ipr-dl, 0ms) 3 both; }
.ipa-guest.is-react-cheer .ipa-guest__arm--drink { animation: ipr-up-r 2200ms ease-in-out var(--ipr-dl, 0ms) both; }
.ipa-guest.is-react-cheer .ipa-guest__arm--free { animation: ipr-up-l 2200ms ease-in-out var(--ipr-dl, 0ms) both; }
@keyframes ipr-hop {
  0%, 100% { transform: none; }
  45% { transform: translateY(-12px); }
}
@keyframes ipr-up-r {
  0%, 100% { transform: none; }
  18%, 82% { transform: rotate(-150deg); }
}
@keyframes ipr-up-l {
  0%, 100% { transform: none; }
  18%, 82% { transform: rotate(150deg); }
}
/* Stöhnen: der Kopf sinkt, die freie Hand fährt an die Stirn. */
.ipa-guest.is-react-groan .ipa-guest__head { animation: ipr-droop 2400ms ease-in-out var(--ipr-dl, 0ms) both; }
.ipa-guest.is-react-groan .ipa-guest__arm--free { animation: ipr-brow 2400ms ease-in-out var(--ipr-dl, 0ms) both; }
@keyframes ipr-droop {
  0%, 100% { transform: none; }
  20%, 80% { transform: translateY(6px) rotate(-10deg); }
}
@keyframes ipr-brow {
  0%, 100% { transform: none; }
  20%, 80% { transform: rotate(160deg); }
}
/* Kopfschütteln (falsche Mehrheit). */
.ipa-guest.is-react-shake .ipa-guest__head { animation: ipr-shake 0.42s ease-in-out var(--ipr-dl, 0ms) 5 alternate both; }
@keyframes ipr-shake {
  from { transform: rotate(-9deg); }
  to { transform: rotate(9deg); }
}
/* Zuprosten (Überholen): das Glas hebt sich zum Nachbarn. */
.ipa-guest.is-react-toast .ipa-guest__arm--drink { animation: ipr-toast 2000ms ease-in-out var(--ipr-dl, 0ms) both; }
.ipa-guest.is-react-toast .ipa-guest__head { animation: ipr-nod 2000ms ease-in-out var(--ipr-dl, 0ms) both; }
@keyframes ipr-toast {
  0%, 100% { transform: none; }
  25%, 75% { transform: rotate(-95deg); }
  45% { transform: rotate(-88deg); }
}
@keyframes ipr-nod {
  0%, 100% { transform: none; }
  30%, 70% { transform: rotate(6deg); }
}

/*
 * Last Call: die Pint-Pyramide steht vor dem Zapfhahn, Finn tritt so lange zur Seite (blendet aus), statt mit Armen hinter den Gläsern
 * hervorzuschauen. Nur in der Einstellung, die die Tafel zeigt (`data-shot="board"`): Die Tafel hängt schon ab dem Podest im DOM, dort und
 * in den Großaufnahmen bleibt Finn sichtbar (Review W1). Die Sprechblase geht mit; finnHost.hidden() wertet die Deckkraft als verdeckt.
 */
:is(.ipf, .ipf-talk) { transition: opacity 600ms ease; }
.view-stage[data-pq-theme="irishpub"]:has(.pq-celebration[data-shot="board"]) :is(.ipf, .ipf-talk) { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  :is(.ipf, .ipf-talk) { transition: none; }
}
