.companion {
  position: fixed;
  z-index: 4;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  justify-items: end;
  width: min(254px, 43vw);
  color: #171717;
  pointer-events: none;
}
.companion button { pointer-events: auto; }
.companion #companion-view { position: relative; width: 100%; }
.companion-stage-wrap { position: relative; }
.companion-stage {
  display: block;
  width: 100%;
  height: min(var(--avatar-desktop-px, 440px), var(--avatar-desktop-vh, 63dvh));
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.companion-stage:disabled { opacity: 1; pointer-events: none; }
.companion-stage canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
.companion-stage:focus-visible { outline-offset: -5px; border-radius: 8px; }
.companion-controls { display: flex; justify-content: end; gap: 5px; }
.companion :is(.companion-controls button, .companion-toggle, .companion-retry) {
  border: 1px solid #dcdcdc;
  border-radius: 999px;
  padding: 5px 10px;
  min-height: 32px;
  background: #fff;
  color: #171717;
  box-shadow: 0 2px 9px #1111;
  font-size: .82rem;
  line-height: 1.2;
  white-space: nowrap;
}
.companion :is(.companion-controls button, .companion-toggle, .companion-retry):hover { border-color: #7d7d7d; }
.companion-message {
  position: absolute;
  right: 0;
  bottom: 7px;
  width: max-content;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 5px;
  background: #fff;
  color: #555;
  font-size: .82rem;
}
.companion-message:empty { display: none; }
.companion .companion-retry { position: absolute; right: 0; bottom: 40px; }
.companion-options {
  position: absolute;
  bottom: 38px;
  right: 0;
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  box-shadow: 0 7px 23px #1112;
}
.companion-options button { border: 1px solid transparent; border-radius: 6px; padding: 5px 9px; background: #fff; color: #171717; font-size: .86rem; }
.companion-options button:hover, .companion-options button[aria-pressed=true] { border-color: #ddd; background: #f4f4f4; }
.companion-chat {
  pointer-events: auto;
  position: absolute;
  bottom: 0;
  right: calc(100% + 12px);
  width: min(330px, calc(100vw - 36px));
  max-height: min(495px, calc(100dvh - 110px));
  display: grid;
  grid-template-rows: auto minmax(50px, 1fr) auto;
  overflow: hidden;
  color: #161616;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 13px;
  box-shadow: 0 8px 32px #1112;
}
.companion-chat header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 13px; border-bottom: 1px solid #eee; }
.companion-chat h2 { font-size: .98rem; letter-spacing: -.02em; }
.companion-chat button { border: 1px solid #d7d7d7; background: #fff; color: #171717; padding: 4px 9px; border-radius: 7px; font-size: .84rem; }
.companion-messages { min-height: min(220px, 28dvh); overflow-y: auto; padding: 12px; display: grid; align-content: start; gap: 8px; }
.companion-messages p { width: fit-content; max-width: 94%; padding: 6px 10px; background: #f1f1f1; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; }
.companion-messages p[data-role=user] { justify-self: end; background: #151515; color: #fff; }
.companion-chat-form { padding: 9px 12px; border-top: 1px solid #eee; }
.companion-chat-form div { display: flex; gap: 5px; }
.companion-chat-form input { min-width: 0; flex: 1; padding: 4px 8px; border: 1px solid #d7d7d7; border-radius: 7px; }
.companion-chat-form p { margin-top: 4px; font-size: .76rem; color: #626262; }
.companion-chat-status:empty { display: none; }
.companion-chat-form .companion-chat-status.is-error { color: #8b2525; overflow-wrap: anywhere; }
@media (max-width: 949px) {
  .companion { width: min(195px, 41vw); }
  .companion-stage { height: min(var(--avatar-tablet-px, 320px), var(--avatar-tablet-vh, 49dvh), var(--avatar-tablet-vw, 52vw)); }
}
@media (max-width: 720px) {
  .companion-chat { right: 0; bottom: 40px; max-height: min(430px, calc(100dvh - 156px)); }
}
@media (max-width: 600px) {
  .companion { right: max(9px, env(safe-area-inset-right)); bottom: max(9px, env(safe-area-inset-bottom)); width: clamp(114px, 36vw, 152px); }
  .companion-stage { height: min(var(--avatar-mobile-px, 220px), var(--avatar-mobile-vh, 34dvh), var(--avatar-mobile-vw, 53vw)); }
}
[data-companion-preview] { overflow: hidden; }
[data-companion-preview] .companion-controls, [data-companion-preview] .companion-toggle { display: none; }
[data-companion-preview] .companion-stage { pointer-events: none; }
@media print { .companion { display: none !important; } }
