/* Omi lives in viewport coordinates: the root sits at the top-left corner and
   is moved with a transform. Before the script runs, the inline head script
   seeds --omi-init-* from the saved state so he paints where he was. */
.omi-companion {
  --omi-size: 124px;
  --omi-bubble-bg: rgba(255, 255, 255, 0.95);
  --omi-bubble-ink: #151516;
  --omi-bubble-soft: rgba(21, 21, 22, 0.6);
  --omi-bubble-line: rgba(21, 21, 22, 0.1);
  --omi-accent: #ff375f;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  width: var(--omi-size);
  height: var(--omi-size);
  transform: var(--omi-init-transform, translate3d(24px, calc(100vh - var(--omi-size) * 0.961), 0));
  pointer-events: none;
  view-transition-name: omi-companion;
}

:root[data-theme="dark"] .omi-companion {
  --omi-bubble-bg: rgba(28, 28, 31, 0.95);
  --omi-bubble-ink: #f2f2f4;
  --omi-bubble-soft: rgba(242, 242, 244, 0.62);
  --omi-bubble-line: rgba(242, 242, 244, 0.12);
  --omi-accent: #ff5c80;
}

/* First visit: Omi drops in from above once the engine starts, so don't paint
   him at the default spot first. */
:root[data-omi-pending] .omi-companion {
  visibility: hidden;
}

.omi-companion[hidden],
.omi-recall[hidden],
.omi-speech[hidden],
.omi-speech__hide[hidden],
:root[data-omi-hidden] .omi-companion {
  display: none !important;
}

.omi-body {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 45% 45% 18% 18%;
  background: none;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.omi-companion.is-held .omi-body {
  cursor: grabbing;
}

.omi-body:focus-visible,
.omi-recall:focus-visible {
  outline: 2px solid var(--omi-accent);
  outline-offset: 2px;
}

/* Frames are 3:2 with Omi's body at one third, leaving room on the facing side
   for flames and props; the button stays the size of Omi himself. */
.omi-sprite {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 150%;
  height: 100%;
  background-image: url("/static/assets/omi/omi-atlas-v1.webp");
  background-image: image-set(
    url("/static/assets/omi/omi-atlas-v1.avif") type("image/avif"),
    url("/static/assets/omi/omi-atlas-v1.webp") type("image/webp")
  );
  background-position: var(--omi-init-bgx, 0%) var(--omi-init-bgy, 0%);
  background-repeat: no-repeat;
  background-size: 400% 1200%;
  transform-origin: 33.333% 50%;
  pointer-events: none;
}

.omi-companion[data-facing="left"] .omi-sprite,
:root[data-omi-facing="left"] .omi-companion:not([data-facing]) .omi-sprite {
  transform: scaleX(-1);
}

.omi-speech {
  position: absolute;
  bottom: 84%;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  width: max-content;
  max-width: min(16rem, calc(100vw - 24px));
  padding: 0.55rem 0.75rem;
  color: var(--omi-bubble-ink);
  border: 1px solid var(--omi-bubble-line);
  border-radius: 0.9rem;
  background: var(--omi-bubble-bg);
  box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.14);
  font-family: "Instrument Sans", "Instrument Sans Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.86rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
  pointer-events: auto;
  animation: omi-speech-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.omi-speech__text {
  margin: 0;
}

.omi-speech__hide {
  padding: 0.15rem 0.5rem;
  color: var(--omi-bubble-soft);
  border: 1px solid var(--omi-bubble-line);
  border-radius: 999px;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.omi-speech__hide:hover,
.omi-speech__hide:focus-visible {
  color: var(--omi-bubble-ink);
  border-color: var(--omi-accent);
  outline: 0;
}

@keyframes omi-speech-in {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.omi-recall {
  position: fixed;
  left: max(12px, env(safe-area-inset-left, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  width: 44px;
  height: 44px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(21, 21, 22, 0.12);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

:root[data-theme="dark"] .omi-recall {
  border-color: rgba(242, 242, 244, 0.14);
  background: rgba(28, 28, 31, 0.85);
}

.omi-recall .omi-sprite {
  top: -12px;
  left: -13px;
  width: 105px;
  height: 70px;
  background-position: 0 0;
  transform: none;
}

@media (max-width: 640px) {
  .omi-companion {
    --omi-size: 92px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .omi-speech {
    animation: none;
  }
}
