/*

Tutorial:
https://www.roboleary.net/animation/2022/10/31/how-to-make-a-slick-animation-schitts-creek-title-sequence.html

Part of Title Sequences collection:
https://codepen.io/collection/nNmwgP

Source code:
https://github.com/robole/title-sequences

*/

@import url("https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600");

:root {
  --bar-scale-y: 0;
  --sparkle-color: rgb(253 244 215 / 40%);
}

@keyframes pop-word {
  to {
    transform: rotateX(0);
  }
}

@keyframes show {
  to {
    opacity: 1;
  }
}

@keyframes bar-scale {
  to {
    transform: scaleY(1);
  }
}

@keyframes sparkle {
  0% {
    transform: scale(0);
  }

  60% {
    transform: scale(1) translate(4px, 1px) rotate(8deg);
  }

  100% {
    transform: scale(0) translate(4px, 1px) rotate(8deg);
  }
}

@keyframes shimmer {
  to {
    text-shadow: 0 0 8px red;
  }
}

body {
  display: grid;
  height: 90vh;

  background-color: black;
  place-items: center;
}

h1 {
  color: white;
  font-family: "Playfair Display", Vidaloka, serif;
  font-size: 8rem;
  margin-top: 10px;
  line-height: 0.85;
  perspective: 500px;
}

.word {
  display: block;

  animation: show 0.01s forwards, pop-word 1.5s forwards;
  animation-timing-function: cubic-bezier(0.14, 1.23, 0.33, 1.16);
  opacity: 0;
  line-height: 130px;
  transform: rotateX(120deg);
  transform-origin: 50% 100%;
}

.word:nth-of-type(2) {
  padding: 0 2rem;

  animation-delay: 1.5s;

  color: gold;
}
.word:nth-of-type(3) {
  padding: 2rem 4rem;

  animation-delay: 4.0s;

  color: gold;
}
.word:nth-of-type(4) {
  padding: 1rem 6rem;

  animation-delay: 6.0s;

  color: gold;
}

.superscript {
  position: relative;
  animation: infinite;
  animation-delay: 7.7s;

  animation-duration: 1s;
  animation-name: shimmer;

  vertical-align: text-top;
}

/* bars */
/*.superscript::before {
  --bar-width: 25%;

  position: absolute;

  top: 37%;
  left: 47%;
  width: 14%;
  height: 48%;

  animation: bar-scale 0.25s linear 7.5s 1 forwards;

  background: linear-gradient(
    to right,
    white var(--bar-width),
    transparent var(--bar-width) calc(100% - var(--bar-width)),
    white calc(100% - var(--bar-width))
  );

  content: "";

  transform: scaleY(var(--bar-scale-y));
}*/

/* sparkle */
.superscript::after {
    --size: 10rem;
    --sparkle-color: #ffdf00; /* Example color for sparkles */

    position: absolute;
    top: -5%;
    left: -80%;

    width: var(--size);
    height: var(--size);

    animation: sparkle 1s linear 7.8s infinite; /* Infinite loop with 7.8s delay */

    background: radial-gradient(
        circle at center,
        rgba(252, 249, 241, 0.94) 0%,
        transparent 7%,
        transparent 100%
    ),
    conic-gradient(
        transparent 0deg 18deg,
        var(--sparkle-color) 18deg,
        transparent 20deg 40deg,
        var(--sparkle-color) 40deg,
        transparent 43deg 87deg,
        var(--sparkle-color) 87deg,
        transparent 95deg 175deg,
        var(--sparkle-color) 175deg,
        transparent 178deg 220deg,
        var(--sparkle-color) 220deg,
        transparent 222deg 270deg,
        var(--sparkle-color) 270deg,
        transparent 275deg 300deg,
        var(--sparkle-color) 300deg,
        transparent 303deg 360deg
    );

    border-radius: 50%;
    clip-path: polygon(
        50% 0,
        59.13% 26.64%,
        85.13% -2.35%,
        100% 50%,
        50% 100%,
        0 50%,
        31.39% 34.86%
    );

    content: "";

    filter: blur(1px);

    transform: scale(0); /* Start small */
}

@media screen and (max-width: 600px) {
  h1 {
    font-size: 5rem;
  }

  /* sparkle */
  .superscript::after {
    --size: 6rem;
  }
}