/* Dialogue (js/dialogue.js): navy speech bubble anchored above the speaking NPC (.dlg.dlg-bubble), or a compact centred
   box near the bottom for signs / narration (.dlg.dlg-box). Uses the HUD tokens from style.css with fallbacks. */
.dlg {
  --dlg-bg: linear-gradient(#1b3f86, #0f2148);
  --dlg-edge: var(--border-hi, #6fa6ff);
  --dlg-tail-bg: #12295a;
  position: fixed; z-index: 8; box-sizing: border-box;
  min-width: 200px; max-width: min(380px, calc(100vw - 32px)); padding: 10px 16px 8px;
  background: var(--dlg-bg);
  border: 2px solid var(--dlg-edge); border-radius: 14px;
  box-shadow: 0 0 0 2px #0a1630, inset 0 0 0 1px rgba(255, 255, 255, .08), 0 8px 22px rgba(0, 0, 0, .45);
  color: var(--text, #f4f7ff); font-family: Nunito, system-ui, sans-serif;
  font-size: 16px; font-weight: 800; line-height: 1.4; letter-spacing: .2px; text-align: left;
  opacity: 0; pointer-events: none; transition: opacity .15s; cursor: pointer; user-select: none;
}
.dlg.open { opacity: 1; pointer-events: auto; }

/* narration / signs / speakers that aren't on screen: compact box, bottom centre */
.dlg.dlg-box { left: 50%; bottom: 26px; transform: translateX(-50%); width: max-content; max-width: min(560px, calc(100vw - 32px)); min-width: 280px; }
.dlg.dlg-box .dlg-tail { display: none; }
.dlg.sign { --dlg-bg: linear-gradient(#3e3322, #241c10); --dlg-edge: #d8b25a; --dlg-tail-bg: #2e2416; }

/* speech bubble: left/top set every frame by Dialogue.update() */
.dlg.dlg-bubble { width: max-content; }
.dlg[data-kind="player"], .dlg[data-kind="sys"] { --dlg-edge: #9cd2ff; }

.dlg-name {
  display: block; margin-bottom: 1px; color: var(--gold, #ffcf4a); font-size: 14px; font-weight: 900; letter-spacing: .6px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .45);
}
.dlg-name[data-color="female"] { color: #ffb3c8; }
.dlg-name[hidden], .dlg-yesno[hidden], .dlg-choices[hidden] { display: none; }

.dlg-text { white-space: pre-line; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); overflow-wrap: anywhere; }
.dlg-rest { visibility: hidden; }
.dlg-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.dlg-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px; height: 18px; margin-top: 2px;
  color: #c8d8ff; font-size: 12px; font-weight: 800; opacity: 0; transition: opacity .12s;
}
.dlg-foot.show { opacity: 1; }
.dlg-next { color: var(--gold, #ffcf4a); font-size: 13px; }
.dlg-foot.show .dlg-next { animation: dlg-bob .7s ease-in-out infinite; }
@keyframes dlg-bob { 50% { transform: translateY(3px); } }

/* tail: a rotated square straddling the bottom edge (top edge when .flip), x set by Dialogue.update() */
.dlg-tail {
  position: absolute; top: 100%; left: 50%; width: 16px; height: 16px; margin: -8px 0 0 -9px;
  background: var(--dlg-tail-bg); border: solid var(--dlg-edge); border-width: 0 2px 2px 0;
  transform: rotate(45deg); box-shadow: 3px 3px 0 -1px #0a1630;
}
.dlg.flip .dlg-tail { top: auto; bottom: 100%; margin: 0 0 -8px -9px; border-width: 2px 0 0 2px; box-shadow: -3px -3px 0 -1px #0a1630; background: #1b3f86; }

/* YES / NO and choice lists float next to the bubble (positioned by Dialogue._dock) */
.dlg-yesno, .dlg-choices {
  position: fixed; z-index: 9; left: 0; top: 0; display: flex; flex-direction: column; gap: 3px; padding: 6px;
  max-height: 50vh; overflow: auto;
  background: linear-gradient(#1b3f86, #0f2148); border: 2px solid var(--border-hi, #6fa6ff); border-radius: 12px;
  box-shadow: 0 0 0 2px #0a1630, 0 6px 18px rgba(0, 0, 0, .4);
}
.dlg-yesno button, .dlg-choices button {
  display: flex; align-items: center; gap: 6px; min-width: 96px; padding: 5px 12px 5px 6px; border: 2px solid transparent; border-radius: 8px;
  background: none; color: var(--text, #f4f7ff); font: 900 16px Nunito, system-ui, sans-serif; text-align: left; cursor: pointer;
}
.dlg-yesno button::before, .dlg-cur { content: '▶'; color: var(--gold, #ffcf4a); font-size: 12px; visibility: hidden; }
.dlg-yesno button.sel::before, .dlg-choices button.sel .dlg-cur { visibility: visible; }
.dlg-yesno button.sel, .dlg-choices button.sel { border-color: var(--gold, #ffcf4a); background: rgba(255, 207, 74, .14); }
.dlg-yesno button:focus-visible, .dlg-choices button:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ambient NPC chatter / online-player chat bubbles (Trainer.say → .bubble, style.css): same navy look */
.bubble {
  background: linear-gradient(#1b3f86, #0f2148); color: var(--text, #f4f7ff); font-family: Nunito, system-ui, sans-serif;
  font-size: 14px; font-weight: 800; line-height: 1.35; padding: 6px 12px; border-radius: 12px; max-width: 240px;
  border: 2px solid var(--border-hi, #6fa6ff); box-shadow: 0 0 0 2px #0a1630, 0 6px 14px rgba(0, 0, 0, .4);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}
.bubble::after {
  left: 50%; bottom: -7px; width: 10px; height: 10px; margin-left: -6px; border: solid var(--border-hi, #6fa6ff);
  border-width: 0 2px 2px 0; background: #11275a; transform: rotate(45deg);
}

@media (max-width: 760px) {
  .dlg { font-size: 15px; padding: 9px 12px 7px; }
  .dlg.dlg-box { bottom: 12px; min-width: 0; width: calc(100vw - 32px); }
  .dlg-yesno button, .dlg-choices button { font-size: 15px; min-width: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  .dlg-foot.show .dlg-next { animation: none; }
  .dlg { transition: none; }
}
