/* ==========================================================================
   Welcome intro — storybook-style overlay shown on a visitor's first visit.
   Timeline (motion): cloud 0.04s → sparkles 0.33s → children 0.48–1.3s
   → tagline 1.15s → short hold → fade into the homepage at ~2s (≈2.5s total).
   Everything animates transform/opacity only. Reduced motion = static, short.
   ========================================================================== */

/* Sky cover painted with the very first frame, so the homepage never
   flashes before the intro mounts. Fades on its own if the script fails. */
html.intro-play::after {
  content: "";
  position: fixed; inset: 0; z-index: 999;
  background: linear-gradient(180deg, #A9D5FF 0%, #BCDFFF 45%, #DCEBFF 70%, #F9E9F1 100%);
  animation: intro-failsafe 400ms ease 4s forwards;
}
html.intro-active { overflow: hidden; scrollbar-gutter: stable; }

.intro {
  --kid-stagger: 110ms;
  --kid-start: 480ms;
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  overflow: hidden;
  padding: 1.5rem 1rem 5.5rem;
  /* same morning sky as the hero: blue, with a hint of sunrise along the horizon */
  background:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 56% 40% at 86% 102%, rgba(255, 139, 73, 0.5), rgba(255, 168, 112, 0.22) 45%, rgba(255, 168, 112, 0) 74%),
    radial-gradient(ellipse 72% 40% at 14% 102%, rgba(249, 164, 198, 0.58), rgba(249, 164, 198, 0.22) 45%, rgba(249, 164, 198, 0) 74%),
    radial-gradient(ellipse 72% 52% at 84% 100%, rgba(255, 238, 224, 0.75), rgba(255, 238, 224, 0) 70%),
    radial-gradient(ellipse 85% 52% at 16% 100%, rgba(255, 238, 246, 0.7), rgba(255, 238, 246, 0) 70%),
    linear-gradient(180deg, #A9D5FF 0%, #BCDFFF 45%, #DCEBFF 70%, #F9E9F1 100%);
  font-family: var(--font-body);
  color: var(--navy);
  touch-action: none;
  /* safety net: never let the overlay outstay its welcome */
  animation: intro-failsafe 500ms ease 9s forwards;
}

/* ---------- Scene layout (everything scales with the scene width) ---------- */
.intro__scene {
  width: min(96vw, 760px, 78svh);
  text-align: center;
}
.intro__stage {
  position: relative;
  aspect-ratio: 600 / 360;
  margin-top: 13%; /* room for the children peeking over the top */
}
.intro__shadow {
  position: absolute; left: 12%; right: 12%; bottom: -5%;
  height: 14%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(54, 86, 216, 0.18), rgba(54, 86, 216, 0) 70%);
}
.intro__cloud { position: absolute; inset: 0; z-index: 2; }
.intro__cloud svg { display: block; width: 100%; height: 100%; overflow: visible; }
.intro__logo {
  position: absolute; z-index: 3;
  left: 18%; top: 43%;
  width: 64%; height: auto;
}

/* Children peek over the cloud's rim; the cloud (z-index 2) hides their lower half */
.intro__kid {
  position: absolute; z-index: 1;
  left: var(--x); top: var(--y);
  width: var(--w, 20%);
  transform: rotate(var(--r, 0deg));
  transform-origin: 50% 100%;
}
.intro__kid-img {
  display: block; width: 100%; height: auto;
  filter: drop-shadow(0 6px 10px rgba(54, 86, 216, 0.14));
}

.intro__sparkle {
  position: absolute; z-index: 4;
  left: var(--x); top: var(--y);
  width: var(--s, 18px); height: var(--s, 18px);
  color: var(--c, #FFD646);
  filter: drop-shadow(0 2px 4px rgba(54, 86, 216, 0.15));
}
.intro__sparkle svg { display: block; width: 100%; height: 100%; }

.intro__tagline {
  margin-top: 7%;
  font-size: clamp(1.6rem, 1rem + 2.6vw, 2.7rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.intro__tagline em {
  font-style: normal;
  color: var(--royal);
  background: linear-gradient(transparent 66%, #FFE27A 66%, #FFE27A 90%, transparent 90%);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.intro__bg-cloud { position: absolute; color: #fff; opacity: 0.55; pointer-events: none; }
.intro__bg-cloud svg { display: block; width: 100%; height: auto; }
.intro__bg-cloud--a { width: clamp(90px, 14vw, 180px); top: 8%; left: 6%; }
.intro__bg-cloud--b { width: clamp(70px, 10vw, 130px); top: 18%; right: 8%; opacity: 0.45; }
.intro__bg-cloud--c { width: clamp(110px, 16vw, 210px); bottom: 10%; left: -3%; opacity: 0.5; }

.intro__skip {
  position: absolute; z-index: 5;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(1.25rem, calc(env(safe-area-inset-bottom) + 0.75rem));
  display: inline-flex; align-items: center; gap: 0.45rem;
  min-height: 46px;
  padding: 0.6rem 1.15rem 0.6rem 1.3rem;
  border: 1px solid rgba(23, 32, 51, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 24px -10px rgba(23, 32, 51, 0.35);
  color: var(--navy);
  font-family: var(--font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 200ms ease, transform 200ms ease;
}
.intro__skip:hover { background: #fff; transform: translateY(-1px); }
.intro__skip:focus-visible { outline: 3px solid var(--royal); outline-offset: 3px; }
.intro__skip svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 600px) {
  .intro__skip { right: 50%; transform: translateX(50%); }
  .intro__skip:hover { transform: translateX(50%) translateY(-1px); }
}

/* Phones held sideways: let the tagline run wider than the cloud, on one line */
@media (orientation: landscape) and (max-height: 500px) {
  .intro { padding-block: 0.75rem; }
  .intro__tagline { margin: 3% -45% 0; font-size: clamp(1.25rem, 5svh, 1.6rem); }
}

/* ---------- Initial (pre-run) state: hidden until the logo is ready ---------- */
.intro__cloud, .intro__logo, .intro__kid-body, .intro__sparkle, .intro__tagline, .intro__shadow { opacity: 0; }
.intro__skip { opacity: 0; }

/* ---------- Motion timeline ---------- */
.intro--run .intro__skip { animation: intro-fade 250ms ease 100ms both; }
.intro--run .intro__stage { animation: intro-float 3.2s ease-in-out 0.55s infinite; }
.intro--run .intro__shadow { animation: intro-fade 320ms ease 100ms both; }
.intro--run .intro__cloud { animation: intro-cloud-pop 460ms cubic-bezier(0.34, 1.4, 0.64, 1) 40ms both; }
.intro--run .intro__logo { animation: intro-logo-in 340ms cubic-bezier(0.22, 0.61, 0.36, 1) 190ms both; }
.intro--run .intro__sparkle {
  animation:
    intro-sparkle-in 320ms cubic-bezier(0.34, 1.56, 0.64, 1) calc(330ms + var(--i) * 40ms) both,
    intro-twinkle 2s ease-in-out calc(700ms + var(--i) * 100ms) infinite;
}
.intro--run .intro__kid-body {
  transform-origin: 50% 100%;
  animation: intro-kid-pop 380ms cubic-bezier(0.34, 1.3, 0.64, 1) calc(var(--kid-start) + var(--i) * var(--kid-stagger)) both;
}
/* after popping up, each child does a little happy wiggle */
.intro--run .intro__kid-img {
  transform-origin: 50% 100%;
  animation: intro-wiggle 0.65s ease-in-out calc(var(--kid-start) + var(--i) * var(--kid-stagger) + 280ms) 1;
}
.intro--run .intro__tagline { animation: intro-rise 400ms cubic-bezier(0.22, 0.61, 0.36, 1) 1150ms both; }
.intro--run .intro__bg-cloud { animation: intro-drift 9s ease-in-out infinite alternate; }
.intro--run .intro__bg-cloud--b { animation-duration: 11s; animation-direction: alternate-reverse; }

/* Exit: the scene dissolves into the sky first, then the sky (same as the hero's) fades
   away to reveal the homepage — no double exposure */
.intro--leaving { animation: intro-out 320ms cubic-bezier(0.4, 0, 0.2, 1) 120ms forwards; pointer-events: none; }
.intro--leaving .intro__scene,
.intro--leaving .intro__skip,
.intro--leaving .intro__bg-cloud { animation: intro-scene-out 260ms cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.intro--leaving.intro--quick { animation-duration: 260ms; animation-delay: 100ms; }
.intro--leaving.intro--quick .intro__scene,
.intro--leaving.intro--quick .intro__skip { animation-duration: 220ms; }

/* ---------- Reduced motion: complete scene, no movement, short hold ---------- */
.intro--static .intro__cloud, .intro--static .intro__logo, .intro--static .intro__kid-body,
.intro--static .intro__sparkle, .intro--static .intro__tagline, .intro--static .intro__shadow,
.intro--static .intro__skip { opacity: 1; animation: none !important; }
.intro--static .intro__stage, .intro--static .intro__bg-cloud,
.intro--static .intro__kid-img { animation: none !important; }
.intro--static.intro--run .intro__scene { animation: intro-fade 400ms ease both; }
.intro--static.intro--leaving .intro__scene { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .intro__skip:hover { transform: none; }
}

/* ---------- Keyframes ---------- */
@keyframes intro-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes intro-cloud-pop {
  0%   { opacity: 0; transform: translateY(24px) scale(0.5); }
  45%  { opacity: 1; }
  70%  { transform: translateY(-4px) scale(1.04); }
  100% { opacity: 1; transform: none; }
}
@keyframes intro-logo-in {
  from { opacity: 0; transform: scale(0.86); }
  to   { opacity: 1; transform: none; }
}
@keyframes intro-sparkle-in {
  0%   { opacity: 0; transform: scale(0) rotate(-60deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes intro-twinkle {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(0.72); }
}
@keyframes intro-kid-pop {
  0%   { opacity: 0; transform: translateY(55%) scale(0.8); }
  35%  { opacity: 1; }
  100% { opacity: 1; transform: none; }
}
@keyframes intro-wiggle {
  0%, 100% { transform: none; }
  25%      { transform: translateY(-4%) rotate(-4deg); }
  55%      { transform: rotate(3deg); }
  78%      { transform: translateY(-1.5%) rotate(-1deg); }
}
@keyframes intro-rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes intro-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
@keyframes intro-drift {
  from { transform: translateX(-14px); }
  to   { transform: translateX(22px); }
}
@keyframes intro-out { to { opacity: 0; visibility: hidden; } }
@keyframes intro-scene-out { to { opacity: 0; transform: translateY(-10px) scale(1.04); } }
@keyframes intro-failsafe { to { opacity: 0; visibility: hidden; } }
