/* ==========================================================================
   Custom keyframes for what animate.css does not cover.
   Confetti and the NOPE stamp arrive in the animations pass.
   ========================================================================== */

@keyframes ays-sweep-left {
  0%, 100% { transform: rotate(-30deg); }
  50% { transform: rotate(-14deg); }
}

@keyframes ays-sweep-right {
  0%, 100% { transform: rotate(30deg); }
  50% { transform: rotate(14deg); }
}

@keyframes ays-bulbs {
  to { background-position: 20px 0; }
}

.spotlights span:nth-child(1) {
  animation: ays-sweep-left 9s ease-in-out infinite;
}

.spotlights span:nth-child(2) {
  animation: ays-sweep-right 11s ease-in-out infinite;
}

.bulbs {
  animation: ays-bulbs 1.2s steps(2) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spotlights span,
  .bulbs {
    animation: none !important;
  }
}

/* Chip: quick squash-and-stretch on the whole head when his expression changes. */
@keyframes chip-squash {
  0% { transform: scale(1, 1); }
  22% { transform: scale(1.12, 0.86); }
  50% { transform: scale(0.94, 1.08); }
  75% { transform: scale(1.03, 0.98); }
  100% { transform: scale(1, 1); }
}

.chip.is-bouncing .chip-body {
  animation: chip-squash 0.42s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .chip.is-bouncing .chip-body {
    animation: none;
  }
}

/* Results: the fake "Calculating your disappointment..." spinner. */
@keyframes ays-spin {
  to { transform: rotate(360deg); }
}

@keyframes ays-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.calc-spinner {
  animation: ays-spin 0.8s linear infinite;
}

.calc-text {
  animation: ays-pulse 1.2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .calc-spinner,
  .calc-text {
    animation: none;
  }
}

/* ---------- Plain fade: the entrance that survives reduced motion ---------- */
@keyframes ays-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.ays-fade {
  animation: ays-fade-in 0.25s ease-out both;
}

/* ---------- Confetti that rises and turns into the letter L ---------- */
.ays-confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}

.ays-confetti i {
  position: absolute;
  bottom: -24px;
  left: var(--x);
  width: 12px;
  height: 16px;
  animation: ays-rise var(--dur) cubic-bezier(0.15, 0.75, 0.3, 1) var(--delay) both;
}

/* The paper bit... */
.ays-confetti i::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background: var(--c);
  animation: ays-bit-out var(--dur) linear var(--delay) both;
}

/* ...becomes an L. */
.ays-confetti i::after {
  content: 'L';
  position: absolute;
  left: 50%;
  top: 50%;
  color: var(--c);
  font-family: var(--font-display);
  font-size: 1.7rem;
  line-height: 1;
  text-shadow: 2px 2px 0 var(--bg-sunk);
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0;
  animation: ays-l-in var(--dur) ease-out var(--delay) both;
}

@keyframes ays-rise {
  0% { transform: translate(0, 0) rotate(var(--spin)); opacity: 1; }
  70% { transform: translate(var(--dx), calc(-1 * var(--rise))) rotate(var(--tilt)); opacity: 1; }
  100% { transform: translate(var(--dx), calc(-1 * var(--rise) - 3vh)) rotate(var(--tilt)); opacity: 0; }
}

@keyframes ays-bit-out {
  0%, 40% { opacity: 1; transform: scale(1); }
  52%, 100% { opacity: 0; transform: scale(0.3); }
}

@keyframes ays-l-in {
  0%, 40% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
  56% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  66%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- Giant NOPE stamp ---------- */
.ays-stamp {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.ays-stamp span {
  padding: 0 0.25em;
  border: 6px solid var(--red);
  border-radius: 14px;
  background: rgba(18, 18, 42, 0.72);
  color: var(--red);
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 18vw, 5rem);
  line-height: 1.1;
  letter-spacing: 0.04em;
  transform: rotate(-12deg);
  animation: ays-stamp-slam 0.42s cubic-bezier(0.2, 1.5, 0.4, 1) both, ays-stamp-out 0.3s ease-in 1s forwards;
}

@keyframes ays-stamp-slam {
  0% { opacity: 0; transform: rotate(-26deg) scale(3); }
  60% { opacity: 1; transform: rotate(-9deg) scale(0.88); }
  100% { opacity: 1; transform: rotate(-12deg) scale(1); }
}

@keyframes ays-stamp-out {
  to { opacity: 0; }
}

/* The card takes the hit. */
@keyframes ays-thud {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(5px) scale(0.99); }
}

.ays-thud {
  animation: ays-thud 0.3s ease-out 0.22s;
}

/* ---------- Answer buttons that quit (after animate.css hinge) ---------- */
.answer.is-quit {
  visibility: hidden;
}

/* ---------- Stage light sweeping behind the question card ---------- */
@keyframes ays-card-sweep {
  from { transform: translateX(-50%) rotate(-28deg); }
  to { transform: translateX(-50%) rotate(28deg); }
}

.play-main {
  position: relative;
  isolation: isolate;
}

.play-main::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: -60px;
  left: 50%;
  width: min(80%, 420px);
  height: 380px;
  background: linear-gradient(to bottom, rgba(255, 214, 10, 0.22), rgba(255, 214, 10, 0));
  clip-path: polygon(44% 0, 56% 0, 100% 100%, 0 100%);
  transform-origin: 50% 0;
  transform: translateX(-50%);
  filter: blur(4px);
  pointer-events: none;
  animation: ays-card-sweep 6s ease-in-out infinite alternate;
  transition: background 0.3s ease;
}

.play-main.is-right::before {
  background: linear-gradient(to bottom, rgba(45, 226, 230, 0.3), rgba(45, 226, 230, 0));
}

.play-main.is-wrong::before {
  background: linear-gradient(to bottom, rgba(255, 77, 46, 0.3), rgba(255, 77, 46, 0));
}

@media (prefers-reduced-motion: reduce) {
  .play-main::before {
    animation: none;
  }

  /* The stamp still appears, but fades instead of slamming. */
  .ays-stamp span {
    animation: ays-fade-in 0.2s ease-out both, ays-stamp-out 0.3s ease-in 1s forwards;
  }

  .ays-thud {
    animation: none;
  }

  .ays-confetti {
    display: none;
  }
}

/* ---------- Results: the Shrinking Brain card crashes in from above ----------
   1.2s: falls with gravity (ease-in) from fully off-screen, squashes on impact
   (scaleY 0.92) with a 2 degree tilt, then two smaller bounces as the tilt
   straightens out. Bottom-centered origin so squashes sit on the floor. */
@keyframes ays-thumb-crash {
  0% { transform: translateY(-120vh) rotate(-2deg); animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  37% { transform: translateY(0) rotate(-2deg) scaleY(0.92); animation-timing-function: ease-out; }
  45% { transform: translateY(0) rotate(-2deg) scaleY(1); animation-timing-function: ease-out; }
  58% { transform: translateY(-48px) rotate(-1.2deg); animation-timing-function: ease-in; }
  70% { transform: translateY(0) rotate(-0.8deg) scaleY(0.96); animation-timing-function: ease-out; }
  77% { transform: translateY(0) rotate(-0.6deg) scaleY(1); animation-timing-function: ease-out; }
  86% { transform: translateY(-16px) rotate(-0.3deg); animation-timing-function: ease-in; }
  94% { transform: translateY(0) rotate(0deg) scaleY(0.985); animation-timing-function: ease-out; }
  100% { transform: none; }
}

.thumb-card.is-crashing {
  animation: ays-thumb-crash 1.2s both;
  position: relative;
  z-index: 20;
  pointer-events: none;
}

/* The page takes the hit on the first impact. */
@keyframes ays-page-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-9px); }
  35% { transform: translateX(8px); }
  55% { transform: translateX(-6px); }
  75% { transform: translateX(4px); }
  90% { transform: translateX(-2px); }
}

.ays-page-shake {
  animation: ays-page-shake 0.3s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .thumb-card.is-crashing,
  .ays-page-shake {
    animation: none;
  }
}

/* ---------- Chip's accessories: slow idle motion (decoration only) ---------- */

/* Propeller beanie: the blades seen side-on, so a spin is a slow horizontal flip. */
@keyframes acc-spin {
  0% { transform: scaleX(1); }
  50% { transform: scaleX(-1); }
  100% { transform: scaleX(1); }
}

.chip-acc .acc-prop {
  transform-box: fill-box;
  transform-origin: center;
  animation: acc-spin 2.6s linear infinite;
}

/* Robot antenna: the light blinks slowly. */
@keyframes acc-blink {
  0%, 55%, 100% { opacity: 1; }
  70%, 85% { opacity: 0.25; }
}

.chip-acc .acc-blink {
  animation: acc-blink 3s ease-in-out infinite;
}

/* Light bulb: the glow breathes. */
@keyframes acc-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 0.8; transform: scale(1.08); }
}

.chip-acc .acc-glow {
  transform-box: fill-box;
  transform-origin: center;
  animation: acc-pulse 3.4s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .chip-acc .acc-prop,
  .chip-acc .acc-blink,
  .chip-acc .acc-glow {
    animation: none;
  }
}
