.avatar-stage {
  position: relative;
  flex: 0 0 clamp(460px, 72vh, 720px);
  min-height: 420px;
  overflow: hidden;
  background: #101010;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
}

.avatar-video-surface {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  animation: avatarBreath 5.8s ease-in-out infinite;
  transform-origin: center 58%;
  will-change: transform;
}

.avatar-three-surface {
  position: absolute;
  inset: 0;
  z-index: 6;
  width: 100%;
  height: 100%;
  border: 0;
  background: #101113;
  pointer-events: none;
}

.avatar-three-surface[hidden] {
  display: none;
}

.avatar-stage.avatar-has-three-surface .avatar-video-surface {
  opacity: 0;
  pointer-events: none;
}

.avatar-portrait {
  position: relative;
  width: min(72vw, 520px, calc((min(72vh, 720px) - 48px) * 2 / 3));
  max-height: calc(100% - 48px);
  max-width: calc(100% - 64px);
  min-width: 0;
  aspect-ratio: 2 / 3;
  background: linear-gradient(180deg, #222, #111);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: box-shadow 180ms ease, transform 180ms ease, filter 180ms ease;
}

.avatar-stage.avatar-click-feedback .avatar-portrait {
  animation: avatarClickPulse 520ms ease-out;
  box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.42), 0 18px 44px rgba(0, 0, 0, 0.48);
}

.avatar-stage:hover .avatar-portrait {
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
}

.avatar-stage.avatar-idle-glance .avatar-image {
  animation: avatarLookAround 1500ms ease-in-out;
}

.avatar-stage.avatar-idle-nod .avatar-portrait {
  animation: avatarIdleNod 1300ms ease-in-out;
}

.avatar-portrait::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 22%;
  height: 24%;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(52, 31, 24, 0) 0%,
    rgba(52, 31, 24, 0.2) 42%,
    rgba(52, 31, 24, 0.32) 52%,
    rgba(52, 31, 24, 0.2) 62%,
    rgba(52, 31, 24, 0) 100%
  );
}

.avatar-stage.avatar-idle-blink .avatar-portrait::after {
  animation: avatarBlink 760ms ease-in-out;
}

.avatar-face {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 222, 198, 0.92) 0 19%, transparent 20%),
    radial-gradient(circle at 43% 32%, #241a17 0 1.4%, transparent 1.6%),
    radial-gradient(circle at 57% 32%, #241a17 0 1.4%, transparent 1.6%),
    linear-gradient(180deg, #4a332d 0 24%, #ead9c8 25% 58%, #efe9df 59% 100%);
}

.avatar-image {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  will-change: transform, filter;
}

.avatar-image[hidden] {
  display: none;
}

.avatar-source-image {
  z-index: 2;
}

.avatar-model-video {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}

.avatar-model-video[hidden] {
  display: none;
}

.avatar-stage.avatar-has-model-video .avatar-face,
.avatar-stage.avatar-has-model-video .avatar-image {
  opacity: 0;
}

.avatar-stage.avatar-has-model-video .avatar-mouth {
  opacity: 0;
}

.avatar-stage.avatar-has-model-video.avatar-fast-mouth-overlay .avatar-mouth {
  z-index: 5;
  top: 58%;
  width: 52px;
  height: 10px;
  background: rgba(109, 39, 42, 0.72);
}

.avatar-mouth {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 2;
  width: 38px;
  height: 12px;
  border-radius: 999px;
  background: #6d272a;
  transform: translateX(-50%) scaleY(0.18);
  transform-origin: center;
  opacity: 0.35;
  transition: transform 40ms linear, opacity 40ms linear;
}

.avatar-portrait:has(.avatar-image:not([hidden])) .avatar-mouth {
  top: 58%;
  width: 52px;
  height: 10px;
  background: rgba(109, 39, 42, 0.72);
}

@keyframes avatarClickPulse {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  28% {
    transform: scale(1.055);
    filter: brightness(1.18);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes avatarBreath {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(4px) scale(1.006);
  }
}

@keyframes avatarBlink {
  0%,
  38%,
  100% {
    opacity: 0;
    transform: scaleY(0.25);
  }
  47%,
  55% {
    opacity: 1;
    transform: scaleY(1);
  }
}

@keyframes avatarLookAround {
  0%,
  100% {
    transform: translateX(0) scale(1);
    filter: brightness(1);
  }
  35% {
    transform: translateX(-7px) scale(1.012);
    filter: brightness(1.05);
  }
  68% {
    transform: translateX(5px) scale(1.008);
    filter: brightness(1.03);
  }
}

@keyframes avatarIdleNod {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  42% {
    transform: translateY(5px) rotate(0.35deg);
  }
  72% {
    transform: translateY(-2px) rotate(-0.2deg);
  }
}

.avatar-status {
  position: absolute;
  left: 20px;
  bottom: 18px;
  color: var(--muted);
  font-size: 12px;
}

.avatar-stage.avatar-click-feedback .avatar-status {
  color: var(--accent);
}

@media (max-width: 760px) {
  .avatar-stage {
    flex-basis: 58vh;
    min-height: 320px;
  }

  .avatar-portrait {
    width: min(86vw, 420px, calc((58vh - 36px) * 2 / 3));
    max-height: calc(100% - 36px);
    max-width: calc(100% - 32px);
  }
}
