/* Animation master - typewriter */

/*
  Usage:
    <div class="t-text-animation t-typewriter is-previewing">
      <span class="t-text-row">
        <span class="t-char" style="--i: 0">C</span>
        <span class="t-char" style="--i: 1">h</span>
        <span class="t-char" style="--i: 2">i</span>
      </span>
    </div>

  Add `.t-typewriter` and `.is-previewing` to run this text animation.
  Wrap each character in `.t-char` and set an incremental `--i` value.
*/

:root {
  --text-motion-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --text-motion-ease-in: cubic-bezier(0.64, 0, 0.78, 0);
  --text-motion-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --typewriter-char-dur: 1ms;
  --typewriter-stagger: 46ms;
}

.t-text-animation {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
  color: #171717;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 28px;
  font-weight: 760;
  line-height: 1.18;
  letter-spacing: 0;
  text-align: center;
  overflow-wrap: normal;
  word-break: normal;
}

.t-text-animation .t-char,
.t-text-animation .t-word,
.t-text-animation .t-line,
.t-text-animation .t-text-row,
.t-text-animation .t-text-whole {
  display: inline-block;
  opacity: 1;
  transform-origin: center;
  will-change: transform, opacity, filter, clip-path, background-position;
}

.t-text-animation .t-text-row {
  display: block;
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  line-height: inherit;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.t-text-animation .t-line {
  flex-basis: 100%;
  max-width: 100%;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.t-text-animation .t-text-whole {
  max-width: 100%;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.t-text-animation .t-char-space {
  width: 0.32em;
}

/* Optional preview wrapper for Animation master demo pages. */
.text-preview {
  width: 272px;
  max-width: calc(100% - 24px);
  min-height: 120px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  padding: 4px 0 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  text-align: center;
  line-height: 1.18;
  overflow-wrap: normal;
  word-break: normal;
}

.text-preview .t-line {
  flex-basis: 100%;
  max-width: 100%;
  line-height: 1.18;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.text-preview .t-text-row {
  display: block;
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  line-height: inherit;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.text-preview .t-text-whole {
  max-width: 100%;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.text-preview .t-char-space {
  width: 0.32em;
}

.text-preview:not(.is-previewing) .t-char,
.text-preview:not(.is-previewing) .t-word,
.text-preview:not(.is-previewing) .t-line,
.text-preview:not(.is-previewing) .t-text-whole {
  animation: none;
}

.t-typewriter .t-char {
  opacity: 1;
}

.t-typewriter:not(.is-previewing) .t-char {
  animation: none;
}

.t-typewriter.is-previewing .t-char {
  animation: t-typewriter var(--typewriter-char-dur) steps(1, end) backwards;
  animation-delay: calc(var(--i) * var(--typewriter-stagger));
}

@keyframes t-typewriter {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .t-typewriter,
  .t-typewriter * {
    animation: none !important;
    transition: none !important;
    filter: none !important;
  }
}
