/* Griselda and Blip visit Tilde's chat: the chat panel's header, as flat pictures.
   Tilde and Clo are the quiet piece (tilde-clo/tilde-clo.css, loaded beside this file); Blip is his
   2x strips; Griselda is five cells cut from her village screen frames. No canvas, no WebGL, no video.
   chat-visit.js sets the data- attributes below; this file only draws what they say.
   Size it with --cv-height (default 104px): everything inside scales with it. */
.chat-visit {
  --cv-height: 104px;
  --u: calc(var(--cv-height) / 104);
  position: relative;
  height: var(--cv-height);
  overflow: hidden;
}
.chat-visit > * { pointer-events: none; }

/* Tilde, with Clo asleep at her boot: on the left, at the size that stands her level with Griselda. */
.chat-visit .cv-tilde {
  --tilde-clo-width: calc(81 * var(--u));
  position: absolute;
  left: calc(10 * var(--u));
  bottom: calc(2 * var(--u));
  cursor: default;
}
/* Clo hears something: her ears lift and her snore stops. She never wakes. */
.chat-visit .cv-tilde .tc-ears { transition: transform 0.25s ease-out; }
.chat-visit[data-clo="heard"] .cv-tilde .tc-ears { animation: none; transform: translate(-0.298%, -78%); }
.chat-visit[data-clo="stir"] .cv-tilde .tc-ears { animation: none; transform: translate(-0.298%, -52%); }
.chat-visit[data-clo="heard"] .cv-tilde .tc-snore,
.chat-visit[data-clo="stir"] .cv-tilde .tc-snore { animation: none; opacity: 0; }

/* The guests stand on the same ground line, measured from the right edge. Their pictures are not
   fetched until chat-visit.js has been asked for an arrival (the cv-ready class). */
.chat-visit .cv-blip,
.chat-visit .cv-griselda { position: absolute; display: block; background-repeat: no-repeat; opacity: 0; }

/* Blip: one cell of his strips is 64 x 67 with the ground under his middle at 30, 52; here 25 units tall sitting. */
.chat-visit .cv-blip {
  width: calc(44.444 * var(--u));
  height: calc(46.528 * var(--u));
  right: calc(130.39 * var(--u));
  top: calc(59.89 * var(--u));
  transform-origin: 46.875% 0;
  transform: scaleX(-1); /* he faces Clo and Tilde; his strips face right */
  transition: right 0.5s ease-in-out;
  background-position: 0 0;
}
.chat-visit.cv-ready .cv-blip { background-image: url(blip/blip-hop@2x.png); background-size: 900% 100%; }
.chat-visit[data-blip="sit"] .cv-blip,
.chat-visit[data-blip="poof-in"] .cv-blip,
.chat-visit[data-blip="peek"] .cv-blip,
.chat-visit[data-blip="nap"] .cv-blip,
.chat-visit[data-blip="wake"] .cv-blip,
.chat-visit[data-blip="poof-out"] .cv-blip { opacity: 1; }
.chat-visit.cv-ready[data-blip="poof-in"] .cv-blip { background-image: url(blip/blip-poof-in@2x.png); background-size: 900% 100%; animation: cv-strip 0.75s steps(9, jump-none) forwards; }
.chat-visit.cv-ready[data-blip="poof-out"] .cv-blip { background-image: url(blip/blip-poof-out@2x.png); background-size: 800% 100%; animation: cv-strip 0.667s steps(8, jump-none) forwards; }
.chat-visit.cv-ready[data-blip="peek"] .cv-blip { background-image: url(blip/blip-peek@2x.png); background-size: 3200% 100%; animation: cv-strip 2.667s steps(32, jump-none) forwards; }
.chat-visit.cv-ready[data-blip="nap"] .cv-blip { background-image: url(blip/blip-nap@2x.png); background-size: 2000% 100%; animation: cv-strip 2.5s steps(20, jump-none) infinite; }
.chat-visit.cv-ready[data-blip="wake"] .cv-blip { background-image: url(blip/blip-wake@2x.png); background-size: 2500% 100%; animation: cv-strip 2.083s steps(25, jump-none) forwards; }
@keyframes cv-strip { from { background-position: 0 0; } to { background-position: 100% 0; } }

/* Griselda: a cell is 300 x 384 with her boots at 352 and her ear balls at 30; here 91 units tall.
   Cells: 0 at work, 1 at work with her head tilted, 2 looking out, 3 and 4 her wave. */
.chat-visit .cv-griselda {
  width: calc(84.78 * var(--u));
  height: calc(108.52 * var(--u));
  right: calc(47.6 * var(--u));
  top: calc(-3.48 * var(--u));
  transform: translateX(calc(140 * var(--u))); /* waiting just past the right edge */
  transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0s linear 0.7s;
  background-position: 50% 0;
}
.chat-visit.cv-ready .cv-griselda { background-image: url(griselda.webp); background-size: 500% 100%; }
.chat-visit[data-guests="here"] .cv-griselda { opacity: 1; transform: none; transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0s; }
.chat-visit[data-griselda="wave"] .cv-griselda { animation: cv-wave 0.5s steps(1, end) infinite; }
.chat-visit[data-griselda="out"] .cv-griselda { background-position: 50% 0; }
.chat-visit[data-griselda="work"] .cv-griselda { animation: cv-work 6s steps(1, end) infinite; }
@keyframes cv-wave { 0% { background-position: 75% 0; } 50% { background-position: 100% 0; } }
@keyframes cv-work { 0% { background-position: 0 0; } 82% { background-position: 25% 0; } }

/* Less motion: nobody arrives or leaves or fidgets; whoever is here is simply here. */
@media (prefers-reduced-motion: reduce) {
  /* Nothing glides or eases. The second line is as specific as the rule that gives Griselda her glide when the
     guests are here (two classes and an attribute), and comes after it, so it wins. */
  .chat-visit .cv-blip, .chat-visit .cv-griselda, .chat-visit .cv-tilde .tc-ears { transition: none; }
  .chat-visit[data-guests] .cv-blip, .chat-visit[data-guests] .cv-griselda, .chat-visit[data-guests] .cv-tilde .tc-ears { transition: none; }
  .chat-visit.cv-ready[data-blip] .cv-blip { animation: none; background-image: url(blip/blip-hop@2x.png); background-size: 900% 100%; background-position: 0 0; }
  .chat-visit.cv-ready[data-blip="nap"] .cv-blip { background-image: url(blip/blip-nap@2x.png); background-size: 2000% 100%; }
  .chat-visit[data-griselda] .cv-griselda { animation: none; }
  .chat-visit[data-griselda="work"] .cv-griselda { background-position: 0 0; }
  .chat-visit[data-griselda="wave"] .cv-griselda { background-position: 50% 0; }
  .chat-visit[data-clo] .cv-tilde .tc-ears { transform: translate(-0.298%, -25.601%); }
}
