/* ---------------------------------------------------------------------------
   Pip, Candid's mascot: the drawing and its state loops
   ---------------------------------------------------------------------------
   From design/mascot.html (spec design/mascot.md). Ink body and tuft, white
   eyes, coral cheeks when pleased. Every loop is transform or opacity only,
   0.8 to 5 seconds, and all of them stop under reduced motion, keeping the
   expression. On a dark surface use .pip--dark (the lifted ink of the spec)
   or, small on the app's ink, .pip--light.
   App: shared/pip.js.
   --------------------------------------------------------------------------- */

.pip { display: block; flex: 0 0 auto; overflow: visible; --pip-body: var(--text); --pip-eye: #fff }
.pip--dark { --pip-body: #34504B }
/* On the app's ink panels and the phone's ink bar the lifted ink is lost at
   small sizes, so there he turns light with ink eyes: the shape is his. */
.pip--light { --pip-body: var(--on-ink); --pip-eye: var(--ink) }
.pip .pip__body, .pip .pip__tuft { fill: var(--pip-body) }
.pip .pip__eye { fill: var(--pip-eye) }
.pip .pip__lid { fill: none; stroke: var(--pip-eye); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; opacity: 0 }
.pip .pip__cheek { fill: var(--coral); opacity: 0 }
.pip .pip__zz { fill: none; stroke: var(--pip-body); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0 }
.pip .pip__ground { fill: var(--text); opacity: .08 }
.pip--flat .pip__ground { display: none }
/* Still: his face for the state, no loop. The small Pips repeated down a
   list or on a button, so only the few reporting live work move. */
.pip--still *, .pip--still { animation: none !important }
/* In a glyph's place (pipOr): on the text's line, the glyph's size. */
.pip--glyph { display: inline-block; vertical-align: -0.2em }
.pip .pip__rig, .pip .pip__act, .pip .pip__ground { transform-box: fill-box; transform-origin: 50% 100% }
.pip .pip__eyes, .pip .pip__eyeL, .pip .pip__eyeR, .pip .pip__eye { transform-box: fill-box; transform-origin: 50% 50% }
.pip .pip__tuft { transform-box: fill-box; transform-origin: 25% 100% }
.pip .pip__eyes, .pip .pip__eyeL, .pip .pip__eyeR, .pip .pip__tuft { transition: transform .25s cubic-bezier(.3,0,.4,1) }
.pip .pip__eye, .pip .pip__lid, .pip .pip__cheek { transition: opacity .15s ease-out }

/* idle: a slow breath and a blink */
.pip[data-state="idle"] .pip__rig { animation: pipBreathe 3.2s ease-in-out infinite }
.pip[data-state="idle"] .pip__eye { animation: pipBlink 4.4s infinite }
.pip[data-state="idle"] .pip__tuft { animation: pipTuftIdle 3.2s ease-in-out infinite }
/* thinking (researching): sways, one eye squinted, scanning */
.pip[data-state="thinking"] .pip__rig { animation: pipSway 2.4s ease-in-out infinite }
.pip[data-state="thinking"] .pip__eyes { animation: pipScan 2.4s ease-in-out infinite }
.pip[data-state="thinking"] .pip__eyeL { transform: scaleY(.55) }
.pip[data-state="thinking"] .pip__tuft { animation: pipTuftTwitch 2.4s ease-in-out infinite }
/* working: bounces, eyes narrowed, tuft flops behind */
.pip[data-state="working"] .pip__rig { animation: pipBounce .8s cubic-bezier(.3,0,.4,1) infinite }
.pip[data-state="working"] .pip__ground { animation: pipGround .8s cubic-bezier(.3,0,.4,1) infinite }
.pip[data-state="working"] .pip__eyeL { transform: rotate(-8deg) scaleY(.6) }
.pip[data-state="working"] .pip__eyeR { transform: rotate(8deg) scaleY(.6) }
.pip[data-state="working"] .pip__tuft { animation: pipTuftFlop .8s cubic-bezier(.3,0,.4,1) .1s infinite }
/* waiting (needs you): a hop every two seconds, eyes wide */
.pip[data-state="waiting"] .pip__rig { animation: pipHop 2s cubic-bezier(.3,0,.4,1) infinite }
.pip[data-state="waiting"] .pip__eyes { transform: scale(1.16) }
.pip[data-state="waiting"] .pip__tuft { animation: pipTuftHop 2s cubic-bezier(.3,0,.4,1) infinite }
/* done: happy arcs, cheeks, one jump then breathe */
.pip[data-state="done"] .pip__eye { opacity: 0; animation: none }
.pip[data-state="done"] .pip__lid--happy, .pip[data-state="done"] .pip__cheek { opacity: 1 }
.pip[data-state="done"] .pip__rig { animation: pipCheer .7s cubic-bezier(.3,0,.4,1) 1, pipBreathe 3.2s ease-in-out .7s infinite }
.pip[data-state="done"] .pip__tuft { animation: pipTuftFlop .7s cubic-bezier(.3,0,.4,1) .08s 1 }
/* blocked: sad slopes, one shake, slumped, tuft wilts */
.pip[data-state="blocked"] .pip__eye { opacity: 0 }
.pip[data-state="blocked"] .pip__lid--sad { opacity: 1 }
.pip[data-state="blocked"] .pip__eyes { transform: translateY(3px) }
.pip[data-state="blocked"] .pip__tuft { transform: rotate(32deg) }
.pip[data-state="blocked"] .pip__rig { animation: pipShake .5s ease-in-out 1, pipSlump 3.6s ease-in-out .5s infinite }
/* asleep (booked tonight): eyes closed, slow breath, a z drifts up */
.pip[data-state="asleep"] .pip__eye { opacity: 0 }
.pip[data-state="asleep"] .pip__lid--closed { opacity: 1 }
.pip[data-state="asleep"] .pip__eyes { transform: translateY(3px) }
.pip[data-state="asleep"] .pip__tuft { transform: rotate(44deg) }
.pip[data-state="asleep"] .pip__rig { animation: pipBreathe 5s ease-in-out infinite }
.pip[data-state="asleep"] .pip__zz { animation: pipZz 5s ease-out infinite }

@keyframes pipBreathe { 0%,100% { transform: scale(1,1) } 50% { transform: scale(1.025,.97) } }
@keyframes pipBlink { 0%,92%,100% { transform: scaleY(1) } 95% { transform: scaleY(.08) } }
@keyframes pipSway { 0%,100% { transform: rotate(-3deg) } 50% { transform: rotate(3deg) } }
@keyframes pipScan { 0%,100% { transform: translate(-4px,-6px) } 50% { transform: translate(5px,-6px) } }
@keyframes pipBounce {
  0%,100% { transform: translateY(0) scale(1.08,.9) }
  35% { transform: translateY(-10px) scale(.94,1.07) }
  60% { transform: translateY(-12px) scale(1,1) }
}
@keyframes pipGround { 0%,100% { transform: scale(1); opacity: .1 } 50% { transform: scale(.7); opacity: .05 } }
@keyframes pipHop {
  0%,70%,100% { transform: translateY(0) scale(1,1) }
  76% { transform: translateY(0) scale(1.08,.9) }
  84% { transform: translateY(-9px) scale(.95,1.06) }
  92% { transform: translateY(0) scale(1.04,.95) }
}
@keyframes pipCheer {
  0% { transform: translateY(0) scale(1.1,.88) }
  45% { transform: translateY(-16px) scale(.92,1.1) rotate(-4deg) }
  80% { transform: translateY(0) scale(1.06,.93) }
  100% { transform: translateY(0) scale(1,1) }
}
@keyframes pipShake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-3px) } 75% { transform: translateX(3px) } }
@keyframes pipSlump { 0%,100% { transform: scale(1.03,.95) } 50% { transform: scale(1.05,.93) } }
@keyframes pipTuftIdle { 0%,100% { transform: rotate(0) } 50% { transform: rotate(-6deg) } }
@keyframes pipTuftTwitch { 0%,40%,100% { transform: rotate(0) } 46% { transform: rotate(-18deg) } 52% { transform: rotate(6deg) } 58% { transform: rotate(0) } }
@keyframes pipTuftFlop { 0%,100% { transform: rotate(-6deg) } 35% { transform: rotate(22deg) } 65% { transform: rotate(-14deg) } }
@keyframes pipTuftHop { 0%,74%,100% { transform: rotate(0) } 84% { transform: rotate(20deg) } 92% { transform: rotate(-12deg) } 97% { transform: rotate(4deg) } }
@keyframes pipZz {
  0% { opacity: 0; transform: translate(0,0) scale(.6) }
  20% { opacity: .9 }
  80% { opacity: 0; transform: translate(8px,-16px) scale(1.1) }
  100% { opacity: 0 }
}

@media (prefers-reduced-motion: reduce) {
  .pip *, .pip *::before { animation: none !important; transition: none !important }
}
