```python
def fill_template(template: str, values: dict) -> str:
    """
    Replace placeholders in a template with corresponding values from a dictionary.

    :param template: A string containing literal text and placeholders.
        Each placeholder is "{{name}}" where 'name' is a valid identifier.
    :param values: A dictionary mapping placeholder names to their replacement values.
    :return: The filled-in string with placeholders replaced by their values.
    """
    if not isinstance(template, str):
        raise ValueError("Template must be a string.")
    
    def replace_placeholder(match):
        name = match.group(1)
        if not (name and name.isalnum() or '_' in name):
            raise ValueError(f"Invalid placeholder: '{name}'")
        return values.get(name, f"{{{name}}}")

    import re
    compiled_template = re.compile(r'{{(?P<name>\w+)}}')
    result = compiled_template.sub(replace_placeholder, template)
    
    if '{{' in result:
        raise ValueError("Unterminated placeholder.")
    
    return result
```