/* The shop's mascot, floating bottom right.
   Sits above the page but below the mobile tab bar's own stacking, and lifts
   clear of it so the two never overlap on a phone. */

.orb-root {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 70;
}

/* ---- the launcher ----
   A robot standing on the page, not a face cropped into a circle. No disc, no
   border: the character's own silhouette with a shadow under it, which is what
   makes it read as a mascot rather than an app icon. */

.orb-button {
  position: relative;
  display: block;
  width: 84px;
  height: 112px;
  /* A scene to rotate inside, so the tilt reads as a figure turning rather
     than a picture skewing. */
  perspective: 620px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s cubic-bezier(.34, 1.56, .64, 1);
}
.orb-button:hover { transform: translateY(-4px) scale(1.03); }
.orb-button:active { transform: translateY(-1px) scale(.99); }
.orb-button:focus-visible { outline: 3px solid var(--rwm-red); outline-offset: 6px; border-radius: 18px; }

/* The glow is now a pool of light on the floor under it, not a halo. */
.orb-glow {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 62%;
  height: 12px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(20, 22, 28, .34), rgba(20, 22, 28, 0));
  animation: orb-hover 3.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes orb-hover {
  0%, 100% { transform: translateX(-50%) scale(1.06); opacity: .55; }
  50%      { transform: translateX(-50%) scale(.78); opacity: .3; }
}

/* ---- the mascot's poses ----
   All of them are in the markup; one is shown at a time. Swapping a src would
   flicker while the next file loaded, and the whole set is smaller than one
   product photo. */
.orb-pose {
  position: absolute;
  inset: 0 0 6px;
  width: 100%;
  height: calc(100% - 6px);
  object-fit: contain;
  object-position: bottom center;
  opacity: 0;
  transform: translateY(4px) scale(.94);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  /* Two shadows: a tight one that grounds him, a soft wide one for depth. */
  filter: drop-shadow(0 4px 5px rgba(20, 22, 28, .26))
          drop-shadow(0 14px 22px rgba(20, 22, 28, .18));
  animation: orb-bobbing 3.4s ease-in-out infinite;
  transform-style: preserve-3d;
  will-change: transform;
}
/* He turns towards the pointer. The angles arrive from script as two custom
   properties, so the motion is one cheap transform, not a render loop. */
.orb-pose.on {
  opacity: 1;
  transform: translateY(0) scale(1)
             rotateX(var(--dex-x, 0deg)) rotateY(var(--dex-y, 0deg));
  transition: opacity .2s ease, transform .26s cubic-bezier(.22, .68, .36, 1);
}

/* A slow float, so it is alive between questions rather than a sticker. */
@keyframes orb-bobbing {
  0%, 100% { margin-bottom: 0; }
  50%      { margin-bottom: 5px; }
}

.orb-head-face { width: 34px; height: 34px; object-fit: contain; flex: none; }

/* A springier bob when the pose changes: that is the character reacting. */
.orb-button.reacting .orb-pose.on { animation: orb-pop .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes orb-pop {
  0%   { transform: translateY(8px) scale(.9); }
  55%  { transform: translateY(-5px) scale(1.05); }
  100% { transform: translateY(0) scale(1); }
}

/* ---- the nudge ----
   A speech bubble from the mascot, not a popup over the page. */
.orb-nudge {
  position: absolute;
  right: 4px;
  bottom: calc(100% + 10px);
  width: 232px;
  text-align: left;
  background: #fff;
  border: 1.5px solid var(--rwm-line);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(20, 22, 28, .18);
  padding: 13px 15px 12px;
  cursor: pointer;
  animation: orb-nudge-in .34s cubic-bezier(.34, 1.56, .64, 1);
}
.orb-nudge[hidden] { display: none; }
.orb-nudge::after {                      /* the tail, pointing at the mascot */
  content: "";
  position: absolute;
  right: 26px;
  bottom: -8px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 1.5px solid var(--rwm-line);
  border-bottom: 1.5px solid var(--rwm-line);
  transform: rotate(45deg);
}
/* Room in the corner for the cross, so no line of the message runs under it. */
.orb-nudge-text { margin: 0; padding-right: 22px; font-size: 13.5px; line-height: 1.45; }
.orb-nudge-cta {
  display: inline-block; margin-top: 7px;
  font-size: 12.5px; font-weight: 700; color: var(--rwm-red);
}

/* Drawn small, hit big.
   At its drawn size this was a 20px target. A thumb needs 44, so dismissing it
   on a phone missed more often than not -- and a miss landed on the bubble
   behind, which opens the chat. Trying to get rid of him opened him instead.
   The cross still sits in the corner at 17px; the button around it is the size
   of the thumb that has to find it. */
.orb-nudge-close {
  position: absolute; top: 0; right: 0;
  width: 44px; height: 44px;
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 5px 8px 0 0;
  font-size: 17px; line-height: 1; color: var(--rwm-muted);
  background: none; border: 0; cursor: pointer;
  border-radius: 0 16px 0 16px;
  -webkit-tap-highlight-color: transparent;
}
.orb-nudge-close:hover { color: var(--rwm-ink); }
.orb-nudge-close:active { background: rgba(20, 22, 28, .07); color: var(--rwm-ink); }
.orb-nudge-close:focus-visible {
  outline: 2px solid var(--rwm-red); outline-offset: -3px; color: var(--rwm-ink);
}

@keyframes orb-nudge-in {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- the panel ---- */

.orb-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: min(370px, calc(100vw - 32px));
  height: min(520px, calc(100dvh - 150px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1.5px solid var(--rwm-line);
  border-radius: var(--r-lg);
  box-shadow: 0 18px 50px rgba(20, 22, 28, .26);
  overflow: hidden;
}

/* A class that sets display beats the browser's own [hidden] rule, so the panel
   opened itself on page load. Both of these need saying explicitly. */
.orb-panel[hidden], .orb-root[hidden], .orb-suggest[hidden] { display: none; }

.orb-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1.5px solid var(--rwm-line);
  background: var(--rwm-paper);
}
.orb-head > div { flex: 1; min-width: 0; }
.orb-head b { display: block; font-size: 14.5px; }
.orb-head span { font-size: 12px; color: var(--rwm-muted); }
.orb-mute {
  font-size: 15px; line-height: 1; background: none; border: 0;
  cursor: pointer; padding: 2px 4px; opacity: .75;
}
.orb-mute:hover { opacity: 1; }
.orb-close {
  font-size: 22px; line-height: 1; color: var(--rwm-muted);
  background: none; border: 0; cursor: pointer; padding: 0 4px;
}
.orb-close:hover { color: var(--rwm-ink); }

.orb-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Grows from the bottom, where the typing is. A short conversation was
     pinned to the top of a full-height panel with a screen of white under it. */
  justify-content: flex-end;
}
/* ...but a long one still scrolls from the top rather than clipping its start. */
.orb-log > :first-child { margin-top: auto; }

.orb-msg {
  max-width: 86%;
  font-size: 14px;
  line-height: 1.5;
  padding: 9px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.orb-msg.them { align-self: flex-start; background: var(--rwm-paper); border-bottom-left-radius: 4px; }
.orb-msg.you  { align-self: flex-end; background: var(--rwm-red); color: #fff; border-bottom-right-radius: 4px; }
.orb-msg.warn { align-self: flex-start; background: #fff6e6; border: 1px solid #f0d79b; color: #7a5a12; }
.orb-msg a { color: inherit; text-underline-offset: 3px; }
.orb-msg.them a { color: var(--rwm-red); }
/* A hand-off to a person is worth more than a link: it gets the weight. */
.orb-wa-inline {
  font-weight: 700; white-space: nowrap; text-decoration: underline;
  text-underline-offset: 3px;
}

/* Three dots while the model is thinking: a quiet reply takes a second or two
   and silence reads as a page that has broken. */
.orb-typing { display: inline-flex; gap: 4px; align-items: center; }
.orb-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--rwm-muted);
  animation: orb-bob 1.1s infinite;
}
.orb-typing i:nth-child(2) { animation-delay: .15s; }
.orb-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes orb-bob {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

.orb-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
.orb-suggest button {
  font: inherit; font-size: 12.5px; color: var(--rwm-ink); cursor: pointer;
  background: #fff; border: 1.5px solid var(--rwm-line); border-radius: var(--pill);
  padding: 6px 11px;
}
.orb-suggest button:hover { border-color: var(--rwm-red); color: var(--rwm-red); }

.orb-ask {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1.5px solid var(--rwm-line);
}
.orb-ask input {
  flex: 1; min-width: 0; font: inherit; font-size: 14px;
  border: 1.5px solid var(--rwm-line); border-radius: var(--pill); padding: 9px 14px;
}
.orb-ask input:focus { outline: 0; border-color: var(--rwm-red); }
.orb-ask button {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: var(--rwm-red); color: #fff; font-size: 17px; cursor: pointer;
}
.orb-ask button:disabled { background: var(--rwm-line); cursor: default; }

.orb-wa {
  display: block; text-align: center; font-size: 12.5px; padding: 0 12px 12px;
  color: var(--rwm-muted); text-decoration: none;
}
.orb-wa:hover { color: var(--rwm-red); }

.orb-note {
  margin: 0; padding: 0 14px 8px; font-size: 11.5px; line-height: 1.4;
  color: var(--rwm-muted);
}
.orb-note a { color: inherit; text-decoration: underline; }

/* On a phone the panel is the screen, not a card floating on it. Sized off the
   viewport with the tab bar and the notch taken out, so it can never run under
   either -- which is what "it doesn't fit mobile" was. */
@media (max-width: 700px) {
  .orb-root {
    right: 12px;
    left: 12px;
    bottom: calc(66px + max(8px, env(safe-area-inset-bottom)));
    pointer-events: none;                /* the gap either side stays clickable */
  }
  .orb-button {
    margin-left: auto;
    width: 65px;
    height: 88px;
    pointer-events: auto;
  }
  .orb-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    /* --kb is however much of the screen the keyboard is covering, measured
       from the visual viewport. Zero when it is closed. */
    bottom: calc(var(--kb, 0px) + 74px + max(8px, env(safe-area-inset-bottom)));
    top: max(12px, env(safe-area-inset-top));
    width: auto;
    height: auto;
    max-height: none;
    pointer-events: auto;
  }
  /* Bigger targets and text once it is the whole screen. */
  /* .orb-root is pointer-events:none on mobile so the gaps either side of the
     mascot pass taps to the page. The button and panel switch it back on; the
     nudge did NOT, so its close cross (and the bubble itself) was dead to touch
     -- tapping the X did nothing. Switch pointer events back on for it too. */
  .orb-nudge { right: 0; width: min(250px, calc(100vw - 36px)); pointer-events: auto; }
  /* With the panel filling the screen the mascot has nowhere to stand without
     sitting on the text box, and the panel has its own close button. */
  .orb-root.is-open .orb-button { display: none; }
  /* The tab bar sits at z-index 60 and the chat covers the screen; leaving it
     visible put a strip of navigation through the middle of the conversation. */
  body.orb-open .tabbar { display: none; }

  /* With the keyboard up, the tab bar is under it anyway and only shows through
     as a stripe across the chat. The panel takes the whole screen instead. */
  .orb-root.kb-open .orb-panel {
    bottom: calc(var(--kb, 0px) + 8px);
    top: max(6px, env(safe-area-inset-top));
  }
  .orb-log { padding: 12px; gap: 9px; }
  .orb-msg { max-width: 92%; font-size: 15px; }
  .orb-ask input { font-size: 16px; }   /* under 16px, iOS zooms the page */
  .orb-suggest { padding: 0 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb-glow, .orb-typing i, .orb-pose { animation: none; }
  .orb-pose.on { transform: none; }
  .orb-pose, .orb-button.reacting .orb-pose.on { transition: none; animation: none; }
  .orb-button { transition: none; }
}

/* ---- standing label beside the mascot (shop request 2026-10-20) ----
   Customers did not read the robot as something to tap. The label sits to its
   left, inside the button so it opens the chat too. It steps aside while the
   nudge bubble is up (they would overlap) and while the chat is open. */
.orb-label {
  position: absolute;
  right: calc(100% + 4px);
  bottom: 26px;
  white-space: nowrap;
  background: var(--rwm-white);
  color: var(--rwm-ink);
  border: 1.5px solid var(--rwm-line);
  border-radius: var(--pill);
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--sh-2);
  pointer-events: auto;
}
.orb-root:has(.orb-nudge:not([hidden])) .orb-label,
.orb-root.is-open .orb-label { display: none; }
/* Phones: icon only. The label reached over form fields at 375px. */
@media (max-width: 767px) {
  .orb-label { display: none; }
}

/* Product pages on phones: the sticky add-to-cart bar (shop.css .p-sticky,
   64px above the tab bar, ~66px tall) sat under the mascot, which covered
   "Add to cart". Lift the mascot over both: tab bar + sticky bar + gap. */
@media (max-width: 767px) {
  body:has(.p-sticky) .orb-root:not(.is-open) {
    --rwm-sticky-h: 70px;
    bottom: calc(64px + var(--rwm-sticky-h) + 8px + env(safe-area-inset-bottom));
  }
}
