/* =============================================================
   Quest Story Styles
   Dialogue, character showcase, and interactive story elements
   used by CYOA and narrative pages. Ported from the old GitHub
   page (charadex-story.css). Loaded only on quest pages.
   ============================================================= */

/* Token bridge — the rules below reference the old charadex `--cd-*`
   variables. Map them onto the site theme (static/css/site.css) so
   fonts and a few semantic colors resolve. The dialogue/character-showcase
   parchment palette below is its own token set (`--dialogue-*`), re-skinned
   for dark mode in dark-mode.css rather than following `--cd-*`/site tokens
   directly, since it needs its own "night parchment" look rather than the
   page's plain card background. */
:root {
  --cd-body-font-family: "Nunito", system-ui, sans-serif;
  --cd-header-font-family: "Fredoka", system-ui, sans-serif;
  --cd-content-background-color: var(--card);
  --cd-border-color: var(--line);
  --cd-primary-text-color: var(--ink);
  --cd-secondary-text-color: var(--ink-soft);
  --cd-secondary-color: var(--bg);
  /* Relationship gauge accents */
  --cd-rarity-common-txt: var(--ink);
  --cd-rarity-uncommon-bg: var(--mint);
  --cd-rarity-rare-bg: var(--rose-deep);

  /* Dialogue/character-showcase parchment palette — light-mode defaults.
     Re-skinned to a "night parchment" palette under [data-theme="dark"]
     in dark-mode.css. */
  --dialogue-bg: #F5E0C9;
  --dialogue-border: #C8A88C;
  --dialogue-border-hover: #B89A7A;
  --dialogue-text: #6B4E3F;
  --dialogue-text-rgb: 107, 78, 63;
  --dialogue-showcase-bg: #E8D8C1;
  --dialogue-illustration-bg: #DAC5AA;
  --dialogue-line: #887765;
}

/* Dialogue Box Styles
/* ============================================================= */

.dialogue-container {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1rem;
  background-color: transparent;
  border: none;
  border-radius: 1rem;
  box-shadow: none;
}

.character-portrait {
  flex-shrink: 0;
  width: 120px;
  height: 120px;
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  background-color: var(--dialogue-bg);
  overflow: hidden;
  position: relative;
}

.character-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0.8rem;
}

.character-name {
  padding: 0.5rem 1rem;
  background-color: var(--dialogue-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 0.5rem;
  color: var(--dialogue-text);
  font-family: var(--cd-header-font-family);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  display: inline-block;
  margin-bottom: 1rem;
}

.speech-bubble {
  flex: 1;
  background-color: var(--dialogue-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  padding: 1.5rem;
  position: relative;
  color: var(--dialogue-text);
  font-family: var(--cd-body-font-family);
  font-size: 20px;
  line-height: 1.6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.speech-bubble::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 30px;
  width: 0;
  height: 0;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-right: 12px solid var(--dialogue-border);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  left: -10px;
  top: 30px;
  width: 0;
  height: 0;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-right: 12px solid var(--dialogue-bg);
}

.speech-bubble p {
  margin: 0 0 1rem;
}

.speech-bubble p:last-child {
  margin-bottom: 0;
}

.speech-bubble strong {
  color: var(--dialogue-text);
  font-weight: 600;
}

/* Responsive design for mobile */
@media (max-width: 768px) {
  .dialogue-container {
    flex-direction: row;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .character-portrait {
    width: 80px;
    height: 80px;
  }
  
  .character-name {
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
  }
  
  .speech-bubble::before {
    left: -8px;
    top: 20px;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid var(--dialogue-border);
  }
  
  .speech-bubble::after {
    left: -6px;
    top: 20px;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid var(--dialogue-bg);
  }
}

/* Alternative layout for dialogue without character portrait */
.dialogue-simple {
  background-color: var(--dialogue-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  padding: 1.5rem;
  margin: 1.5rem 0;
  color: var(--dialogue-text);
  font-family: var(--cd-body-font-family);
  font-size: 20px;
  line-height: 1.6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Character portrait with hidden face shadow */
.character-portrait.hidden-face {
  position: relative;
}

.character-portrait.hidden-face::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(165deg, 
    rgba(0, 0, 0, 1) 0%, 
    rgba(0, 0, 0, 0.95) 40%, 
    rgba(0, 0, 0, 0.8) 70%, 
    rgba(0, 0, 0, 0.4) 90%, 
    transparent 100%);
  border-radius: 0.8rem 0.8rem 0 0;
  pointer-events: none;
  z-index: 1;
}

/* Alternative layout for dialogue with character portrait on the right */
.dialogue-container-right {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1rem;
  background-color: transparent;
  border: none;
  border-radius: 1rem;
  box-shadow: none;
  flex-direction: row-reverse;
}

.dialogue-container-right .character-portrait {
  flex-shrink: 0;
  width: 120px;
  height: 120px;
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  background-color: var(--dialogue-bg);
  overflow: hidden;
  position: relative;
}

.dialogue-container-right .character-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0.8rem;
}

.dialogue-container-right .character-name {
  padding: 0.5rem 1rem;
  background-color: var(--dialogue-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 0.5rem;
  color: var(--dialogue-text);
  font-family: var(--cd-header-font-family);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  display: inline-block;
  margin-bottom: 1rem;
}

.dialogue-container-right .speech-bubble {
  flex: 1;
  background-color: var(--dialogue-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  padding: 1.5rem;
  position: relative;
  color: var(--dialogue-text);
  font-family: var(--cd-body-font-family);
  font-size: 20px;
  line-height: 1.6;
}

.speech-bubble-right {
  flex: 1;
  background-color: var(--dialogue-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  padding: 1.5rem;
  position: relative;
  color: var(--dialogue-text);
  font-family: var(--cd-body-font-family);
  font-size: 20px;
  line-height: 1.6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.speech-bubble-right::before {
  content: '';
  position: absolute;
  right: -12px;
  top: 30px;
  width: 0;
  height: 0;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 12px solid var(--dialogue-border);
}

.speech-bubble-right::after {
  content: '';
  position: absolute;
  right: -10px;
  top: 30px;
  width: 0;
  height: 0;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 12px solid var(--dialogue-bg);
}

.speech-bubble-right p {
  margin: 0 0 1rem;
}

.speech-bubble-right p:last-child {
  margin-bottom: 0;
}

.speech-bubble-right strong {
  color: var(--dialogue-text);
  font-weight: 600;
}

.speech-bubble .big,
.speech-bubble-right .big,
.dialogue-simple .big {
  font-size: 24px;
}

.speech-bubble .bigger,
.speech-bubble-right .bigger,
.dialogue-simple .bigger {
  font-size: 30px;
}

.speech-bubble .bigest,
.speech-bubble-right .bigest,
.dialogue-simple .bigest {
  font-size: 40px;
}

.speech-bubble .small,
.speech-bubble-right .small,
.dialogue-simple .small {
  font-size: 14px;
}

.speech-bubble .smaller,
.speech-bubble-right .smaller,
.dialogue-simple .smaller {
  font-size: 10px;
}

.speech-bubble .smallest,
.speech-bubble-right .smallest,
.dialogue-simple .smallest {
  font-size: 6px;
}

.dialogue-container-right .speech-bubble p {
  margin: 0 0 1rem;
}

.dialogue-container-right .speech-bubble p:last-child {
  margin-bottom: 0;
}

.dialogue-container-right .speech-bubble strong {
  color: var(--dialogue-text);
  font-weight: 600;
}

/* Responsive design for mobile - right portrait */
@media (max-width: 768px) {
  .dialogue-container-right {
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .dialogue-container-right .character-portrait {
    width: 80px;
    height: 80px;
  }
  
  .dialogue-container-right .character-name {
    width: 80px;
    font-size: 0.8rem;
    padding: 0.3rem 0.5rem;
  }
  
  .speech-bubble-right::before {
    right: -8px;
    top: 20px;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid var(--dialogue-border);
  }
  
  .speech-bubble-right::after {
    right: -6px;
    top: 20px;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid var(--dialogue-bg);
  }
}

.dialogue-simple p {
  margin: 0 0 1rem;
}

.dialogue-simple p:last-child {
  margin-bottom: 0;
}

.dialogue-simple strong {
  color: var(--dialogue-text);
  font-weight: 600;
}

/* Illustration styling within dialogue content */
.dialogue-simple img {
  max-width: 100%;
  height: auto;
  border-radius: 1rem;
  border: 2px solid var(--dialogue-border);
  background-color: var(--dialogue-bg);
  padding: 0.5rem;
  margin: 1rem 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: block;
  margin-left: auto;
  margin-right: auto;
}

/* ============================================================= */
/* Character Showcase Styles
=============================================================== */

.dashed-line {
  border-top: 2px dashed var(--dialogue-line);
  border-bottom: none;
  border-left: none;
  border-right: none;
  margin: 1rem 0;
}

.character-showcase-container {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 2rem;
  background-color: var(--dialogue-showcase-bg);
  border-radius: 1rem;
  margin: 1rem 0;
  border: 2px solid var(--dialogue-border);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
  scrollbar-color: var(--dialogue-border) var(--dialogue-showcase-bg);
}

.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.character-illustration {
  width: 200px;
  height: 250px;
  background-color: var(--dialogue-illustration-bg);
  border: 2px solid var(--dialogue-border);
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  overflow: hidden;
}

.character-illustration > img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: opacity 0.3s ease;
}

/* Clickable character functionality */
.clickable-character {
  cursor: pointer;
  position: relative;
  transition: transform 0.2s ease;
}

.clickable-character:hover {
  transform: scale(1.02);
}

.clickable-character.overlay-active > img {
  opacity: 0.3;
}

.character-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 0.75rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  z-index: 10;
  backdrop-filter: blur(5px);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

/* Custom scrollbar for character overlay */
.character-overlay::-webkit-scrollbar {
  width: 6px;
}

.character-overlay::-webkit-scrollbar-track {
  background: transparent;
}

.character-overlay::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.character-overlay::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.5);
}

.overlay-content {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.overlay-content p {
  font-size: 0.85rem;
  line-height: 1.3;
  margin-bottom: 0.75rem;
  color: var(--cd-secondary-text-color);
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  white-space: normal;
}

.character-label {
  font-family: var(--cd-header-font-family);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--cd-primary-text-color);
  background-color: var(--dialogue-illustration-bg);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--dialogue-line);
}

/* Custom scrollbar for character showcase */
.character-showcase-container::-webkit-scrollbar {
  height: 8px;
}

.character-showcase-container::-webkit-scrollbar-track {
  background: var(--dialogue-showcase-bg);
  border-radius: 4px;
}

.character-showcase-container::-webkit-scrollbar-thumb {
  background: var(--dialogue-border);
  border-radius: 4px;
}

.character-showcase-container::-webkit-scrollbar-thumb:hover {
  background: var(--dialogue-border-hover);
}

/* Responsive design for character showcase */
@media (max-width: 768px) {
  .character-showcase-container {
    flex-direction: row;
    gap: 1rem;
    padding: 1rem;
    overflow-x: auto;
  }
  
  .character-illustration {
    width: 150px;
    height: 180px;
    flex-shrink: 0;
  }
  
  .character-label {
    font-size: 1rem;
  }
}

/* ============================================================= */
/* Link Styles for Dialogue
=============================================================== */

.speech-bubble a, .speech-bubble-right a {
  color: #007bff !important;
  text-decoration: underline !important;
  font-weight: 500;
  transition: color 0.2s ease;
  position: relative;
  z-index: 10;
}

.speech-bubble a:hover, .speech-bubble-right a:hover {
  color: #0056b3 !important;
  text-decoration: underline !important;
}

.speech-bubble a:visited, .speech-bubble-right a:visited {
  color: #6610f2 !important;
}

.speech-bubble a:active, .speech-bubble-right a:active {
  color: #e83e8c !important;
}

/* ============================================================= */
/* Clickable Image Styles
=============================================================== */

/* Style for clickable images in gallery items */
a img {
  transition: transform 0.2s ease, opacity 0.2s ease;
  cursor: pointer;
}

a:hover img {
  transform: scale(1.05);
  opacity: 0.9;
}

/* ============================================================= */
/* Relationship Gauge Styles
=============================================================== */

.relationship-row {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.relationship-gauge-container {
  flex: 2;
  min-width: 0; /* Prevents flex item from overflowing */
}

.heart-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0; /* Prevents heart from shrinking */
}

.relationship-gauge {
  position: relative;
}

.gauge-background {
  width: 100%;
  height: 24px;
  background-color: var(--cd-secondary-color);
  border: 1px solid var(--cd-border-color);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cd-rarity-uncommon-bg), var(--cd-rarity-rare-bg));
  border-radius: 12px;
  transition: width 0.5s ease;
  position: relative;
}

.gauge-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 600;
  color: var(--cd-rarity-common-txt);
  white-space: nowrap;
  z-index: 2;
}

/* Heart Icon */
.heart-icon {
  width: 100px;
  height: 100px;
  flex-shrink: 0;
  filter: grayscale(100%) brightness(0.6);
  transition: filter 0.3s ease;
}

.heart-icon.heartbound {
  filter: none;
}

  /* Responsive adjustments for relationship gauge */
  @media (max-width: 768px) {
    .relationship-row {
      flex-direction: column;       /* stack gauge + heart */
      align-items: stretch;
      gap: 1rem;
    }
  
    .relationship-gauge-container {
      flex: none;
      text-align: center;
    }
  
    .heart-container {
      flex: none;
      justify-content: center;
    }
  
.relationship-row .heart-icon {
  margin: 0 auto;
  display: block;
}
}

/* ============================================================= */
/* Scroll To Top Button
=============================================================== */

#scroll-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  padding: 0;
  border-radius: 50%;
  background-color: var(--wood);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease, background-color 0.2s ease;
  box-shadow: 0 3px 0 var(--wood-dark);
}

#scroll-to-top:hover {
  background-color: var(--wood-dark);
}

/* ============================================================= */
/* Locked Image Styles
=============================================================== */

.locked-humanoid-container {
  position: relative;
  display: inline-block;
}

.locked-overlay-container {
  position: relative;
}

.locked-humanoid-overlay,
.locked-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
}

.locked-overlay-icon {
  font-size: 8rem;
  line-height: 1;
}

.locked-overlay.has-message {
  background-color: rgba(15, 18, 23, 0.8);
  padding: 1.2rem 1.8rem;
  border-radius: 1.5rem;
  max-width: min(420px, 90%);
  text-shadow: none;
  gap: 0.75rem;
}

.locked-overlay.has-message .locked-overlay-icon {
  font-size: 2.5rem;
}

.locked-overlay-message {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

.locked-overlay-target {
  filter: grayscale(75%) opacity(0.8);
}

.locked-humanoid-tab {
  background-color: rgba(114, 114, 114, 0.5);
  padding: 20px;
  border-radius: 8px;
  filter: grayscale(70%) opacity(0.7);
}

.locked-tab-icon {
  margin-left: 0.35rem;
  cursor: help;
}

.locked-overlay[title] {
  cursor: help;
}

/* ============================================================= */
/* Quest page chrome — header sizing, body text, author buttons
   Scoped to .quest-page so it only affects generated quest pages.
=============================================================== */

.quest-page .quest-title {
  font-size: 2rem;
  margin: 0 0 0.25rem;
}

.quest-page .quest-scene {
  font-size: 1.1rem;
  font-style: italic;
  color: var(--ink-soft);
  margin: 0 0 0.5rem;
}

/* Quest / trivia / end-of-chapter copy reads larger than default site body. */
.quest-page .quest-section {
  font-size: 1.1rem;
  line-height: 1.65;
}

.quest-page .quest-section h4 {
  font-size: 1.4rem;
}

/* Fallback styling for author-supplied buttons inside quest bodies that still
   use the old Bootstrap `.btn` classes — give them the site secondary look. */
.quest-page .quest-section .btn {
  display: inline-block;
  background: var(--wood);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1.2rem;
  font-family: "Fredoka";
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--wood-dark);
}

.quest-page .quest-section .btn:hover {
  background: var(--wood-dark);
  color: #fff;
}

/* ============================================================= */
/* Dialogue overflow + narrow-screen layout
   General guard so long words / flex children never overflow the
   card, plus a stacked + centered layout for small phones (≤480px):
   portrait and name sit above a full-width, centered bubble.
=============================================================== */

.speech-bubble,
.speech-bubble-right,
.dialogue-container-right .speech-bubble,
.dialogue-simple {
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

@media (max-width: 480px) {
  .dialogue-container,
  .dialogue-container-right {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
  }

  .dialogue-container .speech-bubble,
  .dialogue-container-right .speech-bubble,
  .dialogue-container-right .speech-bubble-right,
  .speech-bubble,
  .speech-bubble-right {
    flex: none;
    width: 100%;
  }

  /* No side pointer when the portrait is stacked on top. */
  .speech-bubble::before,
  .speech-bubble::after,
  .speech-bubble-right::before,
  .speech-bubble-right::after,
  .dialogue-container-right .speech-bubble::before,
  .dialogue-container-right .speech-bubble::after {
    display: none;
  }
}
