/* ============================================================
   Section "เกลี่ยครีม" (v3) — เกลี่ยครีมเพื่อดูจุดเด่นของสินค้า + สลับสินค้าอัตโนมัติ
   ใช้คู่กับ assets/js/pages/swatch.js
   สีของแต่ละสินค้ามาจาก bg / accent ใน story-data.js (ตั้งเป็น --p-bg / --p-accent)
   ============================================================ */
@property --p-bg { syntax: "<color>"; inherits: true; initial-value: #ffbac6; }
@property --p-accent { syntax: "<color>"; inherits: true; initial-value: #9ed89b; }

.wipe {
  --ink: var(--s-char, #2d3a30);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --p-bg: #ffbac6;
  --p-accent: #9ed89b;
  position: relative;
  padding: clamp(4rem, 9vw, 7.5rem) 0;
  color: var(--ink);
  background:
    radial-gradient(70% 55% at 85% 0%, color-mix(in srgb, var(--p-accent) 22%, transparent), transparent 70%),
    /* ไล่สีเข้มสุดกลาง section แล้วจางกลับเป็นขาวที่ขอบล่าง ให้ต่อกับ footer (เริ่มที่สีขาว) แบบไม่เห็นรอย */
    linear-gradient(180deg, var(--s-cream, #fff9fa) 0%, color-mix(in srgb, var(--p-bg) 40%, #fff) 48%, color-mix(in srgb, var(--p-bg) 30%, #fff) 68%, #fff 100%);
  transition: --p-bg 0.9s ease, --p-accent 0.9s ease;
  overflow: hidden;
}

/* เมื่อ section นี้ถูกซ่อน (attribute hidden) ส่วนรีวิวสีครีม #f7f4ee จะต่อกับ footer โดยตรง
   → ให้ขอบบนของ footer เริ่มที่สีเดียวกัน แล้วค่อยจางเผยวิดีโอ จะได้ไม่เห็นรอยต่อ */
body:has(.wipe[hidden]) .sfoot {
  background: #f7f4ee;
}

body:has(.wipe[hidden]) .sfoot__veil {
  background: linear-gradient(180deg, #f7f4ee 0%, #f7f4ee 6%, rgba(247, 244, 238, 0.86) 24%, rgba(250, 248, 245, 0.5) 52%, rgba(255, 255, 255, 0) 80%);
}

/* ---------- Head ---------- */
.wipe__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: clamp(1.6rem, 3.5vw, 2.8rem);
}

.wipe__kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.wipe__kicker::before {
  content: "";
  width: 34px;
  height: 2px;
  background: currentColor;
}

.wipe__title {
  font-family: var(--font-heading);
  font-size: clamp(2rem, 4.6vw, 3.6rem);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.wipe__title em {
  font-style: normal;
  background: linear-gradient(transparent 62%, color-mix(in srgb, var(--p-accent) 70%, #fff) 62%);
  transition: --p-accent 0.9s ease;
}

.wipe__lead {
  max-width: 30ch;
  padding-bottom: 0.5rem;
  text-align: right;
  font-size: 1.02rem;
  line-height: 1.65;
  opacity: 0.75;
}

/* ---------- Stage ---------- */
.wipe__stage {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: clamp(1.2rem, 2.6vw, 2.2rem);
  align-items: stretch;
}

.wipe__pad {
  position: relative;
  min-height: clamp(380px, 46vw, 580px);
  border-radius: 44px;
  overflow: hidden;
  isolation: isolate;
  cursor: grab;
  touch-action: pan-y;
  box-shadow: 0 50px 80px -40px color-mix(in srgb, var(--p-accent) 55%, rgba(45, 58, 48, 0.5)), 0 0 0 1px rgba(255, 255, 255, 0.7) inset;
  transition: --p-accent 0.9s ease;
}

.wipe__pad:active {
  cursor: grabbing;
}

/* ชั้นที่ซ่อนอยู่ใต้ครีม */
.wipe__under {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(46% 52% at 50% 46%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 72%),
    linear-gradient(140deg, color-mix(in srgb, var(--p-bg) 78%, #fff), var(--p-bg) 55%, color-mix(in srgb, var(--p-bg) 72%, var(--p-accent)));
  transition: --p-bg 0.9s ease, --p-accent 0.9s ease;
}

.wipe__big {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-7deg);
  font-family: var(--font-display);
  font-synthesis: none;
  font-size: clamp(3.4rem, 10.5vw, 9.5rem);
  line-height: 0.9;
  white-space: nowrap;
  color: transparent;
  -webkit-text-stroke: 2px rgba(255, 255, 255, 0.75);
  user-select: none;
  pointer-events: none;
}

.wipe__product {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  height: 80%;
  margin: 0;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.wipe__product img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 34px 30px color-mix(in srgb, var(--p-accent) 45%, rgba(45, 58, 48, 0.45)));
  animation: wipe-float 5s ease-in-out infinite;
  transition: transform 0.8s var(--spring);
}

@keyframes wipe-float {
  0%, 100% { translate: 0 0; rotate: 5deg; }
  50% { translate: 0 -12px; rotate: 2deg; }
}

.wipe__pad.is-done .wipe__product img {
  transform: scale(1.08);
}

/* ป้ายจุดเด่น 3 ข้อ */
.wipe__claims {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}

.wipe__claims li {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  max-width: 34%;
  padding: 0.7rem 1.1rem 0.7rem 0.7rem;
  background: rgba(255, 255, 255, 0.82);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  box-shadow: 0 14px 30px -12px rgba(45, 58, 48, 0.35);
  font-family: var(--font-heading);
  font-size: clamp(0.86rem, 1.15vw, 1.05rem);
  font-weight: 600;
  line-height: 1.3;
}

.wipe__claims li i {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--p-accent);
  color: #fff;
  font-family: var(--font-display);
  font-style: normal;
  font-size: 0.72rem;
  transition: --p-accent 0.9s ease;
}

.wipe__claims li:nth-child(1) { left: 5%; top: 13%; rotate: -4deg; }
.wipe__claims li:nth-child(2) { right: 4%; top: 42%; rotate: 3deg; }
.wipe__claims li:nth-child(3) { left: 8%; bottom: 12%; rotate: 2deg; }

/* เปิดครีมครบแล้ว → ป้ายเด้ง */
.wipe__pad.is-done .wipe__claims li {
  animation: wipe-pop 0.7s var(--spring) both;
}

.wipe__pad.is-done .wipe__claims li:nth-child(2) { animation-delay: 0.08s; }
.wipe__pad.is-done .wipe__claims li:nth-child(3) { animation-delay: 0.16s; }

@keyframes wipe-pop {
  40% { scale: 1.12; }
}

/* ชั้นครีม */
.wipe__pad canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y; /* จอสัมผัส: ปัดขึ้นลงยังเลื่อนหน้าได้ ลากซ้ายขวาเพื่อเกลี่ยครีม (เดิม none ทำให้เลื่อนหน้าไม่ได้เมื่อนิ้วอยู่บนครีม) */
  transition: opacity 0.7s ease;
}

.wipe__pad canvas.is-clear {
  opacity: 0;
  pointer-events: none;
}

.wipe__pad canvas.is-squeeze {
  animation: wipe-squeeze 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes wipe-squeeze {
  from { opacity: 0; scale: 1.08; }
}

.wipe__hint {
  position: absolute;
  left: 50%;
  top: 90%; /* ชิดล่าง ไม่บังสินค้า */
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1.3rem;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 16px 34px -10px rgba(45, 58, 48, 0.6);
  font-family: var(--font-heading);
  font-weight: 500;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.5s var(--spring);
}

.wipe__hint svg {
  width: 30px;
  color: var(--p-accent);
  animation: wipe-rub 1.5s ease-in-out infinite;
}

@keyframes wipe-rub {
  50% { transform: translateX(6px); }
}

.wipe__pad.is-touched .wipe__hint {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.6);
}

.wipe__meter {
  position: absolute;
  right: 1.2rem;
  top: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.9rem 0.35rem 0.4rem;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.wipe__meter i {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: conic-gradient(var(--p-accent) calc(var(--k, 0) * 360deg), rgba(45, 58, 48, 0.14) 0);
  -webkit-mask: radial-gradient(circle, transparent 46%, #000 48%);
  mask: radial-gradient(circle, transparent 46%, #000 48%);
}

.wipe__pad.is-touched .wipe__meter { opacity: 1; }
.wipe__pad.is-done .wipe__meter { opacity: 0; }

/* ---------- Info panel ---------- */
.wipe__info {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: clamp(1.4rem, 2.6vw, 2.2rem);
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 36px;
  box-shadow: 0 30px 60px -36px rgba(45, 58, 48, 0.45);
}

.wipe__count {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0.6;
}

.wipe__count b {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 400;
  line-height: 1;
  color: var(--p-accent);
  opacity: 1;
  transition: --p-accent 0.9s ease;
}

.wipe__body {
  margin-top: 1.2rem;
}

.wipe__body.is-swap > * {
  animation: wipe-in 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.wipe__body.is-swap > :nth-child(2) { animation-delay: 0.06s; }
.wipe__body.is-swap > :nth-child(3) { animation-delay: 0.12s; }

@keyframes wipe-in {
  from { opacity: 0; transform: translateY(16px); }
}

.wipe__cat {
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.6;
}

.wipe__name {
  margin: 0.3rem 0 0.6rem;
  font-family: var(--font-heading);
  font-size: clamp(1.5rem, 2.5vw, 2.1rem);
  font-weight: 600;
  line-height: 1.2;
  min-height: 2.4em; /* จองที่ 2 บรรทัด — ความสูงหน้าไม่เปลี่ยนทุกครั้งที่สลับสินค้า (กันหน้ากระตุก) */
  color: var(--ink);
}

.wipe__desc {
  min-height: 3.3em; /* จองที่ 2 บรรทัด */
  font-size: 1rem;
  line-height: 1.65;
  opacity: 0.8;
}

.wipe__buy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: auto;
  padding-top: 1.6rem;
}

.wipe__price {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  font-weight: 400;
  line-height: 1;
}

.wipe__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 50px;
  padding: 0.7rem 1.6rem;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-heading);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.4s var(--spring), background 0.25s ease, box-shadow 0.25s ease;
}

.wipe__btn:hover {
  background: color-mix(in srgb, var(--p-accent) 80%, #000);
  transform: translateY(-3px);
  box-shadow: 0 14px 26px -10px color-mix(in srgb, var(--p-accent) 70%, #000);
}

.wipe__btn.is-pulse {
  animation: wipe-pulse 0.8s var(--spring);
}

@keyframes wipe-pulse {
  40% { scale: 1.12; }
}

.wipe__ctrl {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid rgba(45, 58, 48, 0.12);
}

.wipe__round {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(45, 58, 48, 0.14);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.35s var(--spring), background 0.2s ease, color 0.2s ease;
}

.wipe__round svg {
  width: 18px;
  height: 18px;
}

.wipe__round:hover {
  background: var(--ink);
  color: #fff;
  transform: scale(1.08);
}

.wipe__round .ico-play { display: none; }
.wipe__round.is-paused .ico-play { display: block; }
.wipe__round.is-paused .ico-pause { display: none; }

.wipe__reset {
  margin-left: auto;
  padding: 0.55rem 1.1rem;
  background: none;
  color: var(--ink);
  border: 1px solid rgba(45, 58, 48, 0.2);
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.wipe__reset:hover {
  background: var(--ink);
  color: #fff;
}

.wipe :focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* ---------- Thumbnails ---------- */
.wipe__thumbs {
  display: flex;
  gap: 0.7rem;
  margin-top: clamp(1.2rem, 2.4vw, 2rem);
  padding: 0.5rem 0.25rem 0.9rem;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.wipe__thumbs::-webkit-scrollbar {
  display: none;
}

.wipe__thumb {
  --k: 0;
  position: relative;
  flex: 0 0 auto;
  width: 66px;
  height: 66px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.7);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  scroll-snap-align: center;
  transition: transform 0.4s var(--spring), background 0.25s ease;
}

.wipe__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.55;
  transition: opacity 0.25s ease, transform 0.4s var(--spring);
}

/* วงแหวนเวลา: วิ่งรอบสินค้าที่กำลังแสดง */
.wipe__thumb::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(var(--c, var(--ink)) calc(var(--k) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 64%, #000 66%);
  mask: radial-gradient(circle, transparent 64%, #000 66%);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.wipe__thumb:hover {
  transform: translateY(-4px);
}

.wipe__thumb:hover img,
.wipe__thumb.is-active img {
  opacity: 1;
}

.wipe__thumb.is-active {
  background: #fff;
  transform: scale(1.12);
}

.wipe__thumb.is-active::before {
  opacity: 1;
}

.wipe__thumb.is-active img {
  transform: scale(1.1);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .wipe__head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }

  .wipe__lead {
    max-width: none;
    text-align: left;
    padding-bottom: 0;
  }

  .wipe__stage {
    grid-template-columns: 1fr;
  }

  .wipe__pad {
    min-height: 0;
    aspect-ratio: 4 / 5;
    border-radius: 32px;
  }

  .wipe__info {
    border-radius: 28px;
  }

  .wipe__product {
    top: 34%;
    width: 60%;
    height: 54%;
  }

  .wipe__hint {
    top: 9%;
  }

  .wipe__big {
    top: 34%;
    font-size: clamp(3rem, 19vw, 7rem);
  }

  /* จอเล็ก: ป้ายเรียงกันด้านล่าง */
  .wipe__claims {
    inset: auto 4% 4% 4%;
    display: grid;
    gap: 0.45rem;
  }

  .wipe__claims li,
  .wipe__claims li:nth-child(n) {
    position: static;
    max-width: none;
    padding: 0.5rem 0.9rem 0.5rem 0.5rem;
    rotate: none;
    font-size: 0.9rem;
  }

  .wipe__claims li i {
    width: 28px;
    height: 28px;
  }

  .wipe__thumb {
    width: 58px;
    height: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wipe__product img,
  .wipe__hint svg {
    animation: none;
  }
}
