/* Cutscene overlay and hand-drawn dialogue panel */

.cutscene-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  color: var(--fg);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Speaker label above the text */
.dialogue-speaker {
  font-weight: 700;
  font-size: clamp(calc(14px * var(--ui-scale)), calc(1.0vw * var(--ui-scale)), calc(18px * var(--ui-scale)));
  color: rgba(255,255,255,0.92);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  margin: 0 auto clamp(6px, 1vh, 10px);
  max-width: 90ch;
}
.cutscene-overlay[aria-hidden="false"] { display: block; }

/* Scene image stage */
.cutscene-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.cutscene-black {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  transition: opacity 250ms ease;
  pointer-events: none;
  z-index: 20000; /* cover everything inside cutscene overlay */
}
.cutscene-stage .layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1500ms ease;
}
.cutscene-stage .layer.active { opacity: 1; }

/* Dialogue panel (bottom) */
.dialogue-panel {
  position: fixed !important;
  left: 50% !important;
  bottom: 20px !important;
  top: auto !important;
  transform: translateX(-50%) !important;
  width: min(1100px, 92vw) !important;
  background: rgba(0, 0, 0, 0.42) !important;
  padding: clamp(16px, 2.4vh, 20px) clamp(16px, 2.4vw, 24px) !important;
  min-height: clamp(96px, 18vh, 220px) !important;
  max-height: 35vh !important;
  box-sizing: border-box !important;
  user-select: none !important;
  text-align: center !important;
  z-index: 9999 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important; /* keep scrollbars inside rounded border */
}

/* Hand-drawn white sketch border */
.dialogue-panel.sketch {
  border: 3px solid rgba(255,255,255,0.96);
  border-radius: 18px;
  position: relative;
}

.dialogue-text {
  font-size: clamp(calc(16px * var(--ui-scale)), calc(1.2vw * var(--ui-scale)), calc(22px * var(--ui-scale)));
  line-height: 1.55;
  letter-spacing: 0.2px;
  min-height: 3.5em;
  max-width: 90ch;
  margin: 0 auto;
  padding: 0 clamp(8px, 1.2vw, 12px);
  overflow-wrap: anywhere;
  text-align: center;
  /* Make the text area scrollable while keeping the Continue button visible */
  flex: 1 1 auto;
  min-height: 0; /* required for flex children to shrink and enable scrolling */
  overflow-y: auto;
  /* Firefox scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(160,160,160,0.7) transparent;
}

/* WebKit/Chromium scrollbars for dialogue text */
.dialogue-text::-webkit-scrollbar { width: 10px; height: 10px; }
.dialogue-text::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
}
.dialogue-text::-webkit-scrollbar-thumb {
  background-color: rgba(160,160,160,0.75);
  border-radius: 8px;
  border: 2px solid transparent; /* creates padding */
  background-clip: content-box;
}
.dialogue-text::-webkit-scrollbar-thumb:hover { background-color: rgba(180,180,180,0.9); }
.dialogue-text::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

.dialogue-actions {
  display: flex;
  justify-content: center;
  margin-top: clamp(8px, 1.6vh, 14px);
}
.dialogue-continue {
  appearance: none;
  cursor: pointer;
  border: none;
  color: var(--btn-text);
  background: transparent;
  padding: clamp(8px, 1.1vw, 12px) clamp(14px, 1.6vw, 18px);
  min-height: clamp(34px, 5vh, 48px);
  min-width: clamp(120px, 16vw, 180px);
  font-size: clamp(calc(14px * var(--ui-scale)), calc(1.1vw * var(--ui-scale)), calc(18px * var(--ui-scale)));
  position: relative;
  border: 3px solid rgba(255,255,255,0.96);
  border-radius: 18px;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.dialogue-continue:active { transform: translateY(1px) scale(0.99); }
.dialogue-continue:focus-visible { outline: 2px solid var(--accent); }

/* Character portrait centered at bottom */
.character-portrait {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 30px) scale(var(--char-scale, 1));
  width: min(38vw, 42vh);
  max-height: 60vh;
  object-fit: contain;
  opacity: 0;
  transition: opacity 350ms ease, transform 450ms ease;
  pointer-events: none;
  z-index: 4000; /* below dialogue panel */
}
.character-portrait.visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(var(--char-scale, 1));
}

/* Skip button for cutscene (bottom-left) */
.dialogue-skip {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 10000;
  appearance: none;
  border: 3px solid rgba(255,255,255,0.96);
  border-radius: 14px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  padding: 16px 24px;
  font-size: calc(clamp(12px, 1vw, 14px) * 2);
  cursor: pointer;
  display: none; /* shown conditionally for intro */
}
.dialogue-skip:active { transform: translateY(1px) scale(0.99); }
