Intersection of the general linear group $\text{GL}_n(\mathbb{F}_q)$ and an affine subspace over a finite field Let $\mathbb{F}_q$ be a finite field of $q$ elements, let $\text{M}_n(\mathbb{F}_q)$ be the vector space of $n \times n$ matrices over $\mathbb{F}_q$, let $\text{GL}_n(\mathbb{F}_q)$ be the group of $n \times n$ invertible matrices over $\mathbb{F}_q$, and let $A$ be an affine subspace of $\text{M}_n(\mathbb{F}_q)$ of fixed dimension $d$.
I'm looking for upper bounds for the cardinality of the intersection $A \cap \text{GL}_n(\mathbb{F}_q)$.
In particular, I'm interested in the worst case (i.e., in the quantity $\max_A |A \cap \text{GL}_n(\mathbb{F}_q)|$) and in the average case (i.e., in the expected value $\text{E}(|A \cap \text{GL}_n(\mathbb{F}_q)|)$ with $A$ taken at random with uniform distribution).
This seems quite a natural problem, but I haven't found much about it, probably because I've looked in the wrong places.
What I found is that if $q \geq 3$ and $A \subseteq \text{GL}_n(\mathbb{F}_q)$ then $d \leq n(n-1)/2$ [1], and consequently $|A \cap \text{GL}_n(\mathbb{F}_q)| = |A| \leq q^{n(n-1)/2}$.
Thanks for help
[1] Clément de Deguins Pazzis, Large affine spaces of non-singular matrices, Transactions of the American Mathematical Society, Vol. 365, No. 5 (MAY 2013), pp. 2569-2596
 A: $\def\FF{\mathbb{F}}\def\GL{\text{GL}}\def\Mat{\text{Mat}}$The average case is straightforward, using linearity of expectation. Let $d = \dim A$. Fix an invertible matrix $g$. If $A$ is chosen uniformly at random, then the probability that $g \in A$ is $q^d/q^{n^2}$. There are $\prod_{j=0}^{n-1} (q^n-q^j)$ total matrices in $\text{GL}_n(\mathbb{F}_q)$, so the expected size of $A \cap \text{GL}_n(\mathbb{F}_q)$ is
$$\frac{q^d}{q^{n^2}} \prod_{j=0}^{n-1} (q^n-q^j) = q^d \prod_{k=1}^n (1-q^{-k}).$$
The question of the maximum size seems very natural and much harder. As you almost but not quite say in your question, if $d \leq \binom{n}{2}$, then we can get all of $A$ into $\text{GL}_n(\mathbb{F}_q)$ by taking $A$ to be the matrices of the form
$$\begin{bmatrix} 
1&\ast&\ast&\cdots&\ast \\ 
0&1&\ast&\cdots&\ast \\
0&0&1&\cdots&\ast \\
\vdots&\vdots&\vdots&\ddots&\vdots \\
0&0&0&\cdots& 1 \\
\end{bmatrix}. $$
Beyond this, I don't know. For $d=n=2$, the optimum is $q^2-1$, achieved by $$\begin{bmatrix} x&y \\ Dy&x \end{bmatrix}$$ where $D$ is a quadratic nonresidue.

I've been thinking about the maximum problem. I can't prove anything, but I am going to record the best constructions I've found. I am pretty confident these can't be improved by small tweaks. Whether an entirely different approach could do better, I am not sure.
As I understand it, the problem is "given $d$ and $n$, find the affine $d$-dimensional subspace $A$ of $\Mat_{n \times n}(\mathbb{F}_q)$ for which $\#(A \cap \GL(\FF_q))$ is as large as possible".
Define $p(A)$ to be $\tfrac{\#(A \cap \GL(\FF_q))}{\#(A)}$; we want to maximize $p(A)$, since $\#(A)$ is just $q^d$. It is also convenient to define $e := d - \binom{n}{2}$. So, if $e \leq 0$, then we can achieve $p(A)=1$ as noted above and, if $e>0$, then we cannot, as shown in the paper of de Seguins Pazzis referenced by the OP.
There are two basic constructions that allow us to change values of $e$ and $n$, while preserving $p(A)$:
Random Slicing If $A$ is an affine linear space in $\Mat_{n \times n}(\FF_q)$, and $A'$ is an affine linear subspace of $A$ chosen uniformly at random, then the expected value of $p(A')$ is $p(A)$. So, if we have a construction for $(e,n)$, we can always achieve the same value for all $(e', n)$ with $e' \leq e$.
Padding Let $A$ be an affine linear space in $\Mat_{n \times n}(\FF_q)$ and let $\hat{A}$ be the linear space
$$\begin{bmatrix} 1&\ast \\ 0 & A \end{bmatrix}$$
in $\Mat_{(n+1) \times (n+1)}(\FF_q)$. Then $p(\hat{A}) = p(A)$, and $\dim \hat{A} = \dim A+n-1$, meaning that $\hat{A}$ has the same $e$ value and a larger $n$ value. So, if we have a construction for $(e,n)$, we can always achieve the same value for all $(e, n')$ with $n' \geq n$.
I will now describe three families of constructions.
Construction 1 (for $e \leq n/2$): Fix a quadratic nonresidue $D$. Take $(2e) \times (2e)$ block matrices, made up of $2 \times 2$ blocks, where the blocks above the diagonal are arbitrary, the blocks below the diagonal are $0$, and the diagonal blocks are each of the form $\begin{bmatrix} x&y \\ Dy&x \end{bmatrix}$. We can then pad this, and we get a solution with
$$p(A) = (1-q^{-2})^e.$$
Construction 2 (for $e \leq n$): Take $e \times e$ symmetric matrices, and pad them. This achieves
$$p(A) = \prod_{2j+1 \leq e} (1-p^{-(2j+1)}).$$
Construction 3: Choose the minimal $k$ with $\binom{k+1}{2} \geq e$. Then the space of all $k \times k$ matrices achieves
$$p(A) =  \prod_{j \leq k} (1-p^{-j}).$$
Slicing and padding this, we can get the same value of $p(A)$ for $(e,n)$.
In the ranges where multiple constructions apply, which one is better depends on the value of $q$. For fixed $(e,n)$, as $q \to \infty$, the lower numbered constructions eventually beat the higher numbered ones.
I welcome news of any systematic way to improve these bounds!
