/* Bonjour Bob — the scene: a night sky and a sun that rises once, then answers now and then.
 *
 * Where: the landing page, signing in, the very first screen. Not behind the conversation.
 * Markup: <div class="scene" aria-hidden="true"><canvas class="scene-canvas"></canvas>
 *         <div class="scene-horizon"></div></div>, inside a positioned parent.
 * scene.js draws the grainy sun in the canvas; without it, or without WebGL, the CSS sun below stays.
 * The scene is always night: give its parent the class "on-scene", so that what stands on it
 * keeps the night colours in the day theme too, and put on it only text or a paper sheet.
 */

.on-scene {
  color: var(--color-on-scene);
}

.scene {
  /* Set --scene-horizon on the page to change how high the sun comes; the default suits a full screen. */
  --scene-sun: calc(var(--scene-horizon, clamp(5.5rem, 17vh, 10.5rem)) * 0.84);

  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(var(--color-sky-top), var(--color-sky-low));
}

/* Its height is how much room the sun takes at the bottom. scene.js measures it. */
.scene-horizon {
  position: absolute;
  inset: auto 0 0;
  height: var(--scene-horizon, clamp(5.5rem, 17vh, 10.5rem));
  pointer-events: none;
}

.scene::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% - var(--scene-sun));
  width: min(calc(var(--scene-sun) * 5), 96vw);
  aspect-ratio: 1;
  border-radius: 50%;
  translate: -50% 0;
  background: radial-gradient(
    circle at 50% 20%,
    var(--color-sun-core),
    var(--color-sun-light) 9%,
    var(--color-sun) 16%,
    var(--color-sun-deep) 30%
  );
}

/* The sun answers: data-sun="1" when something is ready, "2" when it is done (see scene.js).
   Without WebGL the CSS sun only comes a little higher. */
.scene[data-sun="1"]::after {
  translate: -50% calc(var(--scene-sun) * -0.08);
}

.scene[data-sun="2"]::after {
  translate: -50% calc(var(--scene-sun) * -0.16);
}

.scene-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  visibility: hidden;
}

.scene.is-live .scene-canvas {
  visibility: visible;
}

.scene.is-live::after {
  display: none;
}

/* A title that comes into focus, one word after the other (after React Bits "Blur Text").
   Markup: one <span> per word inside .focus-in. Played once; the words are plainly there without it. */
.focus-in > span {
  display: inline-block;
}

@media (prefers-reduced-motion: no-preference) {
  .scene::after {
    animation: sun-up 3.2s var(--ease-out) both;
    transition: translate 1.4s var(--ease-out);
  }

  .focus-in > span {
    animation: focus-in 0.9s var(--ease-out) both;
    will-change: filter, opacity, transform;
  }

  .focus-in > span:nth-child(1) { animation-delay: 0.1s; }
  .focus-in > span:nth-child(2) { animation-delay: 0.22s; }
  .focus-in > span:nth-child(3) { animation-delay: 0.34s; }
  .focus-in > span:nth-child(4) { animation-delay: 0.46s; }
  .focus-in > span:nth-child(5) { animation-delay: 0.58s; }
  .focus-in > span:nth-child(6) { animation-delay: 0.7s; }
  .focus-in > span:nth-child(7) { animation-delay: 0.82s; }
  .focus-in > span:nth-child(8) { animation-delay: 0.94s; }
}

@keyframes sun-up {
  from {
    translate: -50% calc(var(--scene-sun) + 2rem);
    opacity: 0.6;
  }
}

@keyframes focus-in {
  0% {
    opacity: 0;
    filter: blur(10px);
    transform: translateY(0.14em);
  }

  55% {
    opacity: 0.7;
    filter: blur(4px);
  }

  100% {
    opacity: 1;
    filter: blur(0);
    transform: none;
  }
}
