/*
 * Referral Gift popup.
 *
 * Design reference is the retired Eid modal: darkened blurred overlay, artwork
 * on one side and copy on the other, stacked on mobile, gold close control.
 * The palette is not carried over. That modal was near-black and bright gold;
 * this one uses the same emerald / cream / muted-gold tokens as the carousel so
 * the two promotional surfaces read as one system.
 *
 * Decoration is CSS only. The original used three full-screen <canvas> particle
 * engines with their own rAF loops; the announcement bar already proves a
 * two-layer radial-gradient drift is enough, costs nothing, and is trivial to
 * disable under reduced motion.
 */

.and-referral-popup,
.and-referral-popup * {
  box-sizing: border-box;
}

.and-referral-popup[hidden] {
  display: none !important;
}

/*
 * Scroll lock. A class, not an inline style: the retired modal wrote
 * body.style.overflow and restored it to '', which would silently discard any
 * inline overflow the page already carried.
 */
body.and-popup-open {
  overflow: hidden;
}

.and-referral-popup {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3vw, 32px);
  font-family: var(--and-font-body);
}

/*
 * The backdrop is its own element rather than a background on the container.
 * Click-to-close then needs no coordinate maths: a click that lands on the
 * backdrop element is unambiguously outside the card.
 */
.and-referral-popup__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 20, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 320ms ease;
}

.and-referral-popup.is-open .and-referral-popup__backdrop {
  opacity: 1;
}

/* Soft gold bloom behind the card, replacing the old 1300px canvas glow. */
.and-referral-popup__glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(1100px, 130vw);
  height: min(1100px, 130vw);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle,
    rgba(197, 160, 89, 0.30) 0%,
    rgba(197, 160, 89, 0.14) 30%,
    rgba(197, 160, 89, 0.05) 52%,
    transparent 70%);
  filter: blur(30px);
  opacity: 0;
  transition: opacity 420ms ease;
  animation: andReferralGlow 4s ease-in-out infinite;
}

.and-referral-popup.is-open .and-referral-popup__glow {
  opacity: 1;
}

@keyframes andReferralGlow {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -50%) scale(1.06); }
}

.and-referral-popup__card {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  display: grid;
  grid-template-columns: 0.92fr 1.08fr;
  background: var(--and-cream);
  border: 1px solid rgba(197, 160, 89, 0.42);
  border-radius: 18px;
  box-shadow: 0 34px 90px rgba(6, 20, 12, 0.42);
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition: opacity 340ms ease, transform 340ms cubic-bezier(0.22, 1, 0.36, 1);
}

.and-referral-popup.is-open .and-referral-popup__card {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.and-referral-popup__card:focus {
  outline: none;
}

/* ---- artwork ---- */

.and-referral-popup__media {
  position: relative;
  overflow: hidden;
  border-radius: 17px 0 0 17px;
  background: var(--and-emerald-800);
  min-height: 300px;
}

.and-referral-popup__media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  /*
   * gift-of-arabic.webp is a full portrait flyer carrying both offers side by
   * side. The Referral Gift is the right-hand panel, so the crop is pushed off
   * centre to keep that panel in frame at every card height.
   */
  object-position: 68% 44%;
}

/* Emerald veil so cream copy beside it does not read as a second photograph. */
.and-referral-popup__media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(15, 58, 46, 0.30) 0%, rgba(15, 58, 46, 0.06) 55%, transparent 100%);
  pointer-events: none;
}

/* ---- copy ---- */

.and-referral-popup__content {
  position: relative;
  padding: clamp(26px, 3.4vw, 44px) clamp(22px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  overflow: hidden;
  border-radius: 0 17px 17px 0;
}

/*
 * Two drifting particle layers, the same technique and the same tile-per-axis
 * loop as the announcement bar. Both sit beneath the copy and take no pointer
 * events, so they cannot interfere with reading, selecting or clicking.
 */
.and-referral-popup__content::before,
.and-referral-popup__content::after {
  content: "";
  position: absolute;
  inset: -25% -15%;
  z-index: 0;
  pointer-events: none;
  background-repeat: repeat;
  will-change: transform;
}

.and-referral-popup__content::before {
  background-image:
    radial-gradient(circle at 18% 32%, rgba(197, 160, 89, 0.20) 0 1.5px, transparent 2px),
    radial-gradient(circle at 62% 74%, rgba(197, 160, 89, 0.14) 0 1.2px, transparent 1.7px),
    radial-gradient(circle at 84% 24%, rgba(197, 160, 89, 0.17) 0 1.4px, transparent 1.9px);
  background-size: 200px 100px;
  animation: andReferralDriftA 58s linear infinite;
}

.and-referral-popup__content::after {
  background-image:
    radial-gradient(circle at 34% 62%, rgba(37, 109, 86, 0.14) 0 1.3px, transparent 1.8px),
    radial-gradient(circle at 72% 38%, rgba(37, 109, 86, 0.10) 0 1px, transparent 1.5px);
  background-size: 270px 130px;
  animation: andReferralDriftB 80s linear infinite;
}

@keyframes andReferralDriftA {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-200px, -100px, 0); }
}

@keyframes andReferralDriftB {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(270px, 130px, 0); }
}

.and-referral-popup__content > * {
  position: relative;
  z-index: 1;
}

.and-referral-popup__eyebrow {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--and-gold-pill-fg);
}

.and-referral-popup__title {
  margin: 0;
  font-family: var(--and-font-heading);
  font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.3rem);
  font-weight: 600;
  line-height: 1.16;
  color: var(--and-emerald-900);
}

.and-referral-popup__body {
  margin: 0;
  font-size: clamp(0.98rem, 0.94rem + 0.2vw, 1.08rem);
  line-height: 1.6;
  color: var(--and-muted);
}

.and-referral-popup__list {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.and-referral-popup__list li {
  position: relative;
  padding-inline-start: 26px;
  color: var(--and-emerald-900);
}

.and-referral-popup__list li::before {
  content: "";
  position: absolute;
  inset-inline-start: 2px;
  top: 0.55em;
  width: 9px;
  height: 9px;
  transform: rotate(45deg);
  background: var(--and-gold);
  border-radius: 2px;
}

.and-referral-popup__list strong {
  display: block;
  font-size: 1.04rem;
  font-weight: 700;
  line-height: 1.35;
}

.and-referral-popup__list small {
  display: block;
  margin-top: 2px;
  font-size: 0.9rem;
  color: var(--and-muted);
}

.and-referral-popup__actions {
  margin-top: 6px;
}

/* ---- close control ---- */

/*
 * padding: 0 is load-bearing. The site theme applies generous horizontal button
 * padding and, with border-box, the used width floors at the padding sum; the
 * announcement bar shipped a control that rendered twice its declared width for
 * exactly this reason. Size is declared once and consumed by width and height.
 */
.and-referral-popup__close {
  --and-popup-close-size: 42px;
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  z-index: 2;
  appearance: none;
  padding: 0;
  width: var(--and-popup-close-size);
  height: var(--and-popup-close-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(197, 160, 89, 0.55);
  border-radius: 999px;
  background: rgba(249, 247, 242, 0.92);
  color: var(--and-emerald-900);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease;
}

/*
 * The glyph colour is restated for the interactive states, not just the rest
 * state. The theme ships `button:focus, button:hover { color: #fff }`, which at
 * (0,1,1) outranks a bare class selector, and this control takes focus the
 * moment the dialog opens. Left alone the mark rendered white on cream at
 * 1.1:1. Bare `:focus` is listed as well as `:focus-visible`, because the theme
 * rule keys off `:focus` and so applies to pointer focus too.
 */
.and-referral-popup__close,
.and-referral-popup__close:hover,
.and-referral-popup__close:focus,
.and-referral-popup__close:focus-visible {
  color: var(--and-emerald-900);
}

.and-referral-popup__close:hover,
.and-referral-popup__close:focus-visible {
  background: var(--and-gold-pill-bg);
  border-color: var(--and-gold);
  outline: none;
}

.and-referral-popup__close:focus-visible {
  box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.45);
}

/* ---- stacked layout ---- */

@media (max-width: 760px) {
  .and-referral-popup__card {
    grid-template-columns: 1fr;
    max-height: calc(100vh - 24px);
  }

  .and-referral-popup__media {
    min-height: 0;
    height: clamp(150px, 34vw, 220px);
    border-radius: 17px 17px 0 0;
  }

  .and-referral-popup__media img {
    object-position: 68% 38%;
  }

  .and-referral-popup__content {
    border-radius: 0 0 17px 17px;
  }

  /* Clear of the close control, which overlays the artwork on this layout. */
  .and-referral-popup__close {
    background: rgba(249, 247, 242, 0.95);
  }
}

/* ---- reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  /* No entrance transform, no glow pulse, no particle drift. The popup still
     appears and still fades, because an instant swap is its own jolt. */
  .and-referral-popup__card {
    transform: none;
    transition: opacity 1ms linear;
  }

  .and-referral-popup.is-open .and-referral-popup__card {
    transform: none;
  }

  .and-referral-popup__backdrop,
  .and-referral-popup__glow {
    transition: none;
  }

  .and-referral-popup__glow,
  .and-referral-popup__content::before,
  .and-referral-popup__content::after {
    animation: none;
  }
}
