/* "What's in my bag?": a small tote bag on the home board (js/whats-in-bag.js).
   Four things pop out of it and settle in a loose circle around it; "Pack it up" (or a click on the bag) sends them back in.
   The bag never moves. Each thing has its own tilt and its own idle wiggle. Nothing here is a card or a panel. */
.bag-stash {
  position: absolute;
  left: 1780px; /* above the first screen, in the empty strip between the rare footage and the pink character; the rule at the end of styles.css slides it up to just above the screen */
  top: 600px;
  z-index: 2;
  width: 440px;
  height: 470px;
  pointer-events: none; /* only the bag and the things that popped out can be hovered, never the empty corners */
  user-select: none;
  -webkit-user-select: none;
  --mouth-x: 205px; /* where the things come out of: the top of the bag */
  --mouth-y: 352px;
  --spring: cubic-bezier(0.34, 1.62, 0.5, 1);
}

.bag-stash__art {
  position: absolute;
  left: var(--mouth-x);
  bottom: 0;
  z-index: 2; /* in front of the things, so they come out from behind the bag */
  width: 170px;
  height: auto;
  margin-left: -85px;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 6px 8px rgba(28, 27, 25, 0.16));
}

/* the bag is a button: it opens and closes the things */
.bag-stash__toggle {
  position: absolute;
  left: var(--mouth-x);
  bottom: 0;
  z-index: 5;
  width: 170px;
  height: 235px;
  margin: 0 0 0 -85px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.bag-stash__toggle:focus-visible,
.bag-stash__pack:focus-visible {
  outline: 2px dashed #9747ff;
  outline-offset: 4px;
}

/* a little wiggle to say "open me" */
.bag-stash__art img {
  display: block;
  width: 100%;
  height: auto;
}

/* the print on the bag: a flower and the title */
.bag-stash__print {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  mix-blend-mode: multiply; /* the ink soaks into the canvas: the weave and the folds of the bag show through it, like a screen print */
  opacity: 0.94;
}

.bag-stash__print text {
  /* big, fat, soft-cornered letters that fill the whole bag, one line stretched to the width of the canvas */
  font-family: "Bowlby One", "Arial Black", Impact, sans-serif;
  fill: #ee4a26;
}

.bag-stash:not(.is-open):hover .bag-stash__art { animation: bag-wiggle 0.7s ease-in-out; }
.bag-stash.is-bump .bag-stash__art { animation: bag-bump 0.55s cubic-bezier(0.3, 1.5, 0.5, 1); }

@keyframes bag-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-3deg); }
  45% { transform: rotate(2.6deg); }
  70% { transform: rotate(-1.4deg); }
}

@keyframes bag-bump {
  0% { transform: scale(1, 1); }
  30% { transform: scale(1.06, 0.9); }
  62% { transform: scale(0.97, 1.05); }
  100% { transform: scale(1, 1); }
}

.bag-stash__items {
  position: absolute;
  inset: 0;
  z-index: 1;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* each thing is an anchor sitting in the mouth of the bag; it slides out to --x / --y and back */
.bag-stash__item {
  position: absolute;
  left: var(--mouth-x);
  top: var(--mouth-y);
  width: 0;
  height: 0;
  translate: 0 0;
  scale: 0.2;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* going back in: quick, one after another, from the last one out to the first */
  transition:
    translate 0.5s cubic-bezier(0.55, -0.25, 0.8, 0.4) calc((3 - var(--i)) * 55ms),
    scale 0.45s ease-in calc((3 - var(--i)) * 55ms),
    opacity 0.2s ease calc((3 - var(--i)) * 55ms + 0.28s),
    visibility 0s linear calc((3 - var(--i)) * 55ms + 0.55s);
}

.bag-stash.is-open .bag-stash__item {
  translate: var(--x) var(--y);
  scale: var(--s);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  /* coming out: springy, one after another */
  transition:
    translate 0.95s cubic-bezier(0.2, 1.45, 0.4, 1) calc(var(--i) * 95ms),
    scale 0.85s var(--spring) calc(var(--i) * 95ms),
    opacity 0.12s ease calc(var(--i) * 95ms),
    visibility 0s linear 0s;
}

.bag-stash__tilt {
  position: absolute;
  left: calc(var(--w) / -2);
  top: calc(var(--h) / -2);
  width: var(--w);
  height: var(--h);
  rotate: calc(var(--r) * -2.6);
  transition: rotate 0.5s ease-in calc((3 - var(--i)) * 55ms);
}

.bag-stash.is-open .bag-stash__tilt {
  rotate: var(--r);
  transition: rotate 1.05s var(--spring) calc(var(--i) * 95ms);
}

.bag-stash__float {
  width: 100%;
  height: 100%;
  transition: scale 0.3s var(--spring);
  filter: drop-shadow(0 5px 7px rgba(28, 27, 25, 0.16));
}

.bag-stash__float img,
.bag-stash__float svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.bag-stash.is-open .bag-stash__item:hover .bag-stash__float { scale: 1.09; }

/* the two stars are flat, with no shadow behind them */
.bag-stash__item--friends .bag-stash__float { filter: none; }

/* each thing wiggles in its own way once it has landed */
.bag-stash.is-open .bag-stash__item--friends .bag-stash__float { animation: bag-sway 3.8s ease-in-out 1.2s infinite; }
.bag-stash.is-open .bag-stash__item--sticker .bag-stash__float { animation: bag-bob 2.1s ease-in-out 1.1s infinite; }
.bag-stash.is-open .bag-stash__item--phone .bag-stash__float { animation: bag-tilt 4.6s ease-in-out 1.3s infinite; }
.bag-stash.is-open .bag-stash__item--drinks .bag-stash__float { animation: bag-juggle 2.7s ease-in-out 1.2s infinite; }

@keyframes bag-sway {
  0%, 100% { transform: rotate(-3deg) translateY(0); }
  50% { transform: rotate(3deg) translateY(-5px); }
}

@keyframes bag-bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-7px) scale(1.04); }
}

@keyframes bag-tilt {
  0%, 100% { transform: rotate(-4deg) translateY(2px); }
  50% { transform: rotate(5deg) translateY(-4px); }
}

@keyframes bag-juggle {
  0%, 100% { transform: translate(0, 0) rotate(-4deg); }
  25% { transform: translate(3px, -6px) rotate(2deg); }
  50% { transform: translate(0, -2px) rotate(5deg); }
  75% { transform: translate(-3px, -7px) rotate(-1deg); }
}

.bag-stash__heart {
  transform-box: fill-box;
  transform-origin: 50% 70%;
  animation: bag-beat 1.5s ease-in-out infinite;
}

@keyframes bag-beat {
  0%, 100% { transform: scale(1); }
  14% { transform: scale(1.22); }
  28% { transform: scale(1); }
  42% { transform: scale(1.14); }
}

.bag-stash__label {
  position: absolute;
  top: calc(var(--h) / 2 + 4px);
  left: calc(var(--lw, 170px) / -2);
  width: var(--lw, 170px);
  text-align: center;
  font-family: var(--scribble);
  font-size: 1.08rem;
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
  /* a thin pale edge keeps the writing readable where it passes over the dotted board */
  paint-order: stroke fill;
  -webkit-text-stroke: 3px var(--bg);
  opacity: 0;
  translate: 0 6px;
  transition: opacity 0.2s ease, translate 0.2s ease;
}

.bag-stash.is-open .bag-stash__label {
  opacity: 1;
  translate: 0 0;
  transition: opacity 0.4s ease calc(var(--i) * 95ms + 0.5s), translate 0.5s var(--spring) calc(var(--i) * 95ms + 0.5s);
}

/* "Pack it up": appears beside the bag once things are out */
.bag-stash__pack {
  position: absolute;
  left: calc(var(--mouth-x) - 52px); /* centred under the bag */
  top: calc(100% + 10px);
  width: 104px;
  box-sizing: border-box;
  z-index: 5;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 6px 11px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  translate: 0 -8px;
  pointer-events: none;
  transition: opacity 0.2s ease, translate 0.3s var(--spring), visibility 0s linear 0.2s, background-color 0.15s ease;
}

.bag-stash__pack svg {
  width: 12px;
  height: 12px;
}

.bag-stash__pack:hover { background: #fff; }
.bag-stash__pack:active { scale: 0.96; }

.bag-stash.is-open .bag-stash__pack {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
  pointer-events: auto;
  transition: opacity 0.3s ease 0.9s, translate 0.4s var(--spring) 0.9s, visibility 0s, background-color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .bag-stash__item,
  .bag-stash.is-open .bag-stash__item {
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  }

  .bag-stash.is-open .bag-stash__item { transition: opacity 0.2s ease; }
  .bag-stash__tilt,
  .bag-stash.is-open .bag-stash__tilt,
  .bag-stash__float,
  .bag-stash__label,
  .bag-stash.is-open .bag-stash__label,
  .bag-stash__pack,
  .bag-stash.is-open .bag-stash__pack { transition: none; }
  .bag-stash.is-open .bag-stash__item .bag-stash__float,
  .bag-stash:not(.is-open):hover .bag-stash__art,
  .bag-stash.is-bump .bag-stash__art,
  .bag-stash__heart { animation: none; }
  .bag-stash.is-open .bag-stash__item:hover .bag-stash__float { scale: 1; }
}

/* phones and tablets get the simpler home page without it */
@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
  body.home .bag-stash {
    display: none;
  }
}
