/* ============================================
   DIALOGUE SYSTEM — Gold ornate frame
   ============================================ */

#dialogue-container {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 82;
  padding: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px) translateZ(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
  will-change: opacity, transform;
}

#dialogue-container.visible {
  opacity: 1;
  transform: translateY(0) translateZ(0);
  pointer-events: auto;
}

/* ---- Main dialogue box — pure CSS gold double-border frame ---- */
.dialogue-box {
  position: relative;
  display: flex;
  gap: 0;
  overflow: visible;
  max-width: 900px;
  margin: 0 auto;
  transform: translateZ(0);
  backface-visibility: hidden;

  /* Dark interior */
  background: rgba(10, 14, 20, 0.94);

  /*
   * Layered gold double-border frame:
   * border = bright gold outer edge
   * box-shadow inset = dark gap + darker gold inner edge
   * box-shadow outer = dark outline + ambient glow
   */
  border: 3px solid #c5952e;
  box-shadow:
    /* Inner border layers: dark gap → inner gold trim */
    inset 0 0 0 2px rgba(8, 10, 16, 0.9),
    inset 0 0 0 4px #8a6518,
    /* Subtle warm inner glow */
    inset 0 0 16px rgba(160, 120, 40, 0.06),
    /* Outer frame: dark edge → soft gold glow → shadow */
    0 0 0 2px rgba(0, 0, 0, 0.8),
    0 0 10px rgba(160, 120, 40, 0.12),
    0 0 24px rgba(0, 0, 0, 0.5);
}

/* Corner diamond accents at all four corners */
.dialogue-box::before,
.dialogue-box::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #ddb240, #b08820);
  border: 1px solid #7a5a14;
  transform: rotate(45deg);
  z-index: 5;
  box-shadow: 0 0 6px rgba(200, 160, 60, 0.35);
  pointer-events: none;
}

/* ::before = top-left, ::after = top-right (positioned via CSS) */
.dialogue-box::before { top: -7px; left: -7px; }
.dialogue-box::after  { top: -7px; right: -7px; }

/* Bottom corners use a wrapper div injected by JS */
.dialogue-corner-bl,
.dialogue-corner-br {
  position: absolute;
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #ddb240, #b08820);
  border: 1px solid #7a5a14;
  transform: rotate(45deg);
  z-index: 5;
  box-shadow: 0 0 6px rgba(200, 160, 60, 0.35);
  pointer-events: none;
}
.dialogue-corner-bl { bottom: -7px; left: -7px; }
.dialogue-corner-br { bottom: -7px; right: -7px; }

/* ---- Portrait section with its own ornate frame ---- */
.dialogue-portrait {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: clamp(80px, 16vw, 120px);
  height: clamp(80px, 16vw, 120px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px 8px 4px 4px;

  /* Portrait sub-frame: gold double border echoing the main frame */
  background: rgba(8, 12, 16, 0.9);
  border: 2px solid #c5952e;
  box-shadow:
    inset 0 0 0 1px rgba(8, 10, 16, 0.8),
    inset 0 0 0 2px #8a6518,
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 0 6px rgba(160, 120, 40, 0.1);
}

.dialogue-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  transition: opacity 0.2s ease;
  /* Subtle breath so the speaker never feels like a still photograph */
  transform-origin: 50% 100%;
  animation: portrait-breathe 3.8s ease-in-out infinite;
}

@keyframes portrait-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.015) translateY(-0.5%); }
}

@media (prefers-reduced-motion: reduce) {
  .dialogue-portrait img { animation: none; }
}

/* ---- Text section ---- */
.dialogue-text-area {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 0.5rem 0.8rem;
  min-height: clamp(70px, 14vw, 110px);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

/* Name plate */
.dialogue-name {
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1.4vw, 0.65rem);
  padding: 0.25em 0.6em;
  display: inline-block;
  margin-bottom: 0.5rem;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  /* Colours set per character via JS */
}

/* Dialogue text */
.dialogue-text {
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1.4vw, 0.65rem);
  color: var(--text-light);
  line-height: 2;
  flex: 1;
}

.dialogue-text .highlight {
  color: var(--text-highlight);
}

/* Typewriter cursor */
.dialogue-text .cursor {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  background: var(--gold-bright);
  margin-left: 2px;
  animation: cursor-blink 0.6s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Continue indicator */
.dialogue-continue {
  position: absolute;
  bottom: 0.4rem;
  right: 0.6rem;
  font-size: 0.5rem;
  color: var(--gold);
  animation: bounce-indicator 1s ease-in-out infinite;
}

@keyframes bounce-indicator {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Per-character name plate colours */
.name-fern { background: #3a5a2a; color: #dae0ca; }
.name-jasper { background: #2a3a4a; color: #c0d0e0; }
.name-fizz { background: #5a2a3a; color: #f0c0d0; }
.name-nimbus { background: #2a2a4a; color: #c8c0e0; }
.name-compass { background: #4a3020; color: #e0c8a0; }
.name-shade { background: #1a1428; color: #c8b888; }
.name-witch { background: #3a1a4a; color: #d0a0e0; }
.name-princess-pumpkin { background: #5a3a1a; color: #f0d8a0; }

/* No portrait variant (for narration) */
.dialogue-box.no-portrait .dialogue-portrait {
  display: none;
}

.dialogue-box.no-portrait .dialogue-text-area {
  padding: 0.8rem 1rem;
  min-height: clamp(60px, 12vw, 90px);
}

.dialogue-box.no-portrait .dialogue-text {
  font-size: clamp(0.55rem, 1.6vw, 0.7rem);
  line-height: 2.2;
}
