/* Buddy locks in for his IA2 (partials/figures/study.php). Plays once on load
   and rests on the last frame; with reduced motion only that frame shows.
   Buddy's bar is the figure's one orange. */

.st-paper {
  fill: var(--frame);
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linejoin: round;
}

.st-paper--thin {
  stroke-width: 3;
}

.st-book {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 4;
}

.st-ink {
  fill: var(--ink);
}

.st-eraser {
  fill: var(--muted);
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
}

.st-line,
.st-write,
.st-tick,
.st-steam {
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.st-line {
  stroke-width: 4;
}

.st-line--thick {
  stroke-width: 5;
}

.st-write {
  stroke-width: 3;
  stroke-dasharray: 1;
}

.st-tick {
  stroke-width: 5;
  stroke-dasharray: 1;
}

.st-steam {
  stroke: var(--muted);
  stroke-width: 3;
}

/* The pencil rests at the end of the tick. */
.st-pencil {
  transform: translate(346px, 168px);
}

.st-fig .buddy__face--think {
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .st-write {
    animation: st-draw 0.55s linear 0.4s both;
  }

  .st-write--2 { animation-delay: 1.05s; }
  .st-write--3 { animation-delay: 1.7s; }
  .st-write--4 { animation-delay: 2.35s; }

  .st-tick {
    animation: st-draw 0.4s linear 3.05s both;
  }

  /* The steam drifts up while he works, then holds still. */
  .st-steam {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: st-steam 1.6s ease-in-out 0.4s 2 both;
  }

  .st-pencil {
    animation: st-pencil 3.5s linear 0.4s both;
  }

  /* He nods along while the pencil writes. */
  .st-nod {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: st-nod 0.62s ease-in-out 0.4s 4 alternate both;
  }

  .st-hop {
    transform-box: fill-box;
    transform-origin: center bottom;
    animation: st-hop 0.7s 3.6s both;
  }

  .st-fig .buddy__face--think {
    animation: st-out 3.6s step-end both;
  }

  .st-fig .buddy__face--smile {
    animation: st-in 3.6s step-end both;
  }

  .st-fig .buddy__eye {
    transform-box: fill-box;
    transform-origin: center;
  }

  .st-fig .buddy__face--smile .buddy__eye {
    animation: st-blink 1.5s ease-in-out 4.5s both;
  }
}

@keyframes st-draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

/* The pencil's tip follows each line of working, then the tick. */
@keyframes st-pencil {
  0% { transform: translate(272px, 120px); }
  15.7% { transform: translate(342px, 120px); }
  18.6% { transform: translate(272px, 136px); }
  34.3% { transform: translate(330px, 136px); }
  37.1% { transform: translate(272px, 152px); }
  52.9% { transform: translate(338px, 152px); }
  55.7% { transform: translate(272px, 168px); }
  71.4% { transform: translate(314px, 168px); }
  75.7% { transform: translate(318px, 178px); }
  80% { transform: translate(328px, 188px); }
  87.1%, 100% { transform: translate(346px, 168px); }
}

@keyframes st-nod {
  from { transform: none; }
  to { transform: rotate(-4deg); }
}

/* A hop with weight: a crouch, a quick rise that slows, a faster fall, a
   squash on landing and a settle. Each keyframe names the easing to the next. */
@keyframes st-hop {
  0% { transform: translateY(0) scale(1, 1); animation-timing-function: cubic-bezier(0.3, 0, 0.6, 1); }
  16% { transform: translateY(0) scale(1.04, 0.93); animation-timing-function: cubic-bezier(0.1, 0.45, 0.5, 1); }
  46% { transform: translateY(-18px) scale(0.98, 1.03); animation-timing-function: cubic-bezier(0.45, 0, 0.9, 0.55); }
  70% { transform: translateY(0) scale(1.05, 0.92); animation-timing-function: cubic-bezier(0.3, 0, 0.3, 1); }
  86% { transform: translateY(0) scale(0.99, 1.015); animation-timing-function: ease-in-out; }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes st-steam {
  0%, 100% { opacity: 1; transform: none; }
  50% { opacity: 0.45; transform: translateY(-3px) scaleY(1.1); }
}

@keyframes st-out {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes st-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Two quick blinks: the lids close faster than they open. */
@keyframes st-blink {
  0%, 12%, 60%, 72%, 100% { transform: none; }
  5%, 65% { transform: scaleY(0.13); }
}
