/* character-rig.css: the companion's seats and the rig's idle loops. Pairs with character-rig.js.
   Owner jp-motion-studio. Values are the ones measured on tweaktheweb.com v2 (2026-11-26); a page sets
   its own colors and sizes through the custom properties, never by editing the rules. */

/* Registered so a recolor TRANSITIONS (a chameleon changing color) instead of snapping. Name the
   page's own color slots here; the rig reads them as var(--cr-a) and var(--cr-b). */
@property --cr-a { syntax: "<color>"; inherits: true; initial-value: #2EE3B0; }
@property --cr-b { syntax: "<color>"; inherits: true; initial-value: #FF7468; }
.cr-svg { overflow: visible; display: block; transition: --cr-a .6s ease, --cr-b .6s ease; }

/* Parts move only by transform; pivots are inline styles in rig units. */
.cr-pupil, .cr-head { transition: transform .25s cubic-bezier(.2,.7,.2,1); }
.cr-alive .cr-body { animation: crBreathe 3.2s ease-in-out infinite; }
.cr-alive .cr-tail { animation: crWag 4.4s ease-in-out infinite; }
.cr-alive .cr-ear  { animation: crEar 5.2s ease-in-out infinite; }
.cr-alive .cr-ear + .cr-ear { animation-delay: -1.7s; }
.is-walking .cr-leg { animation: crStep .42s ease-in-out infinite; }
.is-walking .cr-leg + .cr-leg { animation-delay: -.21s; }
.is-walking .cr { animation: crBob .21s ease-in-out infinite; }
.is-gripping .cr { transform: scale(1.06,.9); }
@keyframes crBreathe { 50% { transform: scale(1.02); } }
@keyframes crWag { 50% { transform: rotate(6deg); } }
@keyframes crEar { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(-6deg); } 86% { transform: rotate(4deg); } }
@keyframes crStep { 50% { transform: rotate(14deg); } }
@keyframes crBob { 50% { transform: translateY(-2%); } }

/* ---------- the companion ---------- */
.cr-buddy {
  position: fixed; right: clamp(14px,2vw,28px); bottom: calc(clamp(14px,2vw,26px) + var(--cr-nudge-h, 0px));
  z-index: 45; display: grid; justify-items: end; pointer-events: none;
  transition: transform 1.05s cubic-bezier(.3,.7,.3,1), translate .45s cubic-bezier(.3,.7,.3,1), opacity .4s ease;
}
.cr-buddy__btn { width: var(--cr-buddy-w, 112px); pointer-events: auto; cursor: pointer; background: none; border: 0; padding: 0;
  -webkit-tap-highlight-color: transparent; position: relative; z-index: 1; }
.cr-buddy__btn:focus-visible { outline: 3px solid var(--cr-focus, #7C5CFF); outline-offset: 4px; border-radius: 12px; }
.cr-buddy.is-away { transform: translateX(calc(100% + 60px)); visibility: hidden;
  transition: transform 1.05s cubic-bezier(.3,.7,.3,1), translate .45s cubic-bezier(.3,.7,.3,1), opacity .4s ease, visibility 0s linear 1.05s; }
/* Ducked: he drops until only his head shows, so he never sits on a control while standing. */
.cr-buddy.is-ducked { translate: 0 calc(100% - var(--cr-peek, 38px)); }
@media (min-width: 701px) { .cr-buddy.is-shy { opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility 0s linear .3s; } }

/* speech */
.cr-bubble { position: absolute; bottom: calc(100% - 4px); right: 20px; width: max-content; max-width: min(300px, calc(100vw - 40px));
  padding: 10px 14px; border-radius: 16px; background: var(--cr-bubble-bg, #fff); color: var(--cr-bubble-ink, #17141f);
  font: 600 .9375rem/1.35 var(--cr-font, system-ui, sans-serif); box-shadow: 0 14px 34px -12px rgba(20,0,60,.45);
  opacity: 0; transform: translateY(6px) scale(.96); transform-origin: 80% 100%; transition: opacity .2s ease, transform .2s ease; pointer-events: none; }
.cr-bubble.is-on { opacity: 1; transform: none; }
.cr-bubble::after { content: ""; position: absolute; top: 100%; right: 42px; border: 8px solid transparent; border-top-color: var(--cr-bubble-bg, #fff); }

/* phone: seated in the bottom action bar, left side, above the bar's glass (the kit bar stacks at 55) */
@media (max-width: 700px) {
  .cr-buddy { right: auto; left: 10px; bottom: calc(9px + env(safe-area-inset-bottom, 0px)); justify-items: start; z-index: 56; }
  .cr-buddy.is-away { transform: translateX(calc(-100% - 40px)); }
  /* taps pass through to the bar button it sits in (tweaktheweb.com: Tweak is the icon of "Tweak this page");
     a tappable seat steals the tap from that button (float_cover_probe.py: "takes the tap") */
  .cr-buddy__btn { width: var(--cr-buddy-w-phone, 62px); pointer-events: none; }
  .cr-bubble { left: 6px; right: auto; bottom: calc(100% + 16px); max-width: min(250px, calc(100vw - 32px)); font-size: .875rem; padding: 9px 12px; }
  .cr-bubble::after { right: auto; left: 30px; }
}

/* Reduced motion: the drawn pose IS the still. Nothing travels; the companion fades instead of walking. */
@media (prefers-reduced-motion: reduce) {
  .cr-alive .cr-body, .cr-alive .cr-tail, .cr-alive .cr-ear, .is-walking .cr, .is-walking .cr-leg { animation: none !important; }
  .cr-svg { transition: none; }
  .cr-buddy { transition: opacity .2s ease; }
  .cr-buddy.is-away { transform: none; opacity: 0; }
  .cr-buddy.is-ducked { translate: none; }
}
