/* Pets: shared by the page (on the chat box's top edge) and the popup preview.
   The mood lives on .cuw-pet[data-mood]: sleep, walk or run. */
.cuw-pet {
  --pet-w: 102px;
  --pet-h: 68px;
  /* walking gait */
  --cycle: .92s;
  --back: 17deg;
  --fwd: -19deg;
  --flex: 30deg;
  --bob: .8px;
  --lean: 0deg;
  --tail-speed: 2.8s;
  --tail-swing: 6deg;
  display: block;
}
.cuw-pet[data-mood="run"] { --cycle: .4s; --back: 30deg; --fwd: -34deg; --flex: 52deg; --bob: 2px; --lean: -3deg; --tail-speed: .4s; --tail-swing: 9deg; }
.cuw-pet[data-type="dog"] { --tail-speed: .55s; --tail-swing: 12deg; }
.cuw-pet[data-type="dog"][data-mood="run"] { --tail-speed: .2s; --tail-swing: 14deg; }

/* On the page: a fixed layer that the script parks on the chat box's top edge */
.cuw-pet-layer {
  position: fixed;
  left: 0; top: 0;
  width: 0; height: 0;
  z-index: 20;
  pointer-events: none;
  contain: layout style;
}
.cuw-pet-layer .cuw-pet { position: absolute; left: 0; top: 0; }
.cuw-pet-walker {
  position: absolute;
  left: 0;
  bottom: -1px;          /* paws rest on the box's top edge */
  width: var(--pet-w);
  height: var(--pet-h);
  will-change: transform;
}
.cuw-pet-layer .cuw-pet-walker { bottom: auto; top: calc(var(--pet-h) * -1 + 1px); }
.cuw-pet-flip { position: relative; width: 100%; height: 100%; transform-origin: 50% 50%; filter: drop-shadow(0 1px 1.2px rgba(0, 0, 0, .22)); }
/* On a dark page a soft rim light keeps dark coats (black cat, sparrow) easy to see */
.cuw-pet-layer[data-theme="dark"] .cuw-pet-flip,
.cuw-pet--preview.dark .cuw-pet-flip { filter: drop-shadow(0 0 .8px rgba(255, 255, 255, .55)) drop-shadow(0 1px 1.2px rgba(0, 0, 0, .4)); }
.cuw-pet-svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* Poses */
.cuw-pet-svg .curl { display: none; }
.cuw-pet[data-mood="sleep"] .cuw-pet-svg .stand { display: none; }
.cuw-pet[data-mood="sleep"] .cuw-pet-svg .curl { display: inline; }
.cuw-pet-svg .curl { transform-box: fill-box; transform-origin: 50% 100%; animation: cuw-breathe 3.8s ease-in-out infinite; }
@keyframes cuw-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.01, 1.035); } }

/* Jointed legs: the upper piece swings from the shoulder or hip, the lower piece folds
   at the knee while the paw is in the air. Diagonal pairs move together. */
.cuw-pet-svg .leg, .cuw-pet-svg .shin, .cuw-pet-svg .tail, .cuw-pet-svg .wing {
  transform-box: view-box;
  transform-origin: var(--ox) var(--oy);
}
.cuw-pet[data-mood="walk"] .cuw-pet-svg .leg,
.cuw-pet[data-mood="run"] .cuw-pet-svg .leg { animation: cuw-swing var(--cycle) ease-in-out infinite; }
.cuw-pet[data-mood="walk"] .cuw-pet-svg .shin,
.cuw-pet[data-mood="run"] .cuw-pet-svg .shin { animation: cuw-fold var(--cycle) ease-in-out infinite; }
.cuw-pet .cuw-pet-svg .leg.b, .cuw-pet .cuw-pet-svg .leg.b .shin { animation-delay: calc(var(--cycle) * -.5); }
@keyframes cuw-swing {
  0%, 100% { transform: rotate(var(--back)); }
  50% { transform: rotate(var(--fwd)); }
}
@keyframes cuw-fold {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(var(--flex)); }
  50%, 100% { transform: rotate(0deg); }
}

.cuw-pet-svg .stand { transform-box: fill-box; transform-origin: 50% 100%; }
.cuw-pet[data-mood="walk"] .cuw-pet-svg .stand,
.cuw-pet[data-mood="run"] .cuw-pet-svg .stand { animation: cuw-trot calc(var(--cycle) / 2) ease-in-out infinite; }
@keyframes cuw-trot {
  0%, 100% { transform: translateY(0) rotate(var(--lean)); }
  50% { transform: translateY(calc(var(--bob) * -1)) rotate(var(--lean)); }
}

.cuw-pet[data-mood="walk"] .cuw-pet-svg .tail,
.cuw-pet[data-mood="run"] .cuw-pet-svg .tail { animation: cuw-tail var(--tail-speed) ease-in-out infinite alternate; }
@keyframes cuw-tail { from { transform: rotate(calc(var(--tail-swing) * -1)); } to { transform: rotate(var(--tail-swing)); } }

.cuw-pet-svg .eyes { transform-box: fill-box; transform-origin: 50% 50%; animation: cuw-blink 6s infinite; }
@keyframes cuw-blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.12); } }
.cuw-pet-svg .tongue { display: none; }
.cuw-pet[data-mood="run"] .cuw-pet-svg .tongue { display: inline; }

/* Birds: hop when strolling, fly when busy */
.cuw-pet[data-type="bird"] .cuw-pet-svg .leg { animation: none !important; }
.cuw-pet-svg .wing.spread { display: none; }
.cuw-pet[data-type="bird"][data-mood="walk"] .cuw-pet-svg .stand { animation: cuw-hop .52s cubic-bezier(.3, 0, .4, 1) infinite alternate; }
@keyframes cuw-hop { from { transform: translateY(0); } to { transform: translateY(-3px); } }
.cuw-pet[data-type="bird"][data-mood="run"] .cuw-pet-svg .leg,
.cuw-pet[data-type="bird"][data-mood="run"] .cuw-pet-svg .wing.folded { display: none; }
.cuw-pet[data-type="bird"][data-mood="run"] .cuw-pet-svg .wing.spread { display: inline; animation: cuw-flap .2s ease-in-out infinite alternate; }
.cuw-pet[data-type="bird"][data-mood="run"] .cuw-pet-svg .wing.far { animation-delay: -.03s; }
@keyframes cuw-flap { from { transform: rotate(-12deg); } to { transform: rotate(78deg) scaleY(.7); } }
.cuw-pet[data-type="bird"][data-mood="run"] .cuw-pet-svg .stand { animation: cuw-fly .6s ease-in-out infinite alternate; }
@keyframes cuw-fly { from { transform: translateY(-14px) rotate(-6deg); } to { transform: translateY(-19px) rotate(-2deg); } }

/* Heavy work (Claude is thinking, searching or using tools): speed lines stream behind */
.cuw-pet-flip::before {
  content: '';
  position: absolute;
  top: 34%; left: -18%;
  width: 30%; height: 30%;
  opacity: 0;
  background:
    linear-gradient(90deg, transparent, rgba(120, 120, 130, .55)) 0 10% / 70% 1.5px no-repeat,
    linear-gradient(90deg, transparent, rgba(120, 120, 130, .45)) 30% 50% / 90% 1.5px no-repeat,
    linear-gradient(90deg, transparent, rgba(120, 120, 130, .5)) 10% 90% / 60% 1.5px no-repeat;
  transform: scaleX(var(--dir, 1));
  pointer-events: none;
}
.cuw-pet[data-mood="run"] .cuw-pet-flip::before { animation: cuw-streak .32s linear infinite; }
.cuw-pet[data-type="bird"][data-mood="run"] .cuw-pet-flip::before { top: 10%; }
@keyframes cuw-streak { 0% { opacity: 0; transform: translateX(8px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateX(-10px); } }
.cuw-pet-layer[data-theme="dark"] .cuw-pet-flip::before { filter: invert(1); }

/* Sleeping: little z letters drift up */
.cuw-z {
  position: absolute;
  left: 70%; bottom: 46%;
  font: 600 calc(var(--pet-h) * .2)/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  font-style: normal;
  color: #8a8f99;
  opacity: 0;
  display: none;
}
.cuw-pet[data-mood="sleep"] .cuw-z { display: block; animation: cuw-zzz 3.8s ease-in infinite; }
.cuw-pet[data-mood="sleep"] .cuw-z:nth-of-type(2) { animation-delay: 1.26s; left: 76%; }
.cuw-pet[data-mood="sleep"] .cuw-z:nth-of-type(3) { animation-delay: 2.52s; left: 82%; }
.cuw-pet-layer[data-theme="dark"] .cuw-z { color: #c3c8d2; }
@keyframes cuw-zzz {
  0% { transform: translate(0, 0) scale(.6); opacity: 0; }
  15% { opacity: .85; }
  100% { transform: translate(8px, calc(var(--pet-h) * -.55)) scale(1.1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cuw-pet-svg .stand, .cuw-pet-svg .leg, .cuw-pet-svg .shin, .cuw-pet-svg .tail, .cuw-pet-svg .wing,
  .cuw-pet-svg .curl, .cuw-pet-svg .eyes, .cuw-z { animation: none !important; }
}
