Regarding the two variables:
$term is a variable from the environment. When you are on the terminal (without opening Vim), echo $term should echo the same as :echo $term from inside Vim. (I'm a little bit surprised that it is not upper case, like $TERM.)
&term represents the option term (see :h 'term'). So the output from :echo &term is the same as ...
In modern vim/neovim there is :h g:terminal_ansi_colors (vim) or 16 of g:terminal_color_0 .. g:terminal_color_15 (neovim).
If you open gruvbox colorscheme you use, you will find those definitions there (most probably).
your whatever terminal can have palette of base 16 colors defined (there are defaults for each type of terminal, but you can ...
In GVim, you can control the 16 ANSI colors used by your terminal with the g:terminal_ansi_colors variable.
See :help g:terminal_ansi_colors:
In GUI mode or with 'termguicolors', the 16 ANSI colors used by default in new
terminal windows may be configured using the variable g:terminal_ansi_colors, which should be a list of 16 color names or