/* ============================================================
   wansuk.com — Raksa (รักษา) product page
   หน้าจอเดียว ไม่ต้องเลื่อน: หัว + ภาพเคลื่อนไหวกระบวนการทำงาน 5 ขั้น (วนเอง)
   โหลดต่อจาก style.css (ใช้ .hero--full / .stage / .stage__bar / .btn ชุดเดียวกับหน้าแรก)
   prefix .r- = โครงหน้า · .s1-…s5- = ชิ้นส่วนในฉากของแต่ละขั้น
   ตัวคุมจังหวะ = assets/js/raksa-flow.js · โทนประจำระบบ = ฟ้าอมเขียว (--tile-raksa-1/2)

   หลักของแอนิเมชันในฉาก (สำคัญ):
   - สไตล์ปกติของทุกชิ้น = "ภาพสุดท้าย" ของขั้นนั้น
   - แอนิเมชันทำงานเฉพาะใต้ .r-scene.is-active และใช้ fill-mode both
     (ช่วง delay = ท่าเริ่มต้น, จบแล้ว = ค่าปกติ)
   ผลคือ ตอนฉากจางออก / reduced-motion / ไม่มี JS จะเห็นภาพที่ทำเสร็จแล้วเสมอ ไม่มีชิ้นไหนกระโดด
   ============================================================ */

/* ---------- 1. โครงหน้า ---------- */
.r-page .stage{gap:0}
.r-cta{display:flex;align-items:center;gap:10px}
.r-cta .btn{padding:11px 20px;font-size:14.5px}

/* ไม่มีป้าย/หัวเรื่องที่มองเห็นแล้ว (h1 เป็น .sr-only) — ภาพเริ่มใต้แถบแบรนด์เลย */

/* ภาพ (ซ้าย) + รายการขั้น (ขวา) กินความสูงที่เหลือทั้งหมด */
.r-flow{
  flex:1;min-height:0;display:grid;margin-top:clamp(14px,2.6vh,28px);
  grid-template-columns:minmax(0,1fr) minmax(290px,370px);
  gap:clamp(12px,1.6vw,22px);
}

/* ---------- 2. เวทีของฉาก ---------- */
.r-stage{position:relative;min-height:0;border-radius:var(--r-lg);overflow:hidden;background:rgba(255,255,255,.5)}
.r-scene{
  position:absolute;inset:0;margin:0;display:grid;place-items:center;
  padding:clamp(10px,2.2vh,26px) clamp(12px,2vw,30px) clamp(52px,8vh,70px);
  opacity:0;visibility:hidden;transform:translateY(10px) scale(.985);
  transition:opacity .5s ease,transform .6s cubic-bezier(.2,.8,.3,1),visibility 0s linear .5s;
}
.r-scene.is-active{opacity:1;visibility:visible;transform:none;transition:opacity .5s ease,transform .6s cubic-bezier(.2,.8,.3,1)}
.r-scene svg{display:block;width:100%;height:100%;filter:drop-shadow(0 22px 34px rgba(12,58,128,.16))}
.r-scene text{font-family:var(--ff-th)}
.r-scene .t-lg{font-size:20px}
.r-scene .t-md{font-size:16px}
.r-scene .t-sm{font-size:13.5px}
.r-scene .t-xs{font-size:11.5px}
.r-scene .b{font-weight:700}
/* ชิ้นที่ย่อ/ขยาย ให้หมุนรอบจุดกลางของตัวเอง (ค่าเริ่มต้นของ SVG = มุม viewBox) */
.r-scene :is(.s1-btn,.s1-ripple,.s2-chip,.s3-beep,.s3-screen,.s4-chip,.s5-chip,.s5-check,.s5-folder){transform-box:fill-box;transform-origin:center}

/* ป้ายบอกขั้นที่กำลังเล่น (มุมซ้ายล่างของเวที) — อัปเดตโดย raksa-flow.js */
.r-now{
  position:absolute;left:clamp(14px,1.6vw,22px);bottom:clamp(12px,1.8vh,18px);z-index:2;
  display:flex;align-items:center;gap:10px;margin:0;
  font-size:clamp(14px,1.9vh,16px);font-weight:600;color:var(--navy-800);
}
.r-now b{
  display:inline-grid;place-items:center;min-width:34px;height:26px;padding:0 8px;border-radius:var(--r-pill);
  background:var(--tile-raksa-1);color:#fff;font-size:12.5px;font-weight:800;letter-spacing:.06em;
}

/* ---------- 3. รายการ 5 ขั้น ---------- */
.r-rail{display:flex;flex-direction:column;gap:clamp(8px,1.4vh,12px);min-height:0}
.r-steps{flex:1;min-height:0;display:grid;grid-auto-rows:minmax(0,1fr);gap:clamp(6px,1vh,10px);margin:0;padding:0;list-style:none}
.r-steps li{min-height:0}
.r-step{
  position:relative;width:100%;height:100%;overflow:hidden;
  display:grid;grid-template-columns:auto minmax(0,1fr);align-items:center;gap:12px;
  padding:clamp(6px,1.1vh,12px) 14px;border-radius:var(--r-md);
  font:inherit;color:inherit;text-align:left;cursor:pointer;
  background:rgba(255,255,255,.36);border:1px solid rgba(255,255,255,.7);
  transition:background .3s,box-shadow .3s,transform .3s cubic-bezier(.2,.8,.3,1);
}
.r-step:hover{background:rgba(255,255,255,.62)}
.r-step__num{
  display:grid;place-items:center;width:34px;height:34px;border-radius:50%;
  font-size:14px;font-weight:800;color:var(--tile-raksa-1);background:rgba(11,138,133,.1);
  transition:background .3s,color .3s;
}
.r-step__text b{display:block;font-size:clamp(13.5px,1.9vh,15px);font-weight:700;line-height:1.4;color:var(--navy-800)}
.r-step__text small{display:block;margin-top:2px;font-size:clamp(11.5px,1.6vh,12.5px);line-height:1.45;color:var(--ink-mute)}
.r-step.is-done .r-step__num{background:rgba(11,138,133,.2)}
.r-step.is-active{background:rgba(255,255,255,.9);border-color:#fff;box-shadow:var(--shadow-md);transform:translateX(-4px)}
.r-step.is-active .r-step__num{background:var(--tile-raksa-1);color:#fff;box-shadow:0 6px 14px -6px rgba(11,138,133,.7)}
/* แถบเวลาใต้ขั้นที่กำลังเล่น — --dur ตั้งโดย JS ตาม data-dur ของฉาก */
.r-step__bar{position:absolute;left:0;right:0;bottom:0;height:3px}
.r-step__bar i{display:block;height:100%;transform:scaleX(0);transform-origin:left;background:linear-gradient(90deg,var(--tile-raksa-1),var(--blue-500))}
.r-step.is-active .r-step__bar i{animation:rBar var(--dur,5s) linear both}
@keyframes rBar{to{transform:scaleX(1)}}

.r-rail__foot{display:flex;align-items:center;justify-content:space-between;gap:8px 12px;flex-wrap:wrap}
.r-play{
  display:inline-flex;align-items:center;gap:7px;padding:7px 14px;border-radius:var(--r-pill);
  font:inherit;font-size:13px;font-weight:600;color:var(--navy-800);cursor:pointer;
  background:rgba(255,255,255,.6);border:1px solid rgba(255,255,255,.88);box-shadow:var(--shadow-sm);
}
.r-play svg{width:14px;height:14px;color:var(--tile-raksa-1)}
/* ไอคอนตามสถานะปุ่ม (aria-pressed=true = หยุดอยู่) ไม่ผูกกับ .is-paused เพราะ reduced-motion ไม่ใส่คลาสนั้น */
.r-play__play{display:none}
.r-play[aria-pressed="true"] .r-play__pause{display:none}
.r-play[aria-pressed="true"] .r-play__play{display:block}
.r-facts{margin:0;font-size:12.5px;color:var(--ink-mute)}
.r-facts a{color:var(--tile-raksa-1);font-weight:600}
/* หยุดชั่วคราว = ทุกอย่างค้างอยู่ที่เดิม */
.r-flow.is-paused :is(.r-scene,.r-scene *,.r-step__bar i){animation-play-state:paused!important}

/* ---------- 4. ฉาก 1: ค้นหา / ลงทะเบียน ---------- */
.s1-cover{transform:translateX(150px)}
.s1-cursor{transform:translate(508px,194px)}
.s1-ripple{opacity:0}
.is-active .s1-cover{animation:s1Type 1.1s steps(10) .3s both}
.is-active .s1-row1{animation:rUp .5s ease-out 1.5s both}
.is-active .s1-row2{animation:rUp .5s ease-out 1.7s both}
.is-active .s1-new{animation:rUp .5s ease-out 1.9s both}
.is-active .s1-cursor{animation:s1Cur 1s cubic-bezier(.4,0,.2,1) 2.3s both}
.is-active .s1-btn{animation:rPress .35s ease 3.3s both}
.is-active .s1-ripple{animation:rRipple .8s ease-out 3.35s both}
@keyframes s1Type{from{transform:translateX(0)}to{transform:translateX(150px)}}
@keyframes s1Cur{from{opacity:0;transform:translate(600px,390px)}25%{opacity:1}to{opacity:1;transform:translate(508px,194px)}}

/* ---------- 5. ฉาก 2: พิมพ์ใบ ---------- */
.is-active .s2-paper{animation:s2Out 2.2s cubic-bezier(.3,.7,.3,1) .5s both}
.is-active .s2-printer{animation:s2Shake .16s linear .5s 12 both}
.is-active .s2-led{animation:rBlink .4s linear .5s 5 both}
.is-active .s2-chip--a{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 2.8s both}
.is-active .s2-chip--b{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 3.1s both}
.is-active .s2-chip--c{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 3.4s both}
@keyframes s2Out{from{transform:translateY(-240px)}}
@keyframes s2Shake{50%{transform:translateY(1.5px)}}

/* ---------- 6. ฉาก 3: ยิงบาร์โค้ด → ประวัติเปิด ---------- */
.s3-beam,.s3-beep{opacity:0}
.is-active .s3-gun{animation:s3Gun .8s cubic-bezier(.2,.8,.3,1) .2s both}
.is-active .s3-beam{animation:s3Flash .55s ease-out 1.05s both}
.is-active .s3-glow{animation:s3Glow .7s ease-out 1.05s both}
.is-active .s3-beep{animation:s3Beep 1.4s ease-out 1.1s both}
.is-active .s3-screen{animation:rPop .55s cubic-bezier(.34,1.56,.64,1) 1.6s both}
.is-active .s3-row--1{animation:rUp .4s ease-out 2.0s both}
.is-active .s3-row--2{animation:rUp .4s ease-out 2.15s both}
.is-active .s3-row--3{animation:rUp .4s ease-out 2.3s both}
.is-active .s3-row--4{animation:rUp .4s ease-out 2.45s both}
.is-active .s3-doc{animation:rUp .5s ease-out 2.6s both}
@keyframes s3Gun{from{opacity:0;transform:translate(80px,60px)}}
@keyframes s3Flash{0%{opacity:0}20%{opacity:1}100%{opacity:0}}
@keyframes s3Glow{0%{opacity:0}25%{opacity:.25}100%{opacity:0}}
@keyframes s3Beep{0%{opacity:0;transform:translateY(8px) scale(.7)}20%{opacity:1;transform:none}75%{opacity:1}100%{opacity:0}}

/* ---------- 7. ฉาก 4: เขียน ----------
   เส้นลายมือ 5 เส้น (pathLength=100) เขียนทีละเส้น เส้นละ .85s ห่างกัน 1s
   ปากกา (ปลายปากกาอยู่ที่ 0,0 ของกลุ่ม) วิ่งตามปลายเส้นที่กำลังเขียน — ช่วง % ในคีย์เฟรมตรงกับเวลาเส้น */
.s4-ink path{stroke-dasharray:100;stroke-dashoffset:0}
.s4-pen{transform:translate(434px,284px)}
.is-active .s4-ink path{animation:s4Ink .85s linear both}
.is-active .s4-ink path:nth-child(1){animation-delay:.4s}
.is-active .s4-ink path:nth-child(2){animation-delay:1.4s}
.is-active .s4-ink path:nth-child(3){animation-delay:2.4s}
.is-active .s4-ink path:nth-child(4){animation-delay:3.4s}
.is-active .s4-ink path:nth-child(5){animation-delay:4.4s}
.is-active .s4-pen{animation:s4Pen 5s linear .4s both}
.is-active .s4-chip{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 5.4s both}
@keyframes s4Ink{from{stroke-dashoffset:100}to{stroke-dashoffset:0}}
@keyframes s4Pen{
  0%{transform:translate(200px,150px)} 17%{transform:translate(408px,150px)}
  20%{transform:translate(200px,174px)} 37%{transform:translate(356px,174px)}
  40%{transform:translate(200px,198px)} 57%{transform:translate(434px,198px)}
  60%{transform:translate(200px,260px)} 77%{transform:translate(330px,260px)}
  80%{transform:translate(200px,284px)} 97%,100%{transform:translate(434px,284px)}
}

/* ---------- 8. ฉาก 5: สแกนเก็บ → แยกเข้าแฟ้ม ----------
   กระดาษ 3 แผ่น (3 คน) ไหลลงเครื่องสแกนทีละแผ่น แล้วแผ่นเล็กบินไปเข้าแฟ้มของเจ้าของ (--dx/--dy ใน HTML) */
.s5-sheet{transform:translateY(150px)}
.s5-mini{opacity:0}
.is-active .s5-sheet{animation:s5Feed .6s ease-in both}
.is-active .s5-sheet--1{animation-delay:.3s}
.is-active .s5-sheet--2{animation-delay:.9s}
.is-active .s5-sheet--3{animation-delay:1.5s}
.is-active .s5-light{animation:rBlink .6s ease-in-out .3s 3 both}
.is-active .s5-mini--1{animation:s5Fly .9s cubic-bezier(.4,0,.2,1) 1.0s both}
.is-active .s5-mini--2{animation:s5Fly .9s cubic-bezier(.4,0,.2,1) 1.6s both}
.is-active .s5-mini--3{animation:s5Fly .9s cubic-bezier(.4,0,.2,1) 2.2s both}
.is-active .s5-folder--1{animation:rBump .4s ease 1.8s both}
.is-active .s5-folder--2{animation:rBump .4s ease 2.4s both}
.is-active .s5-folder--3{animation:rBump .4s ease 3.0s both}
.is-active .s5-folder--1 .s5-check{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 1.85s both}
.is-active .s5-folder--2 .s5-check{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 2.45s both}
.is-active .s5-folder--3 .s5-check{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 3.05s both}
.is-active .s5-chip{animation:rPop .45s cubic-bezier(.34,1.56,.64,1) 3.6s both}
@keyframes s5Feed{from{transform:translateY(0)}to{transform:translateY(150px)}}
@keyframes s5Fly{
  0%{opacity:0;transform:translate(0,0)}
  15%{opacity:1}
  50%{transform:translate(calc(var(--dx) * .5),calc(var(--dy) * .5 - 40px))}
  85%{opacity:1}
  100%{opacity:0;transform:translate(var(--dx),var(--dy))}
}

/* คีย์เฟรมที่ใช้ร่วมกันหลายฉาก */
@keyframes rUp{from{opacity:0;transform:translateY(12px)}}
@keyframes rPop{from{opacity:0;transform:scale(.6)}}
@keyframes rPress{50%{transform:scale(.92)}}
@keyframes rRipple{from{opacity:.9;transform:scale(.5)}to{opacity:0;transform:scale(1.7)}}
@keyframes rBlink{0%,100%{opacity:1}50%{opacity:.25}}
@keyframes rBump{50%{transform:scale(1.04)}}

/* ---------- 9. Responsive ---------- */
/* แท็บเล็ต/มือถือ: ภาพอยู่บน รายการขั้นเหลือแค่วงกลมเลข 5 อันเรียงแถว (ชื่อขั้นดูที่ป้าย .r-now ในเวที) */
@media (max-width:1040px){
  .r-flow{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) auto}
  .r-steps{grid-template-columns:repeat(5,minmax(0,1fr));grid-auto-rows:auto}
  .r-step{grid-template-columns:1fr;justify-items:center;padding:8px 4px 10px}
  .r-step.is-active{transform:translateY(-3px)}
  .r-step__text{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
}
@media (max-width:600px){
  .r-cta__reg{display:none}
  .r-cta .btn{padding:10px 16px;font-size:14px}
  .r-page .brand__en{display:none}
  .r-scene{padding:8px 6px 48px}
  .r-now{font-size:13.5px}
  .r-rail__foot{justify-content:center}
  .r-facts{text-align:center}
}
