/**
 * Image Galaxy widget.
 *
 * A scroll-driven 3D field of floating images behind an animated heading and
 * pill button. Motion is applied per-particle by assets/js/widgets/image-galaxy.js;
 * this file owns layout, the depth wash, the heading word-reveal and the button.
 * All selectors are scoped under .rsi-galaxy so multiple instances and other
 * page styles never collide.
 *
 * Ported from Skyweb Toolkit; theme-variable fallbacks replaced with literals
 * (RSI runs Woodmart, which has no --skyweb-* tokens), heading set to Alexandria.
 */

.rsi-galaxy {
  /* Section background — the image field and fades blend into this. Overridden
     by the Background control (defaults white). */
  --sg-bg: #fff;
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  isolation: isolate;
  display: grid;
  place-items: center;
  background: var(--sg-bg);
  perspective: 800px;
}

.rsi-galaxy__layer {
  position: absolute;
  top: -25%;
  left: 0;
  z-index: 0;
  width: 100%;
  height: 150%;
  perspective: 800px;
  transform-style: preserve-3d;
  pointer-events: none;
}

.rsi-galaxy__fade {
  position: absolute;
  left: -10%;
  z-index: 1;
  width: 120%;
  height: 190px;
  pointer-events: none;
}

/* Each fade defaults to the section background, or its own colour control. */
.rsi-galaxy__fade--top {
  top: 0;
  background: linear-gradient(to bottom, var(--sg-fade-top, var(--sg-bg)) 0%, transparent 100%);
}

.rsi-galaxy__fade--bottom {
  bottom: 0;
  background: linear-gradient(to top, var(--sg-fade-bottom, var(--sg-bg)) 0%, transparent 100%);
}

.rsi-galaxy__particle {
  position: absolute;
  aspect-ratio: 1;
  width: clamp(50px, 6vw, 108px);
  transform-style: preserve-3d;
  will-change: transform, filter;
  pointer-events: auto; /* enable hover; particles sit behind the content layer */
}

.rsi-galaxy__particle-inner {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 12px;
  background: color-mix(in srgb, #111 8%, var(--sg-bg));
  box-shadow: 0 12px 34px rgba(0, 0, 0, .18);
  transition: transform .35s cubic-bezier(.22, 1, .36, 1);
}

/* Optional brand tint wash (Brand Tint control sets --sg-tint). */
.rsi-galaxy__particle-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sg-tint, transparent);
  mix-blend-mode: color;
  pointer-events: none;
}

.rsi-galaxy__particle:hover .rsi-galaxy__particle-inner {
  transform: scale(1.06);
}

/* Any aspect ratio is auto-fitted to the square by centre-cropping.
   width/height forced with !important so themes that ship a global
   `img { height: auto !important }` (Woodmart does) can't letterbox the
   tile — otherwise the image sits at its natural aspect inside the square,
   leaving empty space and defeating object-fit: cover. */
.rsi-galaxy__particle-inner img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transform: scale(1.04);
  transition: opacity .45s ease, transform .9s ease;
}

.rsi-galaxy__particle img.is-loaded {
  opacity: 1;
  transform: scale(1);
}

.rsi-galaxy__wash {
  position: absolute;
  inset: 0;
  background: var(--sg-bg);
  pointer-events: none;
}

/* Soft glow (page-colour) behind the heading so the copy always reads clearly
   over the image field. Sits above the particles (z1) and below content (z2). */
.rsi-galaxy__scrim {
  position: absolute;
  z-index: 1;
  top: 50%;
  /* Follows the "Content Alignment" control so the glow stays under the heading
     wherever it sits. Falls back to centre when the control emits nothing. */
  left: var(--sg-scrim-x, 50%);
  width: min(1100px, 94%);
  height: min(560px, 72%);
  transform: translate(-50%, -50%);
  background: radial-gradient(
    ellipse at center,
    var(--sg-bg) 0%,
    color-mix(in srgb, var(--sg-bg) 55%, transparent) 40%,
    transparent 72%
  );
  pointer-events: none;
}

.rsi-galaxy__content {
  position: relative;
  z-index: 2;
  width: min(100%, 1180px);
  /* Only the TEXT is inset; the image field behind it stays full-bleed. Fed by
     the "Content Inset" control, defaulting to the 20px this always used. */
  padding: 0 var(--sg-content-pad, 20px);
  /* Set by the "Content Alignment" control; centre when it emits nothing.
     image-galaxy.js reads the COMPUTED value of this to move the particles'
     clear zone to match, so images never land on a side-aligned heading. */
  text-align: var(--sg-align, center);
}

.rsi-galaxy__heading {
  margin: 0;
  font-family: 'Alexandria', sans-serif;
  color: #111;
  font-size: clamp(58px, 10vw, 168px);
  font-weight: 500;
  line-height: .92;
  letter-spacing: -.045em;
}

.rsi-galaxy__line {
  display: block;
}

.rsi-galaxy__word {
  position: relative;
  display: inline-block;
  opacity: 0;
  transform: translate3d(var(--tx, 0), var(--ty, 0), 0);
  animation: rsi-galaxy-word-in .9s cubic-bezier(.22, 1, .36, 1) forwards;
  animation-delay: var(--delay, 0s);
}

/* Apple-style "liquid glass" pill: a frosted translucent surface that blurs the
   image field behind it, with a top specular highlight + soft drop shadow. */
.rsi-galaxy__button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 52px;
  margin-top: 48px;
  padding: 15px 24px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.55);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
          backdrop-filter: blur(16px) saturate(1.6);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .20), inset 0 1px 0 rgba(255, 255, 255, .25);
  text-decoration: none;
  font-size: 15px;
  line-height: 1;
  transition: transform .25s ease, background .25s ease, box-shadow .25s ease;
}

.rsi-galaxy__button:hover {
  transform: translateY(-2px);
  background: rgba(17, 24, 39, 0.66);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .26), inset 0 1px 0 rgba(255, 255, 255, .30);
}

/*
 * The arrow points the way the text reads, so it has to turn round for Arabic.
 *
 * It is a literal → in the markup. Flex already puts it on the trailing side —
 * the LEFT in Arabic — but it kept pointing right, back towards the label it is
 * supposed to be leading away from.
 *
 * scaleX(-1) rather than swapping the glyph for ←, matching how
 * .rsi-coming-soon__arrow already handles this in coming-soon.css. One arrow, one
 * behaviour, and it also covers a future SVG.
 */
[dir="rtl"] .rsi-galaxy__arrow {
  display: inline-block;
  transform: scaleX(-1);
}

/* No-backdrop-filter fallback: fall back to a solid readable pill. */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .rsi-galaxy__button { background: #111827; }
}

/* Editor placeholder (no images uploaded yet). */
.rsi-galaxy--empty {
  min-height: 320px;
  color: #777;
  font-size: 16px;
  background: #f5f5f3;
}

@keyframes rsi-galaxy-word-in {
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@media (max-width: 699px) {
  .rsi-galaxy__fade {
    height: 160px;
  }

  .rsi-galaxy__heading {
    font-size: clamp(58px, 17vw, 82px);
    line-height: .98;
    letter-spacing: -.035em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rsi-galaxy__word {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .rsi-galaxy__particle {
    transform: none !important;
  }
}
