.companion-root {
  position: fixed;
  left: 0;
  top: 0;
  width: 96px;
  height: 96px;
  z-index: 2147483000;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.companion-root.dragging {
  cursor: grabbing;
}

.companion-sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

.companion-bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  min-width: 160px;
  max-width: 260px;
  background: color-mix(in srgb, var(--t-bg, #111418) 94%, var(--t-fg, #fff) 6%);
  border: 1px solid var(--t-bd, rgba(255, 255, 255, 0.12));
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--t-fg, #e9ecf1);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  font: 13px/1.4 Inter, system-ui, sans-serif;
}

.companion-bubble textarea {
  width: 100%;
  resize: none;
  background: var(--t-bg, #1b1e24);
  color: var(--t-fg, #e9ecf1);
  border: 1px solid var(--t-bd, rgba(255, 255, 255, 0.15));
  border-radius: 6px;
  padding: 6px;
  font: inherit;
  margin-top: 6px;
  box-sizing: border-box;
}

.companion-bubble .companion-reply {
  white-space: pre-wrap;
}

.companion-bubble .companion-coin-request {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--t-bd, rgba(255, 255, 255, 0.12));
}

.companion-bubble .companion-coin-request button {
  font: inherit;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--t-bd, rgba(255, 255, 255, 0.15));
  background: var(--t-bg, #1b1e24);
  color: var(--t-fg, #e9ecf1);
  cursor: pointer;
  margin-top: 6px;
  margin-right: 6px;
}

.companion-bubble .companion-coin-request button.companion-coin-allow {
  background: #2d6a4f;
  border-color: #2d6a4f;
  color: #fff;
}

/* Preset action animations — fixed, hardcoded reactions, never arbitrary
   code. The widget picks one of these by name; see ACTIONS in
   deepseek.rs, which this list must stay in sync with. */
/* Target the sprite, not .companion-root: the root's own `transform` is
   rewritten every frame by the drag/physics loop for positioning, so an
   animation on that element would fight it instead of layering on top. */
.companion-sprite.action-spin { animation: companion-spin 0.6s ease-in-out; }
.companion-sprite.action-jump { animation: companion-jump 0.5s ease-out; }
.companion-sprite.action-shake { animation: companion-shake 0.5s ease-in-out; }
.companion-sprite.action-grow { animation: companion-grow 0.5s ease-in-out; }
.companion-sprite.action-shrink { animation: companion-shrink 0.5s ease-in-out; }
.companion-sprite.action-wave { animation: companion-wave 0.8s ease-in-out; }
.companion-sprite.action-dance { animation: companion-dance 0.9s ease-in-out; }
.companion-sprite.action-peekaboo { animation: companion-peekaboo 1s ease-in-out; }
.companion-sprite.action-confetti { animation: companion-jump 0.5s ease-out; }
.companion-sprite.action-nap { animation: companion-nap 1.2s ease-in-out; }

@keyframes companion-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes companion-jump {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-28px); }
}
@keyframes companion-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
@keyframes companion-grow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}
@keyframes companion-shrink {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.65); }
}
@keyframes companion-wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-14deg); }
  50% { transform: rotate(10deg); }
  75% { transform: rotate(-8deg); }
}
@keyframes companion-dance {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-10px) rotate(-8deg); }
  50% { transform: translateY(0) rotate(0deg); }
  75% { transform: translateY(-10px) rotate(8deg); }
}
@keyframes companion-peekaboo {
  0%, 100% { transform: scale(1); opacity: 1; }
  45% { transform: scale(0.1); opacity: 0; }
  55% { transform: scale(0.1); opacity: 0; }
}
@keyframes companion-nap {
  0%, 100% { transform: rotate(0deg); opacity: 1; }
  50% { transform: rotate(8deg); opacity: 0.55; }
}

.companion-confetti-piece {
  position: absolute;
  top: 0;
  left: 50%;
  width: 6px;
  height: 10px;
  pointer-events: none;
  animation: companion-confetti-fall 0.9s ease-in forwards;
}

@keyframes companion-confetti-fall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--cx, 0px), 90px) rotate(var(--cr, 180deg)); opacity: 0; }
}

/* Sandevistan (special ability, see sandevistan() in companion-widget.js). */
.companion-sandevistan-veil {
  position: fixed;
  inset: 0;
  z-index: 2147482999;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(40, 255, 180, 0.05), rgba(20, 220, 160, 0.16));
  backdrop-filter: saturate(0.45) hue-rotate(-25deg);
  -webkit-backdrop-filter: saturate(0.45) hue-rotate(-25deg);
  animation: companion-veil-in 0.18s ease-out;
  transition: opacity 0.35s ease;
}
.companion-sandevistan-veil.fading { opacity: 0; }
@keyframes companion-veil-in { from { opacity: 0; } to { opacity: 1; } }
.companion-afterimage {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2147482999;
  object-fit: contain;
  pointer-events: none;
  opacity: 0.7;
  filter: hue-rotate(var(--ghost-hue, 150deg)) saturate(3) brightness(1.2);
  mix-blend-mode: screen;
  animation: companion-afterimage-fade 0.7s ease-out forwards;
}
html[data-theme="light"] .companion-afterimage { mix-blend-mode: multiply; }
@media (prefers-color-scheme: light) { html:not([data-theme="dark"]) .companion-afterimage { mix-blend-mode: multiply; } }
@keyframes companion-afterimage-fade { to { opacity: 0; } }
.companion-root.sandevistan-active .companion-sprite {
  filter: drop-shadow(0 0 8px rgba(40, 255, 180, 0.8)) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

/* Overuse: blood (bleeding strain) and cyberpsychosis (max strain). */
.companion-blood-drop {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 6px;
  height: 9px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: #b3121f;
  pointer-events: none;
  animation: companion-blood-fall 1.1s cubic-bezier(.4, 0, .9, .6) forwards;
}
@keyframes companion-blood-fall {
  0% { transform: translate(0, 0) scale(.6); opacity: 1; }
  100% { transform: translate(var(--bx, 0), var(--bfall, 60px)) scale(1); opacity: 0; }
}
.companion-root.companion-psychosis .companion-sprite {
  filter: drop-shadow(0 0 10px rgba(255, 30, 60, 0.85)) saturate(1.6) contrast(1.2);
  animation: companion-psychosis-jitter 0.18s steps(2) infinite;
}
@keyframes companion-psychosis-jitter {
  0% { transform: translate(0, 0); }
  50% { transform: translate(-2px, 1px) skewX(-3deg); }
  100% { transform: translate(2px, -1px) skewX(2deg); }
}
.companion-psychosis-veil {
  position: fixed;
  inset: 0;
  z-index: 2147482998;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255, 20, 50, 0.05) 0 2px, transparent 2px 5px);
  animation: companion-psychosis-flicker 3.2s steps(1) infinite;
}
@keyframes companion-psychosis-flicker {
  0%, 88%, 100% { opacity: .55; }
  90% { opacity: 1; background-color: rgba(255, 20, 50, 0.12); }
  93% { opacity: .2; }
}
.companion-root.companion-cyberskeleton { width: 112px; height: 112px; }
@media (prefers-reduced-motion: reduce) {
  .companion-root.companion-psychosis .companion-sprite, .companion-psychosis-veil { animation: none; }
}
