from __future__ import annotations

import numpy as np


def crank(data0, data1, mode: str = "distance"):
    """Compute a simple crank-style reaction coordinate."""
    x = np.asarray(data0, dtype=np.float64)
    y = np.asarray(data1, dtype=np.float64)
    if x.shape != y.shape:
        raise ValueError("crank requires data0 and data1 with the same shape")
    mode = mode.lower().strip()
    if mode == "distance":
        return y - x
    if mode == "angle":
        delta = y - x
        return (delta + 180.0) % 360.0 - 180.0
    raise ValueError("crank mode must be 'distance' or 'angle'")
