/* แบบทดสอบบุคลิกภาพในที่ทำงาน — mobile-first, ไม่มี CSS framework
   Design direction: น่ารัก / ลายเส้นมือวาด / minimal (กำหนดโดยอรุณ)
   หมายเหตุ: ไฟล์นี้เปลี่ยนเฉพาะ "หน้าตา" — ชื่อ class เดิมคงไว้ทั้งหมด */

:root {
  --bg: #FFF9F2;
  --card: #FFFFFF;
  --accent: #FF9EAA;   /* โคราลชมพู */
  --accent2: #8FE0D6;  /* มินต์ */
  --text: #4A4458;     /* พลัมเข้ม ใช้แทนดำ/ขาวล้วน */
  --muted: #9A93A8;
  --line: #EFE7F0;
  --radius: 22px;

  /* เงานุ่มแบบมีสี (ไม่ใช้สีดำ) ใช้แทน border เดิม */
  --shadow: 0 10px 26px -14px rgba(255, 158, 170, 0.6),
            0 4px 12px -8px rgba(143, 224, 214, 0.45);
  --shadow-lift: 0 16px 34px -14px rgba(255, 158, 170, 0.7),
                 0 6px 16px -8px rgba(143, 224, 214, 0.5);

  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, "Segoe UI", system-ui, sans-serif;
  line-height: 1.7;
  min-height: 100vh;
}

main, .header, .footer { max-width: 560px; margin: 0 auto; }

/* ---------- Header ---------- */
.header { text-align: center; padding: 20px 0 8px; }
.header h1 { margin: 0; font-size: 1.6rem; }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  margin: 16px 0;
  transition: transform 0.25s var(--bounce), box-shadow 0.25s ease;
}
.card:hover { transform: scale(1.01); box-shadow: var(--shadow-lift); }
.intro-text { margin: 0 0 18px; font-size: 0.98rem; }
.hint { color: var(--muted); font-size: 0.8rem; text-align: center; margin: 12px 0 0; }

/* แถวไอคอนตกแต่งบนหน้าแนะนำ */
.intro-icons {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 16px;
}
.intro-icons .mascot { height: 78px; }

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #FFFFFF;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px -10px rgba(255, 158, 170, 1);
  transition: transform 0.2s var(--bounce), filter 0.2s ease;
}
.btn-primary:hover { transform: scale(1.03); filter: brightness(1.04); }
.btn-primary:active { transform: scale(0.98); }

/* ---------- Progress ---------- */
.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.progress-bar {
  flex: 1;
  height: 10px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 99px;
  transition: width 0.5s var(--bounce); /* bounce easing ตอนเลื่อนข้อ */
}
.progress-label { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }

/* ---------- คำถาม / ตัวเลือก ---------- */
.question { margin: 0 0 16px; font-size: 1.15rem; line-height: 1.6; }
.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 16px;
  font-family: inherit;
  font-size: 0.97rem;
  line-height: 1.6;
  cursor: pointer;
  transition: transform 0.2s var(--bounce), border-color 0.2s ease, background 0.2s ease;
}
.choice-btn:hover, .choice-btn:focus-visible {
  border-color: var(--accent);
  background: #FFF5F6;
  transform: scale(1.02);
}
/* กดแล้วยุบชัดขึ้นเล็กน้อย + เปลี่ยนสีขอบทันที ให้รู้สึกว่า "ระบบรับคำตอบแล้ว"
   ก่อนหน้าจอจะเลื่อนไปข้อถัดไป (จังหวะสั้นมาก จึงใช้ transition เดิมที่มีอยู่แล้ว) */
.choice-btn:active {
  transform: scale(0.97);
  border-color: var(--accent);
  background: #FFECEF;
}
.btn-back {
  margin-top: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 0;
}
.btn-back:hover { color: var(--accent); }

/* ---------- ภาพ mascot (ไฟล์ PNG ในโปรเจกต์ ไม่โหลดจากภายนอก) ----------
   ภาพต้นฉบับเป็นแนวตั้งและอัตราส่วนไม่เท่ากันในแต่ละตัว (กว้าง 300–480 สูง 512)
   จึงล็อก "ความสูง" ให้เท่ากันทุกตัวแล้วปล่อยความกว้างตามสัดส่วนจริง
   ถ้าล็อกเป็นกล่องจัตุรัส ตัวที่ผอมจะดูเล็กกว่าตัวอื่นอย่างเห็นได้ชัด */
.mascot {
  display: block;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  margin: 0 auto;
}

/* ---------- ผลลัพธ์ ---------- */
.result-head { text-align: center; margin-bottom: 16px; }
.result-icon { display: block; margin: 0 auto 6px; }
.result-icon .mascot { height: 168px; }
.result-head h2 { margin: 4px 0 2px; font-size: 1.35rem; }
.result-tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }
.result-desc {
  background: #FFF5F6;
  border-radius: 16px;
  padding: 14px;
  margin: 0 0 12px;
  font-size: 0.96rem;
}

.trait-block { margin-bottom: 12px; }
.trait-block h3 { margin: 0 0 6px; font-size: 1rem; }
.trait-block ul { margin: 0; padding-left: 20px; }
.trait-block li { margin-bottom: 4px; font-size: 0.95rem; }
.trait-block p { margin: 0; font-size: 0.95rem; }

/* ---------- CTA + Disclosure ---------- */
.cta-block {
  border-top: 2px dashed var(--line);
  margin-top: 18px;
  padding-top: 16px;
}
.cta-block h3 { margin: 0 0 10px; font-size: 1rem; }
/* ---------- การ์ดสินค้า ----------
   ทั้งการ์ดคือลิงก์ก้อนเดียว (ไม่มีปุ่มซ้อนในลิงก์) กดตรงไหนก็ไปที่เดียวกัน
   สีส้ม Shopee ทางการ (#EE4D2D) คุมเฉพาะ pill ด้านขวา เพื่อคง brand recognition
   โดยไม่ให้ส้มทั้งแผ่นไปตีกับพาสเทลของหน้าอื่น */
.product-list { display: flex; flex-direction: column; gap: 10px; }

.product-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;               /* touch target รวมของการ์ด */
  padding: 10px 12px;
  background: #FFFFFF;
  border: 1px solid #FFE1D6;
  border-radius: 18px;
  box-shadow: 0 6px 16px -10px rgba(0, 0, 0, 0.12);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.2s var(--bounce), box-shadow 0.2s ease;
}
.product-card:hover {
  transform: scale(1.02);
  box-shadow: 0 10px 22px -10px rgba(0, 0, 0, 0.18);
}
.product-card:active { transform: scale(0.98); }

/* กรอบรูปสินค้า — ตอนนี้เป็น gradient + ไอคอนถุงช้อปปิ้ง (placeholder รอรูปจริง) */
.product-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
}
/* สลับทิศไล่สีของสินค้าชิ้นที่สอง ให้สองการ์ดไม่ดูซ้ำกันเป๊ะ */
.product-card:nth-child(even) .product-thumb {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.thumb-icon { width: 26px; height: 26px; display: block; }

.product-info { flex: 1 1 auto; min-width: 0; }
.product-name {
  display: block;
  font-weight: 700;
  font-size: 0.94rem;
  line-height: 1.45;
}
.product-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.product-cta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 12px;
  background: #EE4D2D;            /* hex ทางการของ Shopee */
  color: #FFFFFF;
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
}
.cta-icon { width: 16px; height: 16px; display: block; }

/* จอแคบมาก: ย่อกรอบรูปและ pill ลง เพื่อให้ชื่อสินค้ายังมีที่พอ */
@media (max-width: 400px) {
  .product-thumb { width: 48px; height: 48px; border-radius: 12px; }
  .thumb-icon { width: 22px; height: 22px; }
  .product-cta { padding: 7px 10px; font-size: 0.78rem; gap: 4px; }
}

/* ---------- ปุ่มท้ายหน้า ---------- */
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions button {
  flex: 1;
  padding: 12px;
  border-radius: 16px;
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--bounce);
}
.actions button:hover { transform: scale(1.03); }
.btn-share { background: var(--accent2); color: var(--text); }
.btn-reset { background: transparent; color: var(--muted); border: 2px solid var(--line) !important; }

.share-fallback {
  margin-top: 12px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}
.share-fallback a { color: var(--accent); margin: 0 8px; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 8px 0 32px;
}
.footer p { margin: 4px 0; }

/* ---------- Micro-interaction: ไอคอนขยับเบา ๆ ---------- */
@keyframes wiggle {
  0%, 100% { transform: rotate(-3deg); }
  50%      { transform: rotate(3deg); }
}
/* หมุนรอบปลายเท้า ไม่ใช่กลางภาพ ตัวละครจะได้ดูโยกตัวแทนที่จะดูลอยหมุน */
.mascot { transform-origin: bottom center; }
.intro-icons .mascot { animation: wiggle 3.4s ease-in-out infinite; }
.intro-icons .mascot:nth-child(2) { animation-delay: 0.4s; }
.intro-icons .mascot:nth-child(3) { animation-delay: 0.8s; }

/* ---------- Animation ตอนเนื้อหาเปลี่ยน (เพิ่มใหม่) ----------

   กติกาสำคัญของทั้งบล็อกนี้ — ห้ามฝ่าฝืนเวลาเพิ่ม animation ใหม่:

   "สถานะซ่อน (opacity: 0 / translate) ต้องอยู่ใน @keyframes เท่านั้น
    ห้ามเขียนไว้ใน rule ปกติของ element เด็ดขาด"

   เหตุผล: ท้ายไฟล์มี @media (prefers-reduced-motion: reduce) ที่สั่ง
   animation: none !important ทับทุก element ถ้าสถานะซ่อนอยู่ใน rule ปกติ
   element จะ "หายไปถาวร" สำหรับผู้ใช้ที่เปิดโหมดลดการเคลื่อนไหว
   เมื่อสถานะซ่อนอยู่ใน keyframes เท่านั้น การปิด animation จะทำให้
   element แสดงที่ค่าปกติ (มองเห็นครบ) ทันที ซึ่งเป็นพฤติกรรมที่ถูกต้อง

   อีกจุด: ใช้ fill-mode เป็น backwards (ไม่ใช่ forwards/both) เพราะถ้าใช้
   forwards ค่า transform ตอนจบจะถูก animation ยึดไว้ ทำให้ transform
   ของ :hover / :active ที่มีอยู่เดิมไม่ทำงานอีกเลยหลัง animation จบ */

/* เลื่อนขึ้นพร้อมจาง — ใช้แกน Y เท่านั้น ไม่ใช้แกน X
   เพราะการเลื่อนแนวนอนเสี่ยงทำให้เกิด scroll แนวนอนบนจอ 375px
   (ข้อ 5 ของ TESTING.md กำหนดว่าต้องไม่มี scroll แนวนอน) */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* การ์ดทั้งใบตอนสลับหน้า (แนะนำ → คำถาม → ผลลัพธ์)
   คลาสนี้ถูก add/remove จาก script.js เพื่อให้ animation เล่นซ้ำได้ */
.card-enter { animation: rise-in 0.4s ease-out backwards; }

/* คำถามตอนเปลี่ยนข้อ — ใช้คลาสจาก JS เพราะ element เดิมถูกใช้ซ้ำ
   (เปลี่ยนแค่ textContent) animation จึงไม่เล่นซ้ำเองถ้าไม่สั่ง */
.q-enter { animation: rise-in 0.32s ease-out backwards; }

/* ตัวเลือกไล่ตามมาทีหลังคำถามเล็กน้อย ให้รู้สึกว่าคำถามใหม่ "ไหลเข้ามา"
   ตรงนี้ไม่ต้องใช้ JS เพราะ showQuestion() สร้างปุ่มใหม่ทุกครั้ง
   element ใหม่ = animation เริ่มเล่นเองอัตโนมัติอยู่แล้ว */
.choice-list .choice-btn { animation: rise-in 0.32s ease-out backwards; }
.choice-list .choice-btn:nth-child(1) { animation-delay: 0.05s; }
.choice-list .choice-btn:nth-child(2) { animation-delay: 0.11s; }

/* mascot หน้าผลลัพธ์: เด้งโผล่ขึ้นมาก่อน แล้วค่อยต่อด้วย wiggle เดิมวนไป
   (หน่วง wiggle ไว้เท่ากับความยาวของ pop เพื่อไม่ให้สอง animation
   แย่งค่า transform กันระหว่างที่ pop ยังเล่นอยู่)
   ตัว <img> ถูกสร้างใหม่ทุกครั้งใน showResult() จึงเล่นเองได้โดยไม่ต้องพึ่ง JS */
@keyframes mascot-pop {
  0%   { opacity: 0; transform: scale(0.72); }
  65%  { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}
.result-icon .mascot {
  animation: mascot-pop 0.55s var(--bounce) backwards,
             wiggle 2.8s ease-in-out 0.55s infinite;
}

/* การ์ดสินค้าไล่กันขึ้นมาทีละใบ — หน่วงหลัง mascot เพื่อให้สายตาไล่จากบนลงล่าง
   จงใจให้เบาและสั้น ไม่ใช้เอฟเฟกต์เรียกร้องความสนใจ (ไม่กระพริบ ไม่เด้งซ้ำ)
   เพราะเป็นพื้นที่ CTA พาณิชย์ ตาม TESTING.md ข้อ 6.2 ห้ามทำ dark pattern */
.product-card { animation: rise-in 0.4s ease-out backwards; }
.product-card:nth-child(1) { animation-delay: 0.18s; }
.product-card:nth-child(2) { animation-delay: 0.26s; }

/* ---------- จอใหญ่ขึ้น ---------- */
@media (min-width: 480px) {
  .header h1 { font-size: 1.9rem; }
  .result-icon .mascot { height: 190px; }
  .intro-icons .mascot { height: 92px; }
}

/* ---------- เคารพการตั้งค่าลดการเคลื่อนไหวของผู้ใช้ ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .card:hover,
  .btn-primary:hover,
  .choice-btn:hover,
  .choice-btn:active,
  .product-card:hover,
  .product-card:active,
  .actions button:hover { transform: none; }

  /* กันพลาดสำหรับ animation กลุ่ม "เข้าฉาก" (rise-in / mascot-pop)
     ตามกติกาด้านบน สถานะซ่อนอยู่ใน keyframes เท่านั้น ปิด animation แล้ว
     element จึงแสดงปกติอยู่แล้ว บรรทัดนี้เป็นตาข่ายรองรับอีกชั้น เผื่อมีคน
     เผลอเพิ่ม opacity: 0 ไว้ใน rule ปกติในอนาคต — เนื้อหาจะต้องไม่มีวันหายไป */
  .card-enter,
  .q-enter,
  .choice-list .choice-btn,
  .result-icon .mascot,
  .product-card {
    opacity: 1 !important;
    transform: none !important;
  }
}
