/* Load after styles.css. The frame stays square; no perspective, rotation,
   warping, or generated face geometry is applied to the original character. */
.portrait-stage {
  isolation: isolate;
  container-type: size;
}

.portrait-frame {
  position: absolute;
  height: var(--portrait-size, min(98%, 165cqw));
  width: auto;
  aspect-ratio: 1;
  left: var(--portrait-left, 50%);
  bottom: var(--portrait-bottom, 0%);
  transform: translateX(-50%);
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 650ms ease;
  /* The source ends at the shoulders. Fade that existing crop into the page. */
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 86%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 86%, transparent 100%);
}

.portrait-frame[data-ready="true"] {
  opacity: 1;
}

.portrait-layer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Boundaries measured against the 1254 x 1254 transparent portrait.
   The stepped cuts keep the cap stem and the low right-hand bubble intact. */
.portrait-layer--cap {
  z-index: 2;
  clip-path: polygon(0 0, 100% 0, 100% 16.1085%, 55% 16.1085%, 55% 17.0654%, 45% 17.0654%, 45% 16.1085%, 0 16.1085%);
  transform: translate3d(var(--cap-shift-x, 0px), var(--cap-float-y, 0px), 0);
}

.portrait-layer--cloud {
  z-index: 1;
  clip-path: polygon(0 16.1085%, 45% 16.1085%, 45% 17.0654%, 55% 17.0654%, 55% 16.1085%, 100% 16.1085%, 100% 42.9825%, 68.6% 42.9825%, 68.6% 40.9091%, 0 40.9091%);
  transform: translate3d(var(--cloud-shift-x, 0px), var(--cloud-float-y, 0px), 0);
}

.portrait-layer--body {
  z-index: 3;
  clip-path: polygon(0 40.9091%, 68.6% 40.9091%, 68.6% 42.9825%, 100% 42.9825%, 100% 100%, 0 100%);
}

.portrait-frame[data-motion="running"] .portrait-layer--cap,
.portrait-frame[data-motion="running"] .portrait-layer--cloud {
  will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
  .portrait-frame { transition: none; }
  .portrait-layer--cap,
  .portrait-layer--cloud { transform: none; will-change: auto; }
}

@media (max-width: 820px) {
  .portrait-frame {
    height: var(--portrait-size-mobile, min(98%, 165cqw));
    bottom: var(--portrait-bottom-mobile, 0%);
  }
}

/* Approved resting portrait dissolves into the original opening layers. */
.portrait-stage { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.portrait-stage:focus-visible { outline: 2px solid #dca863; outline-offset: 5px; border-radius: 20px; }
.portrait-layer--body { transition: opacity 420ms ease 260ms; }
.portrait-stage[data-open="false"] .portrait-layer--body { opacity: 0; }
.portrait-stage[data-open="true"] .portrait-layer--body { opacity: 1; transition-delay: 0ms; }
.portrait-layer--closed { z-index: 5; opacity: 1; transition: opacity 420ms ease 260ms; }
.portrait-layer--cap { z-index: 4; transition: transform 850ms cubic-bezier(.22,.8,.22,1), opacity 350ms ease; }
.portrait-layer--cloud { transform-origin: 50% 41%; transition: transform 750ms cubic-bezier(.22,.8,.22,1), opacity 400ms ease; }
.portrait-stage[data-open="false"] .portrait-layer--cap { transform: translate3d(0,25.5%,0); opacity: 0; }
.portrait-stage[data-open="false"] .portrait-layer--cloud { transform: translateY(5%) scale(.72); opacity: 0; }
.portrait-stage[data-open="true"] .portrait-layer--closed { opacity: 0; transition-delay: 0ms; }
.portrait-stage[data-open="true"] .portrait-layer--cap { opacity: 1; }
.portrait-stage[data-open="true"] .portrait-layer--cloud { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .portrait-layer--closed, .portrait-layer--body, .portrait-layer--cap, .portrait-layer--cloud { transition: none; }
}
