/* --------- Bebiboo logo that sews itself (/work/bebiboo): the live site's logo intro, rebuilt from its own pieces.
   Button letters and the needle are the site's images, the thread is its SVG paths drawn with a stroke dash,
   and timings are the original's. Lengths are in em with 1em = one original pixel, so the font-size sets the
   scale: up to 2× (the pieces' own resolution), smaller in narrow columns.
   States: no class = the finished logo (no JS, reduced motion); .is-waiting = hidden until it scrolls into view;
   .is-sewing = the animation. A click on the logo sews it again. Script at the end of work/bebiboo.html --------- */

/* 157em wide: b1 sticks out 7em left of the original 145em box */
.bb-logo {
  container-type: inline-size;
  margin-top: 24px;
}

.bb-logo__stage {
  position: relative;
  width: 157em;
  height: 116em;
  font-size: min(2px, calc(100cqw / 157));
}

.bb-logo__stage>* {
  position: absolute;
}

/* Set by the script: the logo replays on click */
.bb-logo__stage[role="button"] {
  cursor: pointer;
}

/* Keyboard focus in the site's border style, clear of the thread at the edges */
.bb-logo__stage:focus-visible {
  outline: var(--border) solid var(--text-color);
  outline-offset: 8px;
}

/* Wordmark and thread on top, as on the site: the thread runs over the buttons */
.bb-logo__wordmark,
.bb-logo__thread {
  z-index: 2;
  left: 7em;
  top: 0;
  width: 145em;
  height: 116em;
}

.bb-logo__thread path {
  fill: none;
  stroke: var(--bebiboo-thread);
  stroke-width: 1.3px;
}

/* The big button, the i's dot, finishes the intro turned by 900°: half a turn */
.bb-logo__button { left: 57.73em;  top: 3.44em;  width: 38.92em; height: 37.33em; z-index: 1; transform: rotate(180deg); }
.bb-logo__b1     { left: 0;        top: 38.63em; width: 29.26em; height: 41.5em; }
.bb-logo__e      { left: 21.42em;  top: 60.56em; width: 27.43em; height: 25.06em; }
.bb-logo__b2     { left: 42.58em;  top: 47.51em; width: 30.56em; height: 42.29em; }
.bb-logo__needle { left: 75.23em;  top: 45.68em; width: 7.14em;  height: 64.23em; transform-origin: bottom; }
.bb-logo__b3     { left: 83.86em;  top: 47em;    width: 30.92em; height: 42.82em; }
.bb-logo__o1     { left: 106.84em; top: 59.25em; width: 28.55em; height: 27.36em; }
.bb-logo__o2     { left: 128.53em; top: 49.33em; width: 28.47em; height: 26.89em; }

/* Before and during the intro: pieces at zero size, thread undrawn (dash 320 is longer than any thread path) */
.bb-logo.is-waiting img:not(.bb-logo__wordmark),
.bb-logo.is-sewing img:not(.bb-logo__wordmark) {
  transform: scale(0);
}

.bb-logo.is-waiting .bb-logo__thread path,
.bb-logo.is-sewing .bb-logo__thread path {
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
}

/* The needle comes up, the button pops in and spins, the letters pop in left to right */
.bb-logo.is-sewing .bb-logo__needle { animation: bb-grow .5s ease-out forwards; }
.bb-logo.is-sewing .bb-logo__button { animation: bb-pop .5s .7s forwards, bb-spin 1s 1.2s ease-in-out forwards; }
.bb-logo.is-sewing .bb-logo__b1     { animation: bb-pop .5s 1.5s ease-out forwards; }
.bb-logo.is-sewing .bb-logo__e      { animation: bb-pop .5s 1.7s ease-out forwards; }
.bb-logo.is-sewing .bb-logo__b2     { animation: bb-pop .5s 1.9s ease-out forwards; }
.bb-logo.is-sewing .bb-logo__b3     { animation: bb-pop .5s 2.1s ease-out forwards; }
.bb-logo.is-sewing .bb-logo__o1     { animation: bb-pop .5s 2.3s ease-out forwards; }
.bb-logo.is-sewing .bb-logo__o2     { animation: bb-pop .5s 2.5s ease-out forwards; }

/* The thread is stitched through piece by piece */
.bb-logo.is-sewing .bb-logo__thread path { animation: bb-stitch 4s linear forwards; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(2)  { animation-delay: 1s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(3)  { animation-delay: 1.5s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(4)  { animation-delay: 1.8s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(5)  { animation-delay: 2.1s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(6)  { animation-delay: 2.4s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(7)  { animation-delay: 2.5s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(8)  { animation-delay: 3s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(9)  { animation-delay: 3.2s; }
.bb-logo.is-sewing .bb-logo__thread path:nth-child(10) { animation-delay: 3.4s; }

@keyframes bb-pop {
  40% { transform: scale(1.2); }
  65% { transform: scale(.9); }
  95% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes bb-grow {
  40% { transform: scaleY(1.2); }
  65% { transform: scaleY(.9); }
  95% { transform: scaleY(1.05); }
  100% { transform: scaleY(1); }
}

@keyframes bb-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(900deg); }
}

@keyframes bb-stitch {
  to { stroke-dashoffset: 0; }
}
