.theme-switch {
  position: relative;
  display: inline-flex;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.theme-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.theme-switch__track {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 68px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius, 2px);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  cursor: pointer;
  overflow: hidden;
}

.theme-switch__track::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent, var(--accent-soft), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
}

.theme-switch__track:hover::before {
  transform: translateX(100%);
}

.theme-switch__track:hover {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.theme-switch__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: var(--muted);
  z-index: 1;
}

.theme-switch__icon svg {
  width: 12px;
  height: 12px;
}

.theme-switch__thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius, 2px);
  border: 1px solid var(--line);
  background: var(--text);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--text) 20%, transparent);
  transition: left 0.2s ease;
  z-index: 2;
}

.theme-switch input:checked + .theme-switch__track .theme-switch__thumb {
  left: calc(100% - 28px);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.theme-switch input:not(:checked) + .theme-switch__track .theme-switch__icon--moon {
  color: var(--text);
  opacity: 1;
}

.theme-switch input:checked + .theme-switch__track .theme-switch__icon--sun {
  color: var(--text);
  opacity: 1;
}

.theme-switch input:focus-visible + .theme-switch__track {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (max-width: 768px) {
  .theme-switch__track {
    width: 64px;
    height: 40px;
    padding: 0 8px;
  }

  .theme-switch__thumb {
    width: 24px;
    height: 24px;
    top: 7px;
    left: 7px;
  }

  .theme-switch input:checked + .theme-switch__track .theme-switch__thumb {
    left: calc(100% - 31px);
  }
}

@media (pointer: coarse) {
  .theme-switch__track::before {
    content: none;
  }

  .theme-switch__track:hover {
    border-color: var(--line);
    box-shadow: none;
  }
}