/* ผลคราฟ + ตีบวก (forge-fx.js · 5 ต.ค.) — ต่อยอดจาก ui-celebrate.css (ชั้น .cf-layer) · ชั้น Popup (--z-popup 300) ไม่ตั้ง z เอง
   ทุกชั้นแสง/ควัน/ประกาย = texture assets/particles (Kenney CC0) เป็น mask ลงสี · แกนทึบ (normal) + ชั้นแสง (screen) — กฎสไตล์ข้อ 2
   ไม่มีอะไรขาวจ้า · ลดการเคลื่อนไหว (.cf-still / prefers-reduced-motion) = ไม่สั่น ไม่มีประกาย ไม่นับเลข */

/* ธีมเพิ่ม: ปกติ = หินทราย (อุ่น เรียบ) · พลาด = ควันม่วงเทา */
.cf-t-stone, .cf-aura.cf-free.cf-t-stone { --c1: #c9a26a; --c2: #fff0cf; --c3: #7a5a2e; --rib1: #8a6a3e; --rib2: #5e4424; }
.cf-t-ash { --c1: #6c6480; --c2: #d8d0e6; --c3: #3a3348; --rib1: #5a5270; --rib2: #3a3348; }

/* ── ป๊อปผล: ภาพเล็กลง (เนื้อหามีตรา/คะแนน) — มือถือแนวนอนต้องพอดีความสูง 390 ── */
.fx-pop .cf-stage { --w: min(380px, 78vw, 74vh); }
.fx-pop .cf-art { width: 36%; }
.fx-pop.cf-small .cf-art { width: 30%; }
/* แสงหลังของ: จานมืดนุ่ม ๆ ใต้ออร่า (แกนทึบ) — ออร่าทองอ่านออกบนหน้าต่างสีครีม/พื้นทราย ไม่ขาวจ้า (กฎสไตล์ข้อ 2) */
.fx-pop:not(.cf-small) .cf-stage::before { content: ''; position: absolute; left: 50%; top: 32%; width: 150%; aspect-ratio: 1; transform: translate(-50%, -50%);
  background: radial-gradient(circle, #2a1c32b0 0, #2a1c3270 32%, #2a1c3200 62%); pointer-events: none; z-index: 0; }
/* ชั้นแสงของป๊อปคราฟ (รัศมีจางลง .32/.28 · ดาวทอง→น้ำตาล .6 · ลำแสง .75 ไม่กลืนไอคอน) — วาดในผืนผ้าใบ: celebrate-fx.js baseOp (6 ต.ค.) */
/* ไอคอนบนเหรียญครีมขอบทอง (แบบการ์ดเผยเดิม) — อ่านออกทั้งบนแสงและบนหน้าต่าง */
.fx-pop:not(.fx-gen) .cf-art { border-radius: 50%; padding: 7%; box-sizing: border-box;
  background: radial-gradient(circle at 50% 38%, #fffaf0, #f2dfb2 72%); box-shadow: 0 0 0 3px var(--c1), 0 0 0 6px var(--c3), 0 10px 20px #0007; }
.fx-pop.fr-fail .cf-art { background: radial-gradient(circle at 50% 38%, #f1ecf6, #cfc6dc 72%); }
.fx-pop .cf-stage > .cf-aura { top: 30%; }
.fx-pop.cf-small .cf-stage { --w: min(240px, 52vw); }
.fx-pop.cf-epic .cf-stage { --w: min(560px, 92vw); }
.fx-pop.cf-epic .cf-art { width: min(150px, 26vh); aspect-ratio: 1; }
.fx-pop .cf-art > .ic3d, .fx-pop .cf-art > img { width: 100%; height: 100%; object-fit: contain; }
.fx-pop .cf-art { font-size: calc(var(--w) * .2); line-height: 1; }   /* ไอคอนสำรองที่เป็นอีโมจิ */
.fx-pop .cf-banner { margin-top: 6px; }
.fx-pop.cf-epic .cf-banner { margin-top: 0; }
.fx-pop .cf-title { font-size: clamp(12px, calc(var(--w) * .045), 16px); margin-top: 4px; }
.fx-pop .cf-sub { font-size: clamp(11px, calc(var(--w) * .038), 14px); }
.fx-gen .cf-title { font-size: 14px; }
.fx-gen .cf-banner { font-size: 17px; }
.fx-pop.fx-gen .cf-stage { --w: min(260px, 54vw); }
.fx-pop.fx-gen .cf-art { width: 34%; }
.fx-r2 .cf-aura { width: calc(var(--w) * 1.75); }

/* ── การ์ดคุณภาพ (คราฟอุปกรณ์) ── */
.fq { order: 5; margin-top: 6px; width: min(100%, 320px); padding: 8px 12px 10px; border-radius: 14px; text-align: center;
  background: linear-gradient(#fffaf0f2, #f6e8c8f2); border: 2px solid var(--c1); box-shadow: 0 6px 16px #0005, inset 0 1px 0 #fff;
  font-family: var(--font-head, inherit); color: #4a3418; }
.fq-badge { display: flex; justify-content: center; }
.fq-badge .cq-badge { transform-origin: 50% 60%; }
.fq-q { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-top: 4px; }
.fq-q > span { font: 800 12px/1 var(--font-head, inherit); color: #8a6a32; letter-spacing: .03em; }
.fq-q b { font: 900 clamp(28px, calc(var(--w) * .12), 44px)/1 var(--font-head, inherit); color: var(--c3); font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #fff, 0 0 10px color-mix(in srgb, var(--c1) 45%, #0000); }
.fq-q b small { font-size: .5em; margin-left: 1px; }
.fq-bar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; height: 12px; margin: 6px 2px 4px; }
.fq-seg { position: relative; border-radius: 6px; background: #e3d3ad; box-shadow: inset 0 1px 2px #0003; overflow: hidden; }
.fq-seg.off { background: repeating-linear-gradient(-45deg, #eadfc4 0 4px, #dfd0ac 4px 8px); opacity: .7; }
.fq-seg u { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px; text-decoration: none;
  background: linear-gradient(90deg, var(--c3), var(--c1) 70%, var(--c2)); transition: width var(--qdur, .7s) cubic-bezier(.2, .8, .3, 1) var(--dl, 0s); }
.fq-go .fq-seg u { width: calc(var(--p) * 100%); }
.fq-seg.max u { box-shadow: 0 0 6px var(--c1); }
.fq-ln { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; font: 700 12px/1.35 system-ui, sans-serif; }
.fq-ln li { display: flex; align-items: baseline; gap: 6px; justify-content: center; opacity: 0; transform: translateY(4px); transition: opacity .3s, transform .3s; }
.fq-ln li b { color: #1f6a5a; font-weight: 900; }
.fq-ln li small { color: #9a8458; font-weight: 600; }
.fq-ln li.max b { color: #b5701a; }
.fq-go .fq-ln li { opacity: 1; transform: none; }
.fq-go .fq-ln li:nth-child(2) { transition-delay: .12s; }
.fq-go .fq-ln li:nth-child(3) { transition-delay: .24s; }
/* ตรา "ปัง" ตอนนับจบ */
.fq-bang .fq-badge .cq-badge { animation: fq-stamp .45s cubic-bezier(.2, 1.7, .4, 1) both; }
.fq-bang .fq-q b { animation: fq-pop .4s cubic-bezier(.2, 1.6, .4, 1); }
.fq-bang .fq { animation: fq-flash .6s ease-out; }
@keyframes fq-stamp { 0% { transform: scale(2.1) rotate(-8deg); opacity: .2; } 60% { transform: scale(.92) rotate(1deg); opacity: 1; } 100% { transform: none; } }
@keyframes fq-pop { 40% { transform: scale(1.22); } }
@keyframes fq-flash { 0% { box-shadow: 0 0 0 0 var(--c1), 0 6px 16px #0005; } 40% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--c1) 55%, #0000), 0 6px 16px #0005; } }
.fx-r0 .fq { border-color: #c9a26a; }
.fx-r3 .fq { border-width: 3px; background: linear-gradient(#fffaf0, #fbe7b0); }
.fx-r3 .fq-q b { color: #a8681a; }

/* ── ผลตีบวก: ตัวเลข +N ── */
.fr-art { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.fr-art > .ic3d, .fr-art > img { width: 100%; height: 100%; object-fit: contain; }
.fr-lv { position: absolute; left: 88%; top: 22%; font: 900 clamp(30px, calc(var(--w) * .13), 58px)/1 var(--font-head, inherit); color: #fff4d0;
  -webkit-text-stroke: 2px var(--c3); paint-order: stroke fill; text-shadow: 0 3px 0 var(--c3), 0 6px 12px #0006; white-space: nowrap; }
.fr-lv.old { opacity: 1; }
.fr-lv.new, .fr-lv.keep { opacity: 0; }
.fr-ok.fr-land .fr-lv.old { animation: fr-up .3s ease-in both; }
.fr-ok.fr-land .fr-lv.new { animation: fr-slam .5s cubic-bezier(.2, 1.6, .4, 1) both; color: #ffe58a; }
.fr-ok.fx-r3 .fr-lv { font-size: clamp(34px, calc(var(--w) * .16), 66px); }
.fr-saved.fr-land .fr-lv.keep { animation: fr-slam .45s cubic-bezier(.2, 1.4, .4, 1) both; color: #d8fff6; }
.fr-fail .fr-lv { color: #ece6f4; }
.fr-fail.fr-land .fr-lv.old { animation: fr-wobble .45s ease-in-out both; }
.fr-drop.fr-land .fr-lv.old { animation: fr-fall .7s .25s cubic-bezier(.5, 0, .9, .6) both; }
.fr-drop.fr-land .fr-lv.new { animation: fr-rise .4s .7s ease-out both; color: #cfc6dc; }
@keyframes fr-up { to { transform: translateY(-40%) scale(.7); opacity: 0; } }
@keyframes fr-slam { 0% { transform: scale(2.8) translateY(-20%); opacity: 0; } 55% { transform: scale(.9); opacity: 1; } 100% { transform: none; opacity: 1; } }
@keyframes fr-wobble { 0%, 100% { transform: none; } 25% { transform: rotate(-9deg); } 60% { transform: rotate(7deg); } }
@keyframes fr-fall { 0% { transform: none; opacity: 1; } 100% { transform: translateY(120%) rotate(16deg); opacity: 0; } }
@keyframes fr-rise { from { transform: translateY(30%); opacity: 0; } to { transform: none; opacity: 1; } }
/* พลาด: ภาพของหม่นลงชั่วครู่ (ไม่ใช่แตก — ของไม่หาย) */
.fr-fail .cf-art { filter: drop-shadow(0 6px 10px #1a102466) saturate(.75); }
.fr-fail .cf-title { background: linear-gradient(#4a4258, #2e283a); border-color: #8a80a0; }
.fr-ok .cf-sub { color: #fff2b0; letter-spacing: .01em; }   /* ตัวเลขตีบวก "ATK +2 → รวม +12" อ่านชัดบนหน้าต่างช่าง */
.fr-fail .cf-sub { color: #e6def2; background: #2e283ae0; border-color: #6c6480; }
.fr-saved .cf-sub { color: #c8f4ee; background: #1d4a4de0; }

/* ควันมืด (auraHtml ตอนพลาด) — แกนทึบ ไม่ใช้แสงบวก */
.cf-layer .fx-dark { inset: 14%; background: radial-gradient(circle, #3a3348 0%, #4a4258 50%, #0000 75%); opacity: 0; animation: fx-puff 1.6s ease-out both; }
.cf-layer .fx-dark2 { inset: 4%; background: #5a5270; opacity: 0; animation: fx-puff 1.9s .1s ease-out both; }
.fx-smoke { position: absolute; left: 50%; top: 50%; width: calc(130px * var(--s)); aspect-ratio: 1; margin: calc(-65px * var(--s));
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; background: #3e374c; opacity: 0;
  animation: fx-smoke 1.7s var(--dl) cubic-bezier(.15, .7, .3, 1) both; }
@keyframes fx-puff { 0% { transform: scale(.4); opacity: 0; } 25% { opacity: .85; } 60% { opacity: .55; } 100% { transform: scale(1.2); opacity: 0; } }
@keyframes fx-smoke { 0% { transform: translate(0, 0) scale(.3); opacity: 0; } 18% { opacity: .92; } 55% { opacity: .7; }
  100% { transform: translate(calc(var(--x) * var(--R)), calc(var(--y) * var(--R) - 30px)) scale(1.2) rotate(40deg); opacity: 0; } }

/* ── ฉากลุ้น (ค้อนตีทั่ง) ── */
.fx-forge { position: fixed; inset: 0; z-index: var(--z-popup, 300); display: grid; place-items: center; touch-action: none; cursor: pointer;
  --c1: #e8b64a; --c2: #fff2c0; --c3: #a8681a; --k: 0; }
.fx-vig { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 50%, #1a102488 0%, #1a102440 30%, #1a1024b0 85%); opacity: 0; transition: opacity .25s; }
.fx-forge.in .fx-vig { opacity: 1; }
.fx-stage { position: relative; width: var(--w); aspect-ratio: 1; display: grid; place-items: center; opacity: 0; transform: scale(.8);
  transition: opacity .2s, transform .3s cubic-bezier(.2, 1.4, .4, 1); --w: min(300px, 50vw, 66vh); --R: calc(var(--w) * .6); }
.fx-forge.in .fx-stage { opacity: 1; transform: none; }
.fx-forge.out .fx-stage, .fx-forge.out .fx-vig { opacity: 0; transition: opacity .2s; }
.fx-forge .cf-l { position: absolute; -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
/* แสงสว่างขึ้นทีละจังหวะ (--k 0→1) */
.fx-glow { inset: -10%; background: radial-gradient(circle, var(--c2), var(--c1) 45%, #0000 70%); mix-blend-mode: screen; opacity: calc(.12 + var(--k) * .45);
  transform: scale(calc(.7 + var(--k) * .45)); transition: opacity .25s, transform .3s; }
.fx-halo { inset: 8%; background: var(--c1); opacity: calc(var(--k) * .55); transition: opacity .25s; animation: cf-spin 9s linear infinite; }
.fx-ring { inset: 4%; background: var(--c3); opacity: 0; }
.fx-forge.hit .fx-ring { animation: fx-ring .42s ease-out; }
.fx-item { position: relative; z-index: 1; width: 42%; aspect-ratio: 1; margin-top: -38%; display: grid; place-items: center; font-size: calc(var(--w) * .22);
  box-sizing: border-box; padding: 7%; border-radius: 50%; background: radial-gradient(circle at 50% 38%, #fffaf0, #f2dfb2 72%);
  box-shadow: 0 0 0 3px var(--c1), 0 0 0 6px var(--c3), 0 0 calc(8px + var(--k) * 26px) calc(var(--k) * 8px) var(--c1), 0 8px 16px #0007; transition: box-shadow .25s; }
.fx-item > img, .fx-item > .ic3d { width: 100%; height: 100%; object-fit: contain; }
.fx-anvil { position: absolute; z-index: 2; width: 48%; bottom: 0; left: 26%; transform-origin: 70% 85%; filter: drop-shadow(0 5px 6px #2a160866); pointer-events: none; }
.fx-forge.hit .fx-anvil { animation: fx-hammer .4s cubic-bezier(.3, 0, .2, 1); }
.fx-forge.hit .fx-item { animation: fx-squash .32s cubic-bezier(.2, 1.4, .4, 1); }
.fx-hint { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 0; right: 0; margin: 0; text-align: center;
  font: 700 12px var(--font-head, inherit); color: #fff4d6cc; text-shadow: 0 1px 2px #000a; opacity: 0; animation: cf-up .3s .5s ease-out both; pointer-events: none; }
@keyframes fx-hammer { 0% { transform: rotate(0); } 35% { transform: rotate(-16deg) translateY(-6%); } 55% { transform: rotate(5deg) translateY(2%); } 100% { transform: none; } }
@keyframes fx-squash { 0% { transform: none; } 30% { transform: scale(1.12, .86) translateY(5%); } 100% { transform: none; } }
@keyframes fx-ring { 0% { transform: scale(.5); opacity: .9; } 100% { transform: scale(1.25); opacity: 0; } }
/* ประกายจากจุดกระทบ */
.fx-spg { position: absolute; left: 50%; top: 52%; width: 0; height: 0; z-index: 3; pointer-events: none; }
.fx-sp { position: absolute; left: 0; top: 0; width: calc(24px * var(--s)); aspect-ratio: 1; margin: calc(-12px * var(--s));
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; background: #ffd76a;
  filter: drop-shadow(0 0 1px #a8681a); animation: fx-sp .62s var(--dl) cubic-bezier(.15, .7, .3, 1) both; }
@keyframes fx-sp { 0% { transform: translate(0, 0) scale(.3); opacity: 1; }
  100% { transform: translate(calc(var(--x) * var(--R)), calc(var(--y) * var(--R) + 26px)) scale(1) rotate(120deg); opacity: 0; } }

/* ลดการเคลื่อนไหว */
.cf-still .fq-seg u, .cf-still .fq-ln li { transition: none; }
.cf-still .fr-lv, .cf-still .fx-smoke, .cf-still .fx-dark, .cf-still .fx-dark2, .cf-still .fx-anvil, .cf-still .fx-item, .cf-still .fx-halo { animation: none !important; }
.cf-still .fr-lv.new, .cf-still .fr-lv.keep { opacity: 1; }
.cf-still.fr-ok .fr-lv.old, .cf-still.fr-drop .fr-lv.old { display: none; }
@media (prefers-reduced-motion: reduce) { .fq-bang .fq, .fq-bang .fq-q b, .fq-bang .fq-badge .cq-badge { animation: none; } }

/* หน้าต่างตีบวก: สวิตช์ข้ามฉากลุ้น */
.rw-fast { display: inline-flex; align-items: center; gap: 6px; font: 600 12px/1.2 system-ui, sans-serif; color: #7a5a2e; cursor: pointer; user-select: none; }
.rw-fast input { width: 16px; height: 16px; accent-color: #2f6f73; }

/* จอเตี้ย (มือถือแนวนอน ~390 px) — ภาพ/ตัวเลขเล็กลงให้ป๊อปพอดีความสูง ไม่ล้นขอบบน */
@media (max-height: 460px) {
  .fx-pop:not(.cf-small) .cf-art { width: 25%; }
  .fx-pop.cf-epic .cf-art { width: min(110px, 24vh); }
  .fr-lv, .fr-ok.fx-r3 .fr-lv { font-size: 34px; }
  .fq { padding: 6px 10px 8px; }
  .fq-q b { font-size: 30px; }
  .fx-pop .cf-banner { font-size: 22px; }
}
