.game-stage .portrait-layer {
  z-index: 20;
  inset: 0;
  display: block;
  overflow: hidden;
  isolation: isolate;
  pointer-events: none;
}

.game-stage .portrait-layer[hidden] {
  display: block;
  visibility: hidden;
}

.portrait-slot {
  position: absolute;
  inset-block: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 30%;
  overflow: visible;
}

.portrait-slot-left {
  left: -2%;
}

.portrait-slot-left-center {
  left: 17%;
}

.portrait-slot-center {
  left: 35%;
}

.portrait-slot-right-center {
  left: 53%;
}

.portrait-slot-right {
  right: -2%;
}

.stage-portrait {
  position: relative;
  z-index: 1;
  display: grid;
  flex: 0 0 auto;
  place-items: end center;
  width: auto;
  height: var(--portrait-height, 66%);
  max-height: 72%;
  aspect-ratio: 3 / 4;
  margin: 0;
  overflow: visible;
  filter: brightness(0.7) saturate(0.84);
  opacity: 0.92;
  transform: scale(1);
  transform-origin: center bottom;
  transition:
    filter 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.stage-portrait[data-character='ryan'] {
  --portrait-height: 69%;
  --portrait-mobile-height: min(64dvh, 34rem);
}

.stage-portrait[data-character='cooper'],
.stage-portrait[data-character='sterling'] {
  --portrait-height: 67%;
  --portrait-mobile-height: min(62dvh, 33rem);
}

.stage-portrait[data-character='cydney'] {
  --portrait-height: 63%;
  --portrait-mobile-height: min(58dvh, 31rem);
}

.stage-portrait[data-character='gabi'],
.stage-portrait[data-character='ashley'] {
  --portrait-height: 58%;
  --portrait-mobile-height: min(54dvh, 29rem);
}

.stage-portrait[data-character='kenly'] {
  --portrait-height: 56%;
  --portrait-mobile-height: min(52dvh, 28rem);
}

.stage-portrait.is-speaking,
.stage-portrait[data-focused='true'] {
  z-index: 4;
  filter: brightness(1) saturate(1);
  opacity: 1;
}

.stage-portrait.is-speaking {
  transform: scale(1.045);
}

.stage-portrait .portrait-image,
.stage-portrait .portrait-fallback {
  grid-area: 1 / 1;
  align-self: end;
  justify-self: center;
}

.stage-portrait .portrait-image {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 1.1rem 1.2rem rgba(0, 0, 0, 0.38));
  user-select: none;
  -webkit-user-drag: none;
}

.stage-portrait .portrait-image[hidden] {
  display: none;
}

.stage-portrait .portrait-fallback {
  display: grid;
  width: 78%;
  height: 88%;
  place-items: center;
  border: 1px solid rgba(224, 228, 240, 0.28);
  border-radius: 1rem 1rem 0.25rem 0.25rem;
  background: linear-gradient(145deg, rgba(215, 223, 242, 0.22), rgba(19, 22, 42, 0.92));
  box-shadow: 0 1.2rem 2.5rem rgba(0, 0, 0, 0.28);
  color: rgba(248, 242, 230, 0.72);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(2rem, 5cqw, 4rem);
  font-weight: 600;
}

.stage-portrait.has-image .portrait-fallback,
.stage-portrait:has(.portrait-image:not([hidden])) .portrait-fallback {
  visibility: hidden;
}

.stage-portrait .portrait-caption {
  display: none;
}

@media (max-width: 680px) and (orientation: portrait) {
  .portrait-slot {
    inset: 0;
    width: 100%;
  }

  .stage-portrait {
    display: none;
    height: var(--portrait-mobile-height, min(60dvh, 32rem));
    max-height: 70dvh;
    filter: brightness(0.78) saturate(0.9);
    transform: translateX(var(--mobile-x, 0)) scale(1);
  }

  .stage-portrait[data-mobile-visible='true'] {
    display: grid;
  }

  .stage-portrait.is-speaking {
    transform: translateX(var(--mobile-x, 0)) scale(1.035);
  }

  .stage-portrait[data-mobile-pair='true'][data-mobile-side='left'] {
    --mobile-x: -15vw;
  }

  .stage-portrait[data-mobile-pair='true'][data-mobile-side='right'] {
    --mobile-x: 15vw;
  }

  .stage-portrait[data-mobile-pair='true'][data-mobile-visible='true'] {
    transform: translateX(var(--mobile-x, 0)) scale(0.74);
  }

  .stage-portrait.is-speaking[data-mobile-pair='true'][data-mobile-visible='true'] {
    transform: translateX(var(--mobile-x, 0)) scale(0.79);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .stage-portrait {
    height: var(--portrait-height, 66%);
    max-height: 70%;
  }
}
