/* ==========================================================================
   SAMLAR — "alive" layer
   Loaded on top of styles.css. Everything here is motion and
   the small layout changes needed because the art is inline SVG, not <img>.
   ========================================================================== */

/* ---- Buttons that wrap the art ------------------------------------------ */

.peep,
.cat__art {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* Own layer, so the constant motion never forces the textured card or
     ground line underneath to be repainted. */
  will-change: transform;
}

.peep svg,
.cat__art svg { display: block; width: 100%; height: auto; overflow: visible; }

.peep:focus-visible,
.cat__art:focus-visible {
  outline: 3px dashed var(--cream);
  outline-offset: 4px;
  border-radius: 16px;
}

/* Each person is two stacked drawings. The figure sits BEHIND the sign, so the
   sign's inked edge always shows in front of the body and no gap can open when
   the figure moves. The hands sit IN FRONT, resting on the edge. */
.peep { will-change: auto; }
/* Re-state the sink over the sign's edge here, because the button reset above
   zeroes all margins. Without it the hands hover above the paper. */
.card__peeker.peep { margin-bottom: calc(var(--peeker-w) * -0.0534); }
.peep__back  { position: relative; z-index: -3; }
.peep__front { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

/* Every moving SVG part pivots around a point given in its own drawing
   coordinates (--ox / --oy), set inline next to the shape. */
.cat__tail,
.cat__head,
.cat__ear,
.cat__breath {
  transform-box: view-box;
  transform-origin: var(--ox) var(--oy);
}

/* ---- People -------------------------------------------------------------- */

/* Pop up from behind the card on load */
.peep__figure {
  animation: peep-rise .9s cubic-bezier(.3, 1.5, .5, 1) backwards;
  transition: transform .5s cubic-bezier(.3, 1.6, .5, 1);
}
.card--samantha .peep__figure { animation-delay: .25s; }
.card--larry    .peep__figure { animation-delay: .55s; }

@keyframes peep-rise {
  from { transform: translateY(150px); }
  to   { transform: translateY(0); }
}

/* Hovering a sign lifts its person a little. Only the figure moves: the hands
   stay on the paper, and the body continues down behind the sign. */
.card:hover .peep__figure,
.card:focus-within .peep__figure { transform: translateY(-9px); }

/* Tap or click: duck behind the card, then pop back */
.peep.is-ducking .peep__figure {
  transform: translateY(140px);   /* just the hair left showing */
  transition: transform .22s ease-in;
}

/* Gentle idle bob */
.peep__bob { animation: peep-bob 4.6s ease-in-out infinite; }
.card--larry .peep__bob { animation-duration: 5.3s; animation-delay: -1.7s; }

@keyframes peep-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(3px); }
}

/* Hair */
.strand {
  transform-box: fill-box;
  animation: 3.2s ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * -0.37s);
}
.peep__hair--long .strand  { transform-origin: 100% 0%;  animation-name: hair-flow; }
.peep__hair--spiky .strand { transform-origin: 50% 100%; animation-name: hair-twitch; animation-duration: 2.4s; }

@keyframes hair-flow {
  from { transform: rotate(-2.5deg) scaleX(.98); }
  to   { transform: rotate(3deg) scaleX(1.03); }
}
@keyframes hair-twitch {
  from { transform: rotate(-6deg); }
  to   { transform: rotate(6deg); }
}

/* Hovering a card stirs up the wind */
.card:hover .peep__hair--long .strand  { animation-duration: 1.1s; }
.card:hover .peep__hair--spiky .strand { animation-duration: .8s; }

/* Hands give a little squeeze when their person is poked */
.peep__hands { transition: transform .2s ease; transform-box: fill-box; transform-origin: 50% 100%; }
.peep.is-ducking .peep__hands { transform: scaleY(.86); }

/* ---- Eyes (people and cats) --------------------------------------------- */

.eyes { transition: transform .18s ease-out; }       /* alive.js nudges these toward the pointer */

.eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 5.2s infinite;
}
.card--larry .eye    { animation-duration: 6.1s; animation-delay: -2s; }
.cat--lloyd .eye     { animation-duration: 4.4s; animation-delay: -1s; }
.cat--harry .eye     { animation-duration: 5.7s; animation-delay: -3s; }

@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  96%           { transform: scaleY(.08); }
}

/* ---- Cats ---------------------------------------------------------------- */

.cat__art { display: block; }
.cat__art        { width: clamp(5.6rem, 22vw, 11.5rem); }
.cat--lloyd .cat__art { width: clamp(5.15rem, 20.2vw, 10.6rem); }
.cat--kitty .cat__art { width: clamp(7.2rem, 29vw, 15rem); }

/* Harry is Lloyd's mirror image */
.cat__art.is-flipped svg { transform: scaleX(-1); }

.cat__art {
  transform-origin: 50% 100%;
  transition: transform .3s cubic-bezier(.3, 1.4, .5, 1);
}
.cat:hover .cat__art { transform: scale(1.04) rotate(-2deg); }
.cat__art.is-hopping { animation: cat-hop .55s cubic-bezier(.3, 1.3, .6, 1); }

@keyframes cat-hop {
  0%   { transform: translateY(0) scale(1, 1); }
  20%  { transform: translateY(0) scale(1.06, .92); }
  50%  { transform: translateY(-18%) scale(.97, 1.05); }
  80%  { transform: translateY(0) scale(1.05, .95); }
  100% { transform: translateY(0) scale(1, 1); }
}

/* Tails */
.cat__tail { animation: tail-swish 2.6s ease-in-out infinite alternate; }
.cat--harry .cat__tail { animation-duration: 3.1s; animation-delay: -1.2s; }
.cat__tail--lazy { animation-name: tail-lazy; animation-duration: 4.5s; }
.cat:hover .cat__tail:not(.cat__tail--lazy) { animation-duration: .9s; }

@keyframes tail-swish {
  from { transform: rotate(-7deg); }
  to   { transform: rotate(8deg); }
}
@keyframes tail-lazy {
  0%, 60% { transform: rotate(0deg); }
  100%    { transform: rotate(-9deg); }
}

/* Head tilt when you hover, ear flicks now and then */
.cat__head { transition: transform .35s cubic-bezier(.3, 1.5, .5, 1); }
.cat:hover .cat__head { transform: rotate(-5deg); }
.cat--kitty:hover .cat__head { transform: none; }

.cat__ear--l { animation: ear-flick 7s infinite; }
.cat__ear--r { animation: ear-flick 9s infinite -4s; }

@keyframes ear-flick {
  0%, 90%, 100% { transform: rotate(0deg); }
  93%           { transform: rotate(-12deg); }
  96%           { transform: rotate(6deg); }
}

/* Kitty: slow breathing, floating z's, and one-eye-open when poked */
.cat__breath { animation: breathe 3.8s ease-in-out infinite; }

@keyframes breathe {
  0%, 100% { transform: scale(1, 1); }
  50%      { transform: scale(1.012, 1.045); }
}

.zzz text {
  font-family: var(--font-hand);
  opacity: 0;
  animation: zzz 3.8s ease-in-out infinite;
  animation-delay: calc(var(--i) * .7s);
}
@keyframes zzz {
  0%   { opacity: 0; transform: translate(0, 8px); }
  30%  { opacity: .95; }
  70%  { opacity: .95; }
  100% { opacity: 0; transform: translate(8px, -12px); }
}

.cat__eyes-open { display: none; }
.cat__art.is-awake .cat__eyes-open { display: inline; }
.cat__art.is-awake .cat__eyes-shut { display: none; }
.cat__art.is-awake .zzz { display: none; }
.cat__art.is-awake .cat__ear { animation: ear-flick 1.2s 2 -1s; }

/* Hearts that float up when a cat is petted (added by alive.js) */
.heart {
  position: absolute;
  left: 50%;
  top: 0;
  font-size: 1.6rem;
  line-height: 1;
  color: #ff8fa3;
  text-shadow: 0 2px 0 rgba(8, 24, 90, .45);
  z-index: 2;
  pointer-events: none;
  animation: heart-float 1.1s ease-out forwards;
}
@keyframes heart-float {
  from { opacity: 0; transform: translate(-50%, 40%) scale(.4) rotate(var(--tilt, 0deg)); }
  25%  { opacity: 1; }
  to   { opacity: 0; transform: translate(calc(-50% + var(--drift, 0px)), -160%) scale(1.25) rotate(var(--tilt, 0deg)); }
}

/* ---- Sky doodles and the + ---------------------------------------------- */

.doodle {
  animation: twinkle 5s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.9s);
}
@keyframes twinkle {
  0%, 100% { opacity: .25; scale: .85; }
  50%      { opacity: .7;  scale: 1.1; }
}

.plus__mark {
  transform-box: fill-box;
  transform-origin: center;
  animation: plus-wiggle 3.4s ease-in-out infinite;
  transition: transform .6s cubic-bezier(.3, 1.5, .5, 1);
}
@keyframes plus-wiggle {
  0%, 100% { transform: rotate(-7deg) scale(1); }
  50%      { transform: rotate(7deg) scale(1.08); }
}
.plus:hover .plus__mark { animation: plus-spin .7s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes plus-spin {
  from { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(100deg) scale(1.25); }
  to   { transform: rotate(180deg) scale(1); }
}

/* ---- Small extras -------------------------------------------------------- */

/* Sign ornaments: the vine draws itself in, then sways; the squares rock and
   spin when you hover the sign. */
.deco { overflow: visible; }

.deco--vine { animation: deco-sway 7s ease-in-out infinite alternate; transform-origin: 50% 100%; }
@keyframes deco-sway {
  from { transform: rotate(-2.5deg); }
  to   { transform: rotate(2.5deg); }
}

.deco__line {
  stroke-dasharray: 1;
  animation: deco-draw 1.1s ease-out backwards;
  animation-delay: calc(1.2s + var(--i) * .7s);
}
@keyframes deco-draw {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}

.deco__square {
  transform-box: fill-box;
  transform-origin: center;
  animation: square-rock 6s ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * -1.7s);
  transition: rotate .7s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes square-rock {
  from { transform: rotate(-8deg); }
  to   { transform: rotate(8deg); }
}
.card:hover .deco__square { rotate: 90deg; transition-delay: calc(var(--i) * .08s); }

.deco__dots circle,
.deco__dots rect {
  transform-box: fill-box;
  transform-origin: center;
  animation: dot-pulse 3.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.9s);
}
@keyframes dot-pulse {
  0%, 100% { scale: .7; opacity: .6; }
  50%      { scale: 1.15; opacity: 1; }
}

.links .icon { transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.links a:hover .icon { transform: rotate(-10deg) scale(1.15); }

/* ---- Respect "reduce motion" -------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .alive *,
  .alive *::before,
  .alive *::after {
    animation: none !important;
    transition: none !important;
  }
  .zzz text { opacity: .9; }
}
