/* =========================================================
   吉祥物 Kiki & Mei Mei
========================================================= */
.pet-dock {
  position: fixed; left: 0; right: 0; bottom: 0; height: 110px;
  z-index: 80; pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}
.pet {
  position: absolute; bottom: 0;
  pointer-events: auto; cursor: pointer; outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.6s var(--ease), opacity 0.4s var(--ease);
}
.pet .dog { display: block; width: 100%; height: auto; overflow: visible; }
.pet:focus-visible .dog { filter: drop-shadow(0 0 0 var(--btn-color)) drop-shadow(0 0 3px var(--btn-color)); }
.pet::after {                                 /* 地面阴影 */
  content: ''; position: absolute; left: 22%; right: 12%; bottom: -3px; height: 8px; border-radius: 50%;
  background: rgba(0,0,0,0.16); filter: blur(2px); z-index: -1;
}
.pet-flip { transition: transform 0.25s var(--ease); transform-origin: 50% 100%; }

.kiki {
  left: 14px; width: 96px; z-index: 3;
  --fur: #D7772E; --fur-dark: #B95F22; --cream: #F5DEC0;
}
.meimei {
  left: 0; width: 84px; z-index: 2;
  translate: var(--x, 104px) 0;
  --fur: #F4EADC; --fur-dark: #E4D5C0; --ear-tip: #DDB48A; --nose: #8C5A50; --tongue: #E66F86;
  --scarf: #E07A8F;
}
.meimei.is-hiding { z-index: 1; transform: translateY(16px) scale(0.86); transform-origin: 30% 100%; }
.meimei.face-left .pet-flip { transform: scaleX(-1); }

/* —— SVG 部件动画（以 viewBox 坐标为原点） —— */
.dog .tail, .dog .head, .dog .ear, .dog .leg { transform-box: view-box; }
.dog .tail { transform-origin: 37px 74px; animation: tailIdle 3.4s ease-in-out infinite; }
.dog .head { transform-origin: 61px 51px; transform: rotate(var(--look, 0deg)); transition: transform 0.35s var(--ease); }
.dog .ear-front { transform-origin: 70px 24px; transition: transform 0.3s var(--ease); }
.dog .ear-back { transform-origin: 50px 28px; transition: transform 0.3s var(--ease); }
.dog .leg-a { transform-origin: 62px 78px; }
.dog .leg-b { transform-origin: 71px 78px; }
.dog .eyes { transform-box: fill-box; transform-origin: center; transition: transform 0.08s; }
.dog .body { transform-box: view-box; transform-origin: 50px 97px; animation: breathe 3.2s ease-in-out infinite; }
.dog .mouth-open { display: none; }
@keyframes tailIdle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(6deg); } }
@keyframes tailWag { 0% { transform: rotate(-16deg); } 100% { transform: rotate(16deg); } }
@keyframes breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.018); } }

.pet.blink .eyes { transform: scaleY(0.1); }
.pet.wag .tail { animation: tailWag 0.16s ease-in-out infinite alternate; }

/* Kiki：吠叫 / 低吼 / 紧张 */
.kiki.barking .head { animation: barkJerk 0.25s ease-in-out 3; }
.kiki.barking .mouth-open, .kiki.wag .mouth-open { display: inline; }
.kiki.barking .mouth-closed, .kiki.wag .mouth-closed { display: none; }
@keyframes barkJerk { 0%, 100% { transform: rotate(var(--look, 0deg)); } 50% { transform: rotate(-9deg) translateY(-2px); } }
.kiki.growl .head { transform: rotate(5deg) translateY(2px); }
.kiki.nervous { transform: translateX(-8px); }
.kiki.nervous .ear-front { transform: rotate(28deg); }
.kiki.nervous .ear-back { transform: rotate(-24deg); }
.kiki.nervous .tail { animation: none; transform: rotate(-30deg) scale(0.85); }
.kiki.nervous .head { transform: rotate(8deg) translateY(2px); }

/* Mei Mei：默认吐舌头 */
.meimei .mouth-open { display: inline; }
.meimei .mouth-closed { display: none; }
.meimei.scared .mouth-open, .meimei.is-hiding .mouth-open { display: none; }
.meimei.scared .mouth-closed, .meimei.is-hiding .mouth-closed { display: inline; }
.meimei.scared .pet-flip { animation: tremble 0.12s linear infinite; }
.meimei.scared .ear-front, .meimei.is-hiding .ear-front { transform: rotate(18deg); }
.meimei.scared .tail, .meimei.is-hiding .tail { animation: none; transform: rotate(-26deg) scale(0.8); }
@keyframes tremble { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(1.2px); } }
.meimei.face-left.scared .pet-flip { animation: none; }
.meimei.hovered .head, .meimei.happy .head { transform: rotate(-10deg); }
.meimei.asking .head { animation: askTilt 0.9s ease-in-out infinite; }
@keyframes askTilt { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(4deg) translateY(-1px); } }
.meimei.eating .head { animation: nom 0.3s ease-in-out infinite; }
@keyframes nom { 0%, 100% { transform: rotate(16deg) translateY(4px); } 50% { transform: rotate(22deg) translateY(6px); } }

/* 走路 / 奔跑 */
.pet.walking .dog { animation: bob 0.32s ease-in-out infinite; }
.pet.walking .leg-a { animation: step 0.32s ease-in-out infinite; }
.pet.walking .leg-b { animation: step 0.32s ease-in-out infinite reverse; }
.pet.walking .tail { animation: tailWag 0.2s ease-in-out infinite alternate; }
.pet.running .dog { animation-duration: 0.18s; }
.pet.running .leg-a, .pet.running .leg-b { animation-duration: 0.18s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes step { 0%, 100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }

/* 配饰：默认隐藏，按季节 / 节日显示 */
.dog .acc { display: none; }
.pet-dock[data-edition="christmas"] .acc-santa,
.pet-dock[data-edition="winter"] .acc-scarf,
.pet-dock[data-edition="spring"] .acc-flower,
.pet-dock[data-edition="summer"] .kiki .acc-shades,
.pet-dock[data-edition="summer"] .meimei .acc-flower,
.pet-dock[data-edition="autumn"] .acc-leaf,
.pet-dock[data-edition="cny"] .acc-bandana { display: inline; }
.pet-dock[data-edition="autumn"] .acc-scarf { display: inline; }
.pet-dock[data-edition="autumn"] .kiki { --scarf: #8A5A2B; }
.pet-dock[data-edition="autumn"] .meimei { --scarf: #C4622D; }

/* 对话气泡 */
.pet-bubble {
  position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translate(-50%, 6px) scale(0.9); transform-origin: 50% 100%;
  width: max-content; max-width: 190px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; line-height: 1.4; letter-spacing: 0.2px;
  color: var(--text-main); background: var(--surface);
  border: 1.5px solid var(--text-main); border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--btn-color) 70%, transparent);
  opacity: 0; pointer-events: none; white-space: normal; text-align: center;
  transition: opacity 0.2s var(--ease), transform 0.25s var(--ease);
}
.pet-bubble::after {
  content: ''; position: absolute; top: 100%; left: 50%; width: 9px; height: 9px;
  background: var(--surface); border-right: 1.5px solid var(--text-main); border-bottom: 1.5px solid var(--text-main);
  transform: translate(-50%, -4px) rotate(45deg);
}
.pet-bubble.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.kiki .pet-bubble { left: 10px; transform: translate(0, 6px) scale(0.9); transform-origin: 20% 100%; }
.kiki .pet-bubble.show { transform: none; }
.kiki .pet-bubble::after { left: 46px; }

/* 爱心 */
.pet-heart {
  position: absolute; bottom: 70px; font-size: 15px; color: #E25A73; pointer-events: none;
  animation: heartUp 1.4s var(--ease) forwards;
}
@keyframes heartUp { 0% { opacity: 0; transform: translateY(10px) scale(0.6); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-46px) scale(1.2) rotate(-12deg); } }

/* 狗碗 */
.pet-bowl {
  position: absolute; left: 66px; bottom: -2px; width: 30px; height: 12px;
  background: #4E7FB5; border-radius: 3px 3px 12px 12px;
  opacity: 0; transform: translateY(8px); transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  pointer-events: none;
}
.pet-bowl .bone { position: absolute; left: 6px; top: -12px; font-size: 13px; }
.meimei.asking .pet-bowl, .meimei.eating .pet-bowl { opacity: 1; transform: none; }
.meimei.face-left .pet-bowl { left: -14px; }

/* 节日道具 */
.pet-prop { position: absolute; left: 4px; bottom: 0; width: 28px; z-index: 4; opacity: 0; transform: translateY(10px); transition: opacity 0.4s var(--ease), transform 0.4s var(--ease); }
.pet-prop.show { opacity: 1; transform: none; }
.pet-prop svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.2)); }

/* 小动物 */
.critter { position: absolute; left: 0; bottom: 2px; translate: var(--x, 2000px) 0; opacity: 0; pointer-events: none; z-index: 1; }
.critter.show { opacity: 1; }
.critter svg { display: block; width: 100%; height: auto; overflow: visible; transition: transform 0.2s; }
.critter.fleeing svg { transform: scaleX(-1); }
.critter .c-leg-a { animation: cLeg 0.3s ease-in-out infinite; transform-box: fill-box; transform-origin: top; }
.critter .c-leg-b { animation: cLeg 0.3s ease-in-out infinite reverse; transform-box: fill-box; transform-origin: top; }
@keyframes cLeg { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(12deg); } }
.critter .c-tongue { animation: tongue 1.1s steps(1) infinite; }
@keyframes tongue { 0%, 60% { opacity: 0; } 61%, 80% { opacity: 1; } 81% { opacity: 0; } }
.critter .c-wiggle { transform-box: fill-box; transform-origin: center; animation: wiggle 0.45s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: scaleY(1) skewX(0); } 50% { transform: scaleY(0.82) skewX(-6deg); } }
.c-bird svg { animation: hop 0.5s ease-in-out infinite; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.c-bird.fleeing { transition: transform 1s var(--ease); transform: translateY(-180px) rotate(-18deg); }
.c-bird.fleeing svg { animation: none; transform: scaleX(-1); }
.c-bird .c-wing { transform-box: fill-box; transform-origin: 20% 80%; }
.c-bird.fleeing .c-wing { animation: flap 0.12s linear infinite alternate; }
@keyframes flap { from { transform: rotate(0); } to { transform: rotate(-55deg); } }
.c-biawak.fleeing .c-leg-a, .c-biawak.fleeing .c-leg-b { animation-duration: 0.12s; }

/* 收起 / 唤醒 */
.pet-sleep {
  position: absolute; left: 6px; bottom: 96px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; padding: 5px;
  background: var(--surface); color: var(--text-sub); border: 1px solid var(--line); cursor: pointer;
  pointer-events: auto; opacity: 0; transition: opacity 0.25s var(--ease), bottom 0.4s var(--ease), background 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.pet-sleep svg { width: 100%; height: 100%; display: block; }
.pet-sleep .i-show { display: none; }
.pet-dock:hover .pet-sleep, .pet-sleep:focus-visible { opacity: 1; }
.pet-sleep:hover { background: var(--btn-color); color: var(--bg-main); }
.pet-dock.is-asleep .pet, .pet-dock.is-asleep .pet-prop, .pet-dock.is-asleep .critter { transform: translateY(130%); opacity: 0; pointer-events: none; }
.pet-dock.is-asleep .pet-sleep { opacity: 1; bottom: 14px; width: 40px; height: 40px; padding: 9px; color: var(--btn-color); }
.pet-dock.is-asleep .i-hide { display: none; }
.pet-dock.is-asleep .i-show { display: block; }
@media (hover: none) { .pet-sleep { opacity: 0.75; } }

@media (max-width: 600px) {
  .pet-dock { height: 90px; }
  .kiki { width: 74px; left: 6px; }
  .meimei { width: 64px; }
  .pet-sleep { bottom: 76px; left: 4px; }
  .pet-bubble { font-size: 10.5px; max-width: 160px; }
  .pet-heart { bottom: 52px; }
  .pet-bowl { left: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  .dog .tail, .dog .body, .pet.walking .dog, .pet.walking .leg-a, .pet.walking .leg-b { animation: none; }
}
@media print { .pet-dock, .season-canvas, .season-banner { display: none !important; } }
