/* THE FIRST PEARL - Readanah's opening sequence.
   A line of writing becomes a string; a point of reading light travels along it;
   the light becomes a pearl; the pearl leads into the homepage.

   The whole sequence is CSS, so it plays from the first painted frame and needs
   no JavaScript. assets/js/splash.js only conducts the final movement: it
   measures where the hero pearl sits and flies this pearl to meet it.

   Everything is gated on html[data-splash]. Without that attribute the homepage
   is exactly what it was before. */

:root {
  /* The boot script in index.html reads this before it shows anything.
     If this stylesheet is missing, the intro never runs. */
  --rs-ready: 1;

  /* --- the clock ---
     Every moment below is a plain number of milliseconds at tempo 1, so that
     assets/js/splash.js can read the same figures and the two can never drift.
     --rs-tempo stretches the whole sequence at once: raise it for a slower,
     more unhurried reading, lower it to quicken. 1 is the briskest version.
     At 1.4 the sequence runs a little under five seconds. */
  --rs-tempo: 1.4;
  --rs-ms: calc(1ms * var(--rs-tempo));

  --rs-veil-d: 500;
  --rs-dust-at: 200;      --rs-dust-d: 1400;
  --rs-line-at: 360;      --rs-line-d: 560;
  --rs-settle-at: 1320;   --rs-settle-d: 520;
  --rs-spark-at: 500;     --rs-spark-d: 540;
  --rs-pearl-at: 980;     --rs-pearl-d: 560;   --rs-spark-out-d: 240;
  --rs-halo-at: 1040;     --rs-halo-d: 860;
  --rs-name-at: 1480;
  --rs-en-at: 1600;
  --rs-ar-at: 1710;
  --rs-sig-at: 1880;      --rs-sig-d: 340;
  --rs-text-d: 440;
  --rs-skip-at: 1000;     --rs-skip-btn-d: 400;
  --rs-intro-end: 2220;   /* --rs-sig-at plus --rs-sig-d */
  --rs-handoff-at: 2900;  /* the finished lockup holds still for a beat first */
  --rs-flight: 620;
  --rs-dissolve: 600;
  --rs-lift-d: 300;       --rs-lift-at: 40;
  --rs-halo-out-d: 240;

  /* These answer the visitor rather than tell the story, so they stay quick
     whatever the tempo. */
  --rs-skip-d: 300;
  --rs-rise-d: 420;
  --rs-reveal-d: 700;     /* the longest hero delay plus --rs-rise-d */

  --rs-ease: cubic-bezier(0.22, 0.72, 0.24, 1);
  --rs-ease-in: cubic-bezier(0.45, 0, 0.25, 1);

  /* --- the sea. Everything else is borrowed from base.css. --- */
  --rs-deep: #081B32;
  --rs-abyss: #04101C;
  --rs-current: rgba(30, 72, 119, 0.32);

  /* Flight defaults: with no measurable hero pearl the flight degrades into a
     graceful shrink where it stands. splash.js overwrites these. */
  --rs-fx: 0px; --rs-fy: 0px; --rs-fs: 0.55;

  --rs-pearl-size: clamp(56px, 16vmin, 88px);
  --rs-line-w: min(560px, 74vw);
}

/* Hidden unless the boot script has decided to play. */
.rs-root { display: none; }
html[data-splash] { background-color: var(--rs-deep); }

html[data-splash] .rs-root {
  position: fixed; inset: 0; z-index: 9999;
  display: block; overflow: hidden; contain: layout paint;
  touch-action: none; overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

/* ---------- Phase 1: the deep sea ---------- */

/* Opaque from the very first painted frame: the homepage is never glimpsed
   through it on the way in. Only the glow above it is animated. */
.rs-veil {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 112% 92% at 50% 46%, rgba(8, 27, 50, 0) 26%, rgba(3, 11, 20, 0.78) 100%),
    linear-gradient(180deg, var(--rs-abyss) 0%, var(--rs-deep) 50%, #0A2038 100%);
}
.rs-glow {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 58% 44% at 50% 40%, var(--rs-current) 0%, rgba(30, 72, 119, 0) 72%);
  animation: rs-glow-in calc(var(--rs-veil-d) * var(--rs-ms)) ease-out both;
}
@keyframes rs-glow-in { from { opacity: 0; transform: scale(1.06); } to { opacity: 1; transform: none; } }

/* Underwater dust: a few slow motes, never glitter. Positions are set inline. */
.rs-dust { position: absolute; inset: 0; opacity: 0; animation: rs-dust-in calc(var(--rs-dust-d) * var(--rs-ms)) ease-out calc(var(--rs-dust-at) * var(--rs-ms)) forwards; }
@keyframes rs-dust-in { to { opacity: 1; } }
.rs-dust i {
  position: absolute; left: var(--x); top: var(--y);
  width: var(--s); height: var(--s); border-radius: 50%;
  background: radial-gradient(circle, rgba(222, 234, 250, 0.55) 0%, rgba(222, 234, 250, 0) 70%);
  opacity: var(--o);
  animation: rs-drift var(--t) ease-in-out var(--dl) infinite alternate;
  will-change: transform;
}
@keyframes rs-drift { from { transform: none; } to { transform: translate3d(var(--dx), var(--dy), 0); } }

/* ---------- Phases 2-5: the lockup ---------- */

.rs-stage {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(10px, 2.2vmin, 18px);
  padding: max(28px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(84px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  text-align: center;
}

/* Phase 2: the reading line, and the point of light that travels it */
.rs-orbit { position: relative; width: var(--rs-line-w); height: var(--rs-pearl-size); }
.rs-line, .rs-line-glow {
  position: absolute; left: 0; right: 0; top: 50%;
  transform: scaleX(0); transform-origin: 50% 50%; will-change: transform;
  animation: rs-draw calc(var(--rs-line-d) * var(--rs-ms)) var(--rs-ease) calc(var(--rs-line-at) * var(--rs-ms)) both,
             rs-line-settle calc(var(--rs-settle-d) * var(--rs-ms)) ease-out calc(var(--rs-settle-at) * var(--rs-ms)) forwards;
}
.rs-line { height: 1px; margin-top: -0.5px; background: var(--hairline); }
.rs-line-glow {
  height: 3px; margin-top: -1.5px; opacity: 0.55; filter: blur(3px);
  background: linear-gradient(90deg, rgba(241, 213, 138, 0) 0%, rgba(241, 213, 138, 0.5) 28%,
              rgba(241, 213, 138, 0.8) 50%, rgba(241, 213, 138, 0.5) 72%, rgba(241, 213, 138, 0) 100%);
}
@keyframes rs-draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes rs-line-settle { to { opacity: 0.62; } }

.rs-spark {
  position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%; will-change: transform, opacity;
  background: radial-gradient(circle, #FFFDF4 0 22%, rgba(241, 213, 138, 0.85) 44%, rgba(201, 161, 74, 0) 72%);
  box-shadow: 0 0 14px rgba(241, 213, 138, 0.75);
  animation: rs-spark-in calc(var(--rs-spark-d) * var(--rs-ms)) cubic-bezier(0.32, 0, 0.12, 1) calc(var(--rs-spark-at) * var(--rs-ms)) both,
             rs-spark-out calc(var(--rs-spark-out-d) * var(--rs-ms)) ease-out calc(var(--rs-pearl-at) * var(--rs-ms)) forwards;
}
@keyframes rs-spark-in {
  0% { transform: translate3d(calc(var(--rs-line-w) * -0.5), 0, 0) scale(0.5); opacity: 0; }
  16% { opacity: 1; }
  100% { transform: translate3d(0, 0, 0) scale(1); opacity: 1; }
}
@keyframes rs-spark-out { to { opacity: 0; } }

/* Phase 3: the first pearl */
.rs-pearl {
  position: absolute; left: 50%; top: 50%;
  width: var(--rs-pearl-size); height: var(--rs-pearl-size);
  margin: calc(var(--rs-pearl-size) / -2) 0 0 calc(var(--rs-pearl-size) / -2);
  border-radius: 50%; will-change: transform, opacity;
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.96) 0 5%, rgba(255, 255, 255, 0.28) 13%, rgba(255, 255, 255, 0) 26%),
    radial-gradient(circle at 70% 33%, rgba(244, 204, 205, 0.34) 0 14%, rgba(244, 204, 205, 0) 44%),
    radial-gradient(circle at 60% 82%, rgba(229, 192, 121, 0.34) 0 10%, rgba(229, 192, 121, 0) 40%),
    radial-gradient(circle at 26% 68%, rgba(188, 209, 232, 0.5) 0 16%, rgba(188, 209, 232, 0) 52%),
    radial-gradient(circle at 38% 30%, #FFFEFB 0 10%, #FAF6EC 27%, #EBE4D3 49%, #C8BFAB 71%, #8E8879 88%, #6B675C 100%);
  box-shadow:
    inset -6px -8px 18px rgba(11, 31, 58, 0.34),
    inset 4px 5px 14px rgba(255, 255, 255, 0.42),
    0 8px 22px rgba(3, 10, 20, 0.5),
    0 0 26px rgba(241, 213, 138, 0.16);
  animation: rs-bloom calc(var(--rs-pearl-d) * var(--rs-ms)) var(--rs-ease) calc(var(--rs-pearl-at) * var(--rs-ms)) both;
}
@keyframes rs-bloom {
  0% { transform: scale(0.08); opacity: 0; }
  22% { opacity: 1; }
  70% { transform: scale(1.045); }
  100% { transform: none; opacity: 1; }
}

.rs-halo {
  position: absolute; left: 50%; top: 50%;
  width: var(--rs-pearl-size); height: var(--rs-pearl-size);
  margin: calc(var(--rs-pearl-size) / -2) 0 0 calc(var(--rs-pearl-size) / -2);
  border-radius: 50%; opacity: 0; will-change: transform, opacity;
  background: radial-gradient(circle, rgba(241, 213, 138, 0.3) 0%, rgba(241, 213, 138, 0.14) 46%, rgba(241, 213, 138, 0) 68%);
  animation: rs-ripple calc(var(--rs-halo-d) * var(--rs-ms)) ease-out calc(var(--rs-halo-at) * var(--rs-ms)) both;
}
@keyframes rs-ripple {
  0% { transform: scale(0.4); opacity: 0; }
  30% { opacity: 0.85; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Phases 4 and 5: the words. Opacity and transform only - never a filter, so
   neither the English nor the Arabic is ever softened. */
.rs-name, .rs-en, .rs-ar, .rs-sig { margin: 0; opacity: 0; will-change: transform, opacity; }
.rs-name, .rs-en, .rs-ar { animation: rs-word calc(var(--rs-text-d) * var(--rs-ms)) var(--rs-ease) both; }
.rs-name {
  font-family: var(--font-display); font-weight: 600; color: var(--ivory);
  font-size: clamp(2.8rem, 11vmin, 5.4rem); line-height: 1; letter-spacing: -0.01em;
  margin-top: clamp(4px, 1.4vmin, 12px);
  animation-delay: calc(var(--rs-name-at) * var(--rs-ms));
}
.rs-en {
  font-family: var(--font-display); font-style: italic; color: var(--champagne);
  font-size: clamp(1.1rem, 4.4vmin, 1.7rem); line-height: 1.3;
  animation-delay: calc(var(--rs-en-at) * var(--rs-ms));
}
.rs-ar {
  font-family: var(--font-ar); color: #D9BD78;
  font-size: clamp(1rem, 4vmin, 1.35rem); line-height: 2;
  animation-delay: calc(var(--rs-ar-at) * var(--rs-ms));
}
@keyframes rs-word {
  from { opacity: 0; transform: translate3d(0, 12px, 0); }
  to { opacity: 1; transform: none; }
}

.rs-sig {
  position: absolute; left: 0; right: 0;
  bottom: max(30px, calc(env(safe-area-inset-bottom) + 18px));
  font-family: var(--font-ui); font-size: clamp(0.58rem, 2.4vmin, 0.7rem);
  font-weight: 700; letter-spacing: 0.24em; text-transform: uppercase; color: #A98F57;
  padding: 0 24px;
  animation: rs-word calc(var(--rs-sig-d) * var(--rs-ms)) var(--rs-ease) calc(var(--rs-sig-at) * var(--rs-ms)) both;
}

/* A discreet way out for anyone who would rather not wait. Every click, tap,
   Enter, Space and Escape does the same thing; this is only for people who
   want a control to aim at. */
/* Top right, clear of the signature at every width. */
.rs-skip {
  position: absolute; right: max(12px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  padding: 8px 14px; border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: #C9B58A; cursor: pointer;
  font-family: var(--font-ui); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; opacity: 0;
  animation: rs-word calc(var(--rs-skip-btn-d) * var(--rs-ms)) ease-out calc(var(--rs-skip-at) * var(--rs-ms)) both;
}
.rs-skip:hover { color: var(--gold-hi); border-color: rgba(231, 200, 120, 0.4); }

/* ---------- Phase 6: the handoff ---------- */

.rs-root.is-handoff .rs-veil,
.rs-root.is-handoff .rs-dust { animation: rs-dissolve calc(var(--rs-dissolve) * var(--rs-ms)) ease-in-out both; }
.rs-root.is-handoff .rs-name,
.rs-root.is-handoff .rs-en,
.rs-root.is-handoff .rs-ar,
.rs-root.is-handoff .rs-sig,
.rs-root.is-handoff .rs-line,
.rs-root.is-handoff .rs-line-glow,
.rs-root.is-handoff .rs-skip {
  animation: rs-lift calc(var(--rs-lift-d) * var(--rs-ms)) ease-in calc(var(--rs-lift-at) * var(--rs-ms)) both;
}
.rs-root.is-handoff .rs-halo { animation: rs-dissolve calc(var(--rs-halo-out-d) * var(--rs-ms)) ease-out both; }
/* The pearl carries on alone, into the oyster it came from. */
.rs-root.is-handoff .rs-pearl { animation: rs-fly calc(var(--rs-flight) * var(--rs-ms)) var(--rs-ease-in) both; }

@keyframes rs-dissolve { to { opacity: 0; } }
@keyframes rs-lift { to { opacity: 0; transform: translate3d(0, -8px, 0); } }
@keyframes rs-fly {
  0% { transform: none; opacity: 1; }
  62% { opacity: 0.9; }
  100% { transform: translate3d(var(--rs-fx), var(--rs-fy), 0) scale(var(--rs-fs)); opacity: 0; }
}

/* Dismissed: the sequence keeps playing underneath and simply dissolves, so a
   skip never leaves a broken half-drawn frame on screen. */
.rs-root.is-skipping { animation: rs-dissolve calc(var(--rs-skip-d) * 1ms) ease-out both; }
.rs-root.is-skipping .rs-skip { visibility: hidden; }

/* ---------- The homepage, waiting underneath ---------- */
/* The homepage is never hidden, only covered: the veil above it is opaque, so
   the hero paints normally and stays a largest-contentful-paint candidate, in
   the accessibility tree and in the document from the first byte. Only at the
   handoff do these elements take a step back and rise into place, and by then
   the veil is still solid, so the step back is never seen. Nothing here can
   move the layout: opacity and transform only. */

html[data-splash="reveal"] .hero-oyster,
html[data-splash="reveal"] .hero-copy > *,
html[data-splash="reveal"] .bar .brand,
html[data-splash="reveal"] .bar-links,
html[data-splash="reveal"] .me-chip,
html[data-splash="reveal"] #btn-mute {
  animation: rs-rise calc(var(--rs-rise-d) * 1ms) var(--rs-ease) both;
}
@keyframes rs-rise {
  from { opacity: 0; transform: translate3d(0, 14px, 0); }
  to { opacity: 1; transform: none; }
}

/* Oyster first, then the heading, then the words, then the way in. */
html[data-splash="reveal"] .hero-oyster { animation-delay: 0ms; }
html[data-splash="reveal"] .hero-copy > * { animation-delay: 170ms; }
html[data-splash="reveal"] .hero-copy > .eyebrow { animation-delay: 60ms; }
html[data-splash="reveal"] .hero-copy > .wordmark { animation-delay: 80ms; }
html[data-splash="reveal"] .hero-copy > .welcome { animation-delay: 110ms; }
html[data-splash="reveal"] .hero-copy > .tagline { animation-delay: 130ms; }
html[data-splash="reveal"] .hero-copy > .lede { animation-delay: 170ms; }
html[data-splash="reveal"] .hero-copy > .hero-stats { animation-delay: 190ms; }
html[data-splash="reveal"] .hero-copy > .hero-cta { animation-delay: 210ms; }
html[data-splash="reveal"] .bar .brand,
html[data-splash="reveal"] .bar-links,
html[data-splash="reveal"] .me-chip,
html[data-splash="reveal"] #btn-mute { animation-delay: 250ms; }

/* ---------- Reduced motion ---------- */
/* The boot script already bows out before any of this. These rules make that
   promise independent of JavaScript: no intro, no held-back homepage. */
@media (prefers-reduced-motion: reduce) {
  html[data-splash] { background-color: transparent; }
  html[data-splash] .rs-root { display: none !important; }
  html[data-splash="reveal"] .hero-oyster,
  html[data-splash="reveal"] .hero-copy > *,
  html[data-splash="reveal"] .bar .brand,
  html[data-splash="reveal"] .bar-links,
  html[data-splash="reveal"] .me-chip,
  html[data-splash="reveal"] #btn-mute { animation: none !important; }
}

/* ---------- Short and small screens ---------- */

@media (max-height: 560px) {
  :root { --rs-pearl-size: clamp(42px, 11vmin, 62px); }
  .rs-stage { gap: 6px; padding-bottom: 62px; }
  .rs-name { font-size: clamp(2.1rem, 8vmin, 3.2rem); }
  .rs-en { font-size: clamp(0.95rem, 3.4vmin, 1.2rem); }
  .rs-ar { font-size: clamp(0.9rem, 3.2vmin, 1.1rem); line-height: 1.8; }
  .rs-sig { bottom: 18px; letter-spacing: 0.2em; }
}
@media (max-width: 420px) {
  .rs-sig { letter-spacing: 0.18em; }
}

/* the wordmark in the intro */
.rs-name .rs-word { display: block; width: clamp(240px, 58vmin, 560px); height: auto; margin: 0 auto;
  filter: drop-shadow(0 12px 26px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 30px rgba(241, 213, 138, 0.18)); }
