/* @import 'normalize.css' layer(normalize); */
@import url('https://unpkg.com/normalize.css') layer(normalize);
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@100..800&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Gloria+Hallelujah&display=swap');

@layer normalize, base, demo, parallax, explode;

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

  :has([data-active='true']) .arrow {
    opacity: 0.8;
  }

  .arrow {
    display: inline-block;
    opacity: 0;
    position: absolute;
    font-size: 0.875rem;
    font-family: 'Gloria Hallelujah', cursive;
    transition: opacity 0.26s ease-out;

    &.arrow--debug {
      top: 50%;
      left: 50%;
      rotate: 10deg;
      translate: calc(-40% + var(--card-width) * -1) 0;
      width: 80px;
      z-index: 99999;

      @media (max-width: 580px) {
        translate: -50% calc(var(--card-width) * 7 / 5 * 0.5);
      }

      span {
        display: inline-block;
        rotate: -24deg;
        translate: 30% 100%;
        @media (max-width: 580px) {
          translate: 80% 160%;
        }
      }
      svg {
        rotate: 10deg;
        scale: 1 -1;
        translate: 120% 20%;
        rotate: -25deg;
        left: 0%;
        width: 80%;

        @media (max-width: 580px) {
          rotate: 190deg;
          top: unset;
          bottom: 100%;
          translate: 0 0;
        }
      }
    }
  }

  .minimap {
    position: fixed;
    width: 60px;
    aspect-ratio: 5/7;
    background: hsl(0 0% 50%);
    top: 50%;
    left: 50%;
    translate: calc(var(--card-width) * 1) -50%;
    border-radius: 6px;
    cursor: pointer;
    border: var(--border-color) 4px solid;
    z-index: 999999;
    transform: translate3d(0, 0, 100vmin);
    pointer-events: none;
    visibility: hidden;

    .minimap__stats {
      position: absolute;
      top: calc(100% + 0.5rem);
      left: 0;
      right: 0;
      display: flex;
      flex-direction: column;
      opacity: 0.7;
      font-family: monospace;

      span {
        white-space: nowrap;
      }
    }

    &::after {
      content: 'trackpad';
      position: absolute;
      top: 50%;
      left: 100%;
      font-family: 'Sora', sans-serif;
      transform: translate(-50%, -50%) rotate(-90deg) translateY(100%);
      font-size: 0.875rem;
      pointer-events: none;
      opacity: 0.35;
    }
  }

  [data-explode='true'] {
    .minimap {
      pointer-events: all;
      visibility: visible;
    }
    .arrow {
      opacity: 0;
    }
    .card {
      pointer-events: none;
      transition: transform 0.2s 0.2s;
      transform: rotateX(-24deg) rotateY(32deg) rotateX(90deg);

      .spotlight,
      .watermark,
      .pattern {
        mix-blend-mode: unset;
      }

      .watermark,
      .pattern,
      .debug,
      .img,
      .spotlight::after,
      .card__frame,
      .spotlight {
        transition-property: transform, opacity;
        transition-duration: 0.2s;
        transition-delay: 0.4s;
        transform: translate3d(0, 0, calc(var(--index) * 80px));
      }

      .card__front .debug {
        --index: -2;
      }

      .card__front .img {
        --index: -3;
      }

      .card__front .pattern {
        --index: -1;
      }

      .card__front .watermark {
        --index: 0;
      }

      .card__front .card__frame {
        --index: 1;
      }

      .card__front .spotlight {
        --index: 2;
      }

      .debug {
        visibility: visible;
      }

      .debug,
      .spotlight::after {
        opacity: 1;
      }
    }
  }
}

@layer parallax {
  :root {
    --pointer-x: 0;
    --pointer-y: 0;
    --parallax-img-x: 5%;
    --parallax-img-y: 5%;
    --rotate-x: 25deg;
    --rotate-y: -20deg;
  }
  .card[data-active='true'] {
    display: block;
    transition: transform 0.2s;
  }

  [data-explode='false'] {
    .card[data-active='true']:hover {
      transition: transform 0s;
      transform: rotateX(calc(var(--pointer-y) * var(--rotate-x)))
        rotateY(calc(var(--pointer-x) * var(--rotate-y)));
      animation: set backwards 0.2s;
    }
  }
  [data-explode='false'] .card[data-active='true']:hover,
  [data-explode='true']:has(.minimap:hover) {
    .card__front img {
      transition: transform 0s;
      translate: calc(var(--pointer-x) * var(--parallax-img-x))
        calc(var(--pointer-y) * var(--parallax-img-y));
      animation: set-img backwards 0.2s;
    }
  }

  [data-animate='false'] .card[data-active='true']:not(:hover) img,
  [data-animate='false'] .card[data-active='true'],
  [data-explode='false'][data-animate='false'] .card[data-active='true']:hover .card__front img,
  [data-explode='false'][data-animate='false'] .card[data-active='true']:hover {
    animation: none;
    transition: none;
  }

  @keyframes set {
    0% {
      transform: rotateX(0deg) rotateY(0deg);
    }
  }

  @keyframes set-img {
    0% {
      translate: 0 0;
    }
  }

  .card:not(:hover) img {
    transition: translate 0.2s;
  }

  :is(.refraction, .spotlight::before) {
    opacity: 0;
    transition: opacity 0.2s ease-out;
  }
  /* .debug is only visible on explode */
  [data-explode='true']:has(.minimap:hover) .refraction,
  [data-explode='true']:has(.minimap:hover) .spotlight::before,
  .card[data-active='true']:hover :not(.debug) .refraction,
  .card[data-active='true']:hover .spotlight::before {
    opacity: 1;
  }
  [data-explode='true']:has(.minimap:hover)
    :is(.debug:not(.debug--clipped) .refraction) {
    opacity: 0.2;
  }
}

@layer demo {
  :root {
    --border-color: hsl(0 0% 25%);
    --card-width: 260px;
  }
  .scene {
    perspective: 1000px;
    position: fixed;
    inset: 0;
    transform: translate3d(0, 0, 100vmin);
  }
  .card {
    --ratio-x: 0;
    --ratio-y: 0;
    --border: 8cqi;
    aspect-ratio: 5 / 7;
    width: var(--card-width);
    container-type: inline-size;
    touch-action: none;
    background: #0000;
    color: hsl(0 0% 10%);
    font-family: 'Sora', sans-serif;
    perspective: 1600px;
    position: fixed;
    top: 50%;
    left: 50%;
    translate: -50% -50%;

    img,
    *::after,
    *::before {
      will-change: translate, scale, filter;
    }

    button {
      position: absolute;
      z-index: 100;
      inset: 0;
      cursor: pointer;
      -webkit-tap-highlight-color: #0000;
      user-select: none;
      opacity: 0;
    }

    *:not(button) {
      pointer-events: none;
    }

    .debug,
    .img,
    .pattern,
    .spotlight,
    .watermark,
    .card__rear,
    .card__content,
    .card__emboss,
    .glare-container,
    .card__front {
      position: absolute;
      inset: 0;
      border-radius: var(--border);
    }

    .debug {
      opacity: 0;
      visibility: hidden;

      &::after {
        content: '';
        position: absolute;
        inset: 0;
        border: 4px dashed canvasText;
        border-radius: var(--border);
      }

      &.debug--clipped {
        clip-path: inset(0 0 0 0 round var(--border));

        .refraction {
          opacity: 1;
        }
      }
      .refraction {
        opacity: 0.2;
      }
    }

    .card__emboss {
      filter: url(#lighting);
    }

    .card__front .img::before {
      content: '';
      position: absolute;
      inset: 0;
      background: hsl(0 0% 50%);
    }

    .card__front,
    .card__rear {
      backface-visibility: hidden;
    }

    .card__front > *:not(.debug:not(.debug--clipped)) {
      clip-path: inset(0 0 0 0 round var(--border));
    }

    .card__rear {
      clip-path: inset(0 0 0 0 round var(--border));
      --border-color: oklch(28.55% 0.09665440679544547 265.51146531290146);
      transform-style: preserve-3d;
      position: absolute;
      inset: 0;
      background: color-mix(in oklch, var(--border-color), #000);
      transform: rotateY(180deg) translate3d(0, 0, 1px);
    }

    .card__rear > img,
    .card__front > .img img {
      width: 100%;
      object-fit: cover;
      height: 100%;
      scale: 1.1;
      position: absolute;
      inset: 0;
    }

    /* this handles the details for the card like the title, sticker, etc. */
    .card__frame {
      position: absolute;
      inset: 0;
      z-index: 2;
      border-radius: var(--border);
      /* clip-path: inset(0 0 0 0 round var(--border)); */

      * {
        will-change: translate, scale, filter;
      }

      h3 {
        margin: 0;
        top: var(--border);
        right: var(--border);
        text-align: right;
        letter-spacing: -0.05em;
        font-weight: 1000;
        line-height: 1;
        z-index: 100;
        position: absolute;

        span {
          filter: url(#sticker);
        }

        span:first-of-type {
          font-size: 10cqi;
        }
        span:last-of-type {
          font-size: 5cqi;
        }
      }

      img {
        width: 100%;
        object-fit: cover;
        height: 100%;
        scale: 1.1;
        position: absolute;
        inset: 0;
        filter: saturate(0.8) contrast(1.2)
          drop-shadow(0 0 10cqi hsl(0 0% 10% / 0.75));
      }

      .signature {
        color: hsl(45 20% 60%);
        position: absolute;
        z-index: 100;
        width: 38cqi;
        bottom: calc(var(--border) * 1.1);
        right: calc(var(--border) * 0.6);
        rotate: 20deg;
      }

      .sticker {
        position: absolute;
        width: calc(var(--border) * 2.75);
        bottom: calc(var(--border) * 0.75);
        left: calc(var(--border) * 0.65);
        z-index: 100;
      }
    }
    &:has([aria-pressed='true']) .card__content {
      rotate: 180deg y;
    }
    .card__content {
      transition: rotate 0.26s ease-out;
      transform-style: preserve-3d;
    }
    .card__emboss {
      position: absolute;
      inset: 0;
      filter: url(#lighting);
      border-radius: var(--border);
      clip-path: inset(0 0 0 0 round var(--border));

      &::before {
        content: 'TechTrades © 2025';
        position: absolute;
        bottom: 0;
        left: 50%;
        height: calc(var(--border) * 0.5);
        display: flex;
        place-items: center;
        translate: -50% 0;
        color: #fff;
        font-size: 1.5cqi;
        opacity: 0.8;
        z-index: 100;
      }
      &::after {
        /* filter: url(#lighting); */
        content: '';
        position: absolute;
        inset: 0;
        border: calc((var(--border) * 0.5)) solid var(--border-color);
        border-radius: var(--border);
        z-index: 99;
      }
    }
    .img img {
      filter: brightness(0.85);
    }
  }

  .pattern,
  .watermark {
    filter: saturate(0.8) contrast(1) brightness(1);
    mask: url(https://assets.codepen.io/605876/figma-texture.png) 50% 50% / 4cqi
      4cqi;
    opacity: 0.4;
    mix-blend-mode: multiply;
  }

  .pattern {
    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background: hsl(0 0% 80%);
    }
  }

  .watermark {
    filter: saturate(0.9) contrast(1.1) brightness(1.2);
    mask: url(https://assets.codepen.io/605876/shopify-pattern.svg) 50% 50% /
      14cqi 14cqi repeat;
    opacity: 1;
    mix-blend-mode: hard-light;

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background: hsl(0 0% 100% / 0.2);
    }
  }

  .refraction {
    position: absolute;
    width: 500%;
    aspect-ratio: 1 / 1;
    bottom: 0;
    left: 0;
    filter: saturate(2);
    will-change: translate, scale, filter;
    background: radial-gradient(
      circle at 0 100%,
      #0000 10%,
      hsl(5 100% 80%),
      hsl(150 100% 60%),
      hsl(220 90% 70%),
      #0000 60%
    );
    transform-origin: 0 100%;
    scale: min(1, 0.15 + var(--pointer-x) * 0.25);
    translate: clamp(-10%, -10% + var(--pointer-x) * 10%, 10%)
      calc(max(0%, (var(--pointer-y) * -1) * 10%));

    &:nth-of-type(2) {
      bottom: unset;
      top: 0;
      left: unset;
      right: 0;
      scale: min(1, 0.15 + var(--pointer-x) * -0.65);
      translate: clamp(-10%, 10% - var(--pointer-x) * -10%, 10%)
        calc(min(0%, var(--pointer-y) * -10%));
      transform-origin: 100% 0;
      background: radial-gradient(
        circle at 100% 0,
        #0000 10%,
        hsl(5 100% 80%),
        hsl(150 100% 60%),
        hsl(220 90% 70%),
        #0000 60%
      );
    }
  }
  .glare {
    position: absolute;
    opacity: 0.5;
    inset: 0;
    background: linear-gradient(
      -65deg,
      #0000 0 40%,
      #fff 40% 50%,
      #0000 30% 50%,
      #0000 50% 55%,
      #fff 55% 60%,
      #0000 60% 100%
    );
  }
  .spotlight {
    mix-blend-mode: overlay;
    z-index: 9999999;
    clip-path: inset(0 0 0 0 round var(--border));

    &::after {
      content: '';
      position: absolute;
      inset: 0;
      opacity: 0;
      border: 4px dashed canvasText;
      border-radius: var(--border);
    }

    &::before {
      content: '';
      position: absolute;
      left: 50%;
      top: 50%;
      width: 500%;
      opacity: 0;
      aspect-ratio: 1;
      background: radial-gradient(
        hsl(0 0% 100% / 0.4) 0 2%,
        hsl(0 0% 10% / 0.2) 20%
      );
      filter: brightness(1.2) contrast(1.2);
      translate: calc(-50% + (var(--pointer-x) * 20%))
        calc(-50% + (var(--pointer-y) * 20%));
      z-index: 99999;
    }
  }

  .wordmark {
    position: absolute;
    width: 70%;
    left: 50%;
    translate: -50% 0;
    top: 12%;
    height: max-content;
    /* filter: saturate(0) contrast(1.2); */

    &::after {
      content: '™';
      position: absolute;
      top: 100%;
      right: 0;
      color: #fff;
    }

    &:last-of-type {
      top: unset;
      bottom: 12%;
      rotate: 180deg;
    }

    img {
      position: static;
      width: 100%;
      height: auto;
    }
  }

  .gemstone {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: auto;
    translate: -50% -50%;
    filter: hue-rotate(320deg);
  }
}

@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(#fff, #000);
    min-height: 100vh;
    overflow: hidden;
    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 hsl, canvasText, transparent 80%);
    content: '';
    height: 100vh;
    width: 100vw;
    position: fixed;
    background: linear-gradient(
          90deg,
          var(--line) 1px,
          transparent 1px var(--size)
        )
        calc(var(--size) * 0.36) 50% / var(--size) var(--size),
      linear-gradient(var(--line) 1px, transparent 1px var(--size)) 0%
        calc(var(--size) * 0.32) / var(--size) var(--size);
    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;
  }
}

div.tp-dfwv {
  width: 280px;
  transform: translate3d(0, 0, 200vmin);
  z-index: 9999999;
}
