.scene-portrait {
  inline-size: var(--scene-portrait-size);
  border: 1px solid #a88e68;
  border-radius: 6px;
  background-color: #182331;
  box-shadow: 0 2px 5px #694c3526;
}

.scene-speech {
  min-inline-size: 0;
}

.scene-speaker {
  margin: 4px 0 0;
  color: #654d35;
  font: 700 clamp(.7rem, 2.2vmin, .82rem)/1.2 var(--text);
  text-align: center;
  overflow-wrap: anywhere;
}

.scene-line {
  position: relative;
  margin: 7px auto 0;
  padding: 0 2px;
  max-inline-size: 15em;
  color: #362b23;
  font-family: var(--text);
  font-size: clamp(.79rem, 1.64vw, .93rem);
  font-weight: 650;
  line-height: 1.39;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.scene-line > .caption-text {
  inset-inline: 2px;
}


.scene-comment {
  --scene-comment-inset: clamp(8px, 2.1vmin, 14px);
  position: absolute;
  z-index: 4;
  inset-block-end: var(--scene-comment-inset);
  inset-inline-start: var(--scene-comment-inset);
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vmin, 9px);
  inline-size: max-content;
  max-inline-size: calc(100% - 2 * var(--scene-comment-inset));
  padding: 3px 8px 3px 4px;
  border: 1px solid #e4c9a453;
  border-radius: 6px;
  color: #fff3df;
  background: #17222be0;
  pointer-events: none;
}

.scene-comment[data-position="right-margin"] {
  inset-inline: auto var(--scene-comment-inset);
}

.scene-comment[data-position="bottom-margin"] {
  inset-inline: var(--scene-comment-inset);
  margin-inline: auto;
}

.scene-comment > .scene-portrait {
  flex: 0 0 auto;
  inline-size: clamp(44px, 14.4vmin, 64px);
  image-rendering: pixelated;
  margin: 0;
  border-radius: 4px;
  box-shadow: none;
}

.scene-comment .scene-speaker {
  margin: 0 0 2px;
  color: #f3d39f;
  text-align: start;
}

.scene-portrait[data-expression] {
  position: relative;
  overflow: hidden;
  background-size: 0 0;
}

.speaking-sprite {
  position: absolute;
  inset: 0;
  background-image: inherit;
  background-position: inherit;
  background-size: 300% 200%;
  background-repeat: no-repeat;
}

@media (prefers-reduced-motion: no-preference) {
  :is(#scene-comment, #scene-montage-speech):not([hidden]) .speaking-sprite {
    animation: speaker-reaction 480ms ease-in-out;
    animation-play-state: var(--speaker-play-state, running);
  }

  .scene-picture[data-speech-paused] .speaking-sprite {
    --speaker-play-state: paused;
  }

  .scene-portrait[data-expression="1"] { --speaker-pose: translateY(-4%) scale(1.09); }
  .scene-portrait[data-expression="2"] { --speaker-pose: translateY(-6%) scale(1.13); }
  .scene-portrait[data-expression="4"] { --speaker-pose: rotate(-4deg) scale(1.075); }
  .scene-portrait[data-expression="5"] { --speaker-pose: rotate(3deg) scale(1.06); }

}

@keyframes speaker-reaction {
  0%, 100% { transform: none; }
  40% { transform: var(--speaker-pose, translateY(3%) scale(1.065)); }
}

.scene-comment .scene-line {
  margin: 0;
  padding: 0;
  max-inline-size: none;
  color: inherit;
  font-size: clamp(.77rem, 2.6vmin, .92rem);
  font-weight: 550;
  text-align: start;
}

.scene-comment .scene-line > .caption-text {
  inset-inline: 0;
}

.scene-comment-outgoing {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}

.scene-picture:has(> .scene-photo-outgoing:not([hidden], [data-transition="print"])) > #scene-comment,
.scene-picture:has(> .scene-page-photos[data-leaving]) > #scene-comment {
  z-index: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .scene-montage-speech:not([hidden]) {
    animation: scene-comment-appear 260ms ease-out;
  }
}

@keyframes scene-comment-appear {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}
