@layer component {
  theme-select {
    --icon-size: 12px;
    --color-overlay: var(--color-drawer-overlay);
    --overlay-opacity: 0.3;

    position: relative;
    display: inline-block;
    cursor: pointer;
    user-select: none;
    color: rgb(var(--color-text));
  }

  theme-select::before {
    content: '';
    display: block;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100svh;
    opacity: 0;
    pointer-events: none;
    background-color: rgb(var(--color-overlay) / var(--overlay-opacity));
    transition: opacity 1s cubic-bezier(.19, 1, .22, 1);
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' width='20' height='20'%3E%3Cg fill='%23ffffff' transform='translate(0.5%2C0.5)'%3E%3Cline stroke='%23ffffff' stroke-width='6' stroke-linecap='round' x1='46' y1='2' x2='2' y2='46'/%3E%3Cline stroke='%23ffffff' stroke-width='6' stroke-linecap='round' x1='46' y1='46' x2='2' y2='2'/%3E%3C/g%3E%3C/svg%3E") 10 10, pointer;
  }

  theme-select[open]::before {
    opacity: 1;
    pointer-events: auto;
  }

  theme-select>select {
    width: 100%;
    height: calc(0.5em * 2 + 1.625em);
    padding: 0.5em calc(2em + var(--icon-size)) 0.5em 0.75em;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-style: inherit;
    color: inherit;
    appearance: none;
    background: none;
    border: none;
    outline: none;
  }

  theme-select .theme-select__arrow {
    position: absolute;
    inset-inline-end: 1em;
    inset-block-start: 50%;
    margin-block-start: -8px;
    z-index: var(--z-index-hover);
    width: var(--icon-size);
    color: inherit;
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
    transition: transform 0.2s;
  }

  theme-select .theme-select__main {
    position: absolute;
    inset-inline-start: 0;
    z-index: var(--z-index-dropdown);
    display: none;
    width: max-content;
    min-width: 100%;
    cursor: default;
  }

  @media (max-width: 959px) {
    theme-select .theme-select__main {
      content: '';
      position: fixed;
      inset-block: auto 0;
      inset-inline-start: 0;
      z-index: var(--z-index-popover);
      width: 100%;
      height: 100%;
      font-size: 1em;
    }
  }

  theme-select .theme-select__content {
    min-width: 100px;
    padding-block: 28px;
    padding-inline: 24px;
    overflow: hidden;
    background-color: rgb(var(--color-background));
    animation-duration: 0.2s;
    animation-timing-function: ease;
  }

  @media (max-width: 959px) {
    theme-select .theme-select__content {
      --select-animation-name: animation-slide-in-bottom;

      position: absolute;
      inset-block-end: 0;
      inset-inline-start: 0;
      width: 100%;
      height: fit-content;
      min-height: 120px;
      padding-block: 24px;
      padding-inline: 20px;
      border: none;
      border-radius: 0;
      border-start-end-radius: 16px;
      border-start-start-radius: 16px;
    }
  }

  @media (min-width: 960px) {

    theme-select .theme-select__main,
    theme-select .theme-select__main[data-position="bottom"] {
      inset-block: calc(100% + 10px) auto;
    }

    theme-select .theme-select__main[data-position="top"] {
      inset-block: auto calc(100% + 10px);
    }
  }

  theme-select .theme-select__list {
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scroll-snap-type: y mandatory;
    scrollbar-width: thin;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
    max-height: 60vh;
  }

  theme-select .theme-select__option {
    position: relative;
    display: block;
    cursor: pointer;
    background-color: transparent;
    background-image: linear-gradient(to top, rgb(var(--color-text)) 0px), linear-gradient(to top, transparent 0px);
    background-position-x: var(--transform-origin-end);
    background-position-y: bottom;
    background-repeat: no-repeat, no-repeat;
    background-size: 0 1px, 100% 1px;
  }

  @media (pointer: fine) {
    theme-select .theme-select__option {
      transition: background-size 0.3s ease;
    }

    theme-select .theme-select__option:hover {
      background-position-x: var(--transform-origin-start);
      background-size: 100% 1px, 100% 1px;
    }
  }

  theme-select .theme-select__option[selected] {
    display: none;
  }

  theme-select .theme-select__option[disabled] {
    cursor: not-allowed;
    background: none;
    opacity: 0.3;
  }

  theme-select[open] .theme-select__arrow {
    transform: scaleY(-1);
  }

  theme-select[open] .theme-select__main {
    display: block;
  }

  theme-select:has(.theme-select__list > :only-child) .theme-select__main {
    display: none;
  }

  theme-select:has(.theme-select__list > :only-child) .theme-select__arrow {
    transform: none;
  }
}