Hermione always liked to go through their exam papers afterward, but Ron said this made him feel ill, so they wandered down to the lake and flopped under a tree. The Weasley twins and Lee Jordan were tickling the tentacles of a giant squid, which was basking in the warm shallows. (Harry Potter and the Sorcerer's Stone)
Though the head of noun phrase before 'which' is tentacles, 'which' seems to refer to squid, because of the singular verb ‘was’. Can 'which' refer to the closest noun before it, not the head?