/* Loading splash on a full page load: the logo waits dim while a gold light swings around the C and
   runs along the underline, lighting what it passes, and a sparkle answers each time it goes by. The
   light keeps passing until the page has loaded; then the whole logo lights, both sparkles twinkle and
   the screen fades out. Turbo visits skip it (see splash_controller.js). */

.splash {
  --comet: #F5C451;
  --comet-head: #FFF3C9;
  --pass: 1.5s;

  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-0);

  /* Without the script the light would pass for ever, so in the end the screen leaves by itself. */
  animation: splash-out 0.45s ease 6s forwards;
}

:root[data-theme="light"] .splash {
  --comet: #E5A823;
  --comet-head: #D4950F;
}

.splash--ready {
  animation: splash-leave 0.4s ease 0.55s forwards;
}

html[data-splash-done] .splash {
  display: none;
}

.splash__stage {
  position: relative;
  width: min(320px, 70vw);
  animation: splash-rise 0.5s ease-out both;
}

.splash__glow {
  position: absolute;
  inset: -45%;
  z-index: -1;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 35%, transparent), transparent);
  opacity: 0.35;
  transition: opacity 0.4s ease;
}

.splash__art {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.splash__dim {
  opacity: 0.22;
  transition: opacity 0.35s ease;
}

/* The light is a dash sliding along its path, from just before the start to just past the end. Its
   parts are dashes of their own lengths, so each says where it starts and ends to keep the heads
   together. Lengths count the path as 100. */
.splash__beam,
.splash__comet {
  fill: none;
  stroke-dasharray: var(--len) 400;
  stroke-dashoffset: var(--from);
  animation-duration: var(--pass);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

.splash__beam--orbit,
.splash__comet--orbit {
  animation-name: splash-orbit;
}

.splash__beam--line,
.splash__comet--line {
  animation-name: splash-line;
}

.splash__beam {
  --len: 34;
  --from: 36;
  --to: -98;

  stroke: #fff;
  stroke-width: 900;
}

.splash__comet {
  stroke: var(--comet);
  stroke-linecap: round;
}

.splash__comet--tail {
  --len: 30;
  --from: 32;
  --to: -102;

  stroke-width: 14;
  opacity: 0.35;
}

.splash__comet--body {
  --len: 14;
  --from: 16;
  --to: -118;

  stroke-width: 24;
  opacity: 0.7;
}

.splash__comet--head {
  --len: 3;
  --from: 5;
  --to: -129;

  stroke: var(--comet-head);
  stroke-width: 34;
}

.splash__twinkle {
  position: absolute;
  width: 10%;
  aspect-ratio: 1;
  margin: -5% 0 0 -5%;
  fill: var(--comet-head);
  opacity: 0;
  animation: splash-twinkle-pass var(--pass) ease-out infinite backwards;
}

/* Centers of the two sparkles in logo.svg, each twinkling as the light goes by. */
.splash__twinkle--a {
  top: 29%;
  left: 19%;
  animation-delay: calc(var(--pass) * 0.2);
}

.splash__twinkle--b {
  top: 19%;
  left: 60%;
  animation-delay: calc(var(--pass) * 0.38);
}

/* The page has loaded: the logo lights, the light is gone and the sparkles twinkle once more. */
.splash--ready .splash__dim,
.splash--ready .splash__glow {
  opacity: 1;
}

.splash--ready .splash__lit,
.splash--ready .splash__comets {
  visibility: hidden;
}

.splash--ready .splash__twinkle {
  animation: splash-twinkle 0.7s ease-out forwards;
}

.splash--ready .splash__twinkle--b {
  animation-delay: 0.12s;
}

/* Around the C in the first part of a pass, speeding up into the turn. */
@keyframes splash-orbit {
  0% {
    stroke-dashoffset: var(--from);
    animation-timing-function: cubic-bezier(0.45, 0, 0.3, 1);
  }

  42%,
  100% {
    stroke-dashoffset: var(--to);
  }
}

/* Then along the underline, setting off as the first light comes out of its turn. */
@keyframes splash-line {
  0%,
  24% {
    stroke-dashoffset: var(--from);
    animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
  }

  90%,
  100% {
    stroke-dashoffset: var(--to);
  }
}

@keyframes splash-twinkle-pass {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-45deg);
  }

  12% {
    opacity: 1;
    transform: scale(1.15) rotate(0deg);
  }

  28%,
  100% {
    opacity: 0;
    transform: scale(0.4) rotate(30deg);
  }
}

@keyframes splash-twinkle {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-45deg);
  }

  50% {
    opacity: 1;
    transform: scale(1.15) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: scale(0.4) rotate(30deg);
  }
}

@keyframes splash-rise {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes splash-leave {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

@keyframes splash-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* Without motion the splash would never fade, so it is not shown at all. */
@media (prefers-reduced-motion: reduce) {
  .splash {
    display: none;
  }
}
