@import url('https://unpkg.com/normalize.css') layer(normalize);

@font-face {
  font-family: 'Geist Sans';
  src: url('https://assets.codepen.io/605876/GeistVF.ttf');
}

*,
*::before,
*::after {
  transform-style: preserve-3d;
}

@layer normalize, base, demo;

@layer demo {
  .words,
  .word,
  .char,
  .char::before,
  .char::after {
    transform-style: preserve-3d;
    display: inline-block;
  }
  main {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: transform 0.5s;
  }
  [data-debug='true'] main {
    transform: rotateX(-23deg) rotateY(45deg);
  }

  [data-debug='true'] .char::after,
  [data-debug='true'] .char::before,
  [data-debug='true'] .char {
    --opacity: 1;
    opacity: 1;
    -webkit-animation: none;
            animation: none;
  }

  [data-debug='true'] p:not(:nth-of-type(2)) {
    opacity: 0;
    pointer-events: none;
  }

  p {
    transition: opacity 0.5s;
  }

  .char {
    display: inline-block;
  }

  [data-debug='true'] .char::before {
    -webkit-text-stroke: 2px hsl(0 0% 100% / 0.5);
    color: hsl(0 0% 100% / 0.25);
  }
  [data-debug='true'] .char {
    outline: 2px solid red;
  }

  [data-debug='true'][data-scrub='true'] p .char {
    -webkit-animation: none;
            animation: none;
    --offset: calc(
      (sin((var(--char-index) / var(--char-total)) * 90deg) * 100)
    );
    --r: calc((var(--progress) * 2) - var(--offset));
    transform: rotateX(calc((clamp(0, var(--r), 100) / 100) * 90deg));
  }

  p:nth-of-type(1) {
    --idx: 0;
  }
  p:nth-of-type(2) {
    --idx: 1;
  }
  p:nth-of-type(3) {
    --idx: 2;
  }
  p:nth-of-type(4) {
    --idx: 3;
  }

  main p {
    --font-level: 4;
    margin: 0;
    font-family: 'Geist Sans', sans-serif;
    font-weight: 120;
    text-decoration: none;
    width: -webkit-fit-content;
    width: -moz-fit-content;
    width: fit-content;
    line-height: 1;
    vertical-align: baseline;
  }

  p .char {
    --duration: 2.2s;
    --delay: calc(
      (
          sin((var(--char-index) / var(--char-total)) * 90deg) *
            (var(--duration) * 0.25)
        ) - (var(--idx) * -0.25s)
    );
    display: inline-block;
    -webkit-animation: flip var(--duration) var(--delay) infinite ease;
            animation: flip var(--duration) var(--delay) infinite ease;
  }

  [data-debug='true'] p .char {
    -webkit-animation: flip-debug calc(var(--duration) * 2) var(--delay) infinite ease;
            animation: flip-debug calc(var(--duration) * 2) var(--delay) infinite ease;
    /* animation: none; */
  }

  @-webkit-keyframes flip-debug {
    0%,
    25% {
      transform: rotateX(0deg);
    }
    50%,
    100% {
      transform: rotateX(90deg);
    }
  }

  @keyframes flip-debug {
    0%,
    25% {
      transform: rotateX(0deg);
    }
    50%,
    100% {
      transform: rotateX(90deg);
    }
  }

  @-webkit-keyframes flip {
    25%,
    100% {
      transform: rotateX(90deg);
    }
  }

  @keyframes flip {
    25%,
    100% {
      transform: rotateX(90deg);
    }
  }

  .char {
    color: transparent;
    position: relative;
    height: 0.9lh;
    line-height: 1;
    vertical-align: middle;

    &::after,
    &::before {
      color: canvasText;
      content: attr(data-char);
      position: absolute;
      top: 50%;
      left: 50%;
      height: 1lh;
      width: 100%;
      -webkit-animation: fade var(--duration) var(--delay) infinite ease;
              animation: fade var(--duration) var(--delay) infinite ease;
    }

    &::before {
      transform-origin: 50% 50%;
      translate: -50% -50%;
      transform: rotateX(-90deg) translate3d(0, 0, 0.45lh);
      opacity: 0;
      --opacity: 1;
    }

    &::after {
      translate: -50% -50%;
      transform: translate3d(0, 0, 0.45lh);
    }
  }

  @-webkit-keyframes fade {
    30%,
    100% {
      opacity: var(--opacity, 0);
    }
  }

  @keyframes fade {
    30%,
    100% {
      opacity: var(--opacity, 0);
    }
  }
}

@layer base {
  :root {
    --font-size-min: 16;
    --font-size-max: 20;
    --font-ratio-min: 1.2;
    --font-ratio-max: 1.33;
    --font-width-min: 375;
    --font-width-max: 1500;
  }

  html {
    color-scheme: light dark;
  }

  [data-theme='light'] {
    color-scheme: light only;
  }

  [data-theme='dark'] {
    color-scheme: dark only;
  }

  :where(.fluid) {
    --fluid-min: calc(
      var(--font-size-min) * pow(var(--font-ratio-min), var(--font-level, 0))
    );
    --fluid-max: calc(
      var(--font-size-max) * pow(var(--font-ratio-max), var(--font-level, 0))
    );
    --fluid-preferred: calc(
      (var(--fluid-max) - var(--fluid-min)) /
        (var(--font-width-max) - var(--font-width-min))
    );
    --fluid-type: clamp(
      (var(--fluid-min) / 16) * 1rem,
      ((var(--fluid-min) / 16) * 1rem) -
        (((var(--fluid-preferred) * var(--font-width-min)) / 16) * 1rem) +
        (var(--fluid-preferred) * var(--variable-unit, 100vi)),
      (var(--fluid-max) / 16) * 1rem
    );
    font-size: var(--fluid-type);
  }

  *,
  *:after,
  *:before {
    box-sizing: border-box;
  }

  body {
    background: light-dark(white, black);
    display: grid;
    place-items: center;
    min-height: 100vh;
    font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
      Helvetica, Arial, sans-serif, system-ui;
  }

  body::before {
    --size: 45px;
    --line: color-mix(in lch, canvasText, transparent 70%);
    content: '';
    height: 100vh;
    width: 100vw;
    position: fixed;
    background: linear-gradient(
          90deg,
          var(--line) 1px,
          transparent 1px var(--size)
        )
        50% 50% / var(--size) var(--size),
      linear-gradient(var(--line) 1px, transparent 1px var(--size)) 50% 50% /
        var(--size) var(--size);
    -webkit-mask: linear-gradient(-20deg, transparent 50%, white);
            mask: linear-gradient(-20deg, transparent 50%, white);
    top: 0;
    transform-style: flat;
    pointer-events: none;
    z-index: -1;
  }

  .bear-link {
    color: canvasText;
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 48px;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    opacity: 0.8;
  }

  :where(.x-link, .bear-link):is(:hover, :focus-visible) {
    opacity: 1;
  }

  .bear-link svg {
    width: 75%;
  }

  /* Utilities */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }
}

/* Responsividade Mobile */
@media (max-width: 768px) {
  main {
    padding: 1rem 2rem;
    gap: 0.5rem;
    max-width: 90vw;
    margin: 0 auto;
  }
  
  main p {
    --font-level: 2;
    text-align: center;
    line-height: 1.1;
  }
  
  .char {
    height: 0.8lh;
  }
  
  .char::before,
  .char::after {
    height: 0.8lh;
  }
}

@media (max-width: 480px) {
  main {
    padding: 1rem 1.5rem;
    max-width: 95vw;
  }
  
  main p {
    --font-level: 1;
  }
  
  .char {
    height: 0.7lh;
  }
  
  .char::before,
  .char::after {
    height: 0.7lh;
  }
}