@layer reset, tokens, base, layout, components, utilities, overrides;

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

  body {
    margin: 0;
  }
}

@layer tokens {
  :root {
    color-scheme: dark;
    --color-page: oklch(19% 0.025 300);
    --color-cream: oklch(95% 0.035 90);
    --color-rod: oklch(92% 0.03 90 / 0.8);
    --color-sage: oklch(72% 0.06 160);
    --color-blush: oklch(84% 0.07 30);
    --color-mustard: oklch(82% 0.15 85);
    --color-tangerine: oklch(70% 0.18 50);
    --color-cherry: oklch(56% 0.2 27);
    --color-forest: oklch(40% 0.07 170);
    --color-teal: oklch(55% 0.09 205);
    --color-speck: oklch(92% 0.04 90 / 0.75);
    --color-mask: oklch(0% 0 0);

    --duration-sway: 7s;
    --duration-spin: 16s;

    --scene-grid: 600;
    --scene-size: min(100dvi - 2rem, (100dvb - 2rem) * 600 / 1000, 36rem);
  }
}

@layer base {
  body {
    min-block-size: 100dvh;
    display: grid;
    place-items: center;
    background: var(--color-page);
  }
}

@layer components {
  .scene {
    --u: calc(100cqi / var(--scene-grid));
    --slip: calc(7 * var(--u)) calc(6 * var(--u)) 0;

    position: relative;
    container-type: inline-size;
    inline-size: var(--scene-size);
    aspect-ratio: 600 / 1000;
    forced-color-adjust: none;

    @media (hover: hover) {
      &:hover,
      &:hover * {
        animation-play-state: paused;
      }
    }
  }

  .totem {
    position: absolute;
    inset: 0;
    transform-origin: 50% 2.4%;
    animation: sway var(--duration-sway) ease-in-out infinite alternate;

    & > * {
      position: absolute;
      inset-inline-start: calc(var(--x) * var(--u));
      inset-block-start: calc(var(--y) * var(--u));
      inline-size: calc(var(--w) * var(--u));
      block-size: calc(var(--h) * var(--u));
    }
  }

  .hook,
  .tail {
    --w: 26;
    --h: 26;

    border: calc(3 * var(--u)) solid var(--color-cream);
    border-radius: 50%;
  }

  .hook {
    --x: 287;
    --y: 10;
  }

  .tail {
    --x: 289;
    --y: 974;
    --w: 22;
    --h: 22;
  }

  .rod {
    --x: 299;
    --y: 36;
    --w: 2.5;
    --h: 938;

    background: var(--color-rod);
  }

  .ball {
    --x: 278;
    --y: 50;
    --w: 44;
    --h: 44;

    border-radius: 50%;
    background: var(--color-sage);
    box-shadow: var(--slip) var(--color-blush);
  }

  .print {
    filter: drop-shadow(var(--slip) var(--shadow));

    & > div {
      position: absolute;
      inset: 0;
      background: var(--fill);
      clip-path: var(--shape);
    }

    &[data-shape="star"] {
      --x: 228;
      --y: 104;
      --w: 144;
      --h: 144;
      --fill: var(--color-mustard);
      --shadow: var(--color-tangerine);
      --shape: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
    }
  }

  .boomerang {
    --x: 196;
    --y: 262;
    --w: 208;
    --h: 32;

    filter: drop-shadow(var(--slip) var(--color-blush));

    &::before,
    &::after {
      content: "";
      position: absolute;
      inset-block: 0;
      inline-size: 54%;
      border-radius: calc(16 * var(--u));
      background: var(--color-tangerine);
    }

    &::before {
      inset-inline-start: 0;
      transform-origin: 92% 50%;
      rotate: 16deg;
    }

    &::after {
      inset-inline-end: 0;
      transform-origin: 8% 50%;
      rotate: -16deg;
    }
  }

  .atom {
    --x: 246;
    --y: 300;
    --w: 108;
    --h: 108;
  }

  .orbits {
    position: absolute;
    inset: 0;
    animation: spin var(--duration-spin) linear infinite;
  }

  .ring {
    position: absolute;
    inset-inline: 0;
    inset-block: 35%;
    border: calc(2.5 * var(--u)) solid var(--color-cream);
    border-radius: 50%;

    &::after {
      content: "";
      position: absolute;
      inset-inline-end: calc(-6 * var(--u));
      inset-block-start: calc(50% - 5 * var(--u));
      inline-size: calc(10 * var(--u));
      block-size: calc(10 * var(--u));
      border-radius: 50%;
      background: var(--color-blush);
    }

    &[data-n="2"] {
      rotate: 60deg;
    }

    &[data-n="3"] {
      rotate: 120deg;
    }
  }

  .nucleus {
    position: absolute;
    inset: 42%;
    border-radius: 50%;
    background: var(--color-mustard);
  }

  .bowl {
    --x: 204;
    --y: 420;
    --w: 192;
    --h: 96;

    border-radius: 0 0 calc(96 * var(--u)) calc(96 * var(--u));
    background: var(--color-sage);
    box-shadow: var(--slip) var(--color-forest);
  }

  .speckles {
    background: radial-gradient(circle calc(2.2 * var(--u)), var(--color-speck) 90%, transparent) 0 0 / calc(9 * var(--u)) calc(8 * var(--u));
    mask: radial-gradient(closest-side, var(--color-mask) 60%, transparent 100%);

    &[data-n="1"] {
      --x: 140;
      --y: 470;
      --w: 90;
      --h: 70;
    }

    &[data-n="2"] {
      --x: 352;
      --y: 908;
      --w: 80;
      --h: 56;
    }
  }

  .speed {
    --x: 410;
    --y: 432;
    --w: 84;
    --h: 34;

    border-radius: calc(4 * var(--u));
    background: repeating-linear-gradient(var(--color-teal) 0 calc(5 * var(--u)), transparent 0 calc(14.5 * var(--u)));
  }

  .hourglass {
    --w: 124;
    --h: 120;

    &[data-n="top"] {
      --x: 238;
      --y: 540;

      background: var(--color-teal);
      clip-path: polygon(0 0, 100% 0, 50% 50%);
    }

    &[data-n="bottom"] {
      --x: 246;
      --y: 540;

      background: var(--color-tangerine);
      clip-path: polygon(50% 50%, 100% 100%, 0 100%);
    }
  }

  .sputnik {
    --x: 232;
    --y: 676;
    --w: 136;
    --h: 136;
    --tip: calc(6 * var(--u));

    background:
      radial-gradient(circle calc(8 * var(--u)) at 50% 50%, var(--color-blush) 92%, transparent),
      radial-gradient(circle var(--tip) at 50% 8%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 79.7% 20.3%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 92% 50%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 79.7% 79.7%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 50% 92%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 20.3% 79.7%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 8% 50%, var(--color-mustard) 90%, transparent),
      radial-gradient(circle var(--tip) at 20.3% 20.3%, var(--color-mustard) 90%, transparent);

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: 50%;
      background: repeating-conic-gradient(from -0.9deg, var(--color-cream) 0 1.8deg, transparent 0 45deg);
      mask: radial-gradient(closest-side, transparent 12%, var(--color-mask) 0 84%, transparent 0);
      z-index: -1;
    }
  }

  .dome {
    --x: 208;
    --y: 812;
    --w: 184;
    --h: 92;

    border-radius: calc(92 * var(--u)) calc(92 * var(--u)) 0 0;
    background: var(--color-forest);
    box-shadow: var(--slip) var(--color-mustard);
  }

  .bean {
    --x: 240;
    --y: 920;
    --w: 120;
    --h: 46;

    border-radius: 60% 40% 55% 45% / 55% 60% 40% 45%;
    background: var(--color-tangerine);
    box-shadow: var(--slip) var(--color-cherry);
  }

  @keyframes sway {
    from {
      rotate: -1.6deg;
    }

    to {
      rotate: 1.6deg;
    }
  }

  @keyframes spin {
    to {
      rotate: 1turn;
    }
  }
}

@layer overrides {
  @media (prefers-reduced-motion: reduce) {
    .scene * {
      animation: none;
    }
  }
}
