.story-overlay {
  --portal-x: 0px;
  --portal-y: 0px;
  --portal-scale: 1;
  --hole-x: 39%;
  --hole-y: 46%;
  position: absolute;
  inset: 0;
  z-index: 9;
  transform: translate3d(var(--portal-x), var(--portal-y), 70px) scale(var(--portal-scale));
  transform-origin: center;
  transition:
    transform 0.42s cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 0.35s;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.story-overlay[hidden] {
  display: none;
}
.story-overlay.summoned:not(.aligned):not(.dragging) {
  animation: portalHover 2.2s ease-in-out infinite alternate;
  filter: drop-shadow(0 24px 22px rgba(20, 36, 59, 0.3));
}
.story-overlay.dragging {
  transition: none;
  cursor: grabbing;
  animation: none;
  translate: 0 0;
}
.story-overlay.aligned {
  filter: drop-shadow(0 12px 18px rgba(20, 36, 59, 0.18));
  animation: portalSettle 0.48s cubic-bezier(0.2, 0.9, 0.22, 1);
}
.story-overlay.aligned::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 7;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 0 0 rgba(255, 214, 103, 0.66);
  animation: portalGlow 0.8s ease-out forwards;
}
.portal-paper,
.portal-overlay-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.portal-paper {
  z-index: 0;
  background: rgba(255, 255, 255, 0.84);
  -webkit-mask-image: radial-gradient(
    circle at var(--hole-x) var(--hole-y),
    transparent 0 7.5%,
    #000 8.2%
  );
  mask-image: radial-gradient(circle at var(--hole-x) var(--hole-y), transparent 0 7.5%, #000 8.2%);
}
.portal-overlay-art {
  z-index: 1;
  object-fit: contain;
  opacity: 0.72;
  mix-blend-mode: multiply;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(
    circle at var(--hole-x) var(--hole-y),
    transparent 0 7.5%,
    #000 8.2%
  );
  mask-image: radial-gradient(circle at var(--hole-x) var(--hole-y), transparent 0 7.5%, #000 8.2%);
}
.story-overlay.composite .portal-paper {
  display: none;
}
.story-overlay.composite .portal-overlay-art {
  opacity: 1;
  mix-blend-mode: normal;
  -webkit-mask-image: none;
  mask-image: none;
}
.story-overlay.composite .portal-window-link {
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  transform: none;
  border-radius: 0;
}
.portal-window-ring {
  display: none;
}
.portal-drag-label {
  position: absolute;
  left: 50%;
  bottom: -38px;
  z-index: 4;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(20, 36, 59, 0.84);
  color: white;
  font-size: 11px;
  letter-spacing: 0.06em;
}
.story-overlay.aligned .portal-drag-label {
  opacity: 0;
  pointer-events: none;
}
.portal-inline-flip {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 5;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.9);
  padding: 7px 12px;
  cursor: pointer;
}
.portal-window-link {
  position: absolute;
  left: var(--hole-x);
  top: var(--hole-y);
  z-index: 6;
  width: 17%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: transparent;
  box-shadow: none;
}
.portal-window-link[hidden] {
  display: none;
}
.selected-card.portal-open .card-front::after {
  opacity: 0;
}
.selected-card.portal-open {
  filter: drop-shadow(0 14px 20px rgba(20, 36, 59, 0.18));
}
.viewer.portal-active .viewer-actions {
  display: none;
}
.viewer.portal-active .inspection-stage {
  margin-top: 48px;
}
@keyframes portalHover {
  from {
    translate: 0 -3px;
  }
  to {
    translate: 0 3px;
  }
}
@keyframes portalSettle {
  0% {
    scale: 1.018;
  }
  62% {
    scale: 0.994;
  }
  100% {
    scale: 1;
  }
}
@keyframes portalGlow {
  from {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(255, 214, 103, 0.66);
  }
  to {
    opacity: 0;
    box-shadow: 0 0 34px 18px rgba(255, 214, 103, 0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .story-overlay.summoned:not(.aligned),
  .story-overlay.aligned,
  .story-overlay.aligned::after {
    animation: none;
  }
}
