/* checkout-overlay.css
 *
 * Restyles the Lemon Squeezy checkout overlay into a proper in-page modal.
 *
 * Lemon.js (app.lemonsqueezy.com/js/lemon.js) appends a bare
 *   <iframe allow="payment" src="...?embed=1">
 * straight to <body>, with these INLINE styles:
 *
 *   position: fixed; left: 0; top: 0; width: 100%; height: 100%;
 *
 * It sets no id and no class, so the iframe is targeted structurally. Because
 * those styles are inline, every override needs !important.
 *
 * WIDTH MATTERS: Lemon Squeezy's checkout is responsive and drops to its
 * mobile layout below roughly 600px of viewport width. A 460px iframe made
 * the desktop checkout render as a phone-sized column, so the modal is sized
 * ABOVE that breakpoint and the margins are preserved with max-width/height.
 */

/* ---------- backdrop ---------- */
#ls-overlay-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  background: rgba(2, 4, 7, 0.78);
  backdrop-filter: blur(10px) saturate(0.9);
  -webkit-backdrop-filter: blur(10px) saturate(0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

#ls-overlay-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* Lock the page behind the modal while it is open.
   <html> must be locked too: on most browsers <body> alone is not the scrolling
   element, so an unlocked <html> keeps the background scrolling behind the modal.

   Deliberately NO `touch-action: none` here. touch-action participates in the
   ancestor hit-test chain, so declaring it on <body> suppresses scroll and tap
   gestures *inside* the checkout iframe, which made the form feel dead. */
html.ls-overlay-open,
body.ls-overlay-open {
  overflow: hidden !important;
  overscroll-behavior: none;
}
body.ls-overlay-open {
  position: fixed !important;
  width: 100% !important;
}

/* ---------- the checkout iframe ---------- */
body > iframe.ls-checkout-frame {
  position: fixed !important;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) scale(0.985) !important;
  transform-origin: center center !important;

  /* FULL-WIDTH checkout with an even gap on all four sides.
     WIDTH IS LOAD-BEARING, DO NOT SHRINK IT BACK.
     Lemon Squeezy picks its mobile vs desktop checkout from this frame's own
     viewport. While the frame was 680px it served the MOBILE checkout even on a
     desktop browser, which produced two hard failures seen in the console:
       - hCaptcha installed a non-passive, scroll-blocking 'touchmove'
         listener  -> the checkout could not be scrolled at all.
       - PayPal's SDK got platform=mobile and a forced iPhone user agent and
         threw repeatedly from checkIframe  -> a visible crash/retry loop.
     Going near-full-width makes Lemon serve the desktop checkout, which uses
     neither code path.
     Verify after any change: the PayPal SDK URL must NOT contain
     `platform=mobile`. If it does, the frame is still too narrow. */
  --ls-checkout-gap: 20px;
  width: calc(100vw - var(--ls-checkout-gap) * 2) !important;
  max-width: calc(100vw - var(--ls-checkout-gap) * 2) !important;
  height: calc(100vh - var(--ls-checkout-gap) * 2) !important;
  max-height: calc(100vh - var(--ls-checkout-gap) * 2) !important;
  /* dvh tracks the real visible area, so the bottom gap survives mobile
     browser chrome collapsing. Falls back to the vh values above. */
  height: calc(100dvh - var(--ls-checkout-gap) * 2) !important;
  max-height: calc(100dvh - var(--ls-checkout-gap) * 2) !important;
  margin: 0 !important;
  padding: 0 !important;

  /* Deliberately transparent, NOT white.
     Lemon.js can close the checkout content while leaving the <iframe> element
     in the DOM. With a white background that orphan iframe renders as a blank
     panel over the page and swallows every click; transparent makes it
     invisible, and teardownOverlay() still removes it. */
  background-color: transparent !important;
  border: 0 !important;
  border-radius: 16px !important;
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.7),
    0 8px 24px -8px rgba(0, 0, 0, 0.45) !important;

  /* Allow scrolling inside the checkout; prevent chaining to parent. */
  overflow: auto !important;
  overscroll-behavior: contain !important;
  touch-action: auto !important;

  opacity: 0;
  will-change: opacity, transform;
  transition: opacity 0.42s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.52s cubic-bezier(0.16, 1, 0.3, 1);
}

body > iframe.ls-checkout-frame.ls-overlay-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1) !important;
  /* Opaque once revealed: while Lemon is still painting its first frames the
     page must not show through the panel (reported as a "transparent" checkout).
     The orphan-iframe case this originally guarded against is handled in JS --
     teardownOverlay() removes the element outright. */
  background-color: #ffffff !important;
  /* Release the compositor layer: a permanently promoted full-screen iframe
     costs a large texture and shows up as lag while the user types. */
  will-change: auto;
}

/* ---------- our own close control ---------- */
/*
 * Lemon.js only renders its own X when the store has the overlay close button
 * enabled. Without this, a store with it disabled has no way out of the modal.
 * Appended after the iframe so it paints on top at the same z-index.
 */
#ls-overlay-close {
  position: fixed;
  z-index: 2147483647;
  right: 24px;
  top: 24px;
  width: 44px;
  height: 44px;
  margin: 0;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 2px solid rgba(47, 238, 204, 0.35);
  border-radius: 999px;
  cursor: pointer;
  color: #0b1220;
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(47, 238, 204, 0.25);
  opacity: 0;
  transition: opacity 0.42s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.52s cubic-bezier(0.16, 1, 0.3, 1),
    background-color 0.15s ease,
    box-shadow 0.15s ease;
}

#ls-overlay-close.is-visible {
  opacity: 1;
}

#ls-overlay-close:hover {
  background: #f0f7f5;
  transform: scale(1.04);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(47, 238, 204, 0.45);
}

#ls-overlay-close:focus-visible {
  outline: 2px solid var(--accent-1, #2feecc);
  outline-offset: 3px;
}

#ls-overlay-close svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.75;
  stroke-linecap: round;
}

/* ---------- loader ---------- */
#ls-overlay-loader {
  position: fixed;
  z-index: 2147483647;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 32px;
  background: rgba(2, 4, 7, 0.92);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-radius: 16px;
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(47, 238, 204, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

#ls-overlay-loader.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.ls-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(47, 238, 204, 0.2);
  border-top-color: #2feccc;
  border-radius: 50%;
  animation: ls-spin 0.9s linear infinite;
}

@keyframes ls-spin {
  to { transform: rotate(360deg); }
}

.ls-loader-text {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: #e6f0f0;
  text-align: center;
  white-space: nowrap;
}

/* ---------- small viewports ---------- */
@media (max-width: 560px) {
  body > iframe.ls-checkout-frame {
    width: 96vw !important;
    height: 92vh !important;
    border-radius: 12px !important;
  }
}

@media (max-height: 560px) {
  body > iframe.ls-checkout-frame {
    height: 94vh !important;
  }
}

/* ---------- accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  #ls-overlay-backdrop,
  body > iframe.ls-checkout-frame,
  #ls-overlay-close,
  #ls-overlay-loader {
    transition: none !important;
    transform: translate(-50%, -50%) !important;
    opacity: 1;
  }
}