/* ความทรงจำมอน (memory-fx.js · codex.js · jigsaw.js · 5 ต.ค.) — จิ๊กซอว์ 3×3 · ป้ายชิ้นบนพื้น · ฉากเก็บครบ · ป้ายแตะเพื่อเปิด · ตำแหน่งใต้ชื่อ */

/* ── จิ๊กซอว์ (SVG) ── */
.jz { display: block; width: 100%; height: auto; overflow: visible; }
.jz .jz-edge { fill: none; stroke: #fff6dc; stroke-width: 2.2; stroke-linejoin: round; opacity: .9; }
.jz .jz-hole { fill: #3d2d44; stroke: #261b2c; stroke-width: 2; stroke-linejoin: round; }
.jz .jz-miss text { font: 900 34px var(--font-head, sans-serif); fill: #7a6584; }
.jz .jz-got { filter: drop-shadow(0 1px 1px #0005); }
.jz .jz-fresh { animation: jz-fresh 1.6s ease-out 2; }
@keyframes jz-fresh { 30% { filter: drop-shadow(0 0 6px #ffd76a) brightness(1.15); } }
.jz .jz-rv { opacity: 0; animation: jz-rv .45s calc(.35s + var(--k) * .12s) cubic-bezier(.2, 1.4, .4, 1) forwards; transform-box: fill-box; transform-origin: center; }
@keyframes jz-rv { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }

/* ชิ้นเดียว (ป๊อปค้นพบ) */
.jp { width: 100%; height: 100%; overflow: visible; }
.jp .jp-back { fill: #3a2a3e; }
.jp .jp-rim { fill: none; stroke-width: 7; stroke-linejoin: round; paint-order: stroke; filter: drop-shadow(0 0 1.5px #6b3f12); }
.mem-pop-row { display: flex; gap: 4%; width: 140%; margin-left: -20%; justify-content: center; }
.mem-pop-row .jp { width: 32%; height: auto; }

/* ── ป้ายชิ้นบนพื้น (ตามตำแหน่งในฉาก) ── */
.mem-tag { position: fixed; left: 0; top: 0; z-index: var(--z-hud, 100); pointer-events: none; display: flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 6px; border-radius: 10px; background: linear-gradient(#4a3020ee, #2e1d14ee); border: 1.5px solid #e8b64a;
  color: #fff4d6; box-shadow: 0 3px 8px #0006; white-space: nowrap; animation: mem-tag-in .25s ease-out both; }
.mem-tag.out { opacity: 0; transition: opacity .25s; }
.mem-tag span { display: grid; line-height: 1.15; }
.mem-tag b { font: 800 12.5px var(--font-head, inherit); color: #ffd76a; }
.mem-tag small { font-size: 12px; }
.mem-tag-ic { width: 18px; height: 18px; background: #e8b64a; -webkit-mask: url('assets/particles/k_magic_05.webp') center / contain no-repeat; mask: url('assets/particles/k_magic_05.webp') center / contain no-repeat; }
@keyframes mem-tag-in { from { opacity: 0; transform: translateY(6px); } }

/* ── ป้าย "ความทรงจำครบ! แตะเพื่อเปิด" ── */
#mem-badge { pointer-events: auto; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  font: 700 13.5px var(--font-head, inherit); color: #4a2a06; background: linear-gradient(#ffe48a, #e8b64a); border: 2px solid #a8681a;
  box-shadow: 0 3px 0 #a8681a, 0 6px 14px #0005; animation: mem-badge 1.6s ease-in-out infinite; position: relative; }
#mem-badge[hidden] { display: none; }
#mem-badge small { font-weight: 600; color: #6b4510; }
html:not(.touch-ui) #mem-badge { position: fixed; top: 72px; left: 50%; transform: translateX(-50%); z-index: var(--z-hud, 100); }
@keyframes mem-badge { 50% { box-shadow: 0 3px 0 #a8681a, 0 0 16px #ffd76a; } }
.mem-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #e0453a; box-shadow: 0 0 0 2px #fff; vertical-align: top; margin-left: 3px; }
#mem-badge > .mem-dot { position: absolute; top: -2px; right: -2px; margin: 0; }

/* ── ฉากเก็บครบ (ใน celebrate epic) ── */
.mem-done { order: 5; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: center; width: 100%;
  padding: 14px; border-radius: 18px; background: linear-gradient(#fff8e6, #f3e3bd); border: 2px solid #d9b56a; box-shadow: 0 0 0 4px #fff3d0, 0 14px 30px #0007; }
.mem-done.one { grid-template-columns: minmax(0, 1fr); max-width: 420px; }
.mem-done-pz { display: grid; justify-items: center; gap: 6px; }
.mem-done-pz .jz { width: min(100%, 46vh, 340px); }
.mem-done-n { padding: 3px 14px; border-radius: 999px; background: linear-gradient(#5a3a28, #3e2618); color: #ffd76a; font: 800 14px var(--font-head, inherit); }
.mem-done-rw { display: grid; gap: 7px; text-align: left; color: #3e2c16; }
.mem-done-rw h4 { margin: 0; font: 800 16px var(--font-head, inherit); color: #6b4510; }
.mem-rw { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 12px; background: #fffdf6; border: 1.5px solid #ecdcb6; }
.mem-rw > i { font-style: normal; font-size: 22px; width: 30px; text-align: center; font-family: 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif; }
.mem-rw > span { display: grid; flex: 1; min-width: 0; }
.mem-rw small { font-size: 12px; color: #8a7350; }
.mem-rw b { font: 800 15px/1.25 var(--font-head, inherit); color: #7a3a10; overflow-wrap: anywhere; }
.mem-rw.dim { opacity: .62; }
.mem-show { display: flex; align-items: center; gap: 8px; min-height: 36px; font-size: 13.5px; cursor: pointer; }
.mem-show input { width: 20px; height: 20px; accent-color: #2f6f73; }
.mem-story { margin: 0; font-size: 13px; font-style: italic; color: #7a6548; }
/* จอเตี้ย (มือถือแนวนอน): ย่อจิ๊กซอว์ตามความสูง ไม่ให้ปุ่มตกจอ */
@media (max-height: 520px) {
  .cf-epic .cf-banner { font-size: 22px; margin-bottom: 4px; }
  .mem-done { padding: 8px 10px; gap: 10px; }
  .mem-done-pz .jz { width: min(100%, 52vh); }
  .mem-done-rw { gap: 4px; } .mem-rw { padding: 4px 8px; } .mem-rw > i { font-size: 18px; }
  .mem-story { display: none; }
  /* 5 ต.ค. รางวัลค่าพลังเพิ่ม 1–2 แถว (🧠 + ✨) — ซ่อนหัวข้อ/แถวความคืบหน้าภูมิภาค (ดูได้ในสมุด) ย่อตัวหนังสือ ให้ปุ่มรับยังอยู่ในจอ */
  .mem-done-rw h4, .mem-done-rw > .mem-rw.dim { display: none; }
  .mem-done-rw .mem-rw small { font-size: 11px; line-height: 1.2; } .mem-done-rw .mem-rw b { font-size: 13.5px; }
  .mem-show { min-height: 30px; }
  .cf-epic .cf-acts { margin-top: 6px; } .cf-epic .cf-btn { min-height: 44px; }
}
@media (max-width: 560px) and (min-height: 521px) { .mem-done { grid-template-columns: minmax(0, 1fr); } }

/* ── สมุด: หน้ามอน ── */
.cx-mem { font-style: normal; font-weight: 700; color: #9a6410; white-space: nowrap; }
.cx-mem.full { color: #2f6f3c; }
.cx-mwrap { margin-top: 10px; display: grid; gap: 10px; }
.cx-mtabs { display: none; gap: 4px; }
.cx-mtabs button { flex: 1; min-height: 40px; padding: 0 8px; border-radius: 10px; border: 1px solid #dcc898; background: #fbf4e2; color: #6b5530; font: 700 13.5px var(--font-head, inherit); cursor: pointer; position: relative; }
.cx-mtabs button.on { background: linear-gradient(#fff6dc, #f6e3b0); border-color: #c8901a; color: #6b4510; box-shadow: inset 0 -3px 0 #e8b64a; }
.cx-mt[data-p="info"] > .cx-stats:first-child { margin-top: 0; }
.cx-mem-box { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 4px 12px; align-items: center; padding: 10px; border-radius: 13px;
  background: linear-gradient(#fbf1d8, #f3e3bd); border: 1.5px solid #d9b56a; }
.cx-mem-box .jz { grid-row: 1 / span 3; }
.cx-mem-box.off .jz { opacity: .45; }
.cx-mem-n { display: flex; gap: 8px; align-items: baseline; } .cx-mem-n b { font: 800 20px var(--font-head, inherit); color: #7a3a10; } .cx-mem-n em { font-style: normal; font-weight: 700; color: #2f6f3c; }
.mem-claim { animation: mem-badge 1.6s ease-in-out infinite; background: linear-gradient(#ffe48a, #e8b64a) !important; color: #4a2a06 !important; border-color: #a8681a !important; }
.cx-mem-rw { display: grid; gap: 6px; }
.mem-ttl.on { background: linear-gradient(#e6f4ea, #cfe8d6); color: #2f6f3c; border-color: #2f6f3c; }
.cx-ttls h5 small { font-weight: 600; color: #8a5a10; margin-left: 6px; }
.cx-ttl { min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid #dcc898; background: #fffdf6; color: #6b4510; font: 700 13px var(--font-head, inherit); cursor: pointer; }
.cx-ttl.on { background: linear-gradient(#ffe48a, #e8b64a); border-color: #a8681a; color: #4a2a06; }
/* ตำแหน่งใต้ชื่อ (ป้ายเหนือหัว main.js renderLabel) */
.label .ttl { margin-top: 1px; font: 700 11px/1.2 var(--font-head, inherit); color: #ffe48a; text-shadow: 0 1px 2px #000c, 0 0 4px #0008; letter-spacing: .02em; }
.label .ttl::before { content: '👑 '; font-size: 10px; }

/* แคบ/เตี้ย (มือถือแนวนอนทุกรุ่น): แท็บ จิ๊กซอว์ / ข้อมูล / รางวัล — ทีละหน้า */
@container cxw (max-width: 860px) {
  .cx-mtabs { display: flex; }
  .cx-mwrap .cx-mt { display: none; }
  .cx-mwrap[data-mt="jig"] .cx-mt[data-p="jig"], .cx-mwrap[data-mt="info"] .cx-mt[data-p="info"], .cx-mwrap[data-mt="rew"] .cx-mt[data-p="rew"] { display: block; }
  .cx-mem-box { grid-template-columns: minmax(0, min(200px, 46cqw)) minmax(0, 1fr); }
  /* หน้ามอนที่มีแท็บ: หัวเตี้ยลง (จอแนวนอนสูง ~390px — จิ๊กซอว์ต้องโผล่โดยไม่ต้องเลื่อนมาก) */
  .cx-detail:has(.cx-mwrap) .cx-big { width: 52px; height: 52px; }
  .cx-detail:has(.cx-mwrap) .cx-back { min-height: 40px; margin-bottom: 2px; }
  .cx-mwrap { margin-top: 6px; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) { #mem-badge, .mem-claim, .jz .jz-fresh { animation: none; } .jz .jz-rv { animation: none; opacity: 1; } }

/* รางวัลค่าพลัง (5 ต.ค.) — A: แถว 🧠 ต่อมอน · B: ขั้นโบนัสในหน้าคอลเลกชัน · บรรทัด "ปลดโบนัสใหม่" ในหน้าฉลอง */
.mem-rw.on { border-color: #8cc79a; background: #f2fbf3; }
.mem-rw .mem-ok { font-style: normal; font-weight: 800; color: #2f6f3c; font-size: 18px; }
.mem-rw.mem-new { border-color: #e8b64a; background: linear-gradient(#fff8dc, #fdeaae); box-shadow: 0 0 0 2px #e8b64a55; }
.cx-membonus .cx-bar { margin: 2px 0 8px; }
.cx-membonus h5 small { font-weight: 600; color: #8a5a10; margin-left: 6px; }
.mem-tiers { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.mem-tiers li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 9px; background: #fffdf6; border: 1px solid #ecdcb6; opacity: .6; }
.mem-tiers li.on { opacity: 1; border-color: #8cc79a; background: #f2fbf3; }
.mem-tiers li.next { opacity: 1; border-color: #e8b64a; }
.mem-tiers b { font: 800 13px var(--font-head, inherit); color: #7a3a10; }
.mem-tiers li.on b { color: #2f6f3c; }
.mem-tiers span { font-size: 13.5px; color: #4a3a20; overflow-wrap: anywhere; }
.mem-tiers small { font-size: 12px; color: #8a7350; white-space: nowrap; }
