@layer components {
  /* Header switch that turns on dark mode and the ASCII background animation */
  .theme-toggle {
    --toggle-height: 1.5rem;
    --toggle-width: 2.5rem;
    --toggle-padding: 0.125rem;
    --toggle-thumb-size: calc(var(--toggle-height) - var(--toggle-padding) * 2);
    --toggle-translate: calc(var(--toggle-width) - var(--toggle-thumb-size) - var(--toggle-padding) * 2);
    --toggle-bg: var(--color-ink-lighter);

    background: var(--toggle-bg);
    block-size: var(--toggle-height);
    border-radius: var(--radius-full);
    cursor: pointer;
    display: inline-block;
    inline-size: var(--toggle-width);
    position: relative;
    transition: background 300ms var(--ease-out-expo);

    @media (min-width: 48rem) {
      --toggle-height: 1.75rem;
      --toggle-width: 3.5rem;
    }

    &:has(input:checked) {
      --toggle-bg: var(--color-selected);
    }

    input {
      display: none;
    }
  }

  /* The knob carries the icon: it spins while off and rests in the brand color when on */
  .theme-toggle__thumb {
    align-items: center;
    background: var(--color-canvas);
    block-size: var(--toggle-thumb-size);
    border-radius: var(--radius-full);
    box-shadow: 0 1px 2px oklch(var(--lch-ink-darkest) / 20%);
    color: var(--color-ink-dark);
    display: flex;
    inline-size: var(--toggle-thumb-size);
    inset-block-start: var(--toggle-padding);
    inset-inline-start: var(--toggle-padding);
    justify-content: center;
    position: absolute;
    transition: transform 300ms var(--ease-out-expo);

    .theme-toggle:has(input:checked) & {
      color: var(--color-blue-medium);
      transform: translateX(var(--toggle-translate));
    }

    svg {
      animation: rotate 3s linear infinite;
      block-size: 70%;
      inline-size: 70%;

      .theme-toggle:has(input:checked) & {
        animation: none;
      }

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