/* ==========================================================================
   SmartAGM v2 — Welcome intro (v2 launch), "ring reveal"
   The title fades in with one light sweep and then flips (bottom to top)
   through its sentences, while a ring around the SmartAGM wordmark fills
   from 0 to 100% (ring and percentage share one ease-in-out curve, driven by
   the JS); then the navy screen opens from the ring's centre. No glows.
   Markup: templates/home/v2/partials/welcome_intro.html (a <template>),
   behaviour: static/script/v2/welcome-intro.js. Only linked while the view
   says the intro is active (welcome_intro_active() in home/views.py).
   ========================================================================== */

/* Both set by welcome-intro.js in <head>, before the first paint.
   .welcome-intro-on (until the intro is gone): no scrolling under it, with the
   scrollbar's space kept reserved (scrollbar-gutter), so the page width never
   changes when the scrollbar comes back; that was a visible jump at the start
   of the opening. The reserved strip is painted navy (the root background).
   .welcome-intro-cover (until the opening or Skip starts): a navy cover so the
   page never shows before the intro is inserted. */
html.welcome-intro-on {
  overflow: hidden;
  scrollbar-gutter: stable;
  background-color: var(--navy-950);
}

html.welcome-intro-cover body::after,
.welcome-intro {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 85% at 50% 0%, var(--navy-800) 0%, var(--navy-900) 55%, var(--navy-950) 100%);
}

html.welcome-intro-cover body::after {
  content: "";
  z-index: calc(var(--z-header) + 50);
}

.welcome-intro {
  z-index: calc(var(--z-header) + 51);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--gutter);
  overflow: hidden;
  color: var(--color-on-dark);
  text-align: center;
}

/* Skip: a quick fade instead of the reveal. */
.welcome-intro.is-leaving {
  opacity: 0;
  transition: opacity 0.3s ease; /* keep in step with SKIP_MS in the JS */
}

.welcome-intro__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-10);
  max-width: 100%;
  transition: opacity 0.35s ease;
}

/* While the screen opens from the ring, the text and ring fade away. */
.welcome-intro.is-opening .welcome-intro__content,
.welcome-intro.is-opening .welcome-intro__skip {
  opacity: 0;
}

/* The title is a flip window: every sentence sits in the same grid cell (so the
   box is as tall as the longest one and nothing below it moves), only
   .is-current shows, and the JS moves it along (bottom to top). */
.welcome-intro__title {
  position: relative;
  display: grid;
  margin: 0;
  padding-block: 0.1em; /* room for accents and Arabic marks inside the clip */
  width: min(22ch, 100%);
  overflow: hidden;
  font-size: clamp(28px, 5vw, 52px);
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  text-wrap: balance;
  opacity: 0;
}

.welcome-intro__title:lang(ar) {
  width: min(26ch, 100%); /* the Arabic face runs wider: keeps the welcome sentence to two rows */
}

.welcome-intro.is-playing .welcome-intro__title {
  animation: welcome-rise 1s ease-out forwards;
}

.welcome-intro__line {
  grid-area: 1 / 1;
  align-self: center;
  opacity: 0;
  transform: translateY(100%);
  transition:
    transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.6s ease;
}

.welcome-intro__line.is-current {
  opacity: 1;
  transform: none;
}

.welcome-intro__line.is-past {
  opacity: 0;
  transform: translateY(-100%);
}

/* The sweep runs over the whole line (never letter by letter), so Arabic
   letters stay joined. It starts and ends on the plain text colour. */
.welcome-intro__sweep {
  background-image: linear-gradient(
    100deg,
    var(--color-on-dark) 0 38%,
    var(--paper-100) 44%,
    var(--color-accent) 50%,
    var(--paper-100) 56%,
    var(--color-on-dark) 62% 100%
  );
  background-size: 300% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.welcome-intro.is-playing .welcome-intro__sweep {
  animation: welcome-sweep 2.4s ease-in-out 0.3s forwards; /* done before the first flip at 3s */
}

[dir="rtl"] .welcome-intro.is-playing .welcome-intro__sweep {
  animation-name: welcome-sweep-rtl; /* right to left, with the reading direction */
}

/* ---- Ring loader -------------------------------------------------------- */

.welcome-intro__loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  max-width: 100%;
  opacity: 0;
}

.welcome-intro.is-playing .welcome-intro__loader {
  animation: welcome-rise 0.5s ease-out 0.2s forwards;
}

.welcome-intro__ring {
  position: relative;
  width: clamp(124px, 20vw, 168px);
  aspect-ratio: 1;
}

.welcome-intro__ring svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  /* Both languages: start at the top (12 o'clock), go down the right side first,
     then round to the left (clockwise). */
  transform: rotate(-90deg);
}

.welcome-intro__track {
  fill: none;
  stroke: var(--color-on-dark-border);
  stroke-width: 5;
}

.welcome-intro__progress {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 5;
  stroke-linecap: round;
}

.welcome-intro__ring-inner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: var(--space-1);
}

.welcome-intro__mark {
  font-family: var(--font-latin);
  font-size: clamp(16px, 2.4vw, 20px);
  font-weight: var(--weight-bold);
  color: var(--color-on-dark);
}

.welcome-intro__mark b {
  font-weight: inherit;
  color: var(--color-accent);
}

.welcome-intro__pct {
  font-family: var(--font-latin);
  font-size: var(--text-sm);
  color: var(--color-on-dark-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- Skip --------------------------------------------------------------- */

.welcome-intro__skip {
  position: absolute;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  inset-inline-end: var(--gutter);
  min-height: 40px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-accent); /* orange, like the site's "Book a demo" button */
  color: var(--color-on-accent);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-standard),
    opacity 0.35s ease;
}

.welcome-intro__skip:hover {
  background: var(--color-accent-hover);
}

.welcome-intro__skip:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 3px;
}

@keyframes welcome-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes welcome-sweep {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@keyframes welcome-sweep-rtl {
  from { background-position: 0 0; }
  to { background-position: 100% 0; }
}

/* Reduced motion: base.css shortens every CSS animation to its end state and
   the JS skips the fill and the opening, so the intro shows still and then goes. */
