.avatar-helper {
  --avatar-bubble-x: 0px;
  --avatar-bubble-y: 0px;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 40;
  width: clamp(560px, 52vw, 820px);
  height: min(82vh, 820px);
  pointer-events: none;
  transform: translateX(calc(-100% + 54px));
  transition: transform 260ms ease;
}

.avatar-helper.is-open {
  transform: translateX(0);
}

.avatar-helper:not(.is-open) .avatar-helper__bubble,
.avatar-helper:not(.is-open) .avatar-helper__bubble-toggle {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.avatar-helper__image {
  position: absolute;
  left: 0;
  bottom: 0;
  width: auto;
  max-width: clamp(260px, 28vw, 500px);
  height: 100%;
  object-fit: contain;
  object-position: bottom left;
}

.avatar-helper__bubble {
  position: absolute;
  left: clamp(190px, 20vw, 300px);
  top: clamp(18px, 8vh, 82px);
  width: clamp(260px, 25vw, 380px);
  padding: 16px 18px;
  border: 1px solid rgba(219, 226, 239, 0.94);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.14);
  color: #334155;
  backdrop-filter: blur(14px);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  transform: translate(var(--avatar-bubble-x), var(--avatar-bubble-y));
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.avatar-helper.is-dragging .avatar-helper__bubble {
  cursor: grabbing;
  transition: none;
}

.avatar-helper.is-bubble-hidden .avatar-helper__bubble {
  opacity: 0;
  visibility: hidden;
  transform: translate(var(--avatar-bubble-x), calc(var(--avatar-bubble-y) - 8px));
  pointer-events: none;
}

.avatar-helper__bubble::before {
  content: "";
  position: absolute;
  left: -10px;
  bottom: 28px;
  width: 18px;
  height: 18px;
  border-left: 1px solid rgba(219, 226, 239, 0.94);
  border-bottom: 1px solid rgba(219, 226, 239, 0.94);
  background: rgba(255, 255, 255, 0.94);
  transform: rotate(45deg);
}

.avatar-helper__toggle,
.avatar-helper__hide,
.avatar-helper__bubble-toggle,
.avatar-helper__bubble-close,
.avatar-helper__step-button,
.avatar-helper__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(219, 226, 239, 0.94);
  background: #ffffff;
  color: #0f172a;
  cursor: pointer;
  pointer-events: auto;
}

.avatar-helper__toggle {
  position: absolute;
  right: 0;
  top: clamp(150px, 34vh, 280px);
  width: 54px;
  height: 54px;
  padding: 4px;
  border-radius: 0 8px 8px 0;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.16);
  font-size: 1.1rem;
  font-weight: 850;
  overflow: hidden;
}

.avatar-helper.is-open .avatar-helper__toggle {
  opacity: 0;
  pointer-events: none;
}

.avatar-helper__hide {
  position: absolute;
  left: 18px;
  bottom: 24px;
  width: 42px;
  height: 42px;
  padding: 4px;
  border-radius: 50%;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.16);
  font-size: 1rem;
  line-height: 1;
  overflow: hidden;
}

.avatar-helper__control-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.avatar-helper__bubble-toggle {
  position: absolute;
  left: clamp(178px, 19vw, 286px);
  top: clamp(18px, 8vh, 82px);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.16);
  font-size: 1rem;
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
}

.avatar-helper.is-open.is-bubble-hidden .avatar-helper__bubble-toggle {
  opacity: 1;
  pointer-events: auto;
}

.avatar-helper__bubble-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
}

.avatar-helper__title {
  display: block;
  margin: 0 28px 6px 0;
  color: #071633;
  cursor: grab;
  font-size: 0.95rem;
  font-weight: 850;
  line-height: 1.2;
}

.avatar-helper__message {
  min-height: 74px;
  margin: 0;
  color: #64748b;
  cursor: grab;
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.42;
  white-space: pre-line;
}

.avatar-helper__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.avatar-helper__step-count {
  color: #94a3b8;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.avatar-helper__nav,
.avatar-helper__actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.avatar-helper__actions {
  flex-wrap: wrap;
  margin-top: 10px;
}

.avatar-helper__chat {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(226, 232, 240, 0.9);
}

.avatar-helper__chat-log {
  display: flex;
  max-height: 180px;
  margin-bottom: 9px;
  overflow-y: auto;
  flex-direction: column;
  gap: 7px;
}

.avatar-helper__chat-empty {
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.35;
}

.avatar-helper__chat-message {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.38;
  white-space: pre-line;
}

.avatar-helper__chat-message--user {
  align-self: flex-end;
  background: #dbeafe;
  color: #0f3f8f;
}

.avatar-helper__chat-message--assistant {
  align-self: flex-start;
  background: #f8fafc;
  color: #334155;
  border: 1px solid #e2e8f0;
}

.avatar-helper__chat-form {
  display: flex;
  align-items: stretch;
  gap: 7px;
}

.avatar-helper__chat-input {
  min-width: 0;
  flex: 1 1 auto;
  height: 36px;
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #0f172a;
  font-size: 0.82rem;
  font-weight: 650;
}

.avatar-helper__chat-submit {
  min-width: 58px;
  height: 36px;
  padding: 7px 10px;
  border: 1px solid #2563eb;
  border-radius: 8px;
  background: #2563eb;
  color: #ffffff;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 850;
}

.avatar-helper__chat-submit:disabled {
  cursor: default;
  opacity: 0.55;
}

.avatar-helper__chat-status {
  min-height: 16px;
  margin-top: 6px;
  color: #64748b;
  font-size: 0.72rem;
  font-weight: 750;
}

.avatar-helper__step-button,
.avatar-helper__action {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  color: #1d4ed8;
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.1;
}

.avatar-helper__action {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.avatar-helper__step-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.avatar-helper__step-button:not(:disabled):hover,
.avatar-helper__step-button:not(:disabled):focus,
.avatar-helper__action:hover,
.avatar-helper__action:focus {
  background: #ffffff;
  color: #0b5bd3;
  box-shadow: 0 7px 18px rgba(15, 23, 42, 0.08);
}

.avatar-context-highlight {
  outline: 2px solid rgba(37, 99, 235, 0.68);
  outline-offset: 4px;
  border-radius: 8px;
  box-shadow: 0 0 0 7px rgba(37, 99, 235, 0.12), 0 10px 30px rgba(15, 23, 42, 0.12);
  transition: outline-color 180ms ease, box-shadow 180ms ease;
}

[data-avatar-action].avatar-context-highlight,
button.avatar-context-highlight,
a.avatar-context-highlight {
  outline-color: rgba(245, 158, 11, 0.95);
  box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.2), 0 12px 30px rgba(15, 23, 42, 0.16);
}

@media (max-width: 1180px) {
  .avatar-helper {
    width: min(100vw, 560px);
    height: 360px;
    transform: translateX(calc(-100% + 50px));
  }

  .avatar-helper__image {
    position: absolute;
    max-width: 220px;
    height: 320px;
  }

  .avatar-helper__bubble {
    left: 166px;
    top: 42px;
    width: min(340px, calc(100vw - 188px));
  }

  .avatar-helper__bubble-toggle {
    left: 154px;
    top: 42px;
  }

  .avatar-helper__toggle {
    width: 50px;
    height: 50px;
    top: 178px;
  }
}

@media (max-height: 720px) and (min-width: 1181px) {
  .avatar-helper {
    height: min(76vh, 640px);
  }
}

@media (max-width: 560px) {
  .avatar-helper {
    width: 100vw;
    height: 330px;
    transform: translateX(calc(-100% + 48px));
  }

  .avatar-helper__image {
    max-width: 170px;
    height: 270px;
  }

  .avatar-helper__bubble {
    left: 126px;
    top: 36px;
    width: calc(100vw - 146px);
    padding: 14px;
  }

  .avatar-helper__bubble-toggle {
    left: 116px;
    top: 36px;
  }

  .avatar-helper__toggle {
    width: 48px;
    height: 48px;
    top: 166px;
  }

  .avatar-helper__message {
    min-height: 92px;
    font-size: 0.82rem;
  }

  .avatar-helper__footer {
    align-items: flex-start;
    flex-direction: column;
  }
}
