.library-story-dialogue {
  position: fixed;
  z-index: 76;
  left: calc(max(8px, env(safe-area-inset-left)) + clamp(126px, 14.5vw, 210px) + clamp(18px, 2vw, 34px));
  right: clamp(560px, 48vw, 920px);
  bottom: clamp(16px, 2.5vh, 30px);
  opacity: 1;
  transform: translateY(14px);
  transition: transform .34s cubic-bezier(.2, .74, .24, 1);
  pointer-events: none;
}

/* Narrative Ming text keeps only a faint white outer glow, never a dark shadow. */
.library-story-dialogue__text {
  text-shadow:
    0 0 2px rgba(255, 255, 255, .55),
    0 0 .28em rgba(255, 255, 255, .32) !important;
}

/* Project-wide typography rule: text stays flat and shadow-free. */
*,
*::before,
*::after {
  text-shadow: none !important;
}

body.has-library-story-dialogue .panorama-character-dialogue {
  width: min(48vw, 760px);
}

body.has-library-story-dialogue .panorama-character-portrait {
  transform: translate3d(0, 4.5vh, 0) scale(1.06);
  transform-origin: right top;
}

body.has-library-story-dialogue .panorama-character-close {
  pointer-events: none;
}

.library-story-dialogue[hidden] { display: none; }

.library-story-dialogue.is-visible {
  transform: translateY(0);
  pointer-events: auto;
}

.library-story-dialogue__advance {
  display: block;
  width: 100%;
  min-height: min(76vh, 620px);
  padding: 0;
  border: 0;
  color: rgba(255, 255, 255, .98);
  background: transparent;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.library-story-dialogue__advance:hover,
.library-story-dialogue__advance:focus,
.library-story-dialogue__advance:focus-visible {
  border: 0;
  outline: none;
  background: transparent;
}

.library-story-dialogue__text {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  max-width: 100%;
  color: #bce9c3;
  font-family: "I.MingCP", "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  font-size: clamp(23px, 2.35vw, 38px);
  font-weight: 600;
  line-height: 1.72;
  letter-spacing: .12em;
  text-shadow:
    0 0 3px rgba(255, 255, 255, .84),
    0 0 10px rgba(244, 248, 255, .5),
    0 2px 8px rgba(0, 0, 0, .68);
}

.library-story-dialogue .story-dialogue-line {
  color: #bce9c3;
  font-family: "I.MingCP", "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  font-weight: 600;
}

.library-story-dialogue .story-dialogue-line.speaker-xinling { color: #fff; }

.library-story-dialogue__text::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -.22em -.55em -.28em;
  border-radius: .78em;
  background: rgba(255, 255, 255, .68);
  box-shadow: 0 0 1.05em .42em rgba(255, 255, 255, .48);
  filter: blur(.34em);
  opacity: 0;
  pointer-events: none;
}

.library-story-dialogue.speaker-mingfen .library-story-dialogue__text::before {
  opacity: 1;
}

.library-story-dialogue.speaker-xinling .library-story-dialogue__text {
  color: #fff;
}

.library-story-dialogue__advance small {
  display: block;
  margin-top: .9em;
  color: rgba(255, 255, 255, .7);
  font: 400 13px/1.2 "Microsoft JhengHei", sans-serif;
  letter-spacing: .08em;
  text-align: right;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .72);
}

@media (max-width: 760px) {
  .library-story-dialogue {
    top: max(18px, env(safe-area-inset-top));
    left: max(18px, env(safe-area-inset-left));
    right: max(18px, env(safe-area-inset-right));
    bottom: auto;
    max-height: 48vh;
  }

  .library-story-dialogue__advance {
    min-height: 0;
    padding: .35em 0 .4em;
  }

  .library-story-dialogue__text {
    font-size: clamp(18px, 4.9vw, 23px);
    line-height: 1.46;
    letter-spacing: .06em;
  }

  body.has-library-story-dialogue .panorama-character-dialogue {
    right: max(8px, env(safe-area-inset-right));
    bottom: -8vh;
    width: min(66vw, 360px);
    height: 68vh;
    overflow: visible;
  }

  body.has-library-story-dialogue .panorama-character-portrait {
    top: auto;
    right: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: 68vh;
    object-position: right bottom;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-story-dialogue { transition: none; }
}
/* Keep the phone usable without covering the child at the left edge of this scene. */
.library-panorama-page .panorama-pocket-phone {
  width: clamp(102px, 11vw, 150px);
}

@media (max-width: 640px) {
  .library-panorama-page .panorama-pocket-phone {
    width: 102px;
  }
}
