While you can reference global CSS variables within a styled-component, you can't reference sass variables nor global CSS variables containing strings. Instead, you'll want to leverage the ThemeProvider with theme variables.
Demo
Within the Codesandbox editor, adjust the middle scrollbar by moving it left and right to see changes in the Button
.

The reason this works is because theme.mobile
is interpolated to "(min-width: 320px) and (max-width:479px)"
when the styles are created:
@media (min-width: 320px) and (max-width:479px) { ... }
Whereas, var(--example)
is just interpolated to the string "var(--example)"
, which is invalid CSS syntax:
@media var(--mobile) { ... }
On that note, this may or may be considered anti-pattern since you're reliant upon global CSS variables within a global CSS stylesheet. You can completely avoid using CSS by just using theme variables.
Code
App.js
import { ThemeProvider, css } from "styled-components";
import Button from "./Button";
import "./styles.css";
const theme = {
mobile: "(min-width: 320px) and (max-width:479px)"
};
export default function App() {
return (
<div className="app">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<Button>No Theme</Button>
<br />
<ThemeProvider theme={theme}>
<Button>With Theme</Button>
</ThemeProvider>
</div>
);
}
Button.js
import styled from "styled-components";
const Button = styled.button`
cursor: pointer;
color: var(--white);
background: var(--blue);
outline: 0;
border: 0;
margin: 10px 0;
border-radius: 3px;
padding: 20px;
:hover {
background: var(--darkblue);
}
${({ theme }) =>
`@media ${theme.mobile} {
${css`
background: var(--pink);
:hover {
background: var(--darkpink);
}
`}
}`}
`;
export default Button;
styles.css
.app {
font-family: sans-serif;
text-align: center;
}
body {
margin: 0;
padding: 0;
}
:root {
--blue: #1e87f0;
--darkblue: #0f7ae5;
--white: #ffffff;
--pink: #ff93ac;
--darkpink: #ff6289;
}