.akh-pet {
  --akh-pet-accent: #b52d23;
  --akh-pet-accent-soft: rgba(181, 45, 35, 0.16);
  --akh-pet-panel: color-mix(in srgb, var(--bg, #11100f) 92%, transparent);
  --akh-pet-border: color-mix(in srgb, var(--ink, #e8dfcf) 18%, transparent);
  position: fixed;
  z-index: 86;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 112px;
  height: 122px;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.28));
}

.akh-pet-stage {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100px;
  height: 108px;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  overflow: visible;
}

.akh-pet-stage:active,
.akh-pet.is-dragging .akh-pet-stage {
  cursor: grabbing;
}

.akh-pet-stage:focus-visible {
  outline: 2px solid var(--akh-pet-accent);
  outline-offset: 4px;
  border-radius: 45%;
}

.akh-pet-sprite {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 192px;
  height: 208px;
  display: block;
  background-image: url("img/akhilius/pet/spritesheet.webp");
  background-repeat: no-repeat;
  background-size: 1536px 2288px;
  background-position: 0 0;
  transform: scale(0.52);
  transform-origin: left bottom;
  image-rendering: auto;
  transition: filter 180ms ease, opacity 180ms ease;
}

.akh-pet-stage:hover .akh-pet-sprite {
  filter: saturate(1.05) brightness(1.04);
}

.akh-pet[data-state="failed"] {
  --akh-pet-accent: #d14c43;
  --akh-pet-accent-soft: rgba(209, 76, 67, 0.18);
}

.akh-pet[data-state="waiting"],
.akh-pet.is-offline {
  --akh-pet-accent: #d59b3a;
  --akh-pet-accent-soft: rgba(213, 155, 58, 0.18);
}

.akh-pet[data-state="running"],
.akh-pet[data-state="review"] {
  --akh-pet-accent: #3f8f79;
  --akh-pet-accent-soft: rgba(63, 143, 121, 0.17);
}

.akh-pet-status {
  position: absolute;
  right: 70px;
  bottom: 82px;
  min-width: max-content;
  max-width: min(220px, calc(100vw - 140px));
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--akh-pet-border);
  border-radius: 999px 999px 8px 999px;
  background: var(--akh-pet-panel);
  color: var(--ink, #e8dfcf);
  font: 600 0.68rem/1.1 var(--font-sans, system-ui, sans-serif);
  letter-spacing: 0.035em;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0.82;
  transform: translateY(2px);
  transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
  pointer-events: none;
}

.akh-pet:hover .akh-pet-status,
.akh-pet.panel-open .akh-pet-status,
.akh-pet[data-state="failed"] .akh-pet-status,
.akh-pet[data-state="waiting"] .akh-pet-status {
  opacity: 1;
  transform: translateY(0);
  border-color: color-mix(in srgb, var(--akh-pet-accent) 44%, transparent);
}

.akh-pet-status-dot,
.akh-pet-pulse {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--akh-pet-accent);
  box-shadow: 0 0 0 4px var(--akh-pet-accent-soft);
}

.akh-pet[data-state="running"] .akh-pet-status-dot,
.akh-pet[data-state="review"] .akh-pet-status-dot,
.akh-pet[data-state="waiting"] .akh-pet-status-dot {
  animation: akhPetPulse 1.5s ease-in-out infinite;
}

.akh-pet-panel {
  position: absolute;
  right: 8px;
  bottom: 116px;
  width: min(300px, calc(100vw - 24px));
  padding: 15px;
  border: 1px solid var(--akh-pet-border);
  border-radius: 18px 18px 6px 18px;
  background: var(--akh-pet-panel);
  color: var(--ink, #e8dfcf);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  pointer-events: auto;
  transform-origin: right bottom;
  animation: akhPetPanelIn 170ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.akh-pet.dock-left .akh-pet-panel {
  right: auto;
  left: 8px;
  border-radius: 18px 18px 18px 6px;
  transform-origin: left bottom;
}

.akh-pet-panel[hidden] {
  display: none;
}

.akh-pet-panel-head,
.akh-pet-panel-state,
.akh-pet-actions,
.akh-pet-settings {
  display: flex;
  align-items: center;
}

.akh-pet-panel-head {
  justify-content: space-between;
  gap: 12px;
}

.akh-pet-kicker {
  color: var(--akh-pet-accent);
  font: 700 0.58rem/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.15em;
}

.akh-pet-panel-title {
  margin-top: 5px;
  font: 600 0.94rem/1.2 var(--font-serif, Georgia, serif);
}

.akh-pet-icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--akh-pet-border);
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
}

.akh-pet-panel-state {
  gap: 9px;
  margin-top: 17px;
  font: 650 0.81rem/1.2 var(--font-sans, system-ui, sans-serif);
}

.akh-pet-panel-detail {
  min-height: 1.1em;
  margin: 7px 0 15px 16px;
  color: var(--ink-dim, #a9a196);
  font: 500 0.7rem/1.35 var(--font-mono, ui-monospace, monospace);
  overflow-wrap: anywhere;
}

.akh-pet-actions {
  gap: 7px;
}

.akh-pet-actions button,
.akh-pet-settings button {
  min-height: 34px;
  border: 1px solid var(--akh-pet-border);
  border-radius: 9px;
  background: color-mix(in srgb, var(--akh-pet-accent) 8%, transparent);
  color: inherit;
  font: 600 0.66rem/1 var(--font-sans, system-ui, sans-serif);
  cursor: pointer;
}

.akh-pet-actions button {
  flex: 1;
}

.akh-pet-settings {
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

.akh-pet-settings button {
  flex: 1;
  min-height: 30px;
  background: transparent;
  color: var(--ink-dim, #a9a196);
  font-size: 0.62rem;
}

.akh-pet-actions button:hover,
.akh-pet-settings button:hover,
.akh-pet-icon-btn:hover {
  border-color: color-mix(in srgb, var(--akh-pet-accent) 55%, transparent);
  color: var(--ink, #e8dfcf);
}

.akh-pet-mini-mark {
  display: none;
}

.akh-pet.is-collapsed {
  width: 44px;
  height: 48px;
  filter: drop-shadow(0 9px 16px rgba(0, 0, 0, 0.24));
}

.akh-pet.is-collapsed .akh-pet-stage {
  width: 44px;
  height: 48px;
  border: 1px solid var(--akh-pet-border);
  border-radius: 50%;
  background: var(--akh-pet-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.akh-pet.is-collapsed .akh-pet-sprite,
.akh-pet.is-collapsed .akh-pet-status {
  display: none;
}

.akh-pet.is-collapsed .akh-pet-mini-mark {
  display: grid;
  position: absolute;
  inset: 0;
  place-items: center;
  color: var(--akh-pet-accent);
  font-size: 1.2rem;
}

.akh-pet[data-motion="off"] .akh-pet-status-dot,
.akh-pet[data-motion="off"] .akh-pet-pulse {
  animation: none;
}

@keyframes akhPetPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--akh-pet-accent-soft); opacity: 0.82; }
  50% { box-shadow: 0 0 0 7px transparent; opacity: 1; }
}

@keyframes akhPetPanelIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 720px) {
  .akh-pet {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: 92px;
    height: 102px;
  }

  .akh-pet-stage {
    width: 82px;
    height: 90px;
  }

  .akh-pet-sprite {
    transform: scale(0.43);
  }

  .akh-pet-status {
    right: 58px;
    bottom: 66px;
    max-width: min(190px, calc(100vw - 110px));
    padding: 6px 8px;
    font-size: 0.62rem;
  }

  .akh-pet-panel {
    position: fixed;
    right: 10px;
    bottom: calc(100px + env(safe-area-inset-bottom));
    width: min(310px, calc(100vw - 20px));
  }

  .akh-pet.dock-left .akh-pet-panel {
    right: auto;
    left: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .akh-pet,
  .akh-pet *,
  .akh-pet *::before,
  .akh-pet *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
