:root {
  --live-avatar-surface: #ffffff;
  --live-avatar-text: #17202a;
  --live-avatar-muted: #657285;
  --live-avatar-line: #dfe5ee;
  --live-avatar-accent: #0f766e;
  --live-avatar-accent-strong: #0b5d57;
  --live-avatar-danger: #b42318;
}

.live-avatar-widget {
  --avatar-mouth-left: 50%;
  --avatar-mouth-top: auto;
  --avatar-mouth-bottom: 22%;
  --avatar-mouth-width: 24%;
  --avatar-mouth-transform: translateX(-50%);
  position: fixed;
  z-index: 2147483000;
  color: var(--live-avatar-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.live-avatar--bottom-right { right: 20px; bottom: 20px; }
.live-avatar--bottom-left { left: 20px; bottom: 20px; }
.live-avatar--top-right { right: 20px; top: 20px; }
.live-avatar--top-left { left: 20px; top: 20px; }

.live-avatar-widget button,
.live-avatar-widget input {
  font: inherit;
}

.live-avatar-fab {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: var(--live-avatar-accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 18px 38px rgba(15, 23, 42, .22);
  cursor: pointer;
  position: relative;
}

.live-avatar-fab svg {
  width: 30px;
  height: 30px;
}

.live-avatar-fab:focus-visible,
.live-avatar-icon-button:focus-visible,
.live-avatar-send:focus-visible,
.live-avatar-feedback button:focus-visible {
  outline: 3px solid #f3c969;
  outline-offset: 3px;
}

.live-avatar-fab-pulse {
  position: absolute;
  inset: -5px;
  border: 2px solid rgba(15, 118, 110, .28);
  border-radius: 50%;
  animation: live-avatar-pulse 2.6s ease-out infinite;
}

.live-avatar-panel {
  box-sizing: border-box;
  width: min(380px, calc(100vw - 24px));
  max-height: min(680px, calc(100vh - 104px));
  margin-bottom: 12px;
  background: var(--live-avatar-surface);
  border: 1px solid var(--live-avatar-line);
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, .24);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
}

.live-avatar--top-right .live-avatar-panel,
.live-avatar--top-left .live-avatar-panel {
  margin-top: 12px;
  margin-bottom: 0;
}

.live-avatar-widget[data-open="false"] .live-avatar-panel {
  display: none;
}

.live-avatar-widget[data-open="true"] .live-avatar-fab {
  display: none;
}

.live-avatar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--live-avatar-line);
}

.live-avatar-header h2 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.live-avatar-status {
  margin: 3px 0 0;
  color: var(--live-avatar-muted);
  font-size: .86rem;
}

.live-avatar-controls {
  display: flex;
  gap: 8px;
}

.live-avatar-icon-button,
.live-avatar-send {
  border: 1px solid var(--live-avatar-line);
  background: #f8fafc;
  color: var(--live-avatar-text);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.live-avatar-icon-button svg,
.live-avatar-send svg {
  width: 21px;
  height: 21px;
}

.live-avatar-stage {
  display: grid;
  place-items: center;
  padding: 18px 18px 8px;
  background: linear-gradient(180deg, #f4fbfa 0%, #fff 100%);
}

.live-avatar-head {
  width: 168px;
  max-width: 54vw;
  aspect-ratio: 1;
  position: relative;
  transform-origin: 50% 70%;
  animation: live-avatar-idle 5.5s ease-in-out infinite;
}

.live-avatar--full-body .live-avatar-stage {
  padding: 10px 18px 4px;
  background: linear-gradient(180deg, #f8fbfc 0%, #fff 100%);
  border-bottom: 1px solid var(--live-avatar-line);
}

.live-avatar--full-body .live-avatar-head {
  width: min(172px, 46vw);
  aspect-ratio: 11 / 21;
  animation: live-avatar-fullbody-idle 6.2s ease-in-out infinite;
}

.live-avatar-base {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 50%;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .12);
}

.live-avatar--full-body .live-avatar-base {
  border-radius: 0;
  box-shadow: none;
  object-fit: contain;
}

.live-avatar--full-body .live-avatar-eyes {
  display: none;
}

.live-avatar-mouth,
.avatar-rig-mouth {
  position: absolute;
  left: var(--avatar-mouth-left);
  top: var(--avatar-mouth-top);
  bottom: var(--avatar-mouth-bottom);
  width: var(--avatar-mouth-width);
  transform: var(--avatar-mouth-transform);
  pointer-events: none;
  z-index: 3;
}

.live-avatar-mouth {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .18));
  z-index: 2;
}

.avatar-rig-mouth {
  height: auto;
  aspect-ratio: 240 / 160;
  overflow: visible;
}

.live-avatar-widget[data-rig="true"] .live-avatar-mouth {
  display: none;
}

.live-avatar-eyes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.live-avatar-eyes::before {
  content: "";
  position: absolute;
  left: 28%;
  right: 28%;
  top: 34%;
  height: 4px;
  border-radius: 999px;
  background: rgba(23, 32, 42, .72);
  opacity: 0;
  transform: scaleY(.2);
  animation: live-avatar-blink 5.8s infinite;
}

.live-avatar-widget[data-state="thinking"] .live-avatar-head {
  animation-duration: 1.6s;
}

.live-avatar-widget[data-state="speaking"] .live-avatar-head {
  animation-duration: 2.4s;
}

.live-avatar-widget[data-state="happy"] .live-avatar-head {
  animation: live-avatar-happy 900ms ease-out;
}

.live-avatar-widget[data-state="error"] .live-avatar-status {
  color: var(--live-avatar-danger);
}

.live-avatar-caption {
  margin: 0 14px 8px;
  padding: 9px 11px;
  border: 1px solid #bee3dc;
  background: #effaf8;
  border-radius: 8px;
  color: #104d48;
  font-size: .9rem;
  line-height: 1.35;
}

.live-avatar-messages {
  min-height: 130px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px 14px 14px;
  display: grid;
  gap: 10px;
}

.live-avatar--full-body .live-avatar-messages {
  min-height: 82px;
  max-height: 150px;
}

.live-avatar-message {
  display: grid;
  gap: 5px;
}

.live-avatar-message p {
  margin: 0;
  width: fit-content;
  max-width: 86%;
  padding: 9px 11px;
  border-radius: 8px;
  line-height: 1.38;
  font-size: .94rem;
  overflow-wrap: anywhere;
}

.live-avatar-message--assistant p {
  background: #f1f5f9;
}

.live-avatar-message--user {
  justify-items: end;
}

.live-avatar-message--user p {
  background: var(--live-avatar-accent);
  color: #fff;
}

.live-avatar-message--error p {
  background: #fff1f0;
  color: var(--live-avatar-danger);
}

.live-avatar-feedback {
  display: flex;
  gap: 6px;
  padding-left: 4px;
}

.live-avatar-feedback button {
  border: 1px solid var(--live-avatar-line);
  background: #fff;
  color: var(--live-avatar-muted);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: .78rem;
  cursor: pointer;
}

.live-avatar-form {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--live-avatar-line);
}

.live-avatar-input-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.live-avatar-form input {
  min-width: 0;
  border: 1px solid var(--live-avatar-line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--live-avatar-text);
  background: #fff;
}

.live-avatar-form input:focus {
  outline: 3px solid rgba(15, 118, 110, .18);
  border-color: var(--live-avatar-accent);
}

.live-avatar-send {
  background: var(--live-avatar-accent);
  border-color: var(--live-avatar-accent);
  color: #fff;
}

@keyframes live-avatar-pulse {
  0% { opacity: .72; transform: scale(.9); }
  70%, 100% { opacity: 0; transform: scale(1.28); }
}

@keyframes live-avatar-idle {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-4px) rotate(1.4deg); }
}

@keyframes live-avatar-fullbody-idle {
  0%, 100% { transform: translateY(0) rotate(-.35deg); }
  50% { transform: translateY(-3px) rotate(.45deg); }
}

@keyframes live-avatar-happy {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-7px) scale(1.03); }
}

@keyframes live-avatar-blink {
  0%, 92%, 100% { opacity: 0; transform: scaleY(.2); }
  94%, 96% { opacity: .75; transform: scaleY(1); }
}

@media (max-width: 520px) {
  .live-avatar-widget {
    left: 12px;
    right: 12px;
    bottom: 12px;
    top: auto;
    width: calc(100vw - 24px);
  }

  .live-avatar-fab {
    margin-left: auto;
  }

  .live-avatar-panel {
    width: 100%;
    max-height: calc(100vh - 92px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-avatar-fab-pulse,
  .live-avatar-head,
  .live-avatar-eyes::before {
    animation: none !important;
  }
}

/* ============================================================
   Apple-inspired refinement (V2). Appended last so it cleanly
   overrides the base widget look without touching the rules above.
   Mouth drift is fixed in JS (no base-only transform); the rig
   stays locked to the avatar art.
   ============================================================ */
.live-avatar-widget {
  --jp-blue: #0071e3;
  --jp-blue-dark: #005bbd;
  --jp-line: rgba(17, 24, 39, .10);
  --jp-muted: #6b7280;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
}
.live-avatar-panel {
  border-radius: 22px;
  border: 1px solid var(--jp-line);
  box-shadow: 0 30px 80px rgba(15, 23, 42, .22);
  overflow: hidden;
}
.live-avatar-header {
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--jp-line);
}
.live-avatar-header h2 { letter-spacing: -.01em; }
.live-avatar-fab {
  background: var(--jp-blue);
  box-shadow: 0 14px 30px rgba(0, 113, 227, .35);
}
.live-avatar-fab:hover { background: var(--jp-blue-dark); }
.live-avatar-form input {
  border-radius: 14px;
  border: 1px solid var(--jp-line);
}
.live-avatar-form input:focus {
  border-color: var(--jp-blue);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, .18);
  outline: none;
}
.live-avatar-send { border-radius: 14px; background: var(--jp-blue); }
.live-avatar-send:hover { background: var(--jp-blue-dark); }
.live-avatar-message--assistant p {
  background: #f3f7fe;
  border: 1px solid var(--jp-line);
  border-radius: 14px;
}
.live-avatar-message--user p {
  background: var(--jp-blue);
  border-radius: 14px;
}
.live-avatar-caption {
  background: #f3f7fe;
  border: 1px solid var(--jp-line);
  border-radius: 14px;
}
.live-avatar-chip { transition: background .15s ease, transform .12s ease; }
.live-avatar-chip:active { transform: translateY(1px); }
.live-avatar-fab:focus-visible,
.live-avatar-send:focus-visible,
.live-avatar-chip:focus-visible,
.live-avatar-icon-button:focus-visible {
  outline: 3px solid rgba(0, 113, 227, .5);
  outline-offset: 3px;
}

/* Compact on phones — not full-screen unless it must be. */
@media (max-width: 480px) {
  .live-avatar-panel {
    width: min(420px, calc(100vw - 20px));
    max-height: min(76vh, 620px);
    border-radius: 20px;
  }
}

/* Rig hidden at rest (painted mouth shows), fades in only while speaking. */
.avatar-rig-mouth { opacity: 0; transition: opacity .22s ease; }
.live-avatar-widget[data-state="speaking"] .avatar-rig-mouth { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .avatar-rig-mouth { opacity: 0 !important; }
}
