/* Kapi's dialogue box (Genshin-style, bottom centre) and the Alt cursor hint. */
.world-dialogue {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 16px));
  width: min(760px, calc(100vw - 32px));
  transform: translateX(-50%);
  font-family: Inter, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  color: #fff;
  animation: dialogue-in 0.28s ease-out;
}
.world-dialogue[hidden] {
  display: none;
}
.dialogue-box {
  position: relative;
  min-height: 148px;
  padding: 34px 32px 30px;
  border: 1px solid #f3dc9b55;
  border-radius: 20px;
  background:
    linear-gradient(180deg, #10261ef0, #0b1d16f5),
    #10261e;
  box-shadow:
    0 18px 50px #0008,
    inset 0 0 0 4px #10261e,
    inset 0 0 0 5px #f3dc9b33;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dialogue-box:focus-visible {
  outline: 2px solid #f3dc9b;
  outline-offset: 3px;
}
.dialogue-plate {
  position: absolute;
  top: -20px;
  left: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px 6px 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f3dc9b, #e3c57b);
  color: #10261e;
  box-shadow: 0 6px 16px #0006;
}
.dialogue-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff8e4;
  font-size: 17px;
}
#dialogue-speaker {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.dialogue-text {
  margin: 0;
  min-height: 3em;
  font-size: 18px;
  line-height: 1.75;
  text-shadow: 0 1px 2px #0008;
  white-space: pre-line;
}
.dialogue-count {
  position: absolute;
  top: 10px;
  right: 18px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #f3dc9b99;
}
.dialogue-next {
  position: absolute;
  right: 26px;
  bottom: 12px;
  color: #f3dc9b;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}
.world-dialogue.line-done .dialogue-next {
  opacity: 1;
  animation: dialogue-bob 0.9s ease-in-out infinite;
}
.dialogue-skip {
  position: absolute;
  right: 4px;
  top: -46px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid #ffffff55;
  border-radius: 999px;
  background: #10261ecc;
  color: #fff;
  font: 700 13px/1 inherit;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
}
.dialogue-skip[hidden] {
  display: none;
}
.dialogue-skip:hover {
  background: #315c40;
}
.dialogue-skip:focus-visible {
  outline: 2px solid #f3dc9b;
  outline-offset: 2px;
}
@keyframes dialogue-in {
  from {
    opacity: 0;
    transform: translate(-50%, 16px);
  }
}
@keyframes dialogue-bob {
  50% {
    transform: translateY(4px);
  }
}

/* While talking, keep the screen calm: hide the action HUD (Genshin does the same). */
#game.in-dialogue .weapon-bar,
#game.in-dialogue .interaction-prompt,
#game.in-dialogue .companion-line,
#game.in-dialogue .hp-meter,
#game.in-dialogue .objective-marker,
#game.in-dialogue .touch-stick,
#game.in-dialogue .touch-jump,
#game.in-dialogue .touch-action,
#game.in-dialogue .touch-heal {
  visibility: hidden;
}

/* Alt hint while the pointer is locked. */
.pointer-hint {
  position: absolute;
  z-index: 6;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 6px;
  border-radius: 999px;
  background: #10261e99;
  color: #ffffffd9;
  font: 600 12px/1 Inter, "Segoe UI", sans-serif;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.pointer-hint.visible {
  opacity: 1;
}
.pointer-hint kbd {
  padding: 3px 6px;
  border-radius: 5px;
  background: #f3dc9b;
  color: #10261e;
  font: 700 11px/1 inherit;
}
@media (pointer: coarse) {
  .pointer-hint {
    display: none;
  }
}

@media (max-width: 760px), (max-height: 520px) {
  .dialogue-box {
    min-height: 118px;
    padding: 28px 20px 26px;
    border-radius: 16px;
  }
  .dialogue-text {
    font-size: 15px;
    line-height: 1.65;
  }
  .dialogue-plate {
    left: 16px;
  }
}
@media (max-height: 520px) and (pointer: coarse) {
  /* Landscape phone: leave room for the Interact button on the right. */
  .world-dialogue {
    width: min(620px, calc(100vw - 210px));
    left: max(16px, env(safe-area-inset-left));
    transform: none;
    bottom: max(14px, env(safe-area-inset-bottom));
    animation-name: dialogue-in-left;
  }
  .dialogue-box {
    min-height: 96px;
    padding: 24px 18px 20px;
  }
}
@keyframes dialogue-in-left {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .world-dialogue,
  .world-dialogue.line-done .dialogue-next {
    animation: none;
  }
}
