```python
def match_setting(rules: dict[str, str], name: str) -> str | None:
    if not isinstance(name, str) or not name:
        raise ValueError("Name must be a non-empty string.")
    
    exact_match = rules.get(name)
    if exact_match is not None:
        return exact_match
    
    wildcard_matches = []
    for selector, value in rules.items():
        if (selector == "*" and selector != name) or (".*" in selector and selector.endswith(".*") and name.startswith(selector[:-2])):
            wildcard_matches.append((len(selector), value))
    
    if wildcard_matches:
        return max(wildcard_matches)[1]
    
    return None
```