"""
env_loader.py — Resolve project root at runtime
"""
import os
from pathlib import Path


def _find_env_file() -> Path:
    """Walk up from this file to find .env in project root."""
    d = Path(__file__).resolve().parent.parent
    env = d / ".env"
    if env.exists():
        return env
    return None


def _load_dotenv(path: Path):
    """Minimal .env loader — no external dependency."""
    if path is None or not path.exists():
        return
    with open(path) as f:
        for line in f:
            line = line.strip()
            if not line or line.startswith("#") or "=" not in line:
                continue
            key, val = line.split("=", 1)
            os.environ.setdefault(key.strip(), val.strip())


_load_dotenv(_find_env_file())

PROJECT_BASE = os.environ.get("PROJECT_BASE", "/home/unitree")
PROJECT_NAME = os.environ.get("PROJECT_NAME", "Marcus")
PROJECT_ROOT = Path(__file__).resolve().parent.parent  # always the Marcus/ dir
