:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;

  --bg: #150d13;
  --bg-glow: #2a1422;
  --pig: #ffa3c4;
  --pig-deep: #e0759d;
  --display: "Bagel Fat One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
}

html {
  height: 100%;
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  margin: 0;
  padding: 0;
  padding-inline: 16px;
  height: 100%;
  font: 14px -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(ellipse 60% 50% at 50% 55%, var(--bg-glow), var(--bg) 70%) var(--bg);
  color: var(--pig);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: clamp(0.75rem, 3vw, 1.75rem);
  overflow: hidden;
  box-sizing: border-box;
  text-align: center;
  font-family: var(--display);
}

img {
  max-width: 100%;
}

[hidden]:not([hidden=until-found i]) {
  display: none !important;
}

.stage {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25em 0.45em;
  font-size: clamp(3.5rem, 15vw, 11rem);
  line-height: 1;
  margin: 0;
  font-weight: 400;
  user-select: none;
}

.word {
  position: relative;
  display: inline-block;
  padding-bottom: 0.18em;
}

/* ---------- Hopping pigs ----------
   Pure CSS keyframes animating only transform + opacity, so the browser
   runs them on the compositor thread instead of the main thread.

   Each loop STARTS at the moment of landing (0% / 100%), so the
   `animationiteration` event fires exactly when a pig hits the floor.
   script.js listens for it to play the sound.

   Cycle:  0% land → 9% squash → 18% take off → 59% apex → 100% land     */

.shadow {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 0;
  height: 0.15em;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 163, 196, 0.4) 0%, transparent 70%);
  transform-origin: center;
  animation: pig-shadow 1050ms infinite;
}

.word .text {
  display: inline-block;
  transform-origin: 50% 100%;
  /* Hard (unblurred) offsets only: a large blurred glow on huge,
     constantly transforming text is the most expensive thing to paint. */
  text-shadow:
    0 0.03em 0 var(--pig-deep),
    0 0.06em 0 var(--pig-deep);
  animation: hop-a 1050ms infinite;
}

/* Second pig: different rhythm, mirrored tilt, phase offset
   (negative delay = start partway through the cycle). */
.word:nth-child(2) .text {
  animation: hop-b 1310ms -485ms infinite;
}

.word:nth-child(2) .shadow {
  animation-duration: 1310ms;
  animation-delay: -485ms;
}

/* Easing notes:
   squash in  = cubic-bezier(0.61, 1, 0.88, 1)   sine ease-out
   squash out = cubic-bezier(0.12, 0, 0.39, 0)   sine ease-in
   rise       = cubic-bezier(0.33, 0.67, 0.67, 1)  exact parabola going up
   fall       = cubic-bezier(0.33, 0, 0.67, 0.33)  exact parabola coming down */

@keyframes hop-a {
  0% {
    transform: translateY(0) rotate(-2deg) scale(1, 1);
    animation-timing-function: cubic-bezier(0.61, 1, 0.88, 1);
  }
  9% {
    transform: translateY(0) rotate(0deg) scale(1.16, 0.82);
    animation-timing-function: cubic-bezier(0.12, 0, 0.39, 0);
  }
  18% {
    transform: translateY(0) rotate(2deg) scale(1, 1);
    animation-timing-function: cubic-bezier(0.33, 0.67, 0.67, 1);
  }
  59% {
    transform: translateY(-0.32em) rotate(0deg) scale(0.955, 1.06);
    animation-timing-function: cubic-bezier(0.33, 0, 0.67, 0.33);
  }
  100% {
    transform: translateY(0) rotate(-2deg) scale(1, 1);
  }
}

@keyframes hop-b {
  0% {
    transform: translateY(0) rotate(2deg) scale(1, 1);
    animation-timing-function: cubic-bezier(0.61, 1, 0.88, 1);
  }
  9% {
    transform: translateY(0) rotate(0deg) scale(1.16, 0.82);
    animation-timing-function: cubic-bezier(0.12, 0, 0.39, 0);
  }
  18% {
    transform: translateY(0) rotate(-2deg) scale(1, 1);
    animation-timing-function: cubic-bezier(0.33, 0.67, 0.67, 1);
  }
  59% {
    transform: translateY(-0.26em) rotate(0deg) scale(0.955, 1.06);
    animation-timing-function: cubic-bezier(0.33, 0, 0.67, 0.33);
  }
  100% {
    transform: translateY(0) rotate(2deg) scale(1, 1);
  }
}

@keyframes pig-shadow {
  0% {
    transform: scaleX(1);
    opacity: 1;
  }
  18% {
    transform: scaleX(1);
    opacity: 1;
    animation-timing-function: cubic-bezier(0.33, 0.67, 0.67, 1);
  }
  59% {
    transform: scaleX(0.55);
    opacity: 0.4;
    animation-timing-function: cubic-bezier(0.33, 0, 0.67, 0.33);
  }
  100% {
    transform: scaleX(1);
    opacity: 1;
  }
}

/* ---------- Tagline ---------- */

.love {
  margin: 0;
  font-size: clamp(1.4rem, 4.5vw, 3rem);
  font-weight: 400;
  line-height: 1.1;
  text-wrap: balance;
  text-shadow:
    0 0.04em 0 var(--pig-deep),
    0 0 0.4em rgba(255, 163, 196, 0.2);
  transform-origin: 50% 60%;
  animation: wobble 2.6s ease-in-out infinite;
}

@keyframes wobble {
  0%, 100% { transform: rotate(0deg) scale(1, 1); }
  20%      { transform: rotate(-1.6deg) scale(1.015, 0.985); }
  45%      { transform: rotate(1.2deg) scale(0.99, 1.012); }
  70%      { transform: rotate(-0.6deg) scale(1.008, 0.994); }
  85%      { transform: rotate(0.3deg) scale(1, 1); }
}

/* ---------- Sound toggle ---------- */

.sound-toggle {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: calc(env(safe-area-inset-right, 0px) + 16px);
  z-index: 10;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 163, 196, 0.35);
  border-radius: 50%;
  background: rgba(42, 20, 34, 0.75);
  color: var(--pig);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s, background-color 0.2s, transform 0.15s;
}

.sound-toggle:hover {
  border-color: var(--pig);
}

.sound-toggle:active {
  transform: scale(0.92);
}

.sound-toggle:focus-visible {
  outline: 2px solid var(--pig);
  outline-offset: 3px;
}

.sound-toggle svg {
  width: 22px;
  height: 22px;
  display: block;
}

.sound-toggle[aria-pressed="true"] {
  background: rgba(224, 117, 157, 0.25);
  border-color: var(--pig);
}

.sound-toggle[aria-pressed="true"] .icon-off,
.sound-toggle[aria-pressed="false"] .icon-on {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .love,
  .word .text,
  .shadow {
    animation: none;
  }

  /* No hopping means no landings, so the sound button has nothing to do. */
  .sound-toggle {
    display: none;
  }
}
