/* The first moment after the photos are in (unboxing.js): an empty table with only the photos, their stacks and the
   book on it, and the making's one line under them. The tools wait till the book is there, then come one by one. */

/* while it plays, nothing else on the table: no bar, no pages, no dock, only the table's own surface (so the scene lies
   on the very table the book will); the making's line sits under the scene */
body.is-unboxing :is(#top, #table > *, #agent, #choices) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
body.is-unboxing .making {
  top: auto;
  bottom: calc(env(safe-area-inset-bottom) + clamp(28px, 8vh, 84px));
}
/* the making's line has said it's done under the scene: it goes with the scene, never jumps up to its place */
body.is-unboxed .making {
  top: auto;
  bottom: calc(env(safe-area-inset-bottom) + clamp(28px, 8vh, 84px));
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}
/* then the table first, the bar over it, the dock last: each its own moment (TOOLS_MS and DOCK_MS in unboxing.js) */
body.is-unboxed #table > * {
  transition: opacity 0.5s var(--ease);
}
body.is-unboxed #top {
  transition: opacity 0.45s var(--ease) 0.4s;
}
body.is-unboxed :is(#agent, #choices) {
  transition: opacity 0.45s var(--ease) 0.8s;
}

.unbox {
  position: fixed;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 0.52s var(--ease);
}
.unbox.is-leaving {
  opacity: 0;
}

/* a photo on the table: a small print with its white border, falling in where it lies */
.unbox-photo {
  --size: clamp(64px, 11vmin, 120px);
  position: absolute;
  width: var(--size);
  aspect-ratio: 1;
  object-fit: cover;
  border: calc(var(--size) * 0.05) solid #fff;
  border-bottom-width: calc(var(--size) * 0.12);
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 8px 18px -8px rgb(40 30 20 / 0.5);
  translate: -50% -50%;
  rotate: var(--turn);
  animation: unbox-fall 0.6s var(--ease) both;
  transition:
    left 0.9s var(--ease),
    top 0.9s var(--ease),
    rotate 0.9s var(--ease),
    scale 0.7s var(--ease),
    opacity 0.6s var(--ease),
    filter 0.6s var(--ease);
}
/* a print that steps back fades as an old print does, towards the table's paper, and stays whole: one lying over another
   covers it, never shows it through */
.unbox {
  --unbox-washed: saturate(0.45) contrast(0.5) brightness(1.2) sepia(0.12);
  --unbox-faint: saturate(0.3) contrast(0.32) brightness(1.3) sepia(0.12);
}
@keyframes unbox-fall {
  from {
    opacity: 0;
    scale: 1.25;
    translate: -50% -80%;
  }
}
/* a photo brought forward while the AI looks and thinks (unboxing.js see): large over the table, a print with a deep
   white foot, what the AI saw in it written on that foot as on an instant photo's, so the words lie on their own paper
   and never over the prints behind; its print on the table makes way while it's up, the rest
   step back. On a phone it takes most of the width. */
.unbox-seen {
  --seen: min(max(46vmin, 66vw), 360px, 46dvh);
  --edge: calc(var(--seen) * 0.04);
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 42%;
  box-sizing: border-box;
  width: var(--seen);
  margin: 0;
  padding: var(--edge) var(--edge) 0;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 26px 46px -22px rgb(40 30 20 / 0.55);
  translate: -50% -50%;
}
.unbox-seen img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.unbox-seen figcaption {
  box-sizing: border-box;
  min-height: calc(var(--seen) * 0.14);
  padding: 0.5em 0.3em 0.65em;
  color: var(--text);
  font:
    italic 400 clamp(15px, 2.6vmin, 22px) / 1.25 'Fraunces',
    Georgia,
    serif;
  text-align: center;
  text-wrap: balance;
  animation: unbox-write 0.9s var(--ease) 0.45s both;
}
/* (its print makes way as the photo rises from it, and comes back as it lands: seeing.js crossfades the two) */
.unbox-photo.is-seen {
  opacity: 0 !important;
  transition: opacity 0.2s var(--ease);
}
.unbox.is-seeing .unbox-photo:not(.in-stack) {
  filter: var(--unbox-washed);
}
/* gone into the book: a stack's prints once its moment is laid, a loose print the moment it flies (its flight is its
   own picture, unboxing.js fly), the photos left out off the table as the book closes */
.unbox-photo.is-in {
  scale: 0.4;
  opacity: 0;
}
.unbox-photo.is-flown {
  opacity: 0;
  transition: none;
}
/* once the moments gather, the photos not (yet) in one step back, so the stacks and their names read; further once
   the book lies open, so what's laid on it is what you look at */
.unbox.has-stacks .unbox-photo:not(.in-stack) {
  scale: 0.82;
  filter: var(--unbox-washed);
}
.unbox.has-book .unbox-photo:not(.in-stack) {
  filter: var(--unbox-faint);
}
/* on a phone the open book and the row of stacks fill the screen: the loose prints leave the table as the book opens,
   so nothing lies behind them, and the photos fly in from their moment's stack (unboxing.js narrow, the same query) */
@media (max-width: 599px) {
  .unbox.has-book .unbox-photo:not(.in-stack) {
    scale: 0.7;
    opacity: 0;
  }
}
.unbox.has-stacks .unbox-photo.is-out,
.unbox-photo.is-out {
  scale: 0.7;
  opacity: 0;
}
/* a moment waiting behind the row's last, till one goes into the book */
.unbox-photo.is-queued,
.unbox-stack.is-queued {
  opacity: 0;
  scale: 0.8;
}

/* a moment's stack: its name under it, written in as the AI writes the moment */
.unbox-stack {
  position: absolute;
  z-index: 6;
  width: 0;
  height: 0;
  transition:
    opacity 0.5s var(--ease),
    scale 0.5s var(--ease),
    left 0.9s var(--ease),
    top 0.9s var(--ease);
}
.unbox-label {
  position: absolute;
  top: calc(clamp(64px, 11vmin, 120px) * 0.62);
  left: 0;
  width: max-content;
  max-width: min(var(--pitch) - 16px, 200px); /* its place in the row (unboxing.js arrange), so names never meet */
  translate: -50% 0;
  color: var(--text);
  font:
    italic 400 clamp(13px, 1.9vmin, 17px) / 1.15 'Fraunces',
    Georgia,
    serif;
  text-align: center;
  text-wrap: balance;
  animation: unbox-write 0.6s var(--ease) 0.4s both;
  transition: opacity 0.5s var(--ease);
}
@keyframes unbox-write {
  from {
    opacity: 0;
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}
/* the one going into the book now in full ink, the names still waiting quieter beside it: nothing touches the letters */
.unbox-stack:not(.is-laying) .unbox-label {
  opacity: 0.45;
}
.unbox-stack.is-in {
  opacity: 0;
}

/* the book under the row of stacks, open on the spread being laid; a leaf turns from one to the next (its coming in
   and a leaf's turn are unboxing.js BOOK_IN_MS and TURN_MS) */
.unbox-book {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 58%;
  translate: -50% -50%;
  animation: unbox-book-in 0.7s var(--ease) both;
}
/* the closed book's width, which the line under it reads: on a phone most of the screen's */
.unbox {
  --closed-w: min(max(56vmin, 72vw), 420px);
}
@keyframes unbox-book-in {
  from {
    opacity: 0;
    scale: 0.9;
  }
}
/* open, it lies whole between the row of stacks with their names (STACKS_TOP in unboxing.js, the label's top above)
   and the making's card under the scene (its place at the top of this file, about 100px high with its bar), so on a
   short window the card never covers the foot of the spread, where photos land and drawings stand; --ratio is the
   spread's width over its height (unboxing.js openOn) */
.unbox-book.is-open {
  --above: calc(15dvh + clamp(64px, 11vmin, 120px) * 0.62 + 44px);
  --below: calc(env(safe-area-inset-bottom) + clamp(28px, 8vh, 84px) + 100px);
  top: calc((var(--above) + 100dvh - var(--below)) / 2);
  width: min(94vw, 680px, (100dvh - var(--above) - var(--below)) * var(--ratio));
}
.unbox-pages {
  position: relative;
  perspective: 2400px;
  box-shadow: 0 24px 50px -24px rgb(40 30 20 / 0.55);
}
.unbox-pages > * {
  display: block;
  width: 100%;
}
/* a page copied from a spread: the whole spread under it, the page's half showing */
.unbox-half {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
}
.unbox-whole {
  position: absolute;
  top: 0;
  width: 200%;
  height: 100%;
}
.unbox-half.is-right .unbox-whole {
  left: -100%;
}
.unbox-half.is-left .unbox-whole {
  left: 0;
}
.unbox-left {
  left: 0;
}
.unbox-leaf {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  animation: unbox-turn 0.9s cubic-bezier(0.45, 0.05, 0.25, 1) both;
}
.unbox-leaf .unbox-face {
  left: 0;
  width: 100%;
  backface-visibility: hidden;
}
.unbox-leaf .unbox-face.is-back {
  transform: rotateY(180deg);
}
/* the leaf darkens a touch towards the fold as it lifts, as paper catches less light there */
.unbox-leaf .unbox-face::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgb(40 30 20 / 0.16), transparent 30%);
  animation: unbox-shade 0.9s ease-in-out both;
}
.unbox-leaf .unbox-face.is-back::after {
  background: linear-gradient(270deg, rgb(40 30 20 / 0.16), transparent 30%);
}
@keyframes unbox-shade {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}
@keyframes unbox-turn {
  from {
    transform: rotateY(0deg);
  }
  to {
    transform: rotateY(-180deg);
  }
}
/* a photo on its way from the table to its page (unboxing.js fly) */
.unbox-flier {
  position: fixed;
  z-index: 9;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 14px 26px -10px rgb(40 30 20 / 0.45);
  transform-origin: center;
  pointer-events: none;
}
/* closed on its cover, what it is under it once, as on a box */
.unbox-book.is-closed {
  top: 46%;
  width: var(--closed-w);
  animation: unbox-close 0.7s var(--ease) both;
}
@keyframes unbox-close {
  from {
    opacity: 0.4;
    scale: 1.06;
  }
}
.unbox-cover {
  box-shadow:
    6px 6px 0 #f6f1e7,
    10px 14px 30px rgb(40 30 20 / 0.3);
}
.unbox-cover > * {
  display: block;
  width: 100%;
}
.unbox-what {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(46% + var(--closed-w) / 2 + 26px);
  margin: 0;
  color: var(--quiet);
  font-size: 13px;
  letter-spacing: 0.02em;
  text-align: center;
  animation: unbox-book-in 0.6s var(--ease) 0.4s both;
}

@media (prefers-reduced-motion: reduce) {
  .unbox-photo,
  .unbox-label,
  .unbox-seen figcaption,
  .unbox-book,
  .unbox-what {
    animation: none;
  }
}
