/* Zuvio, drawn: the orb in its graduation cap (Zuvio 2, "Lamplight": docs/DESIGN.md). A page writes

     <span class="zorb calm" aria-hidden="true"><i></i><i></i>
       <svg viewBox="0 0 120 90" aria-hidden="true" focusable="false"><use href="/icons/cap.svg#cap" /></svg></span>

   and sets its size with --s. Its mood is one class, read in the eyes first and then in how the body
   moves (the design's "How Zuvio feels" board): calm (waiting with her), listening (eyes wide, leaning
   in), thinking (looking up, a light circling), explaining (pulsing with each word), seeing (reading
   her page), proud (smiling arches, a hop), curious (head tilted, one eye bigger), focused (eyes
   closed, a slow breath), sleepy (heavy eyes, a nod), shut (asleep or waiting) and resting (grey: live
   help is used up). Every number here is the design's, as a share of the orb's size, so it holds at
   any --s. The colours are tokens (tokens.css, --ui-orb and the rest), the same drawing as the landing
   page and the app icon. web/orb.ts is the other Zuvio: the living one, in three.js. */

.zorb {
  --s: 60px;
  --zorb-glow: var(--ui-orb-glow); /* the light it gives; a small orb in a list sets it to none (0 0 transparent) */
  --zorb-float: 0px; /* how far it floats: only the one big orb of a page sets it (calc(var(--s) * 0.027)) */
  position: relative; flex: none; display: block; width: var(--s); height: var(--s); border-radius: 50%;
  background: var(--ui-orb);
  /* a shade underneath and a light on top, so it reads as a ball, then the light it gives */
  box-shadow: inset 0 calc(var(--s) * -0.087) calc(var(--s) * 0.17) var(--ui-orb-under),
    inset 0 calc(var(--s) * 0.035) calc(var(--s) * 0.07) var(--ui-orb-shine), var(--zorb-glow);
  /* its own size is what its parts ask about (the @container rules below): under 40px no cap */
  container-type: size;
}
/* The eyes: two <i>, placed in percent so they keep their place at any size; never under 3px, so
   the smallest orb in a list still has two dots */
.zorb > i {
  position: absolute; left: 33.65%; top: 45.19%; width: max(3px, 9.62%); height: max(3px, 17.31%);
  border-radius: var(--ui-r-full); background: var(--ui-orb-eye);
}
.zorb > i:last-of-type { left: 56.73%; }
/* a wide eye has a glint of light in it */
.zorb > i::after { content: ""; position: absolute; left: 53%; top: 18%; width: 27%; height: 24%; border-radius: 50%; background: var(--ui-orb-glint); opacity: 0; }
.zorb.listening > i { left: 30.77%; top: 44.23%; width: 14.42%; height: 16.35%; border-radius: 50%; }
.zorb.listening > i:last-of-type { left: 54.81%; }
.zorb.thinking > i { height: 15.38%; }
.zorb.seeing > i { left: 31.73%; width: 13.46%; height: 14.42%; border-radius: 50%; }
.zorb.seeing > i:last-of-type { left: 54.81%; }
.zorb.curious > i:first-of-type { top: 48.08%; height: 13.46%; }
.zorb.curious > i:last-of-type { left: 54.81%; top: 40.38%; width: 14.42%; height: 19.23%; border-radius: 50%; }
.zorb:is(.listening, .seeing) > i::after, .zorb.curious > i:last-of-type::after { opacity: 1; }
/* proud, focused and shut: each eye an arch (a smile's) or a closed lid, drawn as half an outline */
.zorb:is(.proud, .focused, .shut, .resting) > i {
  left: 28.85%; width: 16.35%; background: none; border: max(2px, calc(var(--s) * 0.0385)) solid var(--ui-orb-eye);
}
.zorb:is(.proud, .focused, .shut, .resting) > i:last-of-type { left: 54.81%; }
.zorb.proud > i { top: 44.23%; height: 10.58%; border-bottom: 0; border-radius: var(--ui-r-full) var(--ui-r-full) 0 0; }
.zorb:is(.focused, .shut, .resting) > i { top: 50%; height: 9.62%; border-top: 0; border-radius: 0 0 var(--ui-r-full) var(--ui-r-full); }
/* sleepy: heavy lids, a little dimmer */
.zorb.sleepy { filter: brightness(0.86) saturate(0.85); }
.zorb.sleepy > i { left: 31.73%; top: 50.96%; width: 13.46%; height: 7.69%; border-radius: 0 0 var(--ui-r-full) var(--ui-r-full); }
.zorb.sleepy > i:last-of-type { left: 54.81%; }
.zorb.resting { background: var(--ui-orb-rest); --zorb-glow: 0 0 transparent; }
.zorb.curious { rotate: -9deg; transform-origin: 50% 92.3%; }
/* while it talks: a soft halo round it */
.zorb.explaining { box-shadow: inset 0 calc(var(--s) * -0.087) calc(var(--s) * 0.17) var(--ui-orb-under),
    inset 0 calc(var(--s) * 0.035) calc(var(--s) * 0.07) var(--ui-orb-shine), 0 0 0 calc(var(--s) * 0.048) var(--ui-orb-halo), var(--zorb-glow); }

/* The warm lamp inside, drawn over the top left of the ball: on a big orb it drifts, and it flares
   while Zuvio talks. A small orb has the gradient's own core and no more. */
.zorb::before { content: ""; position: absolute; left: 8%; top: 4%; width: 54%; height: 54%; border-radius: 50%; background: var(--ui-orb-core); opacity: 0; pointer-events: none; }
.zorb.explaining::before { left: 4%; top: 0; width: 60%; height: 60%; opacity: 0.6; }
/* thinking: a light circling it, on a quiet track */
.zorb.thinking::before {
  inset: -11.5%; width: auto; height: auto; opacity: 1;
  background: conic-gradient(var(--ui-cap) 0 17.4%, var(--ui-line) 0);
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
}
/* listening: a ring arriving with her voice */
.zorb.listening::before { inset: -2%; width: auto; height: auto; background: none; border: 2px solid var(--ui-active); }

/* The cap sits on top, a little to one side; its tassel hangs from the button, in amber, and swings */
.zorb > svg { position: absolute; left: -10%; top: -30%; width: 120%; height: 90%; overflow: visible; color: var(--ui-cap); pointer-events: none; }
.zorb::after {
  content: ""; position: absolute; left: -10%; top: -30%; width: 120%; height: 90%; pointer-events: none;
  background: url("/icons/tassel-threads.svg") 0 0 / 100% 100% no-repeat var(--ui-cap);
  -webkit-mask: url("/icons/tassel.svg") 0 0 / 100% 100% no-repeat;
  mask: url("/icons/tassel.svg") 0 0 / 100% 100% no-repeat;
  /* where the cord is tied: (97.6, 22.7) of the cap's 120 x 90 */
  transform-origin: 81.33% 25.22%; rotate: 1deg;
}
.zorb.sleepy > svg, .zorb.sleepy::after { rotate: 8deg; translate: 4% 9%; } /* its cap has slipped */
@container (max-width: 71.9px) {
  /* a small orb: a thicker cord and no ball, and no threads, so the tassel still reads */
  .zorb::after { background: var(--ui-cap); -webkit-mask-image: url("/icons/tassel-small.svg"); mask-image: url("/icons/tassel-small.svg"); }
}
@container (max-width: 39.9px) {
  /* the smallest: the ball and its two eyes, no cap */
  .zorb > svg, .zorb::after { display: none; }
  .zorb > i::after { display: none; }
}

/* Its life. Alive, never busy: it breathes, it blinks, its tassel swings; only the one big orb of
   a page floats and glances aside. A mood is the eyes first (0.3s), then the body. Nothing moves for
   someone who asked for less motion: the face still changes. */
@keyframes zorb-breathe { 0%, 100% { scale: 1; } 50% { scale: 1.035; } }
@keyframes zorb-slow { 0%, 100% { scale: 1; } 50% { scale: 1.03; } }
@keyframes zorb-float { 0%, 100% { translate: 0 0; } 50% { translate: 0 calc(var(--zorb-float) * -1); } }
@keyframes zorb-blink { 0%, 93% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } 99%, 100% { transform: scaleY(1); } }
@keyframes zorb-tassel { 0%, 100% { rotate: -9deg; } 50% { rotate: 11deg; } }
@keyframes zorb-glance { 0%, 38% { translate: 0 0; } 46%, 64% { translate: calc(var(--s) * 0.027) calc(var(--s) * -0.0115); } 72%, 100% { translate: 0 0; } }
@keyframes zorb-core { 0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.92; } 50% { transform: translate(5%, 4%) scale(1.1); opacity: 1; } }
@keyframes zorb-lean { 0%, 100% { scale: 1.03; } 50% { scale: 1.06; } }
@keyframes zorb-ring-in { 0% { transform: scale(1.55); opacity: 0; } 40% { opacity: 0.6; } 100% { transform: scale(1); opacity: 0; } }
@keyframes zorb-look-up { 0%, 100% { translate: calc(var(--s) * -0.048) calc(var(--s) * -0.058); } 50% { translate: calc(var(--s) * 0.0385) calc(var(--s) * -0.067); } }
@keyframes zorb-orbit { to { transform: rotate(360deg); } }
@keyframes zorb-talk { 0%, 100% { scale: 1; } 12% { scale: 1.045; } 24% { scale: 1.01; } 38% { scale: 1.05; } 52% { scale: 1; } 66% { scale: 1.035; } 80% { scale: 1.012; } }
@keyframes zorb-flare { 0%, 100% { opacity: 0.25; } 38% { opacity: 0.9; } 66% { opacity: 0.6; } }
@keyframes zorb-scan { 0%, 100% { translate: calc(var(--s) * -0.058) 0; } 50% { translate: calc(var(--s) * 0.058) 0; } }
@keyframes zorb-hop {
  0%, 55%, 100% { translate: 0 0; scale: 1 1; }
  12% { translate: 0 calc(var(--s) * 0.019); scale: 1.05 0.94; }
  28% { translate: 0 calc(var(--s) * -0.154); scale: 0.97 1.04; }
  42% { translate: 0 0; scale: 1.04 0.96; }
  48% { translate: 0 calc(var(--s) * -0.038); scale: 1 1; }
}
@keyframes zorb-tilt { 0%, 100% { rotate: -9deg; } 50% { rotate: 7deg; } }
@keyframes zorb-nod {
  0%, 30%, 100% { translate: 0 0; rotate: 0deg; }
  52%, 60% { translate: 0 calc(var(--s) * 0.058); rotate: 8deg; }
  68% { translate: 0 calc(var(--s) * -0.019); rotate: -2deg; }
  76% { translate: 0 0; rotate: 0deg; }
}
@media (prefers-reduced-motion: no-preference) {
  .zorb { animation: zorb-breathe 4.2s ease-in-out infinite, zorb-float 6s ease-in-out infinite; }
  .zorb > i { transition: left 0.3s, top 0.3s, width 0.3s, height 0.3s, border-radius 0.3s; }
  .zorb:not(.proud, .focused, .shut, .resting, .sleepy, .listening, .seeing) > i { animation: zorb-blink 4.6s ease-in-out infinite; }
  .zorb::after { animation: zorb-tassel 3.2s ease-in-out infinite; }
  .zorb.listening { animation: zorb-lean 2s ease-in-out infinite; }
  .zorb.listening::before { animation: zorb-ring-in 2s ease-out infinite; }
  .zorb.thinking { animation: zorb-breathe 3s ease-in-out infinite; }
  .zorb.thinking > i { animation: zorb-look-up 3.2s ease-in-out infinite; }
  .zorb.thinking::before { animation: zorb-orbit 1.7s linear infinite; }
  .zorb.thinking::after { animation-duration: 1.7s; }
  .zorb.explaining { animation: zorb-talk 1.4s ease-in-out infinite; }
  .zorb.explaining > i { animation-duration: 5s; }
  .zorb.explaining::before { animation: zorb-flare 1.4s ease-in-out infinite; }
  .zorb.explaining::after { animation-duration: 2.8s; }
  .zorb.seeing > i { animation: zorb-scan 2.2s ease-in-out infinite; }
  .zorb.proud { animation: zorb-hop 2.2s ease-in-out infinite; }
  .zorb.curious { animation: zorb-tilt 3.6s ease-in-out infinite; }
  .zorb.focused { animation: zorb-slow 6.5s ease-in-out infinite; }
  .zorb.sleepy { transform-origin: 50% 96%; animation: zorb-nod 5s ease-in-out infinite; }
  .zorb.sleepy::after { animation: none; }
  .zorb:is(.shut, .resting) { animation: zorb-slow 7s ease-in-out infinite; }
  .zorb:is(.shut, .resting)::after { animation-duration: 5s; }
  @container (min-width: 140px) {
    /* the one big orb of a page: the lamp inside drifts, and now and then it glances aside */
    .zorb:not(.thinking, .listening, .explaining)::before { animation: zorb-core 5s ease-in-out infinite; }
    .zorb.calm > i { animation: zorb-blink 5.2s ease-in-out infinite, zorb-glance 9s ease-in-out infinite; }
  }
}
