:root {
  --bg: #fff8f4;
  --ink: #4b3b3d;
  --muted: #8a7376;
  --rose: #e85d75;
  --rose-dark: #c2415a;
  --rose-soft: #ffe0e6;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(170, 80, 95, .14);
  --font-head: 'Mali', 'Sarabun', sans-serif;
  --font-body: 'Sarabun', system-ui, sans-serif;
  --font-script: 'Dancing Script', cursive;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
html { overscroll-behavior: none; }
/* ภาษาไทยไม่มีช่องว่างระหว่างคำ เบราว์เซอร์เลยชอบตัดกลางคำ
   script.js จะห่อข้อความแต่ละวลี (คั่นด้วยช่องว่าง) ไว้ใน .w ให้ขึ้นบรรทัดใหม่ได้เฉพาะตรงช่องว่าง
   ถ้าวลีไหนยาวเกินบรรทัดจริงๆ ค่อยตัดข้างในวลีนั้น */
.w { display: inline-block; max-width: 100%; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
button, a, input { touch-action: manipulation; } /* กันแตะสองทีแล้วจอซูม */
.hidden { display: none !important; }
.center { text-align: center; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

/* ---------- ปุ่ม ---------- */
.btn {
  font-family: var(--font-head);
  font-size: 1rem;
  background: var(--rose);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 11px 26px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(232, 93, 117, .35);
  transition: transform .15s;
}
.btn:active { transform: scale(.96); }
.btn.ghost { background: transparent; color: var(--rose); border: 2px solid var(--rose); box-shadow: none; }

/* ---------- หน้าเต็มจอ (รหัส / ซอง) ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  /* เว้นที่ให้รอยบาก/ขอบจอโค้งของมือถือ */
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #fff 0%, var(--bg) 70%);
  transition: opacity .8s ease;
}
.screen.fade-out { opacity: 0; pointer-events: none; }
.error { color: var(--rose-dark); font-size: .9rem; min-height: 1.5em; margin: 0; }
.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ---------- ด่านคำถาม ---------- */
.quiz { z-index: 51; justify-content: flex-start; overflow-y: auto; }
.quiz::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at 50% 30%, #fffdf3 0%, #ffeec4 80%);
  opacity: 0;
  transition: opacity .9s ease;
  pointer-events: none;
}
.sparkles { position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0; transition: opacity .9s ease; }
.sparkles span { position: absolute; animation: twinkle 2.4s ease-in-out infinite; }
.quiz.scene-explain::before, .quiz.scene-explain .sparkles { opacity: 1; }
@keyframes twinkle { 50% { opacity: .15; transform: scale(.6) rotate(20deg); } }

.q-panel {
  display: none;
  width: min(380px, 100%);
  margin: auto;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.q-panel.on { display: flex; animation: popIn .55s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes popIn { from { opacity: 0; transform: scale(.82) translateY(18px); } }

.q-head {
  font-family: var(--font-head);
  font-size: clamp(1.3rem, 6vw, 1.6rem);
  line-height: 1.5;
  margin: 0;
  white-space: pre-line;
}
.q-sub { margin: 0; color: var(--muted); }
.q-chip, .q-badge {
  margin: 0;
  font-family: var(--font-head);
  font-size: .9rem;
  color: var(--rose-dark);
  background: var(--rose-soft);
  padding: 2px 14px;
  border-radius: 999px;
}
.q-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: 24px;
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
}
.q-question {
  font-family: var(--font-head);
  font-size: clamp(1.2rem, 5.4vw, 1.45rem);
  line-height: 1.5;
  margin: 2px 0 0;
  white-space: pre-line;
}
.q-tick { margin: -6px 0 0; color: var(--rose); font-family: var(--font-head); animation: tock 1s ease-in-out infinite; }
.q-form { display: flex; gap: 8px; width: 100%; margin-top: 4px; }
.q-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.05rem;
  padding: 10px 14px;
  border: 2px solid var(--rose-soft);
  border-radius: 14px;
  outline: none;
  background: #fffafa;
  color: var(--ink);
}
.q-form input:focus { border-color: var(--rose); }
.q-form .btn { flex: none; padding: 10px 20px; }
.link-btn { border: 0; background: none; padding: 8px 12px; margin: -6px 0; color: var(--rose-dark); font-size: .95rem; text-decoration: underline; cursor: pointer; }

/* นาฬิกานับถอยหลัง */
.timer { position: relative; width: 72px; height: 72px; }
.timer svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 4; }
.t-bg { stroke: var(--rose-soft); }
.t-fg { stroke: var(--rose); stroke-linecap: round; stroke-dasharray: 119.38; transition: stroke .3s; }
.t-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--rose);
}
.timer.hurry .t-fg { stroke: #d62845; }
.timer.hurry .t-num { color: #d62845; animation: throb .5s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.2); } }

/* สติกเกอร์ */
.sticker { width: min(210px, 56vw); }
.sticker.sm { width: 86px; flex: none; }
.q-head, .q-question, .dict-mean { text-wrap: balance; }
.stk { animation: stickerIn .6s cubic-bezier(.2, 1.5, .4, 1) both; }
.stk-art {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  transform-origin: 50% 90%;
  filter: drop-shadow(0 8px 10px rgba(170, 80, 95, .16));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* กดค้างบนมือถือแล้วไม่เด้งเมนูบันทึกรูป */
}
.stk-hi .stk-art { animation: wave 1.6s ease-in-out infinite; }
.stk-pout .stk-art { animation: huff 1.1s ease-in-out infinite; }
.stk-squint .stk-art { animation: lean 2.6s ease-in-out infinite; }
.stk-smug .stk-art { animation: tock 1s ease-in-out infinite; }
.stk-proud .stk-art, .stk-happy .stk-art { animation: hop .9s ease-in-out infinite; }
@keyframes stickerIn { from { opacity: 0; transform: scale(.3) rotate(-12deg); } }
@keyframes wave { 50% { transform: rotate(4deg); } }
@keyframes huff { 50% { transform: scale(1.05, .95); } }
@keyframes lean { 0%, 100% { transform: none; } 50% { transform: rotate(-5deg) translateX(-8px); } }
@keyframes tock { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes hop { 50% { transform: translateY(-10px); } }

/* หน้าเฉลยความหมายชื่อ */
.dict {
  width: 100%;
  background: #fff;
  border: 2px solid #ffe2a0;
  border-radius: 22px;
  padding: 18px 18px 22px;
  box-shadow: 0 10px 30px rgba(190, 140, 40, .16);
}
.dict > * { animation: rise .6s cubic-bezier(.2, .8, .2, 1) both; }
.dict > :nth-child(2) { animation-delay: .35s; }
.dict > :nth-child(3) { animation-delay: .8s; }
.dict > :nth-child(4) { animation-delay: 1.3s; }
.dict > :nth-child(5) { animation-delay: 1.55s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.dict-label { margin: 0; font-family: var(--font-head); font-size: .85rem; color: #b07d1e; }
.dict-name {
  margin: 0 0 12px;
  font-family: var(--font-head);
  font-size: clamp(1.8rem, 9vw, 2.4rem);
  line-height: 1.35;
  color: var(--rose-dark);
}
/* แต่ละส่วนของชื่ออยู่บรรทัดเดียวกัน ถ้าจอแคบไม่พอ script.js จะย่อตัวหนังสือทั้งแถวลงให้พอดี
   (ขนาดทั้งหมดใช้ em จะได้ย่อตามกันทั้งแถว) */
.dict-parts { display: flex; flex-wrap: nowrap; justify-content: center; align-items: center; gap: .375em; }
.dict-parts.wrap { flex-wrap: wrap; } /* ชื่อยาวมากจนย่อแล้วยังไม่พอ ค่อยยอมขึ้นบรรทัดใหม่ */
.dict-part {
  flex: none;
  white-space: nowrap;
  background: #fff6df;
  border-radius: .875em;
  padding: .375em .75em;
  line-height: 1.4;
}
.dict-part b { display: block; font-family: var(--font-head); font-size: 1.1em; }
.dict-part small { display: block; color: var(--muted); font-size: .85em; }
.dict-plus { flex: none; color: #d4a24c; font-weight: 700; }
.dict-mean-label { margin: 14px 0 0; color: var(--muted); font-size: .9rem; }
.dict-mean { margin: 0; font-family: var(--font-head); font-size: 1.25rem; line-height: 1.55; white-space: pre-line; }
.say { display: flex; align-items: center; gap: 6px; width: 100%; }
.bubble {
  position: relative;
  flex: 1;
  margin: 0;
  background: #fff;
  border-radius: 18px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-family: var(--font-head);
  font-size: .98rem;
  line-height: 1.55;
  text-align: left;
  white-space: pre-line;
}
.bubble::before {
  content: '';
  position: absolute;
  left: -8px; top: 50%;
  margin-top: -8px;
  border: 8px solid transparent;
  border-left: 0;
  border-right-color: #fff;
}

.intro-to { font-family: var(--font-head); font-size: 1.3rem; margin: 0; color: var(--rose-dark); }
.intro-tap { color: var(--muted); font-size: .95rem; margin: 0; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* ---------- ซองจดหมาย ---------- */
.envelope {
  position: relative;
  width: min(280px, 78vw);
  aspect-ratio: 16 / 10.5;
  margin: 80px 0 20px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 900px;
  animation: wiggle 2.6s ease-in-out infinite;
}
.envelope > span { position: absolute; display: block; }
.env-back { inset: 0; z-index: 1; background: #e2798d; border-radius: 8px; }
.env-card {
  z-index: 2;
  left: 8%; right: 8%; top: 6%; bottom: 6%;
  background: #fff;
  border-radius: 6px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .08);
  transition: transform .8s cubic-bezier(.2, .8, .2, 1) .35s;
}
.env-pocket {
  inset: 0;
  z-index: 3;
  background: #f4a3b3;
  border-radius: 8px;
  -webkit-clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
}
.env-flap {
  inset: 0;
  z-index: 4;
  background: #ee8fa2;
  border-radius: 8px 8px 0 0;
  -webkit-clip-path: polygon(0 0, 100% 0, 50% 56%);
  clip-path: polygon(0 0, 100% 0, 50% 56%);
  transform-origin: top center;
  transition: transform .6s ease, z-index 0s linear .3s;
}
.env-seal {
  z-index: 5;
  left: 50%; top: 52%;
  width: 42px; height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: #c9405a;
  color: #fff;
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
  transition: opacity .3s, transform .3s;
}
.envelope.open { animation: none; }
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 0; }
.envelope.open .env-seal { opacity: 0; transform: scale(.4); }
.envelope.open .env-card { transform: translateY(-58%); }
@keyframes wiggle {
  0%, 70%, 100% { transform: rotate(0); }
  76% { transform: rotate(-3deg); }
  84% { transform: rotate(3deg); }
  92% { transform: rotate(-1deg); }
}

/* ---------- ฉาก: เล่นทีละฉากเต็มจอ ไม่ต้องเลื่อน ---------- */
#site { position: fixed; inset: 0; overflow: hidden; }
.scene {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(max(14px, env(safe-area-inset-top)) + 34px) max(18px, env(safe-area-inset-right))
           max(22px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto; /* กันเหนียว: จอเล็กมากๆ ถึงจะเลื่อนได้ */
  overscroll-behavior: contain;
  text-align: center;
  background: var(--bg);
}
.scene.alt { background: linear-gradient(#fff, var(--bg)); }
.scene.active { display: flex; z-index: 2; animation: sceneIn .6s cubic-bezier(.2, .8, .2, 1) both; }
.scene.leaving { display: flex; z-index: 1; animation: sceneOut .35s ease both; pointer-events: none; }
@keyframes sceneIn { from { opacity: 0; transform: translateX(36px); } }
@keyframes sceneOut { to { opacity: 0; transform: translateX(-36px); } }
.scene-body {
  width: 100%;
  max-width: 560px;
  margin: auto; /* อยู่กลางจอ ถ้าล้นจะชิดบนแล้วเลื่อนได้ */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; min-height: 50px; }

/* จุดบอกว่าอยู่ฉากไหน */
.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  gap: 7px;
  padding: max(16px, env(safe-area-inset-top)) 0 18px;
  pointer-events: none;
  transition: background .3s;
}
/* ตอนเลื่อนหน้าจดหมาย ให้มีพื้นจางๆ หลังจุด ตัวหนังสือจะได้ไม่ทับ */
.progress.solid { background: linear-gradient(var(--bg) 60%, rgba(255, 248, 244, 0)); }
.progress i { width: 8px; height: 8px; border-radius: 99px; background: #f3c9d1; transition: width .35s, background .35s; }
.progress i.done { background: #f19aab; }
.progress i.on { width: 24px; background: var(--rose); }

/* ---------- Hero ---------- */
.hero { overflow: hidden; background: radial-gradient(circle at 50% 35%, #fff 0%, var(--bg) 65%); }
.balloons { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.balloon {
  position: absolute;
  bottom: -80px;
  opacity: .85;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  0% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-60vh) rotate(6deg); }
  100% { transform: translateY(-125vh) rotate(-6deg); }
}
.hero-content { position: relative; z-index: 1; }
.hero-title {
  font-family: var(--font-script);
  font-weight: 700;
  font-size: clamp(3.2rem, 15vw, 6.5rem);
  line-height: 1.05;
  color: var(--rose);
  margin: 0;
  text-shadow: 0 4px 18px rgba(232, 93, 117, .2);
}
.hero-name { font-family: var(--font-head); font-size: clamp(1.3rem, 5.6vw, 2rem); margin: 14px 0 0; }
.hero-age { color: var(--muted); margin: 4px 0 0; min-height: 1.7em; }
.hero-next { margin-top: 26px; }
.hero-title, .hero-name, .hero-age, .hero-next {
  opacity: 0;
  transform: translateY(20px) scale(.96);
  transition: opacity .9s ease, transform .9s cubic-bezier(.2, .8, .2, 1);
}
.hero.in .hero-title { opacity: 1; transform: none; transition-delay: .1s; }
.hero.in .hero-name { opacity: 1; transform: none; transition-delay: .5s; }
.hero.in .hero-age { opacity: 1; transform: none; transition-delay: .8s; }
.hero.in .hero-next { opacity: 1; transform: none; transition-delay: 1.5s; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* ---------- หัวข้อแต่ละฉาก ---------- */
.section-title {
  font-family: var(--font-head);
  text-align: center;
  font-size: clamp(1.5rem, 6vw, 2rem);
  line-height: 1.4;
  color: var(--rose-dark);
  margin: 0 0 28px;
  text-wrap: balance;
}
.section-title::after {
  content: '';
  display: block;
  width: 44px;
  height: 3px;
  border-radius: 3px;
  background: var(--rose);
  opacity: .6;
  margin: 10px auto 0;
}
.section-title + .section-sub { margin-top: -16px; }
.section-sub { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: .95rem; transition: color .3s; }
.section-sub.wish { color: var(--rose-dark); font-family: var(--font-head); font-size: 1.15rem; }

/* ---------- กล่องสุ่มดวง ---------- */
.gacha { width: 100%; max-width: 340px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.fortune {
  width: 100%;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 20px;
  border-radius: 20px;
  background: #fff;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
  text-align: center;
  transition: opacity .3s, transform .3s;
}
.fortune.placeholder { background: transparent; box-shadow: none; border: 2px dashed #f3c2cc; }
.fortune.dim { opacity: .25; transform: scale(.95); }
.fortune.pop { animation: fortuneIn .6s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes fortuneIn { from { opacity: 0; transform: translateY(46px) scale(.55); } }
.fortune-tag {
  margin: 0;
  font-family: var(--font-head);
  font-size: .9rem;
  color: var(--rose-dark);
  background: var(--rose-soft);
  padding: 2px 14px;
  border-radius: 999px;
}
.fortune-text { margin: 0; font-family: var(--font-head); font-size: 1.05rem; line-height: 1.6; white-space: pre-line; text-wrap: balance; }
.fortune.placeholder .fortune-tag { background: none; padding: 0; font-size: 1.8rem; line-height: 1.2; }
.fortune.placeholder .fortune-text { font-size: .98rem; color: var(--muted); }
.fortune.secret { background: linear-gradient(145deg, #fffaf0, #fff0c9); border-color: #ffd166; }
.fortune.secret .fortune-tag { background: #ffd166; color: #7a5200; }
.gacha-count { text-align: center; color: var(--muted); font-size: .9rem; margin: 18px 0 0; min-height: 1.5em; }
#gacha.rolled .section-sub { display: none; }
#gacha.rolled .section-title { margin-bottom: 20px; }

.gift {
  position: relative;
  width: 130px;
  height: 118px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-origin: 50% 100%;
}
.gift > span { position: absolute; display: block; }
.gift-glow {
  left: 50%; top: -10px;
  width: 170px; height: 170px;
  margin-left: -85px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 209, 102, .8), rgba(255, 209, 102, 0) 65%);
  opacity: 0;
  transform: scale(.4);
  transition: opacity .4s, transform .5s;
}
.gift-body {
  left: 10px; right: 10px; bottom: 0;
  height: 76px;
  border-radius: 8px 8px 14px 14px;
  background: linear-gradient(90deg, transparent 42%, #ffd166 42% 58%, transparent 58%), #ff8fa3;
  box-shadow: 0 12px 22px rgba(232, 93, 117, .25);
}
.gift-lid {
  left: 0; right: 0; bottom: 72px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(90deg, transparent 42%, #ffc93c 42% 58%, transparent 58%), #f2708b;
  box-shadow: 0 4px 0 rgba(150, 40, 60, .12);
  transition: transform .55s cubic-bezier(.2, .9, .3, 1.2), opacity .45s;
}
/* โบว์บนฝากล่อง */
.gift-lid::before, .gift-lid::after {
  content: '';
  position: absolute;
  bottom: calc(100% - 6px);
  left: 50%;
  width: 34px; height: 24px;
  border: 7px solid #ffc93c;
  border-radius: 50%;
}
.gift-lid::before { margin-left: -36px; transform: rotate(-24deg); }
.gift-lid::after { margin-left: 2px; transform: rotate(24deg); }
.gift-lid i {
  position: absolute;
  left: 50%; bottom: 100%;
  width: 16px; height: 14px;
  margin: 0 0 -7px -8px;
  border-radius: 6px;
  background: #ffb703;
  z-index: 1;
}
.gift:not(.open):not(.shaking) { animation: wiggle 2.6s ease-in-out infinite; }
.gift.shaking { animation: giftShake .85s ease-in-out; }
.gift.open .gift-lid { transform: translate(-38px, -74px) rotate(-30deg); opacity: 0; }
.gift.open .gift-glow { opacity: 1; transform: scale(1); }
@keyframes giftShake {
  0%, 100% { transform: none; }
  10% { transform: rotate(-10deg) translateY(-4px); }
  20% { transform: rotate(9deg); }
  30% { transform: rotate(-9deg) translateY(-6px); }
  40% { transform: rotate(8deg); }
  50% { transform: rotate(-7deg) translateY(-4px); }
  60% { transform: rotate(6deg); }
  70% { transform: rotate(-4deg); }
  80% { transform: rotate(3deg); }
  90% { transform: rotate(-1deg); }
}

/* ---------- เค้ก ---------- */
.cake-wrap { display: flex; justify-content: center; padding-top: 96px; }
.cake { position: relative; width: 240px; }
.candles { position: absolute; left: 0; right: 0; bottom: 100%; z-index: 2; display: flex; justify-content: center; gap: 2px; }
.candle-btn { padding: 36px 8px 0; border: 0; background: none; cursor: pointer; }
.candle {
  position: relative;
  display: block;
  width: 12px; height: 46px;
  border-radius: 3px 3px 0 0;
  background: repeating-linear-gradient(-45deg, #fff 0 6px, #ff9fb1 6px 12px);
}
.candle::before {
  content: '';
  position: absolute;
  left: 50%; top: -6px;
  width: 2px; height: 6px;
  margin-left: -1px;
  background: #5a4a4a;
  border-radius: 1px;
}
.flame {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  width: 14px; height: 24px;
  margin-left: -7px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: linear-gradient(to top, #ff8a1f 0%, #ffc93c 45%, #fff3b0 100%);
  box-shadow: 0 0 12px 4px rgba(255, 190, 70, .55), 0 0 30px 10px rgba(255, 200, 90, .22);
  transform-origin: 50% 90%;
  animation: flicker .14s ease-in-out infinite alternate;
  transition: opacity .25s, transform .25s;
}
@keyframes flicker {
  from { transform: scale(1, 1) rotate(-2deg); }
  to { transform: scale(.92, 1.08) rotate(2deg); }
}
.candle-btn.out .flame { opacity: 0; transform: scale(.2); animation: none; }
.smoke {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  width: 10px; height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: rgba(150, 140, 140, .5);
  pointer-events: none;
  animation: smoke 1.2s ease-out forwards;
}
@keyframes smoke { to { transform: translate(6px, -44px) scale(3); opacity: 0; } }

.layer { position: relative; z-index: 1; margin: 0 auto; border-radius: 14px 14px 6px 6px; }
.layer::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 16px;
  background: #fff;
  border-radius: 14px 14px 0 0;
}
.layer::after {
  content: '';
  position: absolute;
  left: 4px; right: 4px; top: 15px;
  height: 12px;
  background: radial-gradient(circle at 50% 0, #fff 8px, transparent 8.5px) 0 0 / 22px 12px repeat-x;
}
.layer-top { width: 180px; height: 58px; background-color: #ffc6d3; }
.layer-bottom {
  width: 232px; height: 74px;
  margin-top: -4px;
  background-color: #f7a1b5;
  background-image:
    radial-gradient(circle, #fff 2px, transparent 2.6px),
    radial-gradient(circle, #ffd166 2px, transparent 2.6px);
  background-size: 28px 22px;
  background-position: 4px 30px, 18px 42px;
}
.plate {
  position: relative;
  width: 272px; height: 16px;
  margin: -7px 0 0 -16px;
  border-radius: 50%;
  background: linear-gradient(#f3ebe8, #e2d6d2);
}

/* ---------- จดหมาย ---------- */
/* หน้าจดหมายเป็นหน้ายาว เลื่อนอ่านได้ทั้งหน้า (ฉากอื่นยังเป็นทีละจอ) */
.paper-wrap { position: relative; width: 100%; }
.paper-wrap::before { /* เทปแปะกระดาษ */
  content: '';
  position: absolute;
  z-index: 1;
  top: -12px; left: 50%;
  width: 110px; height: 26px;
  margin-left: -55px;
  background: rgba(255, 196, 208, .75);
  transform: rotate(-3deg);
}
.paper {
  padding: 40px 26px 36px;
  border-radius: 8px;
  background-color: #fff;
  background-image: repeating-linear-gradient(to bottom, transparent 0 33px, #f7dde2 33px 34px);
  background-position: 0 35px;
  box-shadow: var(--shadow);
  font-family: var(--font-head);
  font-size: 1.05rem;
  line-height: 34px;
  text-align: left;
}
/* ระยะห่างต้องเป็นทวีคูณของ 34px เพื่อให้ตัวหนังสือวางบนเส้นพอดี */
.letter-to { margin: 0; font-weight: 600; color: var(--rose-dark); }
.letter-body { white-space: normal; }
/* แต่ละย่อหน้าเว้นต้นบรรทัดแบบจดหมาย, ตัดบรรทัดตามคำปกติให้บรรทัดเต็มเสมอกัน */
.lp { margin: 0; text-indent: 2em; text-wrap: pretty; }
.lp.blank { height: 34px; } /* บรรทัดว่างใน config = เว้น 1 บรรทัด */
.nw { white-space: nowrap; } /* 1 คำ ห้ามหั่น */
.letter-from { text-align: right; margin: 34px 0 0; }
/* ป้ายลอยล่างจอ บอกว่ายังเลื่อนลงได้ หายไปเมื่อเลื่อนถึงท้าย */
.more-hint {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 3;
  margin: 0 0 0 -70px;
  width: 140px;
  padding: 6px 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
  color: var(--rose-dark);
  font-family: var(--font-head);
  font-size: .85rem;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
}
.more-hint.show { opacity: 1; animation: bob 1.8s ease-in-out infinite; }
.credit { margin: 14px 0 0; color: var(--muted); font-size: .85rem; }

/* ---------- มือถือจอแคบ ---------- */
@media (max-width: 380px) {
  body { font-size: 16px; }
  .section-title { margin-bottom: 24px; }
  .paper { padding: 40px 18px 32px; font-size: 1rem; }
  .fortune { padding: 16px 12px; }
  .fortune-text { font-size: 1rem; }
  .q-box { padding: 18px 16px 16px; }
  .sticker.sm { width: 64px; }
  .bubble { font-size: .9rem; padding: 8px 12px; }
}

/* ---------- จอเตี้ย (มือถือแนวนอน / จอเล็ก) ---------- */
@media (max-height: 620px) {
  .section-title { font-size: 1.4rem; margin-bottom: 20px; }
  .section-title::after { margin-top: 6px; }
  .section-title + .section-sub { margin-top: -10px; margin-bottom: 16px; }
  .gacha { gap: 14px; }
  .fortune { min-height: 110px; padding: 12px; gap: 6px; }
  .fortune-text { font-size: .95rem; line-height: 1.5; }
  .gift { zoom: .78; }
  .gacha-count { margin-top: 10px; }
  .cake-wrap { padding-top: 84px; }
  .actions { margin-top: 14px; }
  .hero-next { margin-top: 18px; }
  .q-panel { gap: 10px; }
  .sticker { width: min(150px, 42vw); }
  .timer { width: 60px; height: 60px; }
  .t-num { font-size: 1.45rem; }
  .dict { padding: 14px 16px 16px; }
  .dict-name { margin-bottom: 8px; }
  .envelope { margin-top: 56px; }
}
@media (max-height: 440px) {
  .sticker { width: 110px; }
  .envelope { width: min(220px, 60vw); margin-top: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
  .balloons { display: none; }
}
