/* The physical object is projected into the same clear area as the canvas.
   On the counter it keeps the original desk scale and lighting. */
#opening-focus #focus-stage[data-engine="dom"] .center {
  container-type: size;
  perspective: max(1800px, 900vw);
  perspective-origin: center;
}
#opening-focus #focus-stage[data-engine="dom"] #pack-art {
  --pack-width: min(82cqw, 47cqh);
  --rest-x: -3deg;
  --rest-y: 4deg;
  --bank: -1.3deg;
  --elevation: 0px;
  --lift: 0%;
  --size: 1;
  transform-origin: center;
  transition: width 260ms var(--ease), transform 180ms var(--ease);
}
#opening-focus #focus-stage[data-engine="dom"] .pile,
#opening-focus #focus-stage[data-engine="dom"] #pack-art::before { display: none; }

/* Keep both the exposed cartridge and the empty sleeve visible as their
   separation grows. The projected edge continues to guide the pull. */
#desk[data-phase="torn"] #opening-focus #focus-stage[data-engine="dom"] #pack-art {
  --pack-width: min(82cqw, calc(47cqh / (1 + .55 * var(--draw, 0))));
  --lift: calc(4% + 8% * var(--draw, 0));
}
#desk:is([data-phase="drawn"], [data-phase="revealed"]) #opening-focus #focus-stage[data-engine="dom"] #pack-art {
  --pack-width: min(88.5cqw, 54cqh);
  --rest-x: -1.6deg;
  --rest-y: 1.8deg;
  --bank: .25deg;
  --size: .92;
}
@supports (scale: calc(1 + sin(1deg))) {
  /* Allow for the case thickness in the projected height while turning a
     cartridge end-over-end. Leave the face at reading size when it settles. */
  #desk:is([data-phase="drawn"], [data-phase="revealed"]) #opening-focus #focus-stage[data-engine="dom"] #pack-art {
    --pitch: calc(var(--rest-x) + var(--angle-x, 0deg));
    --yaw: calc(var(--rest-y) + var(--angle-y, 0deg) + var(--turn, 0) * 180deg);
    --vertical-tilt: max(sin(var(--pitch)), calc(-1 * sin(var(--pitch))));
    --side-facing: max(sin(var(--yaw)), calc(-1 * sin(var(--yaw))));
    --size: min(1, calc(1.015 / (cos(var(--pitch)) + var(--vertical-tilt) * (.596 * var(--side-facing) + .09))));
  }
  #opening-focus #focus-stage[data-engine="dom"] :is(.back-card, #card-area)::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(112deg, transparent 30%, #f4faff17 47%, transparent 60%) 50% 50% / 220% 100%;
    background-position-x: calc(50% + 47% * sin(var(--yaw, 0deg)));
  }
}
#desk:is([data-phase="drawn"], [data-phase="revealed"]) #opening-focus #focus-stage[data-engine="dom"] .cartridge-body {
  inset: 0;
}
#desk[data-phase="revealed"] #opening-focus #focus-stage[data-engine="dom"] .front-wrap {
  display: none;
}
#opening-focus #focus-stage[data-engine="dom"] .center::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(50% + min(69cqw, 41cqh));
  width: min(65cqw, 38cqh);
  height: 7%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, #07142260, #07142225 45%, transparent 73%);
  pointer-events: none;
}
#opening-focus #focus-stage[data-engine="dom"][data-grabbing="true"] #pack-art {
  transition: transform 45ms linear;
  animation-play-state: paused;
}
@media (prefers-reduced-motion: no-preference) {
  #desk:is([data-phase="drawn"], [data-phase="revealed"]) #opening-focus #focus-stage[data-engine="dom"] #pack-art {
    animation: focus-cartridge-hover 4.8s ease-in-out infinite alternate;
  }
  #desk:is([data-phase="drawn"], [data-phase="revealed"]) #opening-focus #focus-stage[data-engine="dom"][data-grabbing="true"] #pack-art {
    animation-play-state: paused;
  }
  @keyframes focus-cartridge-hover { from { translate: 0 1px; } to { translate: 0 -2px; } }
}
@media (prefers-reduced-motion: reduce) {
  #opening-focus #focus-stage[data-engine="dom"] #pack-art { transition: none; }
}
