/* ============================================
   RESET & BASE
   ============================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:          #f5f0e8;
  --bg-soft:     #fffaf2;
  --text:        #3a2818;
  --text-soft:   #8a6a4a;
  --accent:      #d4852a;
  --accent-soft: #f4c888;
  --shadow:      0 4px 20px rgba(90, 60, 30, 0.12);
  --radius:      16px;
}

body {
  font-family: 'Sukhumvit Set', 'Noto Sans Thai', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-image 0.6s ease;
}
/* ตารางพื้นหลังหน้าแชท */
body.chat-mode {
  background-image:
    linear-gradient(rgba(139, 100, 60, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 100, 60, 0.1) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ============================================
   SCENES (show/hide)
   ============================================ */
.scene {
  display: none;
  min-height: 100vh;
  padding: 24px;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.6s ease;
}
.scene.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   SCENE 1: INTRO
   ============================================ */
#scene-intro {
  position: relative;
  overflow: hidden;
  transition: background 2s ease;
}
/* Mood backgrounds */
.mood-rain   { background: linear-gradient(160deg, #3d4a5c 0%, #5a6b7d 100%); }
.mood-warm-1 { background: linear-gradient(160deg, #6b5038 0%, #b07a3a 100%); }
.mood-warm-2 { background: linear-gradient(160deg, #a8692a 0%, #e8a858 100%); }

.story-content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 520px;
  padding: 0 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
/* หน้าร้าน SVG — ปกติซ่อน พอถึง intro 4 ค่อย fade-in */
.shop-illustration {
  width: 0;
  height: 0;
  opacity: 0;
  transform: scale(0.85) translateY(10px);
  margin-bottom: 0;
  overflow: visible;
  transition: opacity 0.9s ease, transform 0.9s ease, width 0.5s ease, height 0.5s ease, margin-bottom 0.5s ease;
  filter: drop-shadow(0 12px 40px rgba(255,180,100,0.25));
}
.shop-illustration.show {
  width: 260px;
  height: 240px;
  opacity: 1;
  transform: scale(1) translateY(0);
  margin-bottom: 18px;
  animation: shopSway 6s ease-in-out infinite;
}
.shop-illustration svg {
  width: 100%;
  height: 100%;
  display: block;
}
@keyframes shopSway {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
@media (max-width: 520px) {
  .shop-illustration.show { width: 210px; height: 200px; margin-bottom: 12px; }
}

.story-avatar {
  width: 0;
  height: 0;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.6);
  margin-bottom: 0;
  filter: drop-shadow(0 10px 28px rgba(0,0,0,0.35));
  transition: opacity 0.8s ease, transform 0.8s ease, width 0.6s ease, height 0.6s ease, margin-bottom 0.6s ease;
}
.story-avatar.show {
  width: 180px;
  height: 180px;
  opacity: 1;
  transform: scale(1);
  margin-bottom: 20px;
  animation: avatarFloat 3.6s ease-in-out infinite;
}
@keyframes avatarFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-6px) scale(1); }
}

.story-content p {
  font-size: 20px;
  line-height: 1.9;
  color: #fff8ec;
  margin: 0 0 32px;
  min-height: 140px;
  display: block;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0,0,0,0.4);
  letter-spacing: 0.5px;
  word-break: keep-all;
  overflow-wrap: break-word;
  padding-top: 1.4em;
}
.story-text .caret {
  display: inline-block;
  width: 2px;
  background: #fff8ec;
  margin-left: 2px;
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Progress dots */
.story-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
}
.story-dots .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: all 0.3s ease;
}
.story-dots .dot.active {
  background: #fff;
  transform: scale(1.4);
}

/* Vignette */
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.5) 100%);
  z-index: 1;
}

/* Rain */
.rain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
  transition: opacity 1.2s ease;
}
.rain.stopped { opacity: 0; }
.rain::before,
.rain::after {
  content: "";
  position: absolute;
  inset: -20% 0 -10% 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><g stroke='white' stroke-width='1.2' stroke-linecap='round'><line x1='15' y1='0' x2='5' y2='30' opacity='0.45'/><line x1='55' y1='20' x2='45' y2='50' opacity='0.35'/><line x1='95' y1='5' x2='85' y2='35' opacity='0.5'/><line x1='130' y1='40' x2='120' y2='70' opacity='0.3'/><line x1='170' y1='15' x2='160' y2='45' opacity='0.4'/><line x1='30' y1='80' x2='20' y2='110' opacity='0.35'/><line x1='75' y1='95' x2='65' y2='125' opacity='0.5'/><line x1='110' y1='110' x2='100' y2='140' opacity='0.3'/><line x1='150' y1='85' x2='140' y2='115' opacity='0.4'/><line x1='185' y1='125' x2='175' y2='155' opacity='0.35'/></g></svg>");
  background-size: 200px 200px;
  background-repeat: repeat;
  animation: rainFall 0.55s linear infinite;
}
.rain::after {
  animation-duration: 0.85s;
  opacity: 0.6;
  transform: translateX(12px) scale(1.3);
}
@keyframes rainFall {
  from { background-position: 0 -200px; }
  to   { background-position: -20px 0; }
}

/* Steam / aroma wisps */
.steam {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 1.4s ease;
}
.steam.active { opacity: 1; }
.steam span {
  position: absolute;
  bottom: -40px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255,245,225,0.55) 0%,
    rgba(255,240,215,0.3) 40%,
    transparent 70%);
  filter: blur(18px);
  opacity: 0;
  animation: steamRise 7s ease-in infinite;
}
.steam span:nth-child(1) { left: 18%; animation-delay: 0s;   animation-duration: 6.5s; }
.steam span:nth-child(2) { left: 38%; animation-delay: 1.4s; animation-duration: 8s;   }
.steam span:nth-child(3) { left: 55%; animation-delay: 2.8s; animation-duration: 7s;   }
.steam span:nth-child(4) { left: 72%; animation-delay: 0.7s; animation-duration: 9s;   }
.steam span:nth-child(5) { left: 85%; animation-delay: 3.5s; animation-duration: 7.5s; }

@keyframes steamRise {
  0%   { transform: translateY(0) scale(0.6); opacity: 0; }
  15%  { opacity: 0.8; }
  60%  { opacity: 0.5; }
  100% { transform: translateY(-110vh) scale(1.6) translateX(30px); opacity: 0; }
}

/* White flash transition */
.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
}
.flash.active {
  animation: whiteFlash 1.2s ease-out forwards;
}
@keyframes whiteFlash {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  60%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Button on intro — ปรับให้เข้ากับพื้นหลังมืด */
#scene-intro .btn-next {
  background: rgba(255,255,255,0.95);
  color: var(--text);
  backdrop-filter: blur(6px);
}

.story-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}
.btn-back {
  padding: 14px 32px;
  background: rgba(255,255,255,0.95);
  color: var(--text);
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(6px);
}
.btn-back:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.btn-back:active {
  transform: translateY(1px) scale(0.96);
  transition: all 0.08s ease;
}
.btn-back[hidden] { display: none; }

@media (max-width: 520px) {
  .story-actions {
    flex-direction: column;
    width: 100%;
  }
  .story-actions .btn-next,
  .story-actions .btn-back {
    width: 100%;
    max-width: 280px;
  }
}

/* ============================================
   SCENE 2: CHAT
   ============================================ */
.chat-container {
  width: 100%;
  max-width: 520px;
  background: var(--bg-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: 75vh;
  max-height: 80vh;
  overflow: hidden;
}

/* scroll wrapper ครอบทั้ง messages + choices */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--accent-soft);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.npc-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #fff;
  object-fit: cover;
}
.npc-name {
  font-weight: 600;
  color: var(--text);
}

.chat-messages {
  margin-top: auto;   /* ดันเนื้อหาลงล่างสุด จนกว่าจะล้น */
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  animation: slideUp 0.4s ease;
}
.msg.npc {
  background: #fff;
  border-top-left-radius: 4px;
  align-self: flex-start;
  box-shadow: var(--shadow);
}
.msg.user {
  background: var(--accent);
  color: #fff;
  border-top-right-radius: 4px;
  align-self: flex-end;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 16px 16px;
}
.choice-btn {
  padding: 12px 16px;
  border: 2px solid var(--accent-soft);
  background: #fff;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}
.choice-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}
.choice-btn:active {
  transform: translateY(1px) scale(0.98);
  transition: all 0.08s ease;
}

/* Typing indicator (3 dots pulsing) */
.msg.typing {
  display: inline-flex;
  gap: 4px;
  padding: 14px 18px;
}
.msg.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-soft);
  opacity: 0.5;
  animation: typingDot 1.2s infinite ease-in-out;
}
.msg.typing span:nth-child(2) { animation-delay: 0.2s; }
.msg.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* Text input area */
.text-input-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#userInput {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--accent-soft);
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: #fff;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
}
#userInput:focus {
  border-color: var(--accent);
}
.submit-btn {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
  text-align: center !important;
  font-weight: 600;
}
.submit-btn:hover {
  background: #b97020 !important;
}

/* ============================================
   SCENE 3: RESULT
   ============================================ */
#scene-result {
  background: radial-gradient(ellipse at center top,
    #fff3dc 0%, var(--bg) 60%);
  position: relative;
  overflow: hidden;
}
.result-content {
  text-align: center;
  max-width: 480px;
  position: relative;
  z-index: 2;
  padding: 20px 0;
}
.result-intro {
  color: var(--text-soft);
  margin-bottom: 20px;
  font-size: 15px;
  letter-spacing: 1px;
  animation: fadeIn 0.8s ease 0.2s backwards;
}

/* Character image with spotlight */
.result-image-wrap {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 0 auto 20px;
}
.result-spotlight {
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle,
    rgba(255, 220, 150, 0.7) 0%,
    rgba(255, 200, 120, 0.3) 30%,
    transparent 65%);
  animation: pulseGlow 3s ease-in-out infinite;
  z-index: 0;
}
@keyframes pulseGlow {
  0%, 100% { transform: scale(1);   opacity: 0.8; }
  50%      { transform: scale(1.1); opacity: 1;   }
}
.result-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: revealPop 1s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes revealPop {
  0%   { opacity: 0; transform: scale(0.3) rotate(-15deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

.result-name {
  font-size: 30px;
  margin-bottom: 10px;
  animation: fadeIn 0.8s ease 0.6s backwards;
}
.result-type-badge {
  display: inline-block;
  padding: 6px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 14px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(212, 133, 42, 0.35);
  animation: fadeIn 0.8s ease 0.8s backwards;
}
.result-description {
  line-height: 1.8;
  color: var(--text-soft);
  margin-bottom: 28px;
  padding: 0 12px;
  animation: fadeIn 0.8s ease 1s backwards;
}

/* Tagline (ใต้ชื่อ) */
.result-tagline {
  color: var(--accent);
  font-size: 15px;
  font-style: italic;
  margin-bottom: 18px;
  animation: fadeIn 0.8s ease 0.8s backwards;
}

/* Traits chips */
.result-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 28px;
  animation: fadeIn 0.8s ease 0.9s backwards;
}
.trait-chip {
  padding: 6px 14px;
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

/* Result section blocks */
.result-section {
  text-align: left;
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 2px 12px rgba(90,60,30,0.06);
  animation: fadeIn 0.8s ease 1s backwards;
}
.result-section h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--text);
}
.result-text {
  line-height: 1.9;
  color: var(--text-soft);
  font-size: 15px;
}

/* Gentle whisper section — softer, warmer */
.result-gentle-section {
  background: linear-gradient(135deg, rgba(255,235,210,0.6), rgba(255,245,230,0.5));
  border-left: 3px solid var(--accent-soft);
}
.result-gentle-section h3 {
  color: var(--accent);
  opacity: 0.9;
}
.result-gentle-section .result-text {
  font-style: italic;
  font-size: 14.5px;
}
.result-subhint {
  color: var(--text-soft);
  font-size: 13px;
  margin-bottom: 14px;
  font-style: italic;
}

/* Compatible pets list */
.compatible-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.compat-card {
  background: #fff;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 8px rgba(90,60,30,0.06);
}
.compat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(90,60,30,0.12);
}
.compat-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg);
}
.compat-card .compat-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-top: 6px;
  line-height: 1.3;
}

/* Shopkeeper final line */
.result-shopkeeper {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-soft);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  text-align: left;
  animation: fadeIn 0.8s ease 1.4s backwards;
}
.result-shopkeeper img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  flex-shrink: 0;
}
.result-shopkeeper .bubble {
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}

/* Action buttons */
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  animation: fadeIn 0.8s ease 1.6s backwards;
}
.btn-share {
  padding: 14px 24px;
  background: #fff;
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 999px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-share:hover {
  background: var(--accent-soft);
  transform: translateY(-2px);
}
.btn-share:active {
  transform: translateY(1px) scale(0.96);
  transition: all 0.08s ease;
}
.btn-share.copied {
  background: #4caf50;
  color: #fff;
  border-color: #4caf50;
}

/* Sparkles floating around */
.result-sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.result-sparkles span {
  position: absolute;
  width: 8px; height: 8px;
  background: radial-gradient(circle, #fff 0%, rgba(255,220,150,0.6) 50%, transparent 70%);
  border-radius: 50%;
  animation: sparkle 4s ease-in-out infinite;
  opacity: 0;
}
.result-sparkles span:nth-child(1) { left:  8%; top: 15%; animation-delay: 0.2s; }
.result-sparkles span:nth-child(2) { left: 88%; top: 22%; animation-delay: 1.1s; }
.result-sparkles span:nth-child(3) { left: 15%; top: 55%; animation-delay: 2.3s; }
.result-sparkles span:nth-child(4) { left: 82%; top: 60%; animation-delay: 0.8s; }
.result-sparkles span:nth-child(5) { left: 25%; top: 80%; animation-delay: 1.9s; }
.result-sparkles span:nth-child(6) { left: 70%; top: 78%; animation-delay: 2.8s; }
.result-sparkles span:nth-child(7) { left:  5%; top: 35%; animation-delay: 3.4s; }
.result-sparkles span:nth-child(8) { left: 92%; top: 42%; animation-delay: 0.5s; }

@keyframes sparkle {
  0%, 100%  { opacity: 0; transform: scale(0.5); }
  50%       { opacity: 1; transform: scale(1.4); }
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-next, .btn-restart {
  padding: 14px 32px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-next:hover, .btn-restart:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.btn-next:active, .btn-restart:active {
  transform: translateY(1px) scale(0.96);
  box-shadow: 0 2px 6px rgba(90,60,30,0.15);
  transition: all 0.08s ease;
}

/* ============================================
   DESKTOP — result page 2-column grid
   ============================================ */
@media (min-width: 900px) {
  #scene-result {
    padding: 40px 24px;
    align-items: flex-start;
  }

  .result-content {
    max-width: 1000px;
    width: 100%;
    display: grid;
    grid-template-columns: minmax(320px, 400px) 1fr;
    column-gap: 44px;
    align-items: start;
  }

  /* ซ้าย: ภาพ + ชื่อ + tagline + traits + compatible */
  .result-left {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .result-left .result-traits { justify-content: center; margin-bottom: 20px; }
  .result-left .result-compatible-section {
    width: 100%;
    text-align: left;
  }
  /* ในคอลัมน์ซ้ายแคบ — compat เรียงเป็น grid 3 ช่องเล็กลง */
  .result-left .compatible-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .result-left .compat-card img { max-width: 100%; }

  /* ขวา: เนื้อหาทั้งหมด */
  .result-right {
    display: flex;
    flex-direction: column;
    text-align: left;
  }

  .result-right .result-actions {
    margin-top: 12px;
    justify-content: flex-start;
  }
  .result-right .result-shopkeeper { justify-content: flex-start; }
}

/* ============================================
   TABLET — ปรับช่องว่างให้พอดี
   ============================================ */
@media (min-width: 700px) and (max-width: 899px) {
  .result-content { max-width: 640px; }
}

/* ============================================
   EXPORT CARD (hidden — ใช้ถ่ายภาพ)
   ============================================ */
.export-card {
  position: fixed;
  top: 0;
  left: -10000px;   /* อยู่นอกจอ */
  width: 640px;
  background: linear-gradient(180deg, #fff5e3 0%, #fffaf2 40%, #fff5e3 100%);
  padding: 40px 36px;
  font-family: 'Sukhumvit Set', 'Noto Sans Thai', sans-serif;
  color: var(--text);
  box-sizing: border-box;
}
.export-card.capturing {
  left: 0;
  z-index: -1;   /* มองไม่เห็น แต่ html2canvas เห็น */
}
.export-header { text-align: center; margin-bottom: 28px; }
.export-intro {
  color: var(--text-soft);
  font-size: 14px;
  margin-bottom: 14px;
}
.export-image-wrap {
  width: 260px;
  height: 260px;
  margin: 0 auto 18px;
  position: relative;
}
.export-image-wrap::before {
  content: "";
  position: absolute;
  inset: 10%;
  background: radial-gradient(circle, rgba(244,200,136,0.55), transparent 65%);
  filter: blur(25px);
  z-index: 0;
}
.export-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.export-name {
  font-size: 30px;
  font-weight: 700;
  margin-bottom: 8px;
}
.export-tagline {
  color: var(--accent);
  font-style: italic;
  font-size: 15px;
  margin-bottom: 16px;
}
.export-traits {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.export-traits span {
  background: var(--accent-soft);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
}

.export-section {
  background: #fffaf2;
  border-radius: 14px;
  padding: 18px 22px;
  margin-bottom: 14px;
  box-shadow: 0 2px 10px rgba(90,60,30,0.05);
}
.export-section h3 {
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--text);
}
.export-text {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.85;
}
.export-gentle {
  background: linear-gradient(135deg, rgba(255,235,210,0.8), rgba(255,245,230,0.7));
  border-left: 3px solid var(--accent-soft);
}
.export-gentle .export-text { font-style: italic; }

.export-compat-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 6px;
}
.export-compat-card {
  text-align: center;
}
.export-compat-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
}
.export-compat-card .name {
  font-size: 12px;
  margin-top: 4px;
  color: var(--text);
}

.export-footer {
  text-align: center;
  margin-top: 22px;
  color: var(--text-soft);
  font-size: 13px;
  opacity: 0.7;
}

/* ============================================
   MOBILE
   ============================================ */
@media (max-width: 520px) {
  .scene { padding: 12px; }
  /* chat scene เต็มจอพอดี ไม่ให้ container + padding ล้น viewport */
  #scene-chat.scene {
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .chat-container {
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
  }
  .chat-header { padding: 12px 16px; }
  .npc-avatar { width: 36px; height: 36px; }
  .chat-messages { padding: 16px 14px 6px; }
  .chat-choices { padding: 6px 12px 12px; }
  .msg { max-width: 85%; padding: 10px 14px; font-size: 15px; }
  .choice-btn { padding: 10px 14px; font-size: 14px; }

  .story-content h1 { font-size: 24px; }
  .story-content p  { font-size: 16px; min-height: 110px; padding-top: 0.8em; }
  .story-avatar.show { width: 140px; height: 140px; margin-bottom: 14px; }
  .result-image     { width: 200px; height: 200px; }
  .result-image-wrap { width: 220px; height: 220px; }
  .result-name      { font-size: 24px; }
}

/* ============================================
   IMAGE PREVIEW MODAL (LINE/IG fallback)
   ============================================ */
#imgPreviewModal {
  position: fixed; inset: 0; z-index: 9999;
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
#imgPreviewModal.show { display: flex; }
.img-preview-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
}
.img-preview-box {
  position: relative;
  max-width: 420px; width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff5e3;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.img-preview-hint {
  color: #3d2510; font-size: 15px; font-weight: 600;
  margin-bottom: 14px;
}
.img-preview-hint b { color: #c06a1a; }
.img-preview-img {
  width: 100%; height: auto;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  -webkit-touch-callout: default;
  user-select: auto;
  pointer-events: auto;
}
.img-preview-sub {
  color: #8a6a40; font-size: 12px;
  margin-top: 12px; line-height: 1.5;
}
.img-preview-external,
.img-preview-close {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 22px;
  border: none; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.img-preview-external {
  background: #c06a1a; color: #fff;
  margin-right: 8px;
}
.img-preview-close {
  background: transparent; color: #8a6a40;
  border: 1px solid #d4b890;
}

/* ============================================
   IMAGE PREVIEW MODAL (LINE/IG fallback)
   ============================================ */
#imgPreviewModal {
  position: fixed; inset: 0; z-index: 9999;
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
#imgPreviewModal.show { display: flex; }
.img-preview-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
}
.img-preview-box {
  position: relative;
  max-width: 420px; width: 100