.miao-avatar,
.miao-avatar * {
  box-sizing: border-box;
}

.miao-avatar {
  --avatar-x: calc(100vw - 388px);
  --avatar-y: calc(100vh - 568px);
  --line: #2d2344;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  width: clamp(300px, 24vw, 420px);
  height: clamp(450px, 36vw, 630px);
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  border: 0;
  padding: 0;
  background: transparent;
  transform: translate3d(var(--avatar-x), var(--avatar-y), 0);
  transition: opacity 180ms ease, filter 180ms ease;
  user-select: none;
  touch-action: none;
  contain: layout paint style;
  will-change: transform;
}

.miao-avatar.is-dragging {
  cursor: grabbing;
  filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.24));
}

.miao-avatar.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.miao-avatar-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  image-rendering: auto;
}

.miao-avatar-bubble {
  position: absolute;
  right: 226px;
  top: 20px;
  min-width: 150px;
  max-width: 220px;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: #2d2030;
  background: #fff7df;
  box-shadow: 4px 5px 0 rgba(18, 174, 185, 0.38);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.miao-avatar-bubble::after {
  content: "";
  position: absolute;
  right: -9px;
  bottom: 18px;
  width: 14px;
  height: 14px;
  border-top: 2px solid var(--line);
  border-right: 2px solid var(--line);
  background: #fff7df;
  transform: rotate(45deg);
}

.miao-avatar.is-speaking .miao-avatar-bubble {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.miao-avatar-loading,
.miao-avatar-error {
  position: absolute;
  inset: auto 18px 18px 18px;
  min-height: 48px;
  padding: 9px 12px;
  border: 1px solid rgba(45, 35, 68, 0.18);
  border-radius: 8px;
  color: #2d2030;
  background: rgba(255, 247, 223, 0.9);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.miao-avatar-loading-text {
  display: block;
}

.miao-avatar-progress {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(45, 35, 68, 0.14);
}

.miao-avatar-progress > span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #12aeb9;
  transition: width 120ms linear;
}

.miao-avatar.is-ready .miao-avatar-loading,
.miao-avatar.is-error .miao-avatar-loading,
.miao-avatar:not(.is-error) .miao-avatar-error {
  display: none;
}

@media (max-width: 640px) {
  .miao-avatar {
    width: min(280px, calc(100vw - 24px));
    height: min(420px, calc(100vh - 24px));
  }

  .miao-avatar-bubble {
    right: 170px;
    top: 8px;
    min-width: 126px;
    font-size: 12px;
  }
}
