/* Start-screen mascots. The gator's mood follows #stage[data-level] (0 = suspicious,
   3 = full evil grin); the resident and the page theme follow body[data-difficulty]. */

.stage {
  position: relative;
  padding: 12px 8px 0;
  border-radius: 18px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.08));
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.6s, border-color 0.6s, box-shadow 0.6s;
}

.bubble {
  position: relative;
  width: fit-content;
  max-width: 85%;
  margin: 0 0 6px 8px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #f5f5f5;
  color: #111;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
  transition: background 0.6s, color 0.6s;
}
.bubble::after {
  content: "";
  position: absolute;
  left: 36px;
  bottom: -8px;
  border: 8px solid transparent;
  border-bottom: 0;
  border-top-color: var(--bubble-bg, #f5f5f5);
}
.bubble.pop { animation: pop 0.25s ease-out; }
@keyframes pop {
  from { transform: scale(0.92); }
  to   { transform: scale(1); }
}

.cast { display: flex; justify-content: space-between; align-items: flex-end; }
.cast svg { width: 46%; height: auto; display: block; overflow: visible; }

/* ---------- Gator ---------- */

.g-skin { fill: #5cae4a; }
.g-line { fill: none; stroke: #1f3d22; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.g-iris { fill: #f6d44a; transition: fill 0.6s; }
.g-pupil { fill: #1b1b1b; transition: fill 0.6s; }
.g-tooth { fill: #fff; stroke: #1f3d22; stroke-width: 1; stroke-linejoin: round; }
.g-lid { fill: #4f9e3f; stroke: #1f3d22; stroke-width: 2.5; }
.g-brow { fill: none; stroke: #1f3d22; stroke-width: 5; stroke-linecap: round; }

.g-lid, .g-brow, .g-pupil, .g-head {
  transform-box: fill-box;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.g-lid { transform-origin: 50% 100%; }
.g-brow, .g-pupil { transform-origin: center; }
.g-head { transform-origin: 50% 100%; }

.g-mouth { opacity: 0; transition: opacity 0.2s; }
.g-glint { fill: #fff; opacity: 0; transform-box: fill-box; transform-origin: center; }

/* 0: suspicious squint, one brow up, shifty eyes */
.stage[data-level="0"] .g-lid     { transform: translateY(11px); }
.stage[data-level="0"] .g-brow-l  { transform: translateY(-5px) rotate(-10deg); }
.stage[data-level="0"] .g-brow-r  { transform: translateY(3px); }
.stage[data-level="0"] .g-pupil   { animation: shifty 2.4s ease-in-out infinite; }
.stage[data-level="0"] .m0        { opacity: 1; }

/* 1: a little smirk */
.stage[data-level="1"] .g-lid-l   { transform: translateY(9px) rotate(10deg); }
.stage[data-level="1"] .g-lid-r   { transform: translateY(9px) rotate(-10deg); }
.stage[data-level="1"] .g-brow-l  { transform: translateY(2px) rotate(10deg); }
.stage[data-level="1"] .g-brow-r  { transform: translateY(2px) rotate(-10deg); }
.stage[data-level="1"] .m1        { opacity: 1; }

/* 2: toothy smirk, head tilts */
.stage[data-level="2"] .g-lid-l   { transform: translateY(9px) rotate(18deg); }
.stage[data-level="2"] .g-lid-r   { transform: translateY(9px) rotate(-18deg); }
.stage[data-level="2"] .g-brow-l  { transform: translateY(4px) rotate(18deg); }
.stage[data-level="2"] .g-brow-r  { transform: translateY(4px) rotate(-18deg); }
.stage[data-level="2"] .g-head    { transform: rotate(-3deg); }
.stage[data-level="2"] .m2        { opacity: 1; }

/* 3: comically evil grin, chuckling, gleaming tooth */
.stage[data-level="3"] .g-lid-l   { transform: translateY(11px) rotate(24deg); }
.stage[data-level="3"] .g-lid-r   { transform: translateY(11px) rotate(-24deg); }
.stage[data-level="3"] .g-brow-l  { transform: translateY(5px) rotate(26deg); }
.stage[data-level="3"] .g-brow-r  { transform: translateY(5px) rotate(-26deg); }
.stage[data-level="3"] .g-pupil   { transform: scaleX(0.7); }
.stage[data-level="3"] .g-head    { animation: chuckle 0.3s ease-in-out infinite alternate; }
.stage[data-level="3"] .m3        { opacity: 1; }
.stage[data-level="3"] .g-glint   { animation: glint 1.6s ease-in-out infinite; }

@keyframes shifty {
  0%, 20%   { transform: translateX(-4px); }
  45%, 65%  { transform: translateX(4px); }
  90%, 100% { transform: translateX(-4px); }
}
@keyframes chuckle {
  from { transform: rotate(-4deg) translateY(0); }
  to   { transform: rotate(-4deg) translateY(-3px); }
}
@keyframes glint {
  0%, 60%, 100% { opacity: 0; transform: scale(0.3) rotate(0deg); }
  75%           { opacity: 1; transform: scale(1) rotate(45deg); }
}

/* ---------- Resident (everyday adult) ---------- */

.e-line { fill: none; stroke: #3b2a20; stroke-width: 3; stroke-linecap: round; }
.e-brow { fill: none; stroke: #4a3022; stroke-width: 3.5; stroke-linecap: round; transform-box: fill-box; transform-origin: center; transition: transform 0.35s; }
.e-mouth, .e-eyes-happy, .e-eyes-dot, .e-sweat { opacity: 0; transition: opacity 0.25s; }
.e-sweat { fill: #7cc6ff; }
.e-eyes-dot { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
.e-body { transform-box: fill-box; transform-origin: 50% 100%; animation: breathe 3s ease-in-out infinite; }

/* easy (and default): cheerful and trusting */
body:not([data-difficulty="medium"]):not([data-difficulty="hard"]) .e-eyes-happy,
body:not([data-difficulty="medium"]):not([data-difficulty="hard"]) .e-happy { opacity: 1; }

/* medium: curious */
body[data-difficulty="medium"] .e-eyes-dot,
body[data-difficulty="medium"] .e-curious { opacity: 1; }
body[data-difficulty="medium"] .e-brow-l { transform: translateY(-3px); }

/* hard: worried, sweating, trembling */
body[data-difficulty="hard"] .e-eyes-dot,
body[data-difficulty="hard"] .e-worried,
body[data-difficulty="hard"] .e-sweat { opacity: 1; }
body[data-difficulty="hard"] .e-brow-l { transform: rotate(-16deg); }
body[data-difficulty="hard"] .e-brow-r { transform: rotate(16deg); }
body[data-difficulty="hard"] .e-body { animation: tremble 0.15s linear infinite; }

@keyframes breathe {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(1.015); }
}
@keyframes blink {
  0%, 94%, 100% { transform: scaleY(1); }
  97%           { transform: scaleY(0.1); }
}
@keyframes tremble {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-1px); }
  75%      { transform: translateX(1px); }
}

/* ---------- Difficulty themes ---------- */

body[data-difficulty="easy"]   { --glow: rgba(52, 199, 89, 0.16);  --accent: #25935d; }
body[data-difficulty="medium"] { --glow: rgba(250, 178, 25, 0.16); --accent: #d9781a; }
body[data-difficulty="hard"]   { --glow: rgba(255, 30, 30, 0.38);  --accent: #d91e2a; }

/* Hard: red vignette that pulses, glowing red eyes, menacing speech bubble */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 140px rgba(255, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.6s;
}
body[data-difficulty="hard"]::after { opacity: 1; animation: menace 2.4s ease-in-out infinite; }
@keyframes menace {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

body[data-difficulty="hard"] h1 { text-shadow: 0 0 18px rgba(255, 40, 40, 0.7); }
body[data-difficulty="hard"] .stage {
  background: linear-gradient(to bottom, rgba(120, 0, 0, 0.25), rgba(40, 0, 0, 0.6));
  border-color: rgba(255, 60, 60, 0.4);
  box-shadow: 0 0 28px rgba(255, 0, 0, 0.25);
}
body[data-difficulty="hard"] .bubble { background: #1a0000; color: #ff5a5a; --bubble-bg: #1a0000; }
body[data-difficulty="hard"] .g-iris { fill: #2a0505; }
body[data-difficulty="hard"] .g-pupil { fill: #ff2a2a; filter: drop-shadow(0 0 3px #ff0000); }
body[data-difficulty="hard"] input,
body[data-difficulty="hard"] select { border-color: rgba(255, 60, 60, 0.45); }

.stage.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px) rotate(-1deg); }
  40%      { transform: translateX(6px) rotate(1deg); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* ---------- Ringing screen ---------- */

.ring-stage { width: 100%; margin-top: 12px; text-align: left; }
.ring-stage + .call-actions { margin-top: 40px; }

/* Gator's disguise: official cap with a badge, and a fake mustache */
.g-cap { fill: #1f2d4a; }
.g-cap-brim { fill: #15203a; }
.g-badge { fill: #f6d44a; stroke: #b8901c; stroke-width: 1; }
.g-stache { fill: #2a1a10; }

/* Resident's phone buzzes while the call rings */
.e-phone { transform-box: fill-box; transform-origin: 50% 100%; animation: buzz 0.4s ease-in-out infinite; }
.e-buzz { fill: none; stroke: #9fd3ff; stroke-width: 2.5; stroke-linecap: round; animation: buzz-fade 0.8s ease-in-out infinite; }
@keyframes buzz {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-7deg); }
  75%      { transform: rotate(7deg); }
}
@keyframes buzz-fade {
  0%, 100% { opacity: 0.2; }
  50%      { opacity: 1; }
}

/* ---------- In-call screen ---------- */

.call-stage { width: 100%; margin-top: 8px; }
.call-stage + #call-status { margin-top: 4px; }
#call-stage .e-phone { animation: none; }

/* Sound waves above the gator while the agent is speaking */
.waves {
  position: absolute;
  left: 38%;
  top: 16px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}
.waves span {
  width: 4px;
  height: 100%;
  border-radius: 2px;
  background: #f5f5f5;
  transform-origin: bottom;
  animation: wave 0.45s ease-in-out infinite alternate;
}
.waves span:nth-child(2) { animation-delay: 0.15s; }
.waves span:nth-child(3) { animation-delay: 0.3s; }
.call-stage.talking .waves { opacity: 1; }
@keyframes wave {
  from { transform: scaleY(0.3); }
  to   { transform: scaleY(1); }
}

/* Gator talking: toothy mouth (level 2) opening and closing */
.call-stage.talking .m2 {
  transform-box: fill-box;
  transform-origin: 50% 0;
  animation: jaw 0.22s ease-in-out infinite alternate;
}
@keyframes jaw {
  from { transform: scaleY(0.35); }
  to   { transform: scaleY(1); }
}

/* Gator listening: leans in with shifty eyes */
.call-stage.listening .g-head { transform: rotate(5deg) translateX(3px); }
.call-stage.listening .g-pupil { animation: shifty 2.4s ease-in-out infinite; }

/* Resident: talking mouth while you speak, zipped mouth while muted */
.e-talk, .e-zip { opacity: 0; transition: opacity 0.15s; }
.e-talk { fill: #7a2e2e; stroke: #3b2a20; stroke-width: 2; transform-box: fill-box; transform-origin: center; }
#call-stage.user-talking .e-mouth,
#call-stage.muted .e-mouth { opacity: 0; }
#call-stage.user-talking .e-talk { opacity: 1; animation: jaw 0.2s ease-in-out infinite alternate; }
#call-stage.muted .e-zip { opacity: 1; }

/* ---------- Recap: ending scene ---------- */

.recap-stage { margin-top: 4px; }
#recap-stage .e-phone { display: none; }
#recap-stage .e-body { animation: breathe 3s ease-in-out infinite; }

/* Resident's face is set by the result, not the difficulty */
#recap-stage.win .e-mouth, #recap-stage.win .e-eyes-dot, #recap-stage.win .e-sweat,
#recap-stage.lose .e-mouth, #recap-stage.lose .e-eyes-happy,
#recap-stage.stopped .e-mouth, #recap-stage.stopped .e-eyes-happy, #recap-stage.stopped .e-sweat { opacity: 0; }
#recap-stage.win .e-happy, #recap-stage.win .e-eyes-happy,
#recap-stage.lose .e-worried, #recap-stage.lose .e-eyes-dot, #recap-stage.lose .e-sweat,
#recap-stage.stopped .e-happy, #recap-stage.stopped .e-eyes-dot { opacity: 1; }

/* Pass: resident hops for joy; the disguise falls off and the gator slinks away */
#recap-stage.win .e-body { animation: hop 0.5s ease-in-out 0.2s 3; }
#recap-stage.win .g-cap,
#recap-stage.win .g-cap-brim,
#recap-stage.win .g-badge { transform-box: fill-box; transform-origin: center; animation: cap-fall 0.9s ease-in 0.4s forwards; }
#recap-stage.win .g-stache { transform-box: fill-box; transform-origin: 0 0; animation: stache-peel 0.7s ease-in 0.9s forwards; }
#recap-stage.win .gator { animation: slink 1s ease-in-out 1.3s forwards; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
@keyframes cap-fall {
  to { transform: translate(-24px, 90px) rotate(-70deg); opacity: 0; }
}
@keyframes stache-peel {
  to { transform: translateY(40px) rotate(35deg); opacity: 0; }
}
@keyframes slink {
  to { transform: translateX(-10%) scale(0.92); opacity: 0.6; }
}

/* Fail: resident is stunned */
#recap-stage.lose .e-body { animation: tremble 0.15s linear 6; }

@media (prefers-reduced-motion: reduce) {
  .stage *, .stage, body::after { animation: none !important; }
}
