export function elapsedSeconds(turn, now = Date.now()) {
  if (!Number.isFinite(turn?.startedAt)) return 0;
  const end = Number.isFinite(turn.completedAt) ? turn.completedAt : now;
  return Math.max(0, Math.floor((end - turn.startedAt) / 1000));
}

export function formatElapsed(seconds) {
  const safeSeconds = Math.max(0, Math.floor(seconds));
  if (safeSeconds < 60) return `${safeSeconds}s`;
  return `${Math.floor(safeSeconds / 60)}m ${safeSeconds % 60}s`;
}
