:root {
  --good: #22a55b;
  --warn: #e0a100;
  --bad: #e5484d;
  --card: #fffdf8;
  --card-ink: #1f1a14;
  --muted: #7a6f63;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: transparent;
  font-family: "Segoe UI", system-ui, sans-serif;
  user-select: none;
}

/* ---------- Character ---------- */
#pet {
  position: absolute;
  left: 0;
  top: 0;
  width: 112px;
  height: 112px;
  cursor: grab;
  will-change: transform;
}
#pet.dragging { cursor: grabbing; }
#pet svg { overflow: visible; display: block; width: 100%; height: 100%; }
#pet svg.flip { transform: scaleX(-1); }
#pet svg { filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.18)); }

.shadow { fill: rgba(0, 0, 0, 0.2); transform-box: fill-box; transform-origin: center; }
.leg { transform-box: fill-box; transform-origin: 50% 8%; }
.tail { transform-box: fill-box; transform-origin: 0% 90%; }
.ear { transform-box: fill-box; transform-origin: 50% 6%; }
.brow { transform-box: fill-box; transform-origin: center; transition: transform 0.25s; }
.iris { transition: transform 0.25s; }
.pupil { transform-box: fill-box; transform-origin: center; transition: transform 0.25s; }
.nose { transform-box: fill-box; transform-origin: center; }
.head { transform-box: view-box; transform-origin: 100px 122px; transition: transform 0.3s; }
.glass { transform-box: view-box; transform-origin: 146px 152px; }
.body-g { transform-box: view-box; transform-origin: 100px 190px; }

/* Expression layers: only the default ones are visible unless a mood swaps them */
.eyes-happy, .mouth-happy, .mouth-sad, .mouth-o { display: none; }

/* idle life: blinking, wagging, breathing */
.lid { animation: blink 5s infinite; }
@keyframes blink {
  0%, 93%, 100% { height: 0; }
  95.5% { height: 28px; }
}
.tail { animation: wag 1.6s ease-in-out infinite; }
@keyframes wag { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(14deg); } }
#pet.idle .head { animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(1.5px); } }

/* walking */
#pet.walking .leg-a { animation: step 0.36s ease-in-out infinite; }
#pet.walking .leg-b { animation: step 0.36s ease-in-out infinite reverse; }
#pet.walking .body-g { animation: bob 0.36s ease-in-out infinite; }
#pet.walking .ear { animation: flop 0.36s ease-in-out infinite; }
@keyframes step { 0%, 100% { transform: rotate(20deg); } 50% { transform: rotate(-20deg); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes flop { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(5deg); } }

/* sniffing: head down, eyes on the lens, nose twitching */
#pet.sniffing .head { transform: rotate(-6deg) translateY(3px); }
#pet.sniffing .iris { transform: translate(3px, 3px); }
#pet.sniffing .nose { animation: sniff 0.22s ease-in-out infinite; }
#pet.sniffing .glass { animation: search 1.3s ease-in-out infinite; }
#pet.sniffing .brow-l { transform: translateY(2px) rotate(8deg); }
#pet.sniffing .brow-r { transform: translateY(-2px) rotate(-4deg); }
@keyframes sniff { 50% { transform: scale(1.18, 0.86); } }
@keyframes search {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  33% { transform: translate(-22px, -8px) rotate(-8deg); }
  66% { transform: translate(-8px, 5px) rotate(4deg); }
}

/* happy: squinty smile, tongue out, hopping */
#pet.happy .eyes-open, #pet.happy .mouth-idle { display: none; }
#pet.happy .eyes-happy, #pet.happy .mouth-happy { display: inline; }
#pet.happy .body-g { animation: hop 0.5s ease-out 3; }
#pet.happy .shadow { animation: shadow-hop 0.5s ease-out 3; }
#pet.happy .tail { animation-duration: 0.35s; }
#pet.happy .brow { transform: translateY(-3px); }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-24px); } }
@keyframes shadow-hop { 0%, 100% { transform: scale(1); } 40% { transform: scale(0.7); opacity: 0.6; } }

/* alarm: wide eyes, open mouth, ears up, shaking */
#pet.alarm .mouth-idle { display: none; }
#pet.alarm .mouth-o { display: inline; }
#pet.alarm .pupil { transform: scale(0.6); }
#pet.alarm .brow { transform: translateY(-5px); }
#pet.alarm .body-g { animation: shake 0.12s linear infinite; }
#pet.alarm .ear-l { transform: translateY(-4px) rotate(12deg); }
#pet.alarm .ear-r { transform: translateY(-4px) rotate(-12deg); }
#pet.alarm .tail { animation: none; transform: rotate(-35deg); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* worried: brows knit, frown, head tilt */
#pet.worried .mouth-idle { display: none; }
#pet.worried .mouth-sad { display: inline; }
#pet.worried .brow-l { transform: rotate(-16deg) translateY(1px); }
#pet.worried .brow-r { transform: rotate(16deg) translateY(1px); }
#pet.worried .head { transform: rotate(7deg); }
#pet.worried .iris { transform: translate(-2px, 1px); }
#pet.worried .tail { animation-duration: 3s; }

#alert {
  position: absolute;
  left: 50%;
  top: -26px;
  transform: translateX(-50%) scale(0);
  font: 900 30px/1 "Segoe UI", sans-serif;
  color: var(--bad);
  text-shadow: 0 2px 0 #fff, 0 0 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
#pet.alarm #alert { transform: translateX(-50%) scale(1); }

/* ---------- Bubble ---------- */
#bubble {
  position: absolute;
  width: 330px;
  max-width: calc(100vw - 32px);
  background: var(--card);
  color: var(--card-ink);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.06);
  padding: 12px 14px 12px;
  font-size: 13px;
  line-height: 1.35;
  transition: opacity 0.18s, transform 0.18s;
  transform-origin: bottom center;
}
#bubble.hidden { opacity: 0; transform: scale(0.85) translateY(8px); pointer-events: none; }
#bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: var(--tail-x, 50%);
  width: 16px;
  height: 16px;
  background: var(--card);
  transform: translateX(-50%) rotate(45deg);
  box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.08);
}
#bubble.good { border-top: 5px solid var(--good); }
#bubble.warn { border-top: 5px solid var(--warn); }
#bubble.bad { border-top: 5px solid var(--bad); }

.b-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.b-head img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; background: #eee; flex: none; }
.b-title { flex: 1; min-width: 0; }
.b-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-sym { color: var(--muted); font-size: 12px; }
.b-score { font-weight: 800; font-size: 15px; color: #fff; border-radius: 999px; padding: 3px 10px; flex: none; }
.good .b-score { background: var(--good); }
.warn .b-score { background: var(--warn); }
.bad .b-score { background: var(--bad); }

.b-say { font-weight: 600; margin: 4px 0 8px; }
.b-checks { list-style: none; margin: 0 0 8px; padding: 0; max-height: 210px; overflow-y: auto; }
.b-checks li { display: flex; gap: 6px; padding: 2px 0; }
.b-checks li span:first-child { flex: none; width: 18px; text-align: center; }
.b-checks li.info { color: var(--muted); }

.b-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.b-stats b { color: var(--card-ink); font-weight: 600; }

.b-actions { display: flex; gap: 6px; }
.b-actions button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 9px;
  padding: 6px 10px;
  cursor: pointer;
  background: #f0e9df;
  color: var(--card-ink);
}
.b-actions button.primary { background: var(--card-ink); color: #fff; }
.b-actions button:hover { filter: brightness(0.95); }
.b-actions .spacer { flex: 1; }
.b-foot { color: var(--muted); font-size: 11px; margin-top: 8px; }
.b-text { font-size: 13.5px; font-weight: 600; }
