/* ==========================================================================
   Suriha's – Hanging rope popup (Shop by Category)
   Load AFTER css/style.css on index.html

   Open : the card lowers from the nail on a rope, bounces, then swings.
   Close: scissors cut the rope, the card falls off the bottom of the screen,
          and the "Order now" button flies (arc + wiggle) to a floating button
          at the bottom-right.
   Only transform/opacity (plus the short rope height) are animated.
   ========================================================================== */

.cp-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.62);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cp-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

/* The swinging group. Pivot = the nail (top-left corner of a 0-width box) */
.cp-hang {
  --rope: clamp(70px, 17vh, 150px);
  --rope-low: 30px;
  --rope-up: calc(var(--rope) - var(--rope-low));
  --w: min(380px, calc(100vw - 32px));
  --amp: 7deg;

  position: absolute;
  top: 14px;
  left: 50%;
  width: 0;
  transform-origin: 0 0;
}

/* ---------------- Nail ---------------- */
.cp-nail {
  position: absolute;
  top: -8px;
  left: -8px;
  z-index: 5;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #9ca3af;
  border: 2px solid #4b5563;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.cp-nail::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: #e5e7eb;
}

/* ---------------- Rope ---------------- */
.cp-rope {
  width: 6px;
  border-radius: 3px;
  background: repeating-linear-gradient(160deg, #c49a55 0 3px, #8a6a30 3px 6px);
  box-shadow: 0 0 0 0.5px rgba(60, 40, 10, 0.5);
}

.cp-rope-up {
  position: relative;
  z-index: 1;
  height: var(--rope-up);
  margin-left: -3px;
  transform-origin: 50% 0;
}

.cp-rope-low {
  height: var(--rope-low);
  margin: 0 auto;
}

/* ---------------- Falling part: short rope + card ---------------- */
.cp-fall {
  position: relative;
  z-index: 2;
  width: var(--w);
  margin-left: calc(var(--w) / -2);
  transform-origin: 50% 25%;
}

.cp-ring {
  position: absolute;
  top: calc(var(--rope-low) - 9px);
  left: 50%;
  z-index: 4;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  border-radius: 50%;
  border: 3px solid #6b7280;
  background: transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* ---------------- Card ---------------- */
.cp-box {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.45);
}

.cp-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.cp-close:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: rotate(90deg);
}

.cp-head {
  padding: 36px 22px 20px;
  text-align: center;
  background: var(--brand-green, #1e824c);
}

.cp-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #ffffff;
  color: var(--brand-green, #1e824c);
  font-size: 1.8rem;
}

.cp-head .cp-title {
  margin: 0 0 4px;
  color: #ffffff;
  font-family: var(--font-heading, sans-serif);
  font-size: 2.3rem;
  font-weight: 700;
}

.cp-head .cp-sub {
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  font-size: 1rem;
}

.cp-body {
  padding: 18px 20px 22px;
}

/* ---------------- Buttons ---------------- */
.cp-btn,
.cp-btn:hover {
  text-decoration: none;
}

.cp-btn {
  position: relative;
  overflow: hidden;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border-radius: 12px;
  font-family: var(--font-heading, sans-serif);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.cp-btn:hover {
  transform: translateY(-2px);
}

.cp-btn-order,
.cp-btn-order:hover {
  color: #ffffff;
}

.cp-btn-order {
  background: #1b4f0e;
  border: 2px solid #1b4f0e;
  box-shadow: 0 8px 20px rgba(27, 79, 14, 0.3);
}

.cp-btn-order:hover {
  background: var(--brand-green-hover, #166534);
  border-color: var(--brand-green-hover, #166534);
}

.cp-btn-order::after {
  content: "";
  position: absolute;
  top: 0;
  left: -75%;
  width: 45%;
  height: 100%;
  background: rgba(255, 255, 255, 0.35);
  transform: skewX(-20deg);
  pointer-events: none;
}

.cp-btn-explore,
.cp-btn-explore:hover {
  color: #1b4f0e;
}

.cp-btn-explore {
  margin-top: 10px;
  background: #ffffff;
  border: 2px solid #1b4f0e;
}

.cp-btn-explore:hover {
  background: var(--brand-green-light, #f0fdf4);
}

.cp-btn-explore i {
  display: inline-block;
}

/* ---------------- Scissors ---------------- */
.cp-scissors {
  position: absolute;
  top: var(--rope-up);
  left: -15px;
  z-index: 6;
  width: 30px;
  height: 30px;
  margin-top: -15px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #ffffff;
  color: #374151;
  font-size: 0.85rem;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
}

/* ==========================================================================
   OPEN: lower on the rope, bounce, swing
   ========================================================================== */
.cp-overlay.is-open .cp-rope-up {
  animation: cpRopeDown 0.95s backwards;
}

@keyframes cpRopeDown {
  0%   { height: 0; animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.6); }
  52%  { height: calc(var(--rope-up) * 1.12); animation-timing-function: ease-out; }
  74%  { height: calc(var(--rope-up) * 0.96); animation-timing-function: ease-in-out; }
  100% { height: var(--rope-up); }
}

.cp-overlay.is-open .cp-hang {
  animation: cpSwing 2.8s ease-in-out 0.6s backwards;
}

@keyframes cpSwing {
  0%   { transform: rotate(0); }
  14%  { transform: rotate(var(--amp)); }
  34%  { transform: rotate(calc(var(--amp) * -0.72)); }
  52%  { transform: rotate(calc(var(--amp) * 0.46)); }
  68%  { transform: rotate(calc(var(--amp) * -0.28)); }
  82%  { transform: rotate(calc(var(--amp) * 0.14)); }
  100% { transform: rotate(0); }
}

.cp-overlay.is-open .cp-icon {
  animation: cpIconPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s backwards;
}

@keyframes cpIconPop {
  0%   { transform: scale(0) rotate(-90deg); }
  100% { transform: scale(1) rotate(0); }
}

.cp-overlay.is-open .cp-btn-order::after {
  animation: cpShine 2.8s ease-in-out 1.6s infinite;
}

@keyframes cpShine {
  0%        { left: -75%; }
  45%, 100% { left: 135%; }
}

.cp-overlay.is-open .cp-btn-explore i {
  animation: cpArrow 1.4s ease-in-out 1.6s infinite;
}

@keyframes cpArrow {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(5px); }
}

/* ==========================================================================
   CLOSE: scissors snip -> rope cut -> card falls away
   ========================================================================== */
.cp-overlay.is-cut .cp-scissors {
  animation: cpSnip 0.42s ease-out forwards;
}

@keyframes cpSnip {
  0%   { opacity: 0; transform: translateX(46px) rotate(-30deg) scale(0.7); }
  35%  { opacity: 1; transform: translateX(0) rotate(0) scale(1); }
  50%  { opacity: 1; transform: rotate(-24deg); }
  65%  { opacity: 1; transform: rotate(8deg); }
  80%  { opacity: 1; transform: rotate(-24deg); }
  100% { opacity: 1; transform: rotate(0); }
}

.cp-overlay.is-falling .cp-scissors {
  animation: cpSnipOut 0.3s ease-in forwards;
}

@keyframes cpSnipOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to   { opacity: 0; transform: translateX(30px) scale(0.7); }
}

/* Upper rope stays on the nail, frayed end, whips back and forth */
.cp-overlay.is-falling .cp-rope-up {
  clip-path: polygon(0 0, 100% 0, 100% 88%, 70% 100%, 50% 84%, 30% 100%, 0 90%);
  animation: cpWhip 1s ease-out;
}

@keyframes cpWhip {
  0%   { transform: rotate(0); }
  18%  { transform: rotate(-16deg); }
  40%  { transform: rotate(11deg); }
  60%  { transform: rotate(-6deg); }
  80%  { transform: rotate(3deg); }
  100% { transform: rotate(0); }
}

/* Lower rope + card drop with gravity */
.cp-overlay.is-falling .cp-rope-low {
  clip-path: polygon(0 12%, 30% 0, 55% 18%, 80% 0, 100% 14%, 100% 100%, 0 100%);
}

.cp-overlay.is-falling .cp-fall {
  animation: cpFall 0.85s cubic-bezier(0.55, 0, 0.95, 0.55) forwards;
}

@keyframes cpFall {
  0%   { transform: translateY(0) rotate(0); }
  100% { transform: translateY(125vh) rotate(var(--fall-rot, 14deg)); }
}

/* ==========================================================================
   Floating "Explore products" button (after popup is cut)
   ========================================================================== */
.cp-fab {
  position: fixed;
  right: 20px;
  bottom: var(--cp-fab-bottom, 36px); /* raise/lower if it touches your back-to-top button */
  z-index: 1030; /* under Bootstrap offcanvas/modal, under the popup */
  display: flex;
  align-items: center;
  height: 58px;
  border-radius: 29px;
  overflow: hidden;
  background: #1b4f0e;
  color: #ffffff;
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(27, 79, 14, 0.4);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease,
    background-color 0.2s ease, box-shadow 0.2s ease;
}

.cp-fab:hover,
.cp-fab:focus-visible {
  color: #ffffff;
  text-decoration: none;
  background: var(--brand-green-hover, #166534);
  box-shadow: 0 10px 26px rgba(27, 79, 14, 0.5);
}

.cp-fab.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.cp-fab-icon {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

/* Text is hidden until hover / focus, then slides out to the left */
.cp-fab-label {
  max-width: 0;
  padding-left: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  font-family: var(--font-heading, sans-serif);
  font-size: 0.95rem;
  font-weight: 700;
  transition: max-width 0.35s ease, padding-left 0.35s ease, opacity 0.25s ease;
}

.cp-fab:hover .cp-fab-label,
.cp-fab:focus-visible .cp-fab-label {
  max-width: 210px;
  padding-left: 20px;
  opacity: 1;
}

/* The copy of "Order now" that flies from the card to the corner
   (position, size, tilt and shadow are driven frame by frame from JS) */
.cp-fly {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow: hidden;
  border-radius: 12px;
  background: #1b4f0e;
  color: #ffffff;
  font-family: var(--font-heading, sans-serif);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  transform-origin: 50% 50%;
  will-change: transform, width, height;
}

.cp-fly i {
  flex: 0 0 auto;
  font-size: 1.35rem;
}

/* Touchdown: squash, wiggle, then a soft pulse ring */
.cp-fab.is-landing {
  transform-origin: 50% 60%;
  animation: cpFabLand 0.95s ease-out, cpFabPulse 0.95s ease-out;
}

@keyframes cpFabLand {
  0%   { transform: scale(1.14, 0.84) rotate(0); }
  16%  { transform: scale(0.92, 1.1) rotate(-17deg); }
  34%  { transform: scale(1.05, 0.96) rotate(14deg); }
  52%  { transform: scale(1) rotate(-9deg); }
  70%  { transform: scale(1) rotate(5deg); }
  86%  { transform: scale(1) rotate(-2deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes cpFabPulse {
  0%   { box-shadow: 0 8px 22px rgba(27, 79, 14, 0.4), 0 0 0 0 rgba(46, 125, 50, 0.55); }
  100% { box-shadow: 0 8px 22px rgba(27, 79, 14, 0.4), 0 0 0 20px rgba(46, 125, 50, 0); }
}

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 480px) {
  .cp-hang { --amp: 4deg; }
  .cp-head { padding: 34px 18px 18px; }
  .cp-body { padding: 16px 16px 20px; }
  .cp-fab { right: 14px; }
}

@media (max-height: 600px) {
  .cp-hang { --rope: 56px; }
  .cp-head { padding: 28px 18px 14px; }
  .cp-icon { width: 46px; height: 46px; margin-bottom: 8px; font-size: 1.3rem; }
  .cp-body { padding: 14px 18px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .cp-overlay.is-open .cp-rope-up,
  .cp-overlay.is-open .cp-hang,
  .cp-overlay.is-open .cp-icon,
  .cp-overlay.is-open .cp-btn-order::after,
  .cp-overlay.is-open .cp-btn-explore i {
    animation: none;
  }

  .cp-fab,
  .cp-fab-label {
    transition: none;
  }

  .cp-fab.is-landing {
    animation: none;
  }
}