/* ============================================================
   Desktop pets (Section 08) — DOM + CSS sprite animation
   ============================================================ */
.pet-layer { position: absolute; inset: 0; z-index: 2000; pointer-events: none; overflow: hidden; }
.pet-layer.hidden-all .pet { display: none; }

.pet {
  position: absolute; left: 0; top: 0;
  width: var(--pw, 96px); height: var(--ph, 116px);
  pointer-events: auto; touch-action: none; cursor: grab;
  will-change: transform;
}
.pet.hidden { display: none; }
.pet.dragged { cursor: grabbing; z-index: 10; }
.pet.stale .pet-sprite { filter: saturate(.55) brightness(.95); }
.pet.unknown .pet-sprite { filter: saturate(.3) brightness(.95); }

.pet-body { position: absolute; inset: 0; transform-origin: 50% 100%; }
.pet-sprite { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
.pet-sprite.flip { transform: scaleX(-1); }
.pet-shadow { position: absolute; left: 22%; right: 22%; bottom: -3px; height: 6px; background: rgba(48, 45, 67, .22); }
.pet.perched .pet-shadow { display: none; }

/* Props */
.pet-prop { position: absolute; pointer-events: none; image-rendering: pixelated; }
.pet-prop img { width: 100%; height: 100%; display: block; }
.pet-prop.hands { width: 42%; height: 38%; left: 29%; bottom: 14%; }
.pet-prop.front { width: 52%; height: 44%; left: 50%; bottom: 0; }
.pet-prop.side { width: 38%; height: 34%; left: 64%; bottom: 26%; animation: prop-wob 1.2s steps(2) infinite; }
.pet-prop.float { width: 30%; height: 27%; left: 70%; top: -6%; animation: prop-float 1.6s steps(4) infinite; }
.pet-prop.board {
  left: 62%; top: 2%; width: auto; height: auto; padding: 3px 6px;
  background: #2F4A3E; color: #EAF6EC; border: 3px solid #8A6A4A;
  font-family: var(--font-mono); font-size: 11px; white-space: nowrap;
}
.pet-prop.text { left: 66%; top: -10%; width: auto; height: auto; font-family: var(--font-pixel); font-weight: 600; font-size: 18px; color: #fff; text-shadow: 2px 2px 0 #51466F; animation: prop-float 1.6s steps(4) infinite; white-space: nowrap; }
@keyframes prop-float { 50% { transform: translateY(-5px); } }
@keyframes prop-wob { 50% { transform: rotate(-12deg); } }

/* Name/status tag on hover */
.pet-tag {
  position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 6px;
  padding: 1px 6px; white-space: nowrap; display: none;
  background: var(--win-bg); color: var(--text); border: 2px solid var(--border);
  font-family: var(--font-label); font-size: 9.5px;
}
.pet:hover .pet-tag { display: block; }
.pet.perched:hover .pet-tag { top: auto; bottom: 100%; margin: 0 0 4px; }

/* Speech bubble */
.pet-bubble {
  position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  max-width: 200px; width: max-content; padding: 5px 9px;
  background: #fff; color: #302D43; border: 2px solid #51466F; box-shadow: 3px 3px 0 rgba(48, 45, 67, .25);
  font-family: var(--font-pixel); font-size: 13px; line-height: 1.25; text-align: center;
  pointer-events: none; opacity: 0; transition: opacity .15s steps(2);
}
.pet-bubble::after {
  content: ""; position: absolute; left: 50%; top: 100%; margin-left: -5px;
  border: 6px solid transparent; border-top-color: #51466F;
}
.pet-bubble.show { opacity: 1; }
.pet.near-top .pet-bubble { bottom: auto; top: 30%; left: calc(100% + 4px); transform: none; }
.pet.near-top .pet-bubble::after { display: none; }

/* FX: hearts, stars, poof */
.pet-fx { position: absolute; pointer-events: none; font-family: var(--font-pixel); font-size: 16px; animation: fx-rise 1s steps(6) forwards; }
@keyframes fx-rise { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-38px); opacity: 0; } }
.pet-fx img { width: 20px; height: 20px; display: block; }
.poof { position: absolute; width: 60px; height: 60px; pointer-events: none; animation: poof .45s steps(5) forwards;
  background: radial-gradient(circle, #fff 0 20%, transparent 21% 30%, #fff 31% 36%, transparent 37%); }
@keyframes poof { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

/* ---------- Animations (behaviour → visual) ---------- */
.pet[data-anim="sway"] .pet-body { animation: a-sway 2.4s steps(6) infinite; }
.pet[data-anim="bob"] .pet-body, .pet[data-anim="calm"] .pet-body { animation: a-bob 1.6s steps(2) infinite; }
.pet[data-anim="chin"] .pet-body { animation: a-tilt 3s steps(3) infinite; }
.pet[data-anim="type"] .pet-body { animation: a-type .5s steps(2) infinite; }
.pet[data-anim="read"] .pet-body { animation: a-bob 2.6s steps(2) infinite; }
.pet[data-anim="write"] .pet-body { animation: a-write 1.1s steps(3) infinite; }
.pet[data-anim="look"] .pet-body { animation: a-look 2.8s steps(1) infinite; }
.pet[data-anim="tap"] .pet-body { animation: a-tap .8s steps(2) infinite; }
.pet[data-anim="stretch"] .pet-body { animation: a-stretch 2.6s steps(4) infinite; }
.pet[data-anim="shake"] .pet-body { animation: a-shake .45s steps(3) 4, a-bob 2s steps(2) 1.8s infinite; }
.pet[data-anim="sleep"] .pet-body { animation: a-breathe 3.2s steps(4) infinite; }
.pet[data-anim="jump"] .pet-body { animation: a-jump .55s steps(5) 4; }
.pet[data-anim="wave"] .pet-body { animation: a-wave .5s steps(2) 3; }
.pet[data-anim="walk"] .pet-body { animation: a-walk .36s steps(2) infinite; }
.pet[data-anim="dangle"] .pet-body { animation: a-dangle .8s steps(4) infinite; transform-origin: 50% 0; }
.pet[data-anim="land"] .pet-body { animation: a-land .3s steps(3) 1; }
.pet[data-anim="wake"] .pet-body { animation: a-wake .7s steps(6) both; }
.pet[data-anim="goodbye"] .pet-body { animation: a-wave .5s steps(2) 2, a-fade .5s steps(4) 1s forwards; }

@keyframes a-sway { 0%, 100% { transform: rotate(0); } 33% { transform: rotate(-3deg); } 66% { transform: rotate(3deg); } }
@keyframes a-bob { 50% { transform: translateY(-3px); } }
@keyframes a-tilt { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-5deg) translateY(-1px); } }
@keyframes a-type { 50% { transform: translateY(1px) translateX(1px); } }
@keyframes a-write { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-2px) rotate(-2deg); } }
@keyframes a-look { 0%, 45% { transform: scaleX(1); } 50%, 95% { transform: scaleX(-1); } }
@keyframes a-tap { 50% { transform: translateY(-2px) rotate(2deg); } }
@keyframes a-stretch { 0%, 100% { transform: scaleY(1); } 40% { transform: scaleY(1.07) scaleX(.96); } }
@keyframes a-shake { 0%, 100% { transform: translateX(0); } 33% { transform: translateX(-3px); } 66% { transform: translateX(3px); } }
@keyframes a-breathe { 50% { transform: scaleY(.96) translateY(1px); } }
@keyframes a-jump { 0%, 100% { transform: translateY(0) scaleY(1); } 15% { transform: translateY(0) scaleY(.9); } 50% { transform: translateY(-28px) scaleY(1.05); } }
@keyframes a-wave { 50% { transform: rotate(-6deg); } }
@keyframes a-walk { 50% { transform: translateY(-3px); } }
@keyframes a-dangle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
@keyframes a-land { 0% { transform: scaleY(.8) scaleX(1.1); } 100% { transform: none; } }
@keyframes a-wake { 0% { transform: translateY(30px); opacity: 0; } 60% { transform: translateY(-4px); opacity: 1; } 100% { transform: none; opacity: 1; } }
@keyframes a-fade { to { opacity: 0; } }

.reduce-motion .pet .pet-body { animation: none !important; }

.pet-layer.paused .pet-body, .pet-layer.paused .pet-prop, .pet-layer.paused .pet-fx { animation-play-state: paused !important; }
.pet.bubble-edge-r .pet-bubble { left: auto; right: 0; transform: none; }
.pet.bubble-edge-l .pet-bubble { left: 0; transform: none; }
.pet.bubble-edge-r .pet-bubble::after { left: auto; right: 30%; }
.pet.bubble-edge-l .pet-bubble::after { left: 30%; }
.screen.handheld .pet-layer { overflow: visible; }
