@view-transition {
  navigation: auto;
}

html, body {
  overscroll-behavior: none;
}

body {
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  min-height: 100svh;

  &.slow {
    .circle {
      transition-duration: 550ms;
      transition-timing-function: ease-out;
    }

    .content {
      .title {
        transition-duration: 550ms;
      }
    }
  }

  &.leaving {
    .circle {

      &:nth-child(1) {
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        border-radius: 0;  
      }

      &:nth-child(2) {
        top: -400px;
        left: -200px;
      }

      &:nth-child(3) {
        width: 500px;
        height: 500px;
        top: calc(100vh + 500px);
        left: -500px;
        background: #BCD28880;  
      }

      &:nth-child(4) {
        top: calc(100vh + 500px);
        left: calc(100vw + 500px);
      }

      &:nth-child(5) {
        top: calc(100vh - 300px);
        left: -600px;
      }

      &:nth-child(6) {
        top: calc(100vh + 400px);
        left: 75vw;
      }
  
      &:nth-child(7) {
        top: calc(100vh + 500px);
      }
  
      &:nth-child(8) {
        top: calc(100vh + 300px);
      }
    }

    .content {
      .title {
        opacity: 0;
      }
    }
  }
}

.background {
  position: fixed;
  z-index: 0;
  top: 0;
  left: 0;
  inset: 0;
  background: #F5FCE5;

  .circle {
    position: absolute;
    border-radius: 9999px;
    transition-property: top, left, width, height, border-radius, translate;
    transition-duration: 400ms;
    transition-timing-function: ease-in;

    &:nth-child(1) {
      width: 500px;
      height: 500px;
      top: 0vh;
      left: calc(55vw - 250px);
      background: #FBECFF;  
    }

    &:nth-child(2) {
      width: 400px;
      height: 400px;
      top: -200px;
      left: 0px;
      background: #91AE4F80;  
    }

    &:nth-child(3) {
      width: 500px;
      height: 500px;
      top: calc(100vh - 400px);
      left: calc(0vw - 100px);
      background: #BCD28880;  
    }

    &:nth-child(4) {
      width: 500px;
      height: 500px;
      top: calc(100vh - 350px);
      left: calc(100vw - 500px);
      background: #FFD0EB80;
    }

    &:nth-child(5) {
      width: 600px;
      height: 600px;
      top: 10vh;
      left: calc(40vw - 300px);
      background: #C565E0;  
    }

    &:nth-child(6) {
      width: 400px;
      height: 400px;
      top: calc(50vh - 175px);
      left: calc(45vw + 200px);
      background: #91AE4F80;  
    }

    &:nth-child(7) {
      width: 500px;
      height: 500px;
      top: 40vh;
      left: calc(50vw - 250px);
      background: #753F83;  
    }

    &:nth-child(8) {
      width: 300px;
      height: 300px;
      top: 65vh;
      left: calc(45vw + 150px);
      background: #FFD0EB80;  
    }


    @media (max-width: 600px) {
      &:nth-child(2) {
        left: -200px;
      }

      &:nth-child(3) {
        top: calc(100vh - 200px);
        left: calc(0 - 300px);
      }

      &:nth-child(4) {
        top: calc(100vh - 200px);
        left: calc(100vw - 200px);
      }

      &:nth-child(5) {
        width: 400px;
        height: 400px;
        top: calc(50vh - 220px);
        left: calc(50vw - 150px);
      }

      &:nth-child(7) {
        width: 300px;
        height: 300px;
        top: calc(70vh - 150px);
        left: calc(100vw - 200px);
      }
    }
  }
}

.overlay {
  view-transition-name: overlay;
  position: fixed;
  z-index: 0;

  width: 100%;
  height: 100%;
  backdrop-filter: blur(100px);
}

.link {
  position: fixed;
  z-index: 2;
  color: #814C8C;
  font-family: 'Fragment Mono', sans-serif;
  font-size: 15px;
  line-height: 1.4;
  text-transform: uppercase;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;

  &.active::before {
    left: -20px;
    top: -13px;
    border: 5px solid #C8CEAE66;
    box-shadow: 0 0 0 5px #C8CEAE66;
    opacity: 1;
  }

  &::before {
    content: '';
    position: absolute;
    left: -15px;
    top: -8px;
    width: calc(100% + 30px);
    height: calc(100% + 16px);
    background: #F3DDF3;
    border-radius: 9999px;
    opacity: 0;
    z-index: -1;
    transition: opacity 200ms ease;
  }

  &::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 2px;
    width: 100%;
    height: 1.5px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 200ms ease;
  }

  &:not(.disabled) {
    &:hover::after,
    &:focus-visible::after {
      transform: scaleX(1);
    }
  }

  &.top-left {
    top: 54px;
    left: 54px;
    view-transition-name: top-left;
  }

  &.top-right {
    top: 54px;
    right: 54px;
    view-transition-name: top-right;
  }

  &.bottom-left {
    bottom: 54px;
    left: 54px;
    view-transition-name: bottom-left; 
  }

  &.bottom-right {
    bottom: 54px;
    right: 54px;
    view-transition-name: bottom-right; 
  }

  @media (max-width: 630px) {
    &.top-left {
      left: 30px;
      top: 40px;
    }

    &.top-right {
      right: 30px;
      top: 40px;
    }

    &.bottom-left {
      left: 30px;
      bottom: 40px;
    }

    &.bottom-right {
      right: 30px;
      bottom: 40px;
    }
  }
}

.content {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  max-width: 570px;
  font-family: 'Baskervville', serif;
  line-height: 1.4;
  color: #814C8C;
  padding: 151px 30px;

  .title {
    color: #E3DBF2;
    text-shadow: 0px 2px 8px #00000026;

    font-weight: 500;
    font-size: 48px;
    text-align: center;
    opacity: 1;
    transition: opacity 300ms ease-in;
  }

  .body {
    view-transition-name: body;

    font-weight: 400;
    font-size: 22px;
  }
}

/* Bubble animation */

@property --a {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0turn;
}

@keyframes float {
  to { --a: 1turn; }
}

body:not(.leaving) .background .circle {
  animation: float var(--t) linear infinite;
  translate:
    calc(var(--range, 1) * (var(--ax) * sin(var(--a) + var(--p1) * 1turn) + var(--bx) * sin(2 * var(--a) + var(--p2) * 1turn)))
    calc(var(--range, 1) * (var(--ay) * sin(var(--a) + var(--p3) * 1turn) + var(--by) * sin(3 * var(--a) + var(--p4) * 1turn)));

  &:nth-child(1) { --t: 23.1s; --ax: 56px; --ay: 67px; --bx: 28px; --by: 21px; --p1: 0.69; --p2: 0.52; --p3: 0.84; --p4: 0.23; }
  &:nth-child(2) { --t: 22.0s; --ax: 78px; --ay: 67px; --bx: 23px; --by: 18px; --p1: 0.69; --p2: 0.96; --p3: 0.96; --p4: 0.23; }
  &:nth-child(3) { --t: 30.3s; --ax: 67px; --ay: 78px; --bx: 30px; --by: 28px; --p1: 0.71; --p2: 0.80; --p3: 1.00; --p4: 0.49; }
  &:nth-child(4) { --t: 24.3s; --ax: 87px; --ay: 47px; --bx: 28px; --by: 16px; --p1: 0.21; --p2: 0.03; --p3: 0.46; --p4: 0.74; }
  &:nth-child(5) { --t: 34.9s; --ax: 88px; --ay: 77px; --bx: 15px; --by: 19px; --p1: 0.04; --p2: 0.51; --p3: 0.36; --p4: 0.19; }
  &:nth-child(6) { --t: 22.0s; --ax: 56px; --ay: 87px; --bx: 25px; --by: 22px; --p1: 0.31; --p2: 0.92; --p3: 0.63; --p4: 0.58; }
  &:nth-child(7) { --t: 23.1s; --ax: 73px; --ay: 46px; --bx: 26px; --by: 15px; --p1: 0.57; --p2: 0.80; --p3: 0.88; --p4: 0.03; }
  &:nth-child(8) { --t: 34.3s; --ax: 58px; --ay: 75px; --bx: 20px; --by: 29px; --p1: 0.34; --p2: 0.89; --p3: 0.52; --p4: 0.15; }
}

@media (max-width: 900px) {
  .background { --range: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  .background .circle { animation: none; }
}
