:root {
  --panel: rgba(9, 13, 22, 0.82);
  --panel-strong: rgba(7, 10, 18, 0.92);
  --line: rgba(110, 186, 255, 0.28);
  --line-strong: rgba(151, 226, 255, 0.42);
  --text: #eef5ff;
  --muted: #9eb5d1;
  --accent: #59b8ff;
  --accent-soft: rgba(89, 184, 255, 0.2);
  --accent-2: #ff73c7;
  --accent-3: #85ffdf;
  --danger: #ff7f97;
  --ground: 168px;
  --pet-width: clamp(150px, 18vw, 214px);
  --bubble-width: min(290px, 48vw);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", "Noto Sans TC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 18%, rgba(89, 184, 255, 0.22), transparent 26%),
    radial-gradient(circle at 82% 14%, rgba(255, 115, 199, 0.18), transparent 24%),
    radial-gradient(circle at 50% 100%, rgba(74, 255, 212, 0.08), transparent 32%),
    linear-gradient(180deg, #0d1220 0%, #111827 44%, #0a0d14 100%);
}

button,
textarea {
  font: inherit;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  cursor: pointer;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(123, 214, 255, 0.58);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.16);
}

button.is-active {
  border-color: rgba(133, 255, 223, 0.56);
  background: linear-gradient(135deg, rgba(89, 184, 255, 0.24), rgba(133, 255, 223, 0.16));
}

.city {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, transparent 0%, black 18%, black 100%);
  opacity: 0.72;
}

.ground {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--ground);
  pointer-events: none;
  background:
    linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.06) 8%, rgba(0, 0, 0, 0.24) 100%),
    linear-gradient(90deg, rgba(89, 184, 255, 0.08), rgba(255, 115, 199, 0.06));
  border-top: 1px solid rgba(89, 184, 255, 0.16);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.24) inset;
}

.ground::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(90deg, rgba(89, 184, 255, 0.14) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 32px 100%, 100% 22px;
  opacity: 0.5;
}

.ground::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(89, 184, 255, 0.45), rgba(255, 115, 199, 0.35), transparent);
  filter: blur(0.4px);
}

.hud {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 20;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  max-width: min(900px, calc(100vw - 36px));
}

.pill {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 260px;
  padding: 12px 15px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 20, 0.68);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
}

.pill-title {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(234, 246, 255, 0.88);
}

.pill-sub {
  font-size: 14px;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pet-layer {
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
}

.pet {
  position: absolute;
  left: 80px;
  bottom: calc(var(--ground) - 12px);
  width: var(--pet-width);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transform-origin: center bottom;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.28));
  will-change: left, bottom;
  transition: bottom var(--drop-duration, 360ms) cubic-bezier(0.22, 0.84, 0.24, 1);
  --face: 1;
  --idle-float: 7px;
  --idle-sway: 1.6deg;
  --walk-bounce: 6px;
  --walk-lean-forward: 3deg;
  --walk-lean-back: -2deg;
  --talk-bounce: 5px;
  --talk-nod: 4deg;
  --think-tilt: -7deg;
  --sleep-sink: 8px;
  --jump-height: 86px;
  --jump-tilt: -4deg;
  --land-rebound: 0.38;
  --land-squash: 1.08;
  --hover-lift: 0px;
  --hover-scale: 1;
  --hover-response: 1.03;
  --eye-x: 0px;
  --eye-y: 0px;
  --micro-tilt: 0deg;
  --micro-shift: 0px;
  --micro-lift: 0px;
  --walk-energy: 1;
  --talk-energy: 1;
  --walk-cycle: 0.62s;
  --talk-cycle: 1.06s;
  --pet-image-url: url("./cyberpet-transparent.png");
  --face-pan-x: 0px;
  --face-pan-y: 0px;
  --face-zoom: 1;
  --face-local-tilt: 0deg;
  --face-brightness: 1;
  --face-contrast: 1;
  --face-saturate: 1;
  --face-overlay-opacity: 0.98;
  --face-gloss-opacity: 0.18;
  --sprite-shift-x: 0px;
  --sprite-shift-y: 0px;
  --sprite-scale: 1;
  --render-scale-x: 1;
  --render-scale-y: 1;
  --carry-shift-x: 0px;
  --carry-shift-y: 0px;
  --carry-tilt: 0deg;
  --emotion-bias: 0deg;
  --emotion-lift: 0px;
  --emotion-scale: 1;
  --shadow-scale: 1;
  --shadow-opacity: 0.66;
  --shadow-softness: 3px;
  --bubble-edge: rgba(89, 184, 255, 0.34);
  --bubble-tag: rgba(89, 184, 255, 0.2);
  --bubble-glow: rgba(89, 184, 255, 0.18);
  --affection-glow: 0.16;
}

.pet.is-dragged {
  cursor: grabbing;
  transition: none;
}

.pet-hover,
.pet-actor,
.pet-shell,
.pet-render-surface,
.pet-sprite,
.pet-shadow {
  transform-origin: center bottom;
  will-change: transform, opacity;
}

.pet-hover {
  position: relative;
  transform: translateY(calc(var(--hover-lift) * -1)) scale(var(--hover-scale));
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.pet-actor,
.pet-shell,
.pet-render-surface,
.pet-sprite {
  position: relative;
}

.pet-render-surface {
  transform:
    translateX(calc(var(--micro-shift) + var(--carry-shift-x)))
    translateY(calc(var(--micro-lift) + var(--carry-shift-y)))
    rotate(calc(var(--micro-tilt) + var(--carry-tilt)))
    scaleX(var(--render-scale-x))
    scaleY(var(--render-scale-y));
  transition: transform 180ms ease;
}

.pet-sprite {
  isolation: isolate;
  transform: translateY(var(--emotion-lift)) rotate(var(--emotion-bias)) scaleX(var(--face)) scaleY(var(--emotion-scale));
  transition: transform 220ms ease;
}

.sprite-layer {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: cover;
  transform:
    translateX(var(--sprite-shift-x))
    translateY(calc(var(--sprite-shift-y) + var(--emotion-lift)))
    rotate(var(--emotion-bias))
    scaleX(calc(var(--face) * var(--sprite-scale)))
    scaleY(calc(var(--emotion-scale) * var(--sprite-scale)));
  transform-origin: center bottom;
  transition: transform 220ms ease, opacity 160ms ease;
}

.pet[data-render-mode="sprite"] .sprite-layer {
  display: block;
}

.pet[data-render-mode="sprite"] .pet-render-surface {
  width: 100%;
  aspect-ratio: 1 / 1;
}

.pet[data-render-mode="sprite"] .pet-sprite {
  opacity: 0;
}

.pet-image {
  display: block;
  width: 100%;
  aspect-ratio: 190 / 200;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.pet.is-image-missing .pet-image {
  opacity: 0;
}

.pet.is-image-missing .pet-sprite::after {
  content: "ENA";
  position: absolute;
  inset: 18% 12%;
  display: grid;
  place-items: center;
  border-radius: 28px;
  border: 1px solid rgba(151, 226, 255, 0.35);
  background:
    linear-gradient(180deg, rgba(89, 184, 255, 0.24), rgba(255, 115, 199, 0.14)),
    rgba(10, 14, 24, 0.88);
  color: rgba(238, 245, 255, 0.9);
  font-weight: 700;
  letter-spacing: 0.2em;
}

.pet-face {
  position: absolute;
  left: 50%;
  top: 22.5%;
  width: 39%;
  height: 25%;
  transform: translateX(-50%);
  pointer-events: none;
  overflow: hidden;
  border-radius: 42% 42% 50% 50%;
  opacity: var(--face-overlay-opacity);
  -webkit-mask-image: radial-gradient(circle at 50% 44%, rgba(0, 0, 0, 0.98) 0 54%, transparent 86%);
  mask-image: radial-gradient(circle at 50% 44%, rgba(0, 0, 0, 0.98) 0 54%, transparent 86%);
  transition: transform 180ms ease, opacity 180ms ease, filter 180ms ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.pet-face::before,
.pet-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pet-face::before {
  background-image: var(--pet-image-url);
  background-repeat: no-repeat;
  background-size: 256.41% 400%;
  background-position: calc(50% + var(--face-pan-x)) calc(30% + var(--face-pan-y));
  transform: scale(var(--face-zoom)) rotate(var(--face-local-tilt));
  transform-origin: center center;
  filter:
    brightness(var(--face-brightness))
    contrast(var(--face-contrast))
    saturate(var(--face-saturate));
  transition:
    transform 110ms linear,
    background-position 110ms linear,
    filter 180ms ease;
}

.pet-face::after {
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 255, 255, 0.32), transparent 52%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 58%, rgba(9, 16, 28, 0.1));
  mix-blend-mode: screen;
  opacity: var(--face-gloss-opacity);
}

.pet[data-render-mode="sprite"] .pet-face,
.pet.is-image-missing .pet-face {
  display: none;
}

.pet-eye,
.pet-brow,
.pet-mouth,
.pet-cheek {
  display: none;
}

.pet.emotion-happy {
  --idle-float: 8px;
  --idle-sway: 2deg;
  --talk-bounce: 7px;
  --talk-nod: 5deg;
  --bubble-edge: rgba(133, 255, 223, 0.42);
  --bubble-tag: rgba(133, 255, 223, 0.18);
  --bubble-glow: rgba(133, 255, 223, 0.18);
}

.pet.emotion-sad {
  --idle-float: 4px;
  --idle-sway: 0.8deg;
  --talk-bounce: 2px;
  --talk-nod: 2deg;
  --sleep-sink: 11px;
  --emotion-lift: 2px;
  --emotion-scale: 0.995;
  --bubble-edge: rgba(124, 181, 255, 0.3);
  --bubble-tag: rgba(124, 181, 255, 0.16);
}

.pet.emotion-angry {
  --talk-bounce: 4px;
  --talk-nod: 3.6deg;
  --bubble-edge: rgba(255, 127, 151, 0.46);
  --bubble-tag: rgba(255, 127, 151, 0.2);
  --bubble-glow: rgba(255, 127, 151, 0.16);
}

.pet.emotion-curious {
  --emotion-bias: -1.4deg;
  --talk-bounce: 4px;
  --think-tilt: -10deg;
  --bubble-edge: rgba(145, 233, 255, 0.36);
  --bubble-tag: rgba(145, 233, 255, 0.18);
  --bubble-glow: rgba(145, 233, 255, 0.14);
}

.pet.emotion-shy {
  --idle-float: 5px;
  --talk-bounce: 3px;
  --talk-nod: 2.5deg;
  --emotion-lift: 1px;
  --emotion-scale: 0.986;
  --bubble-edge: rgba(255, 187, 219, 0.38);
  --bubble-tag: rgba(255, 187, 219, 0.18);
  --bubble-glow: rgba(255, 187, 219, 0.12);
}

.pet.mood-attentive {
  --hover-response: 1.045;
}

.pet.mood-bored {
  --idle-float: 5px;
  --bubble-glow: rgba(89, 184, 255, 0.12);
}

.pet.mood-bored .pet-render-surface {
  filter: saturate(0.96);
}

.pet.mood-sleepy {
  --idle-float: 4px;
  --sleep-sink: 12px;
  --bubble-glow: rgba(145, 233, 255, 0.08);
}

.pet.mood-sleepy .pet-face {
  transform: translateX(-50%) translateY(1px);
}

.pet.is-hovered:not(.is-dragged) {
  --hover-lift: 4px;
  --hover-scale: var(--hover-response);
}

.pet.is-hovered:not(.is-dragged) .pet-face {
  transform: translateX(-50%) translateY(-1px);
}

.pet.is-blinking .pet-face::before {
  transform: translateY(1px) scaleX(var(--face-zoom)) scaleY(calc(var(--face-zoom) * 0.9)) rotate(var(--face-local-tilt));
}

.pet.is-sleeping .pet-face::before {
  transform: translateY(1px) scaleX(var(--face-zoom)) scaleY(calc(var(--face-zoom) * 0.96)) rotate(var(--face-local-tilt));
}

.pet[data-speaking="true"] .pet-mouth {
  animation: mouthChat 0.32s ease-in-out infinite;
}

.pet-shadow {
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: -10px;
  height: 20px;
  border-radius: 999px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.12) 56%, transparent 100%);
  filter: blur(var(--shadow-softness));
  opacity: var(--shadow-opacity);
  transform: scale(var(--shadow-scale));
}

.speech {
  position: absolute;
  left: calc(100% - 8px);
  bottom: calc(100% - 28px);
  width: var(--bubble-width);
  max-width: calc(100vw - 36px);
  opacity: 0;
  filter: blur(10px);
  transform: translate(12px, 14px) scale(0.96);
  transform-origin: left bottom;
  pointer-events: none;
  transition:
    opacity 220ms ease,
    transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
    filter 320ms ease;
}

.pet[data-bubble-side="left"] .speech {
  left: auto;
  right: calc(100% - 14px);
  transform-origin: right bottom;
}

.speech.is-visible {
  opacity: 1;
  filter: blur(0);
  transform: translate(0, 0) scale(1);
}

.speech::after {
  content: none;
  display: none;
  position: absolute;
  bottom: 16px;
  left: 18px;
  width: 14px;
  height: 14px;
  background: rgba(11, 16, 27, 0.92);
  border-right: 1px solid var(--bubble-edge);
  border-bottom: 1px solid var(--bubble-edge);
  transform: rotate(45deg);
}

.pet[data-bubble-side="left"] .speech::after {
  left: auto;
  right: 20px;
}

.speech-glow {
  position: absolute;
  inset: auto 24px 18px 24px;
  height: 36px;
  border-radius: 999px;
  background: radial-gradient(circle at center, var(--bubble-glow), transparent 72%);
  filter: blur(12px);
  opacity: 0.95;
}

.speech-content {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 20px;
  border: 1px solid var(--bubble-edge);
  background:
    linear-gradient(180deg, rgba(12, 18, 30, 0.94), rgba(7, 12, 21, 0.84)),
    rgba(7, 10, 18, 0.92);
  box-shadow:
    0 20px 44px rgba(0, 0, 0, 0.36),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 0 26px rgba(133, 255, 223, var(--affection-glow));
  backdrop-filter: blur(14px);
  overflow: hidden;
}

.speech-content::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--bubble-glow), transparent 52%);
  opacity: 0.88;
}

.speech-tag,
.speech-text {
  position: relative;
  z-index: 1;
}

.speech-tag {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--bubble-tag);
  color: rgba(234, 246, 255, 0.9);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.speech-text {
  font-size: 14px;
  line-height: 1.48;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.pet.is-idle .pet-actor {
  animation: idleFloat 4.7s ease-in-out infinite;
}

.pet.is-idle .pet-shell {
  animation: idleBody 4.3s ease-in-out infinite;
}

.pet.is-idle .pet-shadow {
  animation: idleShadow 4.7s ease-in-out infinite;
}

.pet.is-walking .pet-actor {
  animation: walkFloat var(--walk-cycle) ease-in-out infinite;
}

.pet.is-walking .pet-shell {
  animation: walkBody var(--walk-cycle) ease-in-out infinite;
}

.pet.is-walking .pet-shadow {
  animation: walkShadow var(--walk-cycle) ease-in-out infinite;
}

.pet.is-talking .pet-actor {
  animation: talkFloat var(--talk-cycle) ease-in-out infinite;
}

.pet.is-talking .pet-shell {
  animation: talkBody var(--talk-cycle) cubic-bezier(0.37, 0, 0.2, 1) infinite;
}

.pet.is-talking .pet-shadow {
  animation: talkShadow var(--talk-cycle) ease-in-out infinite;
}

.pet.is-talking.emotion-angry .pet-render-surface,
.pet.is-react-angry .pet-render-surface {
  animation: angryBuzz 0.12s linear infinite alternate;
}

.pet.is-talking.emotion-curious .pet-face,
.pet.is-thinking .pet-face,
.pet.is-react-curious .pet-face {
  animation: curiousTilt 1.18s ease-in-out infinite;
}

.pet.is-waving .pet-actor {
  animation: waveLift 0.88s cubic-bezier(0.2, 0.85, 0.22, 1) 1 both;
}

.pet.is-waving .pet-shell {
  animation: waveBody 0.88s cubic-bezier(0.2, 0.85, 0.22, 1) 1 both;
}

.pet.is-waving .pet-shadow {
  animation: waveShadow 0.88s ease-out 1 both;
}

.pet.is-thinking .pet-actor {
  animation: thinkFloat 1.9s ease-in-out infinite;
}

.pet.is-thinking .pet-shell {
  animation: thinkBody 1.9s ease-in-out infinite;
}

.pet.is-thinking .pet-shadow {
  animation: thinkShadow 1.9s ease-in-out infinite;
}

.pet.is-sleeping .pet-actor {
  animation: sleepFloat 4.8s ease-in-out infinite;
}

.pet.is-sleeping .pet-shell {
  animation: sleepBody 4.3s ease-in-out infinite;
}

.pet.is-sleeping .pet-shadow {
  animation: sleepShadow 4.8s ease-in-out infinite;
}

.pet.is-sleeping .pet-eye {
  height: 5px;
  border-radius: 999px;
  transform: translateY(10px);
  background: rgba(241, 249, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(10, 20, 36, 0.14);
}

.pet.is-sleeping .pet-brow {
  opacity: 0.64;
  transform: translateY(5px);
}

.pet.is-sleeping .pet-mouth {
  width: 22px;
  height: 6px;
  border-bottom-width: 2px;
  opacity: 0.72;
}

.pet.is-dragged .pet-hover {
  transform: translateY(calc((var(--hover-lift) + 6px) * -1)) scale(1.02);
}

.pet.is-dragged .pet-render-surface {
  transition: transform 72ms linear;
}

.pet.is-dragged .pet-actor {
  animation: draggedFloat 0.92s ease-in-out infinite;
}

.pet.is-dragged .pet-shadow {
  transition: transform 72ms linear, opacity 72ms linear;
}

.pet.is-jumping .pet-actor,
.pet.is-jumping .pet-shell,
.pet.is-jumping .pet-shadow,
.pet.is-landing .pet-actor,
.pet.is-landing .pet-shell,
.pet.is-landing .pet-shadow,
.pet.is-react-happy .pet-actor,
.pet.is-react-happy .pet-shell,
.pet.is-react-happy .pet-shadow,
.pet.is-react-sad .pet-actor,
.pet.is-react-sad .pet-shell,
.pet.is-react-sad .pet-shadow,
.pet.is-react-angry .pet-actor,
.pet.is-react-angry .pet-shell,
.pet.is-react-angry .pet-shadow,
.pet.is-react-curious .pet-actor,
.pet.is-react-curious .pet-shell,
.pet.is-react-curious .pet-shadow {
  transition: transform 180ms cubic-bezier(0.22, 0.84, 0.24, 1), opacity 180ms ease;
}

.pet.is-jumping[data-jump-phase="pre-jump"] .pet-actor {
  transform: translateY(4px);
}

.pet.is-jumping[data-jump-phase="pre-jump"] .pet-shell {
  transform: translateY(6px) scaleX(1.08) scaleY(0.92);
}

.pet.is-jumping[data-jump-phase="pre-jump"] .pet-shadow {
  transform: scale(1.05);
  opacity: 0.76;
}

.pet.is-jumping[data-jump-phase="rise"] .pet-actor {
  transform: translateY(calc(var(--jump-height) * -0.82));
}

.pet.is-jumping[data-jump-phase="rise"] .pet-shell {
  transform: rotate(var(--jump-tilt)) scaleX(0.96) scaleY(1.05);
}

.pet.is-jumping[data-jump-phase="rise"] .pet-shadow {
  transform: scale(0.72);
  opacity: 0.4;
}

.pet.is-jumping[data-jump-phase="air"] .pet-actor {
  transform: translateY(calc(var(--jump-height) * -1));
}

.pet.is-jumping[data-jump-phase="air"] .pet-shell {
  transform: rotate(calc(var(--jump-tilt) * -0.35)) scaleX(0.985) scaleY(1.02);
}

.pet.is-jumping[data-jump-phase="air"] .pet-shadow {
  transform: scale(0.66);
  opacity: 0.34;
}

.pet.is-jumping[data-jump-phase="fall"] .pet-actor {
  transform: translateY(calc(var(--jump-height) * -0.16));
}

.pet.is-jumping[data-jump-phase="fall"] .pet-shell {
  transform: rotate(calc(var(--jump-tilt) * -0.2)) scaleX(1.01) scaleY(0.99);
}

.pet.is-jumping[data-jump-phase="fall"] .pet-shadow {
  transform: scale(0.96);
  opacity: 0.72;
}

.pet.is-landing .pet-actor {
  animation: landActor 0.38s cubic-bezier(0.2, 0.8, 0.22, 1) 1 both;
}

.pet.is-landing .pet-shell {
  animation: landBody 0.38s cubic-bezier(0.2, 0.8, 0.22, 1) 1 both;
}

.pet.is-landing .pet-render-surface {
  animation: landSurface 0.38s cubic-bezier(0.2, 0.8, 0.22, 1) 1 both;
}

.pet.is-landing .pet-shadow {
  animation: landShadow 0.38s ease-out 1 both;
}

.pet.is-react-happy .pet-actor {
  animation: reactHappyActor 0.72s ease-out 1 both;
}

.pet.is-react-happy .pet-shell {
  animation: reactHappyBody 0.72s ease-out 1 both;
}

.pet.is-react-happy .pet-shadow {
  animation: reactHappyShadow 0.72s ease-out 1 both;
}

.pet.is-react-sad .pet-actor {
  animation: reactSadActor 0.78s ease-out 1 both;
}

.pet.is-react-sad .pet-shell {
  animation: reactSadBody 0.78s ease-out 1 both;
}

.pet.is-react-sad .pet-shadow {
  animation: reactSadShadow 0.78s ease-out 1 both;
}

.pet.is-react-angry .pet-actor {
  animation: reactAngryActor 0.64s ease-out 1 both;
}

.pet.is-react-angry .pet-shell {
  animation: reactAngryBody 0.64s ease-out 1 both;
}

.pet.is-react-angry .pet-shadow {
  animation: reactAngryShadow 0.64s ease-out 1 both;
}

.pet.is-react-curious .pet-actor {
  animation: reactCuriousActor 0.82s ease-out 1 both;
}

.pet.is-react-curious .pet-shell {
  animation: reactCuriousBody 0.82s ease-out 1 both;
}

.pet.is-react-curious .pet-shadow {
  animation: reactCuriousShadow 0.82s ease-out 1 both;
}

.chat-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(398px, calc(100vw - 24px));
  height: min(570px, calc(100vh - 32px));
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.34);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-title {
  font-size: 15px;
  font-weight: 700;
}

.chat-sub {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.chat-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.chat-quick-actions {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    rgba(255, 255, 255, 0.01);
}

.chat-quick-actions button {
  width: 100%;
  min-height: 42px;
}

.mood-chip {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mood-chip.emotion-happy {
  border-color: rgba(133, 255, 223, 0.42);
  color: rgba(214, 255, 244, 0.92);
}

.mood-chip.emotion-sad {
  border-color: rgba(124, 181, 255, 0.34);
  color: rgba(212, 228, 255, 0.9);
}

.mood-chip.emotion-angry {
  border-color: rgba(255, 127, 151, 0.42);
  color: rgba(255, 224, 230, 0.92);
}

.mood-chip.emotion-curious {
  border-color: rgba(145, 233, 255, 0.36);
  color: rgba(215, 249, 255, 0.92);
}

.mood-chip.emotion-shy {
  border-color: rgba(255, 187, 219, 0.36);
  color: rgba(255, 231, 241, 0.92);
}

.mood-chip.mood-attentive {
  box-shadow: 0 0 16px rgba(89, 184, 255, 0.12);
}

.mood-chip.mood-bored {
  border-color: rgba(124, 181, 255, 0.28);
}

.mood-chip.mood-sleepy {
  border-color: rgba(145, 233, 255, 0.24);
}

.messages {
  flex: 1;
  padding: 14px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 86%;
  padding: 11px 12px;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.msg.pet-msg {
  align-self: flex-start;
  background: rgba(89, 184, 255, 0.13);
  border: 1px solid rgba(89, 184, 255, 0.22);
}

.msg.pet-msg.emotion-happy {
  border-color: rgba(133, 255, 223, 0.34);
}

.msg.pet-msg.emotion-sad {
  border-color: rgba(124, 181, 255, 0.32);
}

.msg.pet-msg.emotion-angry {
  border-color: rgba(255, 127, 151, 0.34);
}

.msg.pet-msg.emotion-curious {
  border-color: rgba(145, 233, 255, 0.32);
}

.msg.pet-msg.emotion-shy {
  border-color: rgba(255, 187, 219, 0.32);
}

.msg.user-msg {
  align-self: flex-end;
  background: rgba(255, 115, 199, 0.12);
  border: 1px solid rgba(255, 115, 199, 0.22);
}

.chat-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

textarea {
  resize: none;
  width: 100%;
  min-height: 48px;
  max-height: 120px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea:focus {
  border-color: rgba(89, 184, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(89, 184, 255, 0.1);
}

.send {
  min-width: 78px;
  align-self: end;
  background: linear-gradient(135deg, rgba(89, 184, 255, 0.22), rgba(255, 115, 199, 0.16));
}

.hint {
  padding: 0 14px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.mini-log {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 12;
  width: min(344px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 10, 16, 0.55);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  backdrop-filter: blur(10px);
}

@keyframes mouthChat {
  0%,
  100% {
    transform: translateX(-50%) scaleY(1);
  }
  35% {
    transform: translateX(-50%) scaleY(1.46);
  }
  65% {
    transform: translateX(-50%) scaleY(0.82);
  }
}

@keyframes idleFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(calc(var(--idle-float) * -1));
  }
}

@keyframes idleBody {
  0%,
  100% {
    transform: rotate(calc(var(--idle-sway) * -0.55)) scaleX(1) scaleY(1);
  }
  25% {
    transform: rotate(calc(var(--idle-sway) * 0.3)) scaleX(1.006) scaleY(0.995);
  }
  50% {
    transform: rotate(var(--idle-sway)) scaleX(1.012) scaleY(0.988);
  }
  75% {
    transform: rotate(calc(var(--idle-sway) * -0.72)) scaleX(0.998) scaleY(1.006);
  }
}

@keyframes idleShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.72;
  }
  50% {
    transform: scale(0.88);
    opacity: 0.54;
  }
}

@keyframes walkFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(calc(-1 * var(--walk-bounce) * var(--walk-energy)));
  }
}

@keyframes walkBody {
  0% {
    transform: rotate(var(--walk-lean-back)) scaleX(1.006) scaleY(0.995);
  }
  25% {
    transform: rotate(calc(var(--walk-lean-forward) * 0.78)) scaleX(0.995) scaleY(1.006);
  }
  50% {
    transform: rotate(var(--walk-lean-forward)) scaleX(calc(1.008 + var(--walk-energy) * 0.008)) scaleY(calc(0.992 - var(--walk-energy) * 0.004));
  }
  75% {
    transform: rotate(calc(var(--walk-lean-back) * 0.82)) scaleX(0.998) scaleY(1.004);
  }
  100% {
    transform: rotate(var(--walk-lean-back)) scaleX(1.006) scaleY(0.995);
  }
}

@keyframes walkShadow {
  0%,
  100% {
    transform: scale(1.02);
    opacity: 0.72;
  }
  50% {
    transform: scale(calc(0.86 - var(--walk-energy) * 0.05));
    opacity: 0.48;
  }
}

@keyframes talkFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(calc(-1 * var(--talk-bounce) * var(--talk-energy)));
  }
}

@keyframes talkBody {
  0%,
  100% {
    transform: rotate(0deg) scaleX(1) scaleY(1);
  }
  18% {
    transform: rotate(calc(var(--talk-nod) * -0.25)) scaleX(1.006) scaleY(0.994);
  }
  34% {
    transform: translateY(1px) rotate(var(--talk-nod)) scaleX(calc(1.008 + var(--talk-energy) * 0.01)) scaleY(calc(0.99 - var(--talk-energy) * 0.006));
  }
  50% {
    transform: rotate(calc(var(--talk-nod) * -0.18)) scaleX(1.004) scaleY(1);
  }
  72% {
    transform: rotate(calc(var(--talk-nod) * 0.5)) scaleX(1.008) scaleY(0.992);
  }
}

@keyframes talkShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(0.9);
    opacity: 0.56;
  }
}

@keyframes waveLift {
  0% {
    transform: translateY(0);
  }
  22% {
    transform: translateY(-10px);
  }
  48% {
    transform: translateY(-6px);
  }
  72% {
    transform: translateY(-11px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes waveBody {
  0% {
    transform: rotate(0deg) scale(1);
  }
  18% {
    transform: rotate(-7deg) scaleX(1.012) scaleY(0.988);
  }
  34% {
    transform: rotate(5deg) scaleX(0.994) scaleY(1.012);
  }
  56% {
    transform: rotate(-8deg) scaleX(1.014) scaleY(0.986);
  }
  78% {
    transform: rotate(4deg) scaleX(0.996) scaleY(1.01);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

@keyframes waveShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
  28%,
  72% {
    transform: scale(0.82);
    opacity: 0.48;
  }
}

@keyframes thinkFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes thinkBody {
  0%,
  100% {
    transform: rotate(0deg) scaleX(1) scaleY(1);
  }
  28% {
    transform: rotate(var(--think-tilt)) translateY(1px) scaleX(1.008) scaleY(0.994);
  }
  65% {
    transform: rotate(calc(var(--think-tilt) * -0.45)) scaleX(0.998) scaleY(1.004);
  }
}

@keyframes thinkShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
  50% {
    transform: scale(0.9);
    opacity: 0.56;
  }
}

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

@keyframes sleepBody {
  0%,
  100% {
    transform: translateY(var(--sleep-sink)) rotate(-1deg) scaleX(1.01) scaleY(0.98);
  }
  50% {
    transform: translateY(calc(var(--sleep-sink) - 3px)) rotate(1deg) scaleX(0.995) scaleY(1.01);
  }
}

@keyframes sleepShadow {
  0%,
  100% {
    transform: scale(1.04);
    opacity: 0.72;
  }
  50% {
    transform: scale(0.94);
    opacity: 0.6;
  }
}

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

@keyframes landActor {
  0% {
    transform: translateY(calc(-8px * var(--land-rebound)));
  }
  45% {
    transform: translateY(0);
  }
  72% {
    transform: translateY(calc(-10px * var(--land-rebound)));
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes landBody {
  0% {
    transform: translateY(-2px) scaleX(0.98) scaleY(1.06);
  }
  45% {
    transform: translateY(0) scaleX(var(--land-squash)) scaleY(calc(2 - var(--land-squash)));
  }
  72% {
    transform: translateY(-1px) scaleX(0.99) scaleY(1.02);
  }
  100% {
    transform: translateY(0) scaleX(1) scaleY(1);
  }
}

@keyframes landSurface {
  0% {
    transform:
      translateX(calc(var(--micro-shift) + var(--carry-shift-x)))
      translateY(calc(var(--micro-lift) + var(--carry-shift-y)))
      rotate(calc(var(--micro-tilt) + var(--carry-tilt)));
  }
  40% {
    transform:
      translateX(calc(var(--micro-shift) + var(--carry-shift-x)))
      translateY(calc(var(--micro-lift) + var(--carry-shift-y) + 1px))
      rotate(calc(var(--micro-tilt) + var(--carry-tilt) * -0.22));
  }
  75% {
    transform:
      translateX(calc(var(--micro-shift) + var(--carry-shift-x)))
      translateY(calc(var(--micro-lift) + var(--carry-shift-y) - 1px))
      rotate(calc(var(--micro-tilt) + var(--carry-tilt) * 0.1));
  }
  100% {
    transform:
      translateX(calc(var(--micro-shift) + var(--carry-shift-x)))
      translateY(calc(var(--micro-lift) + var(--carry-shift-y)))
      rotate(var(--micro-tilt))
      scaleX(var(--render-scale-x))
      scaleY(var(--render-scale-y));
  }
}

@keyframes landShadow {
  0% {
    transform: scale(0.82);
    opacity: 0.44;
  }
  45% {
    transform: scale(1.08);
    opacity: 0.76;
  }
  72% {
    transform: scale(0.96);
    opacity: 0.62;
  }
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
}

@keyframes reactHappyActor {
  0% {
    transform: translateY(0);
  }
  38% {
    transform: translateY(-11px);
  }
  72% {
    transform: translateY(-4px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes reactHappyBody {
  0% {
    transform: rotate(0deg) scale(1);
  }
  30% {
    transform: rotate(-5deg) scaleX(1.02) scaleY(0.98);
  }
  54% {
    transform: rotate(6deg) scaleX(0.99) scaleY(1.02);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

@keyframes reactHappyShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
  38% {
    transform: scale(0.8);
    opacity: 0.48;
  }
}

@keyframes reactSadActor {
  0%,
  100% {
    transform: translateY(0);
  }
  45% {
    transform: translateY(3px);
  }
}

@keyframes reactSadBody {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  45% {
    transform: translateY(4px) rotate(-3deg) scaleX(1.01) scaleY(0.98);
  }
}

@keyframes reactSadShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }
  45% {
    transform: scale(1.06);
    opacity: 0.76;
  }
}

@keyframes reactAngryActor {
  0%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-2px);
  }
  60% {
    transform: translateY(0);
  }
}

@keyframes reactAngryBody {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  20% {
    transform: rotate(-3deg) scaleX(1.01) scaleY(0.99);
  }
  40% {
    transform: rotate(3deg) scaleX(1.01) scaleY(0.99);
  }
  60% {
    transform: rotate(-2deg) scaleX(1.006) scaleY(0.996);
  }
  80% {
    transform: rotate(2deg) scaleX(1.006) scaleY(0.996);
  }
}

@keyframes reactAngryShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
  45% {
    transform: scale(1.02);
    opacity: 0.72;
  }
}

@keyframes reactCuriousActor {
  0%,
  100% {
    transform: translateY(0);
  }
  32% {
    transform: translateY(-4px);
  }
}

@keyframes reactCuriousBody {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  36% {
    transform: rotate(-6deg) scaleX(1.008) scaleY(0.994);
  }
  68% {
    transform: rotate(2deg) scaleX(0.998) scaleY(1.004);
  }
}

@keyframes reactCuriousShadow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
  36% {
    transform: scale(0.9);
    opacity: 0.54;
  }
}

@keyframes angryBuzz {
  0% {
    transform:
      translateX(calc(var(--micro-shift) + var(--carry-shift-x) - 0.8px))
      translateY(calc(var(--micro-lift) + var(--carry-shift-y)))
      rotate(calc(var(--micro-tilt) + var(--carry-tilt)));
  }
  100% {
    transform:
      translateX(calc(var(--micro-shift) + var(--carry-shift-x) + 0.8px))
      translateY(calc(var(--micro-lift) + var(--carry-shift-y)))
      rotate(calc(var(--micro-tilt) + var(--carry-tilt)));
  }
}

@keyframes curiousTilt {
  0%,
  100% {
    transform: translateX(-50%) rotate(0deg);
  }
  35% {
    transform: translateX(-50%) rotate(-5deg);
  }
  70% {
    transform: translateX(-50%) rotate(2deg);
  }
}

@media (max-width: 860px) {
  .chat-panel {
    width: min(360px, calc(100vw - 18px));
  }

  .mini-log {
    width: min(300px, calc(100vw - 18px));
  }
}

@media (max-width: 720px) {
  :root {
    --ground: 148px;
    --pet-width: clamp(128px, 32vw, 176px);
  }

  .hud {
    top: 10px;
    left: 10px;
    max-width: calc(100vw - 20px);
  }

  .pill {
    min-width: 0;
  }

  .chat-panel {
    right: 9px;
    bottom: 9px;
    width: calc(100vw - 18px);
    height: min(52vh, 448px);
  }

  .chat-header {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-tools {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .chat-quick-actions {
    gap: 8px;
    padding: 10px 12px;
  }

  .speech {
    width: min(220px, calc(100vw - 24px));
  }

  .mini-log {
    display: none;
  }

  .actions {
    gap: 8px;
  }

  button {
    padding: 9px 12px;
  }
}
